Parsing Hex Responses
I'm working through my first module for a TOA 9000 series Mixer/Amp. I've setup a buffer in DEFINE_START to catch responses from the device.
Will each individual element in my CHAR array buffer be able to carry any HEX value from 00 to FF?
To illustrate this...let's say the device were to return 91H, 03H, 00H, FFH, 00H. Let's just say nothing else is in the buffer. Would it look like this?
MyBuffer[1] = $91
MyBuffer[2] = $03
MyBuffer[3] = $00
MyBuffer[4] = $FF
MyBuffer[5] = $00
Cheers,
Matthew
Will each individual element in my CHAR array buffer be able to carry any HEX value from 00 to FF?
To illustrate this...let's say the device were to return 91H, 03H, 00H, FFH, 00H. Let's just say nothing else is in the buffer. Would it look like this?
MyBuffer[1] = $91
MyBuffer[2] = $03
MyBuffer[3] = $00
MyBuffer[4] = $FF
MyBuffer[5] = $00
Cheers,
Matthew
0
Comments
Cheers,
Matthew
This is how I would parse this...
DEFINE_DEVICE dvTOA = 5001:1:0 DEFINE_VARIABLE CHAR cBuffer[255]; CHAR cCMD; CHAR cDataLength; CHAR cData[100]; DEFINE_FUNCTION ParseMessage(CHAR cCmd, CHAR cData[]) { SWITCH (cCmd) { // Channel Fader Gain (Position) CASE $91: { } // Channel Fader Gain (Step) CASE $93: { } // Crosspoint Gain CASE $95: { } // Preset Memory Recall CASE $f1: { } } } DEFINE_START CREATE_BUFFER dvTOA,cBuffer; DEFINE_EVENT DATA_EVENT[dvTOA] { STRING: { // Buffer Trash Cleaning // Just for Sanity sake, do not expect this code to run. // FIRST BYTE IS NOT A COMMAND BYTE ($80 - $FF) WHILE (LENGTH_STRING(cBuffer) > 0 && cBuffer[1] < $80) GET_BUFFER_CHAR(cBuffer); // MAKE SURE WE STILL HAVE LENGTH IF (LENGTH_STRING(cBuffer) > 1) { // GET COMMAND BYTE cCMD = GET_BUFFER_CHAR(cBuffer); // GET LENGTH BYTE cDataLength = GET_BUFFER_CHAR(cBuffer); // Check to make sure we have length IF (cDataLength > 0 && LENGTH_STRING(cBuffer) >= cDataLength) { // Get the data cData = GET_BUFFER_STRING(cBuffer, cDataLength); // Parse the message ParseMessage(cCMD, cData); } // Not enough data, put humpty back together ELSE { cBuffer = "cCMD, cDataLength, cBuffer"; } } } }Thanks again!
Cheers,
Matthew
$41 <==> 65 <==> 'A' <==> 0100 0001
Paul
Cheers,
Matthew