Pseudocode for DOGTXmitSM.c InitDOGTXmitSM Initialize into the first state, WaitingToSendFirstByte Set CurrentState to WaitingToSendFirstByte Post the initial transition event end InitDOGTXmitSM RunDOGTXmitSM switch on CurrentState case WaitingToSendFirstByte state if the event type is ES_BEGIN_TXMIT Save the event param that describes the packet type If constructing the packet of specified type is successful Reset the index of number of bytes sent Set CurrentState to SendingAPacket Begin transmitting by calling helper function else constructing packet failed, do nothing end if break case SendingAPacket state if the event type is ES_ALL_BYTES_SENT Set CurrentState to WaitingToSendFirstByte else if the event type is ES_LOST_CONNECTION Set CurrentState to WaitingToSendFirstByte end if break end switch on Current State return ReturnEvent end RunDOGTXmitSM DOGTXmitISR (Only respond to the interrupt that we care about: TXMIS) If transmit interrupts are unmasked and it fired Clear UART TXmit interrupt by setting TXIC in UARTICR (interrupt clear register) if we have sent all of the bytes Disable UART TXmit interrupt by clearing interrupt mask bit in UART mask reg Post ES_ALL_BYTES_SENT to TXmitSM else (we are not done sending bytes yet) Write the new data to data register UARTDR Increment BytesSentIndex end if else (TXMIS is not set, meaning it's not a transmit interrupt, so take no action) end if end DOGTXmitISR ConstructPacket Constructs the packet that will be sent by filling out the TxPacket array with appropriate data If PacketType is STATUS Set PacketSize accordingly Set FrameDataSize accordingly Get destination address from RX service Create XBee header Fill out RF data of TxPacket (just using PacketType) Then fill out RF data of TxPacket using getter function for IMU data Create an index variable to track RF data byte that's being set to a status byte start the 'for' loop at RF data start +1 because of the PacketType bit that's first looping over the IMU data using the getter function, save each to TxPacket SetXBeeChecksum Return true because packet was created successfully else if PacketType is ENCR_RESET Set PacketSize accordingly Set FrameDataSize accordingly Get destination address from RX service Create XBee header Fill out RF data of TxPacket (just using PacketType) SetXBeeChecksum Return true because packet was created successfully else if PacketType is PAIR_ACK Set PacketSize accordingly Set FrameDataSize accordingly Get destination address from RX service Create XBee header Fill out RF data of TxPacket (just using PacketType) SetXBeeChecksum Return true because packet was created successfully else bad packet type, packet was not created. return false end if end ConstructPacket CreateXBeeHeader Creates the header, which is all the bytes before the RF data TxPacket[0] equals 0x7E TxPacket[1] equals length of MSB which is 0x00 TxPacket[2] equals length of LSB TxPacket[3] equals API_ID for a transmit request TxPacket[4] equals FRAME_ID which is arbitrary, not specified in comm protocol TxPacket[5] equals Destination Address MSB TxPacket[6] equals Destination Address LSB TxPacket[7] equals OPTIONS, which in our case is 0x00 end CreateXBeeHeader SetXBeeChecksum Calculates checksum and puts that value in last byte of TxPacket[] for each byte in the framing data Add current TxPacket to the sum end for loop Calculate XBeeChecksum by subtracting sum from 0xff Set the last byte in the TxPacket array to be the XBeeCheckSum that was just calculated end SetXBeeChecksum StartDOGTXmit Kicks off transmission of a packet and will cause a UART Tx interrupt, which will be handled in DOGTXmitISR if there is room to transfer a byte (Txmit Fifo Empty = TXFE is set) Write the new data to data register UARTDR Enable UART TXmit interrupt by setting interrupt mask bit in UART mask reg so that when the byte is done sending, it fires an interrupt Increment BytesSentIndex (goes from 0 to 1 here) Return true because first byte was successfully transmitted else (there is not room to transmit a byte because the transmit fifo is full) return false end if end StartDOGTXmit