<long harangue snipped as I'm talking to myself>
I should probably clarify a few points, as I've got parts of three
separate protocols intermingled above (the previous post).
Pure HDLC, as I recall, has a header that ONLY contains:
From, To, Op/Status code, (I forget if there is a checksum byte?)
where:
From 1 byte address of source
To 1 byte address of destination
Op/Status (1 or 2 bytes, forget which) encodes:
unconnected information
connection request
ready
ready with information
not ready
not ready with information
disconnect
"ready" means "this" end can receive more packets
"not ready" means "stop sending until you receive a ready"
"with information" means a length byte and <length>data bytes are
attached to the packet.
Connection requests and disconnects open/close virtual circuits
(resetting the last sent/last received status bits).
Unconnected information is sort of a UDP broadcast -- there is no
"connection" and no status returns expected.
Amateur packet radio expanded that header structure to allow for
text call signs (FCC requirement for ID needs ASCII call signs in the
packets) so each address becomes 7 bytes (6-byte call: KD6MOG and 1Byte
"node" -- so KD6MOG-15 is different from KD6MOG-10). AND extended to
allow for digipeater routing -- something like an additional six nodes
can be specified by which to route the packet. Digipeaters just receive
packets and, in the next silence, retransmit them, after flagging their
address in the routing header (so they can identify if they've seen the
packet already, or if some node after them has seen it). The status
codes remain the same.
APRS uses ONLY unconnected protocol. It does not create virtual
connections, but also does not require routing tables -- at the cost of
using special RELAY addresses telling any relay nodes to repeat the
packet. If using this transmit method, as I do in my prior example, and
needing a virtual circuit for error checking, one would have to
implement ACK/NAK/time-out and packet counts as part of the information
data.
I should also mention that HDLC is a BIT-synchronized protocol, with
a "0" insert every 5 (or is it 6) bits to avoid having data look like
the synchronization flag... The transmitter sends a series of x7F before
it sends the data packet. Receives look for the 1 bits, and align on the
x7F... Once the data starts, any 0 bit following (5/6?) 1 bits is
dropped. Collisions (two transmitters starting up at the same time) is
handled by timeouts on lack of a ready/not ready count, with a resend of
the data -- or for unconnected... Just ignored...
So... You do NOT want to code the HDLC protocol in Python (I'm not
even sure if common BASIC Stamps have enough program memory to code the
transmit/receive logic -- possibly the bit alignment send/receive can
fit a BASIC Stamp, with the reconstructed bytes handled by a higher
level processor in Python.
Also note that HDLC is an asynchronous packet protocol... so the
receiver operation has to be running all the time to catch any packet
(and the transmit side needs to know when the air is clear before trying
to send). Sounds like a need for threading, at the least. It will be a
layered system:
Application
Robot Protocol (any protocol you put in Information packet)
HDLC Protocol (connection/status/addressing)
HDLC Radio Control (synch flags, bit stuffing on transmit,
reconstruct on receive, silence before send) [This may be subdivided
into two parts -- Byte level packet handling, with serial communication
to the bit-level radio modem]
-=-=-=-=-=-
HDLC-RC, synchs and reconstructs a byte level packet. This packet
would be passed to HDLC-P (somehow this is getting bytes, and would
likely use Queue to relay the full packet to the Protocol layer).
HDLC-P would pull a packet off the Queue, check the last received
status (if connected) and, if needed, back up to an early send packet
and start sending from that (3 bits, up to 8 packets can be sent before
a confirmation of receipt -- if the last-received count doesn't
increment, the sender has to resend from the appropriate packet; so
HDLC-P needs to use a circular buffer of 8 send packets)[a dumb receiver
would drop any packet that wasn't the immediate next packet expected; a
smart one would hold the packet while sending expected count for the
missing packet -- then insert the missing packet into the buffer before
processing it]. For received information packets, the application data
is extracted and passed (another Queue) to the RP level.
Downward data would be passed from RP to HDLC-P via a Queue, HDLC-P
would take these data packets and append them to status (connected mode)
packets, and pass those (another Queue) to the HDLC-RC.
You DO NOT WANT interrupts occurring in the actual radio control
level, just a fairly tight loop of:
if have_outbound_packet and radio_silent
send synch
send packet with bit stuffing
send end packet marker
if not radio_silent and not synched
look for synch pattern
while synched
collect bits and parse into bytes (remove stuffed 0s)
if full byte
send over serial port
if end_packet_marker
break
collect byte for out going packet (should use RTS/CTS on serial with
timeout)
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/