Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Parser wanted #2

Open
insanity54 opened this issue Apr 20, 2018 · 0 comments
Open

Parser wanted #2

insanity54 opened this issue Apr 20, 2018 · 0 comments

Comments

@insanity54
Copy link
Contributor

insanity54 commented Apr 20, 2018

The controlpoint receives HEX encoded data generated by the gateway--

            xbee.remoteTransmit({
                destinationId: device.did,
                broadcast: false,
                data: `DCXST
                       CT${device.controllingTeam.toString(16)}
                       RP${device.redProgress.toString(16)}
                       BP${device.bluProgress.toString(16)}` // Tell DCX to act GAME 0
            })

This is nasty code that currently "parses" the received data

      if (
        rx.getData(0) == 'D' &&
        rx.getData(1) == 'C' &&
        rx.getData(2) == 'X' &&
        rx.getData(3) == 'S' &&
        rx.getData(4) == 'T' 
      )
      {
        // we're getting a state update (ST)
        
        if (rx.getData(5) == 'C' &&
            rx.getData(6) == 'T'
        )
        {
          // Controlling Team
          if (rx.getData(7) < 5) {
            controllingTeam = rx.getData(7);
          }
        }

        if (rx.getData(8) == 'R' &&
            rx.getData(9) == 'P'
        )
        {
          if (rx.getData(10) < 101) {
            redProgress = rx.getData(10);
          }
        }

        if (rx.getData(11) == 'B' &&
            rx.getData(12) == 'P'
        )
        {
          if (rx.getData(13) < 101) {
            bluProgress = rx.getData(11);
          }
        }
      }

You can see it is not flexible. For example, BP must always come after RP.

This is ideal code, but I'm unsure of how to implement a parser class.

    DCXParser dcxParser = DCXParser(rx);

      // interpret the state updates
     if (dcxParser.getDataType() == STATE_UPDATE) {
       controllingTeam = dcxParser.getData(CONTROLLING_TEAM);
       redProgress = dcxParser.getData(RED_PROGRESS);
       bluProgress = dcxParser.getData(BLU_PROGRESS);
     }
@insanity54 insanity54 changed the title dcxParser needed dcxParser wanted Apr 20, 2018
@insanity54 insanity54 changed the title dcxParser wanted Parser wanted Apr 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant