Highslide JS
Click to Enlarge

Communications Protocol Received Message

The communications module on the COACH was implemented using the class wide communications protocol. 

Transmission:  A data packet was sent using an 11 byte message, 3 bytes of which were different depending on the transmission.  The transmit function took three parameters: (1) a destination address, (2) an opcode, and (3) an accompanying parameter.  These filled bytes 6, 9, and 10 respectively, where the data stored in bytes 9 and 10 specified an action to be performed and an accompanying magnitude or numerical parameter.  A check sum was used to allow the receive side to check for integrity of an incoming message.

Highslide JS
Click to Enlarge

Communications Protocol Transferred Message

Receive:  An interrupt response routine was used to create a packet from incoming transmissions.  Upon receiving the start delimiter the ISR would construct a packet and set a software flag upon completion and verification of the check sum.  The source address, opcode, and parameter in bytes 6, 9, and 10 respectively were passed to the state machine for processing.

 

Pseudo Code

Function: SCI_Init
Takes: Nothing
Returns: Nothing

    set the baud rate to 9600
    enable both transmit and receive, with interrupts on the receive
    set 8-bit mode
    set transmit out, with standard break length

Function: Send Packet
Takes: Desired address of the transmission, MSB data, and LSB data
Returns: Nothing

    wait for the transmit data register to be empty (tiny bit of blocking code)
    start by sending the start delimiter (0x7E)
    wait again, and send the MSB of the length of the frame
    wait again, and send the LSB of the length of the frame
    wait again, and sent the TX identifier
    continue, sending the Frame ID, address MSB, address LSB, options byte, data MSB, data LSB
    calculate the sum from TX Identifier through the data LSB
    calculate the check sum from 0xFF – sum (from above)
    send the check sum

Interrupt: Receive Packet
Fires: Upon receipt of a byte indicated by a flag in the SCI1SR1 register

    clear the interrupt flag!
    start a switch/case statement, switching on the state of the data packet transmission (the state indicates what byte was last sent)
    Case 0:
        if the start delimiter was received, reset all the previous byte values and increment the state
        else, reset the state to 0
    Case 1:
        set the MSB of the frame size
        increment the state
    Case 2:
        set the LSB of the frame size
        increment the state
    Case 3:
        switch on the frame size (maximum is 7)
        Case 1:
            set the identifier and increment the state

        repeat for each of the 7 frame bytes…

    Case 4:
        set the check sum
        reset the state to 0
        if the check sum is valid, set a flag
        if the check sum is not valid, return an error, set no flags

Function: Get TOWRP ID
Takes: Nothing
Returns: The address of the transmission

    if a flag has been set by the interrupt response routine, set an Opcode flag, clear the ISR flag, and return the LSB of the address
    else return nothing useful

Function: Get OpCode
Takes: Nothing
Returns: The operational code for the COACH to handle

    if a flag has been set by the Get TOWRP ID function
        set a Parameter flag
        switch on the different Opcodes from the protocol, and return a #define
        Ex: Case1: MutinyInProgress
        Clear Opcode flag
        return MutinyInProgress
        etc.
    else return nothing useful

Function: Get Parameter
Takes: Nothing
Returns: The parameter for the COACH to handle

    if a flag has been set by the Get Opcode function, clear the Parameter flag, and return the MSB of the address
    else return nothing useful