|
|
@ -3,12 +3,13 @@ |
|
|
|
#include <time.h> |
|
|
|
#include <time.h> |
|
|
|
#include "pico/stdlib.h" |
|
|
|
#include "pico/stdlib.h" |
|
|
|
#include "pico/binary_info.h" |
|
|
|
#include "pico/binary_info.h" |
|
|
|
|
|
|
|
#include "hardware/flash.h" |
|
|
|
#include "LoRa-RP2040.h" |
|
|
|
#include "LoRa-RP2040.h" |
|
|
|
#include "Config.h" |
|
|
|
#include "Config.h" |
|
|
|
#include "KISS.h" |
|
|
|
#include "KISS.h" |
|
|
|
|
|
|
|
#include "hardware/claim.h" |
|
|
|
|
|
|
|
|
|
|
|
bool startRadio(); |
|
|
|
bool startRadio(); |
|
|
|
bool LoadSettings(); |
|
|
|
|
|
|
|
void getPacketData(int packetLength); |
|
|
|
void getPacketData(int packetLength); |
|
|
|
int compare_strings(uint8_t a[], uint8_t b[]); |
|
|
|
int compare_strings(uint8_t a[], uint8_t b[]); |
|
|
|
bool is_message_for_me (uint8_t data[], uint8_t mycall[]); |
|
|
|
bool is_message_for_me (uint8_t data[], uint8_t mycall[]); |
|
|
@ -27,14 +28,49 @@ const uint PowerSupply5VControl = 4; |
|
|
|
const uint RelayOffControl = 2; |
|
|
|
const uint RelayOffControl = 2; |
|
|
|
const uint RelayOnControl = 3; |
|
|
|
const uint RelayOnControl = 3; |
|
|
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
// We're going to use a region 256k from the start of flash as non volatile storage for our settings.
|
|
|
|
|
|
|
|
// We can access this at XIP_BASE + 256k.
|
|
|
|
|
|
|
|
#define FLASH_TARGET_OFFSET (512 * 1024) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uint8_t *flash_target_contents = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t ReadSettingsFromFlash(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
uint16_t ServerCommand = 0; |
|
|
|
// If byte zero of flash contains 0x5A we assume the data to be valid, otherwise we fill the flash with default values.
|
|
|
|
uint16_t TxDelay = 0; |
|
|
|
if (flash_target_contents[0] != 0x5A) |
|
|
|
|
|
|
|
{ |
|
|
|
/* Among others, this initializes the USB-serial port at 115200bps 8N1 */ |
|
|
|
printf( "No valid data found in FLASH memory.\n" ); |
|
|
|
|
|
|
|
memset(AprsSettings.FillerData, 0, sizeof(AprsSettings.FillerData)); |
|
|
|
|
|
|
|
uint32_t ints = save_and_disable_interrupts(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// First we erase the FLASH sector we need. After that we can store new values.
|
|
|
|
|
|
|
|
// Note that a whole number of sectors must be erased at a time.
|
|
|
|
|
|
|
|
// Sector size is 4kB, so this is way bigger than the needed 256 bytes for storing the settings.
|
|
|
|
|
|
|
|
printf("Erasing FLASH region..."); |
|
|
|
|
|
|
|
flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE); |
|
|
|
|
|
|
|
printf("done\n"); |
|
|
|
|
|
|
|
printf("Writing default values to FLASH...");
|
|
|
|
|
|
|
|
flash_range_program(FLASH_TARGET_OFFSET, (uint8_t*)&AprsSettings, FLASH_PAGE_SIZE); |
|
|
|
|
|
|
|
printf("done\n"); |
|
|
|
|
|
|
|
restore_interrupts (ints); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Read settings stored in flash memory
|
|
|
|
|
|
|
|
printf("Found valid settings in FLASH memory.\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
memcpy((uint8_t*)&AprsSettings, flash_target_contents, FLASH_PAGE_SIZE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("APRS settings:\n"); |
|
|
|
|
|
|
|
printf("My call: %s\n", AprsSettings.MyCall); |
|
|
|
|
|
|
|
printf("Server call: %s\n", AprsSettings.ServerCall); |
|
|
|
|
|
|
|
printf("Firmware: %s\n",AprsSettings.FirmwareVersion); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setup(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
/* Among others, this initializes the USB-serial port at 115200bps 8N1 */ |
|
|
|
stdio_init_all(); |
|
|
|
stdio_init_all(); |
|
|
|
|
|
|
|
|
|
|
|
// Buffers
|
|
|
|
// Buffers
|
|
|
|
memset(rxBuffer, 0, sizeof(rxBuffer)); |
|
|
|
memset(rxBuffer, 0, sizeof(rxBuffer)); |
|
|
|
memset(txBuffer, 0, sizeof(txBuffer)); |
|
|
|
memset(txBuffer, 0, sizeof(txBuffer)); |
|
|
@ -63,12 +99,20 @@ int main() { |
|
|
|
gpio_put(RelayOffControl, 0); |
|
|
|
gpio_put(RelayOffControl, 0); |
|
|
|
gpio_put(RelayOnControl, 0); |
|
|
|
gpio_put(RelayOnControl, 0); |
|
|
|
Status.ControlRelay = OFF; |
|
|
|
Status.ControlRelay = OFF; |
|
|
|
|
|
|
|
|
|
|
|
sleep_ms(5000); |
|
|
|
sleep_ms(5000); |
|
|
|
|
|
|
|
|
|
|
|
LoadSettings(); |
|
|
|
ReadSettingsFromFlash(); |
|
|
|
|
|
|
|
|
|
|
|
startRadio(); |
|
|
|
startRadio(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t ServerCommand = 0; |
|
|
|
|
|
|
|
uint16_t TxDelay = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setup(); |
|
|
|
|
|
|
|
|
|
|
|
while (1) { |
|
|
|
while (1) { |
|
|
|
int packetSize = LoRa.parsePacket(); |
|
|
|
int packetSize = LoRa.parsePacket(); |
|
|
@ -196,16 +240,6 @@ int main() { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Load settings from EEPROM |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
bool LoadSettings() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
printf("APRS settings:\n"); |
|
|
|
|
|
|
|
printf("My call: %s\n", AprsSettings.MyCall); |
|
|
|
|
|
|
|
printf("Server call: %s\n", AprsSettings.ServerCall); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Initializes the LoRa module with the parameters set in config.h |
|
|
|
* Initializes the LoRa module with the parameters set in config.h |
|
|
|
*/ |
|
|
|
*/ |
|
|
|