Skip to content

Instantly share code, notes, and snippets.

@elfgoh
Created October 25, 2014 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elfgoh/f9b478a3f3e6db804fb3 to your computer and use it in GitHub Desktop.
Save elfgoh/f9b478a3f3e6db804fb3 to your computer and use it in GitHub Desktop.
VC0706 library verify method
uint8_t VC0706::_verify(uint8_t cmd)
{
if((vcBuff[VC0706_PTL_BYTE] != VC0706_RECV_MARK) ||
(vcBuff[VC0706_SERIAL_BYTE] != VC0706_SERIAL_NUMBER)){
DBG("return format error\n");
return RESP_DATA_FORMAT_ERROR;
}
if(vcBuff[VC0706_CMD_BYTE] != cmd){
DBG("return command error\n");
return RESP_DATA_CMD_ERROR;
}
return vcBuff[VC0706_STATUS_BYTE]; // 0 is OK, other is NG
}
@notthetup
Copy link

So vcBuff is the receive buffer from the UART communications.

When you do a _read(num, ...) you try to read those many bytes over the UART bus. The _read() function probably returns the number of bytes successfully read from the UART bus. Those bytes are stored in your vcBuff array. Since this is arduino everything is global. Yay!!

If the comms are happening correctly vcBuff should contain a bunch of bytes based on this protocol. http://www.adafruit.com/datasheets/VC0706protocol.pdf. But if you look through, the first byte after the serial number always identifies the command.

_verify function basically checks a couple of things.

  1. it checks if the message has been received completely (vcBuff[VC0706_PTL_BYTE] != VC0706_RECV_MARK)
  2. checks if the message is from the IC with the same serial as you want to talk to vcBuff[VC0706_SERIAL_BYTE] != VC0706_SERIAL_NUMBER)
  3. checks if the command byte in the message is the same as the one you passed as the argument to this function vcBuff[VC0706_CMD_BYTE] != cmd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment