ampledata / kiss

A pure-Python implementation of the KISS Protocol for communicating with serial TNC devices for use with Amateur Radio.
Other
86 stars 36 forks source link

New frame detection and escaping #27

Open jlangvand opened 4 years ago

jlangvand commented 4 years ago

Read method is more conformant to the KISS spec

According to the spec, a frame should not be read as "FEND frame FEND". Upon reception of a FEND we should consider everything read up to this point a frame and clear the read buffer. When writing a frame, we should start by writing a FEND, so any noise on the receiving end gets flushed out.

Drop search-and-replace for escaping

It works, but is error prone. One could easily, by mistake, apply the replace functions several times and thus potentially corrupt the data. Consider the string FESC TFESC. Escaping this would yield FESC TFESC TFESC. Restoring this would of course give us FESC TFESC again, but if we apply the restore function one more time it will remove the second TFESC, and the data is corrupted.

Write arbitrary commands to the TNC

Sone TNCs implements nonstandard commands. By introducing a command argument in the write method, defaulting it to 0x00, we can pass any command while retaining backwards compatibility.