9-19-05 Master code: the packet to be transmitted: [Packet<<4+DCount, ,STR Value\DCount+1, Checksum] (DCount = data count// data count is decremented by 1 before transmitting) packet that is received by slave: [PacketCount,STR Value\PacketCount&%1111+1,RChecksum] >>the shifed packetcount by 4 just leaves the packet number ie. divided by 2 >> a shift left by 4 is multiplying it by 2^4 << a shift right by 4 is dividing it by 2^4 % just a marker that this is binary number GetNext is done by the data in the Value array by the indexes message1, message2, etc. But the data is not sent by message but by either the amount that has been read in at that spot in memory, or by the data value in the array being the value two Message will be sent by two criteria: 1. The data (ascii chars) in the data array that is seen in GetNext function is 2 a. This will happen before data at spot where 2 is checksummed, thus two is never checksummed 2. The data count of the data array that is seen in GetNext loop is 15 a. This will happen only after the data in loop is checksummed Checksum: Checksum is originally initialized to packet number then calculated using: Checksum = Checksum ^ Value(DCount) in getNext loop Next we are sent to MessageDone where DCount is decremented if data in array does not equal 2 and flow goes to transmit whether or not data is 2 The flow of program now goes to transmit. Here it will continue to loop back through transmit if the receiver failed to get the packet. Only when it is received will it go back to the GetNext loop Now it will get the next message and start over again 9-20-05 Slave Code: receive packet appearance: [PacketCount,STR Value\PacketCount&%1111+1,RChecksum] debug packect contents meanings: 1. packet# = packetcount>>4 2. data count = PacketCount&%1111+1 3. checksum = RChecksum 4. data = STR Value\PacketCount&%1111+1 (Value\amount of data in value) Action Packet# Data Count Checksum Data Status Receive-- packetcount>>4-- Packet Count&%1111+1-- RChecksum-- STR Value\PacketCount&%1111+1 OK *TX Ack Checksum(primed and checksummed) OK *TX Nack Checksum(primed and checksummed) but ERROR not equal to the received checksum *TX Ack: Checksum = RChecksum *TX Nack: Checksum != RChecksum figuring out the Slaves Checksum value: Checksum = PacketCount>>4 Checksum is initialized to the packetCount idx = 0 to current Value arrays data count loop through all values in current message with data count calculating: Checksum = Checksum ^ Value(Idx) all the data is used for checksum, chars are seen as ascii code numbers and these used for calc if this Checksum = RChecksum then it is ok and is the next message elseif Checksum != RChecksum then error and try to receive again right away priming the packet number >>4 of a packet that passed Checksum check will be labeled a duplicate and be ignored When duplicate or no received then set PacketCount = 0 so that we know that no data was received PacketCount&%1111+1 the 8 bit value that has been shifted 4 bits to left and had datacount-1 added to right side is bit masked to find the datacount-1 1 is added for correct value helpful math pages: http://atrevida.comprenica.com/atrtut03.html :: bitwise shifting http://en.wikipedia.org/wiki/Binary_numeral_system#Bitwise_logical_operations :: logical ops http://www.vipan.com/htdocs/bitwisehelp.html 9-21-05 message1 data (message1 is just a label referring to where data is located at) If you modify to one line then the packet number will skip one digit after message1 is completed sending