From 8e97270bb717ff5f30664192ce5fbb69a8a9c08b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 13 Oct 2020 00:43:33 +0200 Subject: [PATCH] packet layout beautified --- ArduinoConfig.h | 21 +++++++++++++++++++++ main.cpp | 33 +++++++++++---------------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/ArduinoConfig.h b/ArduinoConfig.h index 07a4f37..d04fb91 100644 --- a/ArduinoConfig.h +++ b/ArduinoConfig.h @@ -1,9 +1,30 @@ #ifndef ARDUINOCONFIG_H_ #define ARDUINOCONFIG_H_ +static const uint8_t COMMAND_TRANSFER_SPI = 1; + #define BAUD_RATE 115200 #define SERIAL_RX_BUFFER_SIZE 256 #define RING_BUFFER_SIZE 100 #define MAX_PACKET_LENGTH 100 +// Define which port to use for the SPI Chip Select by using the register +// definitions. The data direction register is assigned as well. +// The ports can be looked up on the official Arduino pinout schematics. +#ifdef ARDUINO_AVR_MEGA2560 +// Defines for the Arduino Mega +#define CS_PORT PORTK +#define CS_DDR DDRK +#elif defined(ARDUINO_AVR_UNO) +#define CS_PORT PORTD +#define CS_DDR DDRD +#elif defined(__SAM3X8E__) +// Define for the Arduino Due +#define CS_PORT PORTC +#define CS_DDR DDRC +#else +#define CS_PORT PORTC +#define CS_DDR DDRC +#endif + #endif /* ARDUINOCONFIG_H_ */ diff --git a/main.cpp b/main.cpp index 2f26725..e4ee1cc 100644 --- a/main.cpp +++ b/main.cpp @@ -11,27 +11,6 @@ //from the core and we need to include it explicitly #include -// Define which port to use for the SPI Chip Select by using the register -// definitions. The data direction register is assigned as well. -// The ports can be looked up on the official Arduino pinout schematics. -#ifdef ARDUINO_AVR_MEGA2560 -// Defines for the Arduino Mega -#define CS_PORT PORTK -#define CS_DDR DDRK -#elif defined(ARDUINO_AVR_UNO) -#define CS_PORT PORTD -#define CS_DDR DDRD -#elif defined(__SAM3X8E__) -// Define for the Arduino Due -#define CS_PORT PORTC -#define CS_DDR DDRC -#else -#define CS_PORT PORTC -#define CS_DDR DDRC -#endif - -static const uint8_t COMMAND_TRANSFER_SPI = 1; - SimpleRingBuffer ringBuffer(RING_BUFFER_SIZE, true); uint8_t rawData[2 * RING_BUFFER_SIZE]; @@ -74,7 +53,17 @@ void transferSPI(uint8_t address, uint8_t *data, size_t datalen) { void handlePacket(uint8_t *packet, size_t packetLen) { //Paket layout is: - // 8 bit command | 8 bit address | 16bit length | byte data | 16 bit crc + // byte -------------------- + // 1 | 8 bit command | + // -------------------- + // 1 | 8 bit address | + // -------------------- + // 2 | 16bit length | + // -------------------- + // length | byte data | + // -------------------- + // 2 | 16 bit crc | + // --------------------