Professional Documents
Culture Documents
Dogxbeetransmitservice
Dogxbeetransmitservice
************************************************************************************
Pseudo-code for the DogXBeeTransmit service
Transmits either an ACK, a status packet, or an encryption reset packet back
to the Xbee.
InitDogXBeeTransmitService
Takes a priority number, returns true
PostDogXBeeTransmitService
Create PostDogXBeeTransmitService
RunDogXBeeTransmitService
The parameter it takes in will be ThisEvent and the parameter field of
ThisEvent will be the time that the event occurred. Returns ES_NO_Event.
ConstructTXPacket
Constructs a packet to be transmitted via UART to the Xbee, whos type is based on
the passed in parameter. Takes in packet type, returns nothing.
10
// Set the options byte to default
// Construct packet header by calling on ConstructTXHeader function
// Add the header onto the packet
// The pair acknowledgment packet only contains the header. Append the
// checksum to the end of the packet
// Else if packet type is STATUS_HEADER
// Define local variables based on IMU data
// Set the length of frame data
// Note the total length of the packet to be sent
// Set the API identifier
// Set the Frame ID (can be arbitary except for 0x00 which will disable
// the XBee from sending back an acknowledgement of whether or not the
// transmit was successful. Make sure it does not rollover to 0 which
// will disable ACKs upon transmit)
// Set the destination address
// Set the options byte to default
// Construct packet header
// Add the header onto the packet
// Query the IMU for the status bytes
// Parse the IMU data
// Add the status bytes from the IMU data to the transmit packet RF data
// The pair acknowledgment packet only contains the header. Append the
// checksum to the end of the packet
// Else if packet type is ENCRYPT_RESET_HEADER
// Set the length of frame data
// Note the total length of the packet to be sent
// Set the API identifier
// Set the Frame ID (can be arbitary except for 0x00 which will disable
// the XBee from sending back an acknowledgement of whether or not the
// transmit was successful. Make sure it does not rollover to 0 which
// will disable ACKs upon transmit)
// Set the destination address
// Set the options byte to default
// Construct packet header by calling on ConstructTXHeader function
// Add the header onto the packet
// The encryption reset packet only contains the header. Append the
// checksum to the end of the packet
// Endif
End of ConstructTXPacket
ConstructTXHeader
Constructs the header for the packet.
CalculateChecksum
Calculates a rolling sum of the frame data with which to compute the checksum,
which is appended onto the end of every message.
StartTransmit
Takes in nothing, returns true if transmit started
11
// Initialize the BytesSent to be 0
// If the transmit FIFO is empty, begin the transmission process
// Write TransmitPacket[BytesSent] to the data register (UARTDR)
// Increment BytesSent
// (For efficiency, when writing the first byte of a transmission to the
// data register, it immediately moves to the shift register. Therefore
// you can directly load another byte into the data register)
// Enable the transmit interrupt
// Return success
// Else the transmit FIFO was not empty and message failed to send
// Return failure
End of StartTransmit
TransmitISR
12