forked from mohr/ArduinoIO
packet field beautified
This commit is contained in:
parent
8e97270bb7
commit
da92a31910
35
main.cpp
35
main.cpp
@ -52,25 +52,26 @@ void transferSPI(uint8_t address, uint8_t *data, size_t datalen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handlePacket(uint8_t *packet, size_t packetLen) {
|
void handlePacket(uint8_t *packet, size_t packetLen) {
|
||||||
//Paket layout is:
|
/* Paket layout is:
|
||||||
// byte --------------------
|
------------------------------
|
||||||
// 1 | 8 bit command |
|
|byte | field |
|
||||||
// --------------------
|
| | |
|
||||||
// 1 | 8 bit address |
|
|------------------------------|
|
||||||
// --------------------
|
|1 | 8 bit command |
|
||||||
// 2 | 16bit length |
|
|------------------------------|
|
||||||
// --------------------
|
|1 | 8 bit address |
|
||||||
// length | <length> byte data |
|
|------------------------------|
|
||||||
// --------------------
|
|2 | 16bit length |
|
||||||
// 2 | 16 bit crc |
|
|------------------------------|
|
||||||
// --------------------
|
|length | <length> byte data |
|
||||||
|
|------------------------------|
|
||||||
|
|2 | 16 bit crc |
|
||||||
|
|------------------------------|
|
||||||
|
------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
uint16_t crc = Calculate_CRC(packet, packetLen);
|
uint16_t crc = Calculate_CRC(packet, packetLen);
|
||||||
|
|
||||||
|
|
||||||
if (crc != 0) {
|
if (crc != 0) {
|
||||||
Serial.println("invalid Checksum");
|
Serial.println("invalid Checksum");
|
||||||
return;
|
return;
|
||||||
@ -86,8 +87,6 @@ void handlePacket(uint8_t *packet, size_t packetLen) {
|
|||||||
uint8_t command = packet[0];
|
uint8_t command = packet[0];
|
||||||
uint8_t address = packet[1];
|
uint8_t address = packet[1];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case COMMAND_TRANSFER_SPI:
|
case COMMAND_TRANSFER_SPI:
|
||||||
transferSPI(address, packet + 4, payloadLen);
|
transferSPI(address, packet + 4, payloadLen);
|
||||||
|
Loading…
Reference in New Issue
Block a user