SPLatco Knowledge Base

The controller communicates with the SX10509 via commands. The following table lists the commands and the data that is associated with each one:

  
:: Transmit Buffer (Commands) ::
CommandName CommandValue   NextByte          NextBytes
              Byte 0        Byte 1           Bytes 2...n
-----------------------------------------------------------------
Idle        '00 / '80      Unused            Unused
Write       '01 / '81      bLength           Data..
Read        '02 / '82      CumulativeOffset  Unused
Server      '03 / '83      bLength           Data..
Port        '04 / '84      4 bytes of floating point port number
Path        '05 / '85      bLength           Data..
ContentType '06 / '86      bLength           Data..
DoGet       '07 / '87      Unused            Unused
DoPost      '08 / '88      Unused            Unused
GetID       '09 / '89      Unused            Unused
GetGMT      '0A / '8A      Unused            Unused
GetIP       '0B / '8B      Unused            Unused
  
:: Receive Buffer (responses) ::
CommandName CommandValue   NextByte          NextBytes
              Byte 0        Byte 1           Bytes 2...n
-----------------------------------------------------------------
Idle        '00 / '80      Unused            Unused
ToServer    '01 / '81      Unused            Unused
FromServer  '02 / '82      bLength           Data..
Server      '03 / '83      Unused            Unused
Port        '04 / '84      Unused            Unused
Path        '05 / '85      Unused            Unused
ContentType '06 / '86      Unused            Unused
DoGet       '07 / '87      bLength*          4 bytes of floating point status code
DoPost      '08 / '88      bLength*          4 bytes of floating point status code
GetID       '09 / '89      bLength           IDString..
GetGMT      '0A / '8A      bLength           GMTString..
GetIP       '0B / '8B      IP                IP,IP,IP

* For DoGet and DoPost responses, the bLengthByte is the number of characters available 
  for readout using subsequent Read commands

To send a command, first load up any data associated with it, and the bLength byte is required. Then, once all the data is ready, load the command byte itself.

The SX10509 will ignore the data until the command byte is loaded. Once it sees a new command byte, it will execute the command. When it finishes executing the command it will return a matching command byte in the network receive data block. For most commands this will be nearly instantaneous, but for DoGet and DoPost it may take several seconds.

Be sure to wait for the command byte response before sending the next command.

As the Xwire data blocks are limited to 32 bytes, these commands may require several iterations to be fully completed:

   Write      
   Read       
   Server     
   Path       
   ContentType

For example, setting a path with more than 30 characters, like “custom/scripts/mmi202/poopump/flow_monitor.php“, must be done in two iterations.

Bit 7 of the command byte may be toggled to indicate the next iteration is ready. Here’s an example:

  
;Creating two versions of the Path command provides a simple way to toggle
CMDkPathA   EQU   '05   ;Path command
CMDkPathB   EQU   '85   ;(toggled version of the) Path command
  
   SetMem         bTxByte1,0                          ;set the length to zero to erase any existing path
   SetMem         bTxByte0,CMDkPathA                  ;load the command
WafDoPath1:
   YieldTask
   GoIfMNE        bRxByte0,CMDkPathA,WafDoPath1       ;waf erase to complete
 
   LoadI          0                                   ;zero the index (this will be used as a length indicator)
   iiPrintText    bTxByte2,"custom/scripts/mmi202/p"  ;store the first part of the path
   ItoX                                               ;get the length
   Store          bTxByte1                            ;store the length of the first part
   SetMem         bTxByte0,CMDkPathB                  ;load the path command (toggled version)
WafDoPath2:
   YieldTask
   GoIfMNE        bRxByte0,CMDkPathB,WafDoPath2       ;waf the SX10509 to save the first part
 
   LoadI          0                                   ;zero the index (this will be used as a length indicator)
   iiPrintText    bTxByte2,"oopump/flow_monitor.php"  ;store the second part of the path
   ItoX                                               ;get the length
   Store          bTxByte1                            ;store the length of the second part
   SetMem         bTxByte0,CMDkPathA                  ;load the path command
WafDoPath3:
   YieldTask
   GoIfMNE        bRxByte0,CMDkPathA,WafDoPath3       ;waf the SX10509 to save the second part
   ;-- the full path has now been loaded
  

If, instead of issuing hardcoded strings you’re running in a loop, then you can toggle the command with a NotS instruction, for example:

   NotS           7,bTxByte0                          ;toggle the command
  

Now you can check for command completion by comparing the current Tx command with the Rx command, for example:

   Recall         bTxByte0                            ;get the request
   Recall         bRxByte0                            ;get the response
   Compare                                            ;has the command been performed?
   GoIfNZ         StillWaiting                        ;jump if still waiting

The SX10509 tutorial shows an alternative way of doing this.