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

1 DogXBeeReceiveService

/****************************************************************************
Pseudo-code for the DogXBeeReceive service
Receives messages from the controllers XBee and parses out the logic
in an ISR state machine.

InitDogXBeeTransmitService
Takes a priority number, returns true

// Initialize Defferal Queue


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

PostDogXBeeReceiveService
Create PostDogXBeeReceiveService

RunDogXBeeReceiveService
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 case is InitDogRXState
// Initialization was successful. Set NextState to WaitingToProcess
// If case is WaitingToProcess
// If IC delay timer timed out
// Reset the system and set the next ISR state to WaitFor0x7E
// Else if this event is EV_PacketReceived
// Start the unpair timer again
// Process the byte that was received using the packet in the buffer
// and carry out the relevant action
// Endif
// Endif
// Set CurrentState to NextState
// Return ES_NO_EVENT
End of RunDogXBeeReceiveService

ProcessPacketReceived

// Create local variables


// Grab a copy of ReceivePacket for the relevant message from the buffer
// Store the packet type in a local variable
// Use a getter function to check if were already paired or not
// If the received packet was an incoming packet (and not a transmit status
// packet)
// Check if were paired to see what kinds of packets we should be looking for:
// If unpaired
// If packet type is a pair request
// If the pair request was with the correct (our) DOG tag
// Store the value of the source address to provide to the TX service
// Post a EV_PairRequested event to this service
// Endif
// Endif
// Else if were currently paired
// Store the address of the current sender
// If the sender was the person were currently paired with, carry
out normal actions
// Use a getter function to check if were already encrypting or not
// If were currently not encrypting, the only packet we should be
// looking for is a header indicating an encryption key was sent

13
// If the packet was an encryption key
// Store the encryption key in a module level variable (accessible
// via a getter function)
// Reset the encryption key index to 0
// Post a EV_EncryptReceived event to this service
// Else if we are encrypting, the only packet we should be looking for is
// a control packet
// If packet is a control packet
// Save away important information for use in Control Service
// Post EV_ControlReceived
// Else if the packet was anything other than a control packet (0x04)
// reset the encryption key
// Reset the encryption index to 0
// Post EV_EncryptionReset
// Endif
// Endif
// Else if
// Roll the encryption index back to what it was before (since this was
// not a message from our FARMER
// Endif
// Endif
// Else if the transmit status packet indicates the transmit packet was a NACK or
// a CCA, then resend the previous packet
End of ProcessPacketReceived

ProcessByte
Generalized byte processing procedure, which will add additional functionality
if the input is specified to be frame data

// If this is a data byte, decrement BytesLeft and calculate checksum


// Increment Index
// Restart the intercharacter delay timer to reset the system if it times out
End of ProcessByte

DecryptByte
Decrypts an individual byte using by XORing with the current cipher. Takes in a
decrypted byte and returns an unencrypted byte.

// Define local variables


// Decrypt Byte by XORing with current encryption key (will undo the XOR which
encrypted the byte)
// Must decrypt on previous index since its already been incremented
// Increment encrypt index using modulus 32
// Return Byte
End of DecryptByte

StoreDigitalControlPacket

// Define local variables


// Grab a copy of ReceivePacket for the relevant message from the buffer
// to avoid overwriting the copy in the buffer
// Save away fwd/reverse byte and left/right byte
// Post EV_StartPeripheral to ControlService if peripheral bit is HI
// Check if brake bit changed and post event to ControlService if it did
End of StoreDigitalControlPacket

GetFwdReverseByte
// Return FwdReverseByte

GetFwdReverseByte
// Return LeftRightByte

GetReceivePacketBuffer
Provide a getter function for the ReadBufferIndex

// Store ReadBufferIndex in a local variable


// Increment ReadBufferIndex
// Return the pair status
End of GetReceivePacketBuffer

14
ReceiveISR
Continue the transmission process for sending data to an XBee via UART
and keep sending bytes until there are none left to transmit. Takes in
nothing and returns nothing.

// Define local variables


// Set NextState to CurrentState
// Based on the state of the CurrentState, choose one of the following
// blocks of code
// If case is WaitFor0x7E_ISR
// Initialize the value of checksum to be 0
// Initialize the value of Index to be 0
// Store a local copy of the encryption index used at the beginning
// of the packet
// Store the received byte (0x7E) in ReceivePacket
// Check if the first byte was a start delimeter (0x7E)
// Process the byte and increment Index
// Set the next state to be WaitforMSBLength
// Else if case is WaitforMSBLength_ISR
// Store the received byte in ReceivePacket
// Store the MSB for the length of the Frame Data
// Process the byte and incremend Index
// Set the next state to be WaitforLSBLength
// Else if case is WaitforLSBLength_ISR
// Store the received byte in ReceivePacket
// Store the LSB for the length of the Frame Data
// Calculate length of frame data
// Process the byte and increment Index
// Set the next state to be WaitforLSBLength
// Else if case is SuckUpPacket_ISR:
// Check if BytesLeft is 0
// Use a getter function to check if we need to decrypt or not
// Store the received byte (Frame Data) in ReceivePacket
// Calculate the checksum, increment Index, and restart the
// intercharacter delay timer to reset the system if it times out
// If weve already received the encryption key and were looking at
// the RF data
// Decrypt the previous byte since we have already incremented index
// Else if BytesLeft is 0
// Store the received byte (transmitted checksum) in ReceivePacket
// Store the value of the transmitted checksum in a local variable
// If the checksum is good
// Store the packet in a buffer (memcpy copies an array over)
// Increment WriteBufferIndex
// Post a EV_PacketReceived event to this service
// Else print that checksum was bad
// Endif
// Stop the intercharacter delay timer since the message is over
// With the message received, go back to the initial state and
// wait for the start of another message
// Endif
// Endif
// Set CurrentState to NextState
End of ReceiveISR

End of DogXBeeReceiveService

15

Вам также может понравиться