Вы находитесь на странице: 1из 3

1 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

// Initialize Defferal Queue


// Initialize the MyPriority variable with the passed in parameter.
// Post the initial transition event to this services queue
// Return true if post was successful
End of InitDogXBeeTransmitService

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.

// Create return event and assume no errors


// Define variables
// Set NextState to CurrentState
// Based on the state of the CurrentState, choose one of the following
// blocks of code
// If current state is InitDogTXState
// If event is ES_INIT
// Initialization was successful. Set NextState to Waiting2Transmit
// Endif
// If case is Waiting2Transmit
// If event is EV_StartXmit2Xbee){
// Store a local copy of the packet type
// Construct the packet to be transmitted
// Start the transmission by calling on StartTransmit function
// Change NextState to Transmitting
// Else if event is EV_RetryXmit2Xbee
// Using the PacketType that was stored from last time, try to
// resend the message. The message should still be stored in
// TransmitPacket which is a static variable
// Change NextState to Transmitting
// Endif
// If case is Transmitting
// If event is EV_TransmitComplete
// Since the message transmission is complete, move back to the
// Wating2Transmit state
// Endif
// Endif
// Set CurrentState to NextState
// Return ES_NO_EVENT
End of RunDogXBeeTransmitService

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.

// Define local variables


// Depending on the packet type (header), construct the relevant packet
// If packet type is PAIR_ACK_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

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.

// Set TransmitPacket[0] as START_DELIMITER;


// Set TransmitPacket[1] as FrameLengthMSB;
// Set TransmitPacket[2] as FrameLengthLSB;
// Set TransmitPacket[3] as API_ID;
// Set TransmitPacket[4] as FrameID;
// Set TransmitPacket[5] as DestAddressMSB;
// Set TransmitPacket[6] as DestAddressLSB;
// Set TransmitPacket[7] as Options;
End of ConstructTXHeader

CalculateChecksum
Calculates a rolling sum of the frame data with which to compute the checksum,
which is appended onto the end of every message.

// Define local variables


// If the current byte is inside of the frame data
// Add value of relevant byte inside of Frame Data to the rolling sum
// Endif
// Calculate the checksum as 0xFF minus the rolling sum
// Return calculated value of checksum
End of CalculateChecksum

StartTransmit
Takes in nothing, returns true if transmit started

// Initialize TransmitInitiated to be false and assume the message was not


// initiated properly

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

// Write TransmitPacket[BytesSent] to the data register (UARTDR)


// Increment BytesSent
// Check if the message has completed transmitting. If it has:
// Disable the transmit interrupt
// Post a EV_TransmitComplete event to this service
// Endif
End of TransmitISR

12