From 498b1f12e99f746397326179375f6e54229e5547 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Sun, 13 Feb 2022 16:36:24 -0500 Subject: [PATCH] Get MD5 code building for Linux --- Config.h | 36 +++++++++++++++++++++++++++++++++++- MD5.cpp | 8 +++++++- MD5.h | 10 ++++++++-- Makefile | 13 +++++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/Config.h b/Config.h index ad06363..f5d6f38 100644 --- a/Config.h +++ b/Config.h @@ -8,10 +8,12 @@ #define PLATFORM_AVR 0x90 #define PLATFORM_ESP32 0x80 + #define PLATFORM_LINUX 0x70 #define MCU_1284P 0x91 #define MCU_2560 0x92 #define MCU_ESP32 0x81 + #define MCU_LINUX 0x71 #define BOARD_RNODE 0x31 #define BOARD_HMBRW 0x32 @@ -20,6 +22,10 @@ #define BOARD_GENERIC_ESP32 0x35 #define BOARD_LORA32_V2_0 0x36 #define BOARD_LORA32_V2_1 0x37 + #define BOARD_SPIDEV 0x38 + + #define LIBRARY_ARDUINO 0x1 + #define LIBRARY_C 0x2 #define MODE_HOST 0x11 #define MODE_TNC 0x12 @@ -33,6 +39,9 @@ #elif defined(ESP32) #define PLATFORM PLATFORM_ESP32 #define MCU_VARIANT MCU_ESP32 + #elif defined(__unix__) + #define PLATFORM PLATFORM_LINUX + #define MCU_VARIANT MCU_LINUX #else #error "The firmware cannot be compiled for the selected MCU variant" #endif @@ -54,6 +63,7 @@ const int pin_led_tx = 13; #define BOARD_MODEL BOARD_RNODE + #define LIBRARY_TYPE LIBRARY_ARDUINO #define CONFIG_UART_BUFFER_SIZE 6144 #define CONFIG_QUEUE_SIZE 6144 @@ -70,6 +80,7 @@ const int pin_led_tx = 13; #define BOARD_MODEL BOARD_HMBRW + #define LIBRARY_TYPE LIBRARY_ARDUINO #define CONFIG_UART_BUFFER_SIZE 768 #define CONFIG_QUEUE_SIZE 5120 @@ -130,6 +141,8 @@ #else #error An unsupported board was selected. Cannot compile RNode firmware. #endif + + #define LIBRARY_TYPE LIBRARY_ARDUINO #define CONFIG_UART_BUFFER_SIZE 6144 #define CONFIG_QUEUE_SIZE 6144 @@ -141,6 +154,22 @@ #define GPS_BAUD_RATE 9600 #define PIN_GPS_TX 12 #define PIN_GPS_RX 34 + #elif MCU_VARIANT == MCU_LINUX + const int pin_cs = -1; + const int pin_reset = -1; + const int pin_dio = -1; + const int pin_led_rx = -1; + const int pin_led_tx = -1; + + #define BOARD_MODEL BOARD_SPIDEV + #define LIBRARY_TYPE LIBRARY_C + + #define CONFIG_UART_BUFFER_SIZE 6144 + #define CONFIG_QUEUE_SIZE 6144 + #define CONFIG_QUEUE_MAX_LENGTH 200 + + #define EEPROM_SIZE 4096 + #define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED #endif #if BOARD_MODEL == BOARD_TBEAM @@ -148,7 +177,12 @@ #define I2C_SCL 22 #define PMU_IRQ 35 #endif - + + #if LIBRARY_TYPE == LIBRARY_C + // We need standard int types before we go any further + #include + #endif + #define eeprom_addr(a) (a+EEPROM_OFFSET) // MCU independent configuration parameters diff --git a/MD5.cpp b/MD5.cpp index 56daa77..52317e5 100644 --- a/MD5.cpp +++ b/MD5.cpp @@ -1,5 +1,11 @@ #include "MD5.h" +#if LIBRARY_TYPE == LIBRARY_ARDUINO + #include "Arduino.h" +#elif LIBRARY_TYPE == LIBRARY_C + #include +#endif + MD5::MD5() { //nothing @@ -298,4 +304,4 @@ unsigned char* MD5::make_hash(char *arg,size_t size) MD5Update(&context, arg, size); MD5Final(hash, &context); return hash; -} \ No newline at end of file +} diff --git a/MD5.h b/MD5.h index 3ec8d81..7ca88bd 100644 --- a/MD5.h +++ b/MD5.h @@ -1,7 +1,13 @@ #ifndef MD5_h #define MD5_h -#include "Arduino.h" +#include "Config.h" + +#if LIBRARY_TYPE == LIBRARY_ARDUINO + #include "Arduino.h" +#elif LIBRARY_TYPE == LIBRARY_C + #include +#endif /* * This is an OpenSSL-compatible implementation of the RSA Data Security, @@ -49,4 +55,4 @@ public: static void MD5Update(void *ctxBuf, const void *data, size_t size); }; -#endif \ No newline at end of file +#endif diff --git a/Makefile b/Makefile index 7e3e416..1c2fa08 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,9 @@ prep-samd: arduino-cli core update-index --config-file arduino-cli.yaml arduino-cli core install adafruit:samd +prep-linux: + mkdir -p bin + mkdir -p obj firmware: @@ -135,3 +138,13 @@ release-mega2560: arduino-cli compile --fqbn arduino:avr:mega -e cp build/arduino.avr.mega/RNode_Firmware.ino.hex Release/rnode_firmware_latest_m2560.hex rm -r build + +.PHONY: clean prep-linux + +clean: + rm -Rf bin + rm -Rf obj + +obj/MD5.o: MD5.cpp MD5.h Config.h ROM.h prep-linux + $(CC) -c -o $@ $< +