1

I'm trying to make my own wireless PPP/SLIP protocol and I can't figure out if the radios are at fault or if my thoughts (presented as pseudo-code below) is at fault.

The data packet is as follows:

Byte 1: Special Start flag (same value that starts packet)
Byte 2: Most significant bit = direction packet is going
Byte 2: Remaining 7 bits: Slave the master communicates with.
Byte 3: Packet Sequence number
Byte 4-n: Data
Byte n+1: Checksum

I written my whole code in the 8051 assembler since the target chips are also 8051 based. I have configured the speed of data to be the same throughout the whole system. I verified my assembly code against a 8051 simulator (ucsim). I'm using a version that's fresh as of 2 months ago.

The setup in the end will be one master communicating to each client, one at a time sequentially and will repeat endlessly. Since the radio modules are half-duplex, I make it where only one device may transmit at a time.

Because I am new to perfecting my own SLIP/PPP protocol, I have some questions regarding my setup.

My thought is to make the master check the incoming sequence number from a packet to make sure its not the same as the last one, and if it is, discard the packet. Also, the client accepts any packet at first (for sync) then increments local sequence number, then sends request to master then next packet it receives must match local sequence number.

Am I on the right track with this thought? or did the people who invented SLIP/PPP have a different mindset when it came to synchronizing and receiving proper fixed-length packets?

For wireless operation in general, is three retries enough? Note: when my system sends consecutive packets without a break, the sequence number for each packet in the group is the same.

I did implement byte stuffing along with a data reception timeout.

Suppose a timeout happened. Should I automatically clear the flag (that indicated the bit received was an escape character)? or should I wait until the receiver sends the start flag byte and then clear the flag there?

Also, would there be any benefit to adding a special end-byte to my packet or would that not be beneficial? All devices in my setup know that when the start byte is received it stops receiving the packet at the checksum byte.

So the point of all this is that I'm trying to use similar logic in my PPP/SLIP protocol setup as the people used when they designed the first PPP protocol we use today.

This is my pseudo code. All functions except "Begin Transmit" are automatically called by the system in priority sequence when that event happens. Serial functions have highest priority.

Timeout function:
    clear timer-run
    clear escape-bit
    set ignore-byte
    If packet-received is set then
      clear packet-received
      set packet-official
      ** If device is client then
        Increment sequence number (auto-roll over past 255)
      ** End if
    end if
  Exit Function

  Serial Function
    If byte received then clear receive-flag and run received
    If byte transmitted then clear transmit-flag and run transmitted
  Exit Function

  Begin Transmit Function
      Set packet-count to 3
      Set byte to start code
      clear escape-bit
      Output byte to serial
  Exit Function

  Transmitted Function
    If escape-bit set then
      clear escape-bit
      output saved transmit byte
      Exit Function
    end if
    Save old variables and load new bank
    If transmit-pointer is at end of packet then
      Decrement packet-count
      If packet-count = 0 then
        Enable Receiver
        ** If device is host then
        Enable Timeout timer
        ** End If
        Restore old variables
        Exit Function
      End if
      Set transmit-pointer to start of packet
      Set byte to start code
      goto Output-mode
    ELSE
      increment transmit-pointer
      load byte from current ram location (defined by transmit-pointer)
    End If
    If byte is Escape code then
      Set saved transmit byte to Special escape character
      Set escape-bit
    End If
    If byte is Start code then
      Set saved transmit byte to Special start character  
      Set escape-bit
      Set byte to Escape code
    End If
    Output-mode:
      Output byte to serial
      Restore old variables
  Exit Function

  Received Function
      Clear timer-run
      Save old variables and load new bank  
      Load received byte
      If escape-bit is set then
        clear escape-bit
        If received-byte is special start character then 
          set received byte to start code
          goto receive-2
        End If
        If received-byte is special escape character then
          set received byte to escape code
          goto receive-2
        End If
          goto receive-fail
      End If
      If received-byte is escape code then
        set escape-bit
        reset timer timeout
        set timer-run
        Restore old variables
        Exit function
      End if
      If received-byte is start code then
        reset receive-pointer
        clear ignore-byte
        reset timer timeout
        set timer-run
        Restore old variables
        Exit function
      End if
      receive-2:
      If ignore-byte is set then
        Restore old variables
        Exit Function
      End If 
      If receive-pointer is at checksum byte address then
          Validate checksum
          If checksum is correct then
              Set Packet-received flag 
          End if
          Restore old variables
          Exit Function
      End If
      If receive-pointer is at sequence byte address then
            If received-byte is not expected-sequence then
              set ignore-byte
              Restore old variables
              Exit Function
            End if 
      End If
      If receive-pointer is at beginning then
          reset checksum seed
      End If
      store byte in ram address (defined by receive-pointer)
      calculate checksum on received-byte and update checksum value variable
      reset timer timeout
      set timer-run
      Restore old variables
  Exit Function
Mike -- No longer here
  • 2,064
  • 1
  • 15
  • 37

0 Answers0