This repository contains test code for the Nordic UART Service on the Adafruit Feather NRF52 Bluefruit. It is based on the BLE Uart example from the Adafruit_nRF52_Arduino repo.
Follow this tutorial from Adafruit to set up the Arduino IDE to build and deploy this code.
Data sent to the device over Nordic UART Service is parsed and written out to serial (at 115200 baud). Everytime a new packet is received, the millis() timestamp is written to serial as well.
The data packets can be of two types: Button and SeekBar.
The Button data is an Int16 value sent as a byte array (little-endian) prefixed by 0x2142 (i.e., "!B") and postfixed by a CRC byte.
The SeekBar data is an Int32 value sent as a byte array (little-endian) prefixed by 0x2153 (i.e., "!S") and postfixed by a CRC byte.
The CRC byte is computed simply by taking the sum of all bytes in the payload data (i.e., prefix and Button/SeekBar value) then doing a bitwise negation on the least significant byte of the result. The following code shows an example implementation for checking the CRC byte.
// check checksum!
uint8_t xsum = 0;
uint8_t checksum = packetbuffer[replyidx-1];
for (uint8_t i=0; i<PACKET_LEN; i++) {
xsum += packetbuffer[i];
}
xsum = ~xsum;
// Throw an error message if the checksum's don't match
if (xsum != checksum)
{
Serial.print("Checksum mismatch in packet : ");
printHex(packetbuffer, replyidx+1);
return 0;
}
Where PACKET___LEN is in bytes and does not include the CRC.