All settings can now be saved to FLASH.
This commit is contained in:
@@ -6,6 +6,7 @@ cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
add_library(LoRa_pico_lib LoRa-RP2040.cpp LoRa-RP2040.h)
|
||||
add_library(LoRa_print Print.h Print.cpp)
|
||||
add_library(KISS kiss.h kiss.cpp)
|
||||
|
||||
target_link_libraries(LoRa_pico_lib pico_stdlib hardware_spi hardware_interp LoRa_print)
|
||||
|
||||
@@ -24,7 +25,7 @@ target_include_directories(main PUBLIC ./)
|
||||
|
||||
target_link_directories(main PUBLIC ./)
|
||||
|
||||
target_link_libraries(main pico_stdlib LoRa_pico_lib LoRa_print)
|
||||
target_link_libraries(main pico_stdlib LoRa_pico_lib LoRa_print KISS)
|
||||
|
||||
# enable usb output, disable uart output
|
||||
pico_enable_stdio_usb(main 1)
|
||||
|
6
src/kiss.cpp
Normal file
6
src/kiss.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "kiss.h"
|
||||
|
||||
uint16_t KissClass::EncodeFrame(void)
|
||||
{
|
||||
return 100;
|
||||
}
|
@@ -1,5 +1,9 @@
|
||||
#ifndef KISS_H
|
||||
#define KISS_H
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define FEND 0xC0
|
||||
#define FESC 0xDB
|
||||
@@ -9,6 +13,7 @@
|
||||
#define CMD_UNKNOWN 0xFE
|
||||
#define CMD_DATA 0x00
|
||||
#define CMD_HARDWARE 0x06
|
||||
#define CMD_EXIT_KISS 0xFF
|
||||
|
||||
#define HW_RSSI 0x21
|
||||
|
||||
@@ -17,12 +22,10 @@
|
||||
#define ERROR_TXFAILED 0x02
|
||||
#define ERROR_QUEUE_FULL 0x04
|
||||
|
||||
size_t frameLength;
|
||||
bool inFrame = false;
|
||||
bool escape = false;
|
||||
bool SERIAL_READING = false;
|
||||
uint8_t command = CMD_UNKNOWN;
|
||||
uint32_t lastSerialRead = 0;
|
||||
uint32_t serialReadTimeout = 25;
|
||||
class KissClass
|
||||
{
|
||||
public:
|
||||
uint16_t EncodeFrame(void);
|
||||
};
|
||||
|
||||
#endif
|
112
src/main.cpp
112
src/main.cpp
@@ -7,9 +7,11 @@
|
||||
#include "hardware/flash.h"
|
||||
#include "LoRa-RP2040.h"
|
||||
#include "Config.h"
|
||||
#include "KISS.h"
|
||||
#include "kiss.h"
|
||||
#include "hardware/claim.h"
|
||||
|
||||
KissClass Kiss;
|
||||
|
||||
bool startRadio();
|
||||
void getPacketData(int packetLength);
|
||||
int compare_strings(uint8_t a[], uint8_t b[]);
|
||||
@@ -29,8 +31,8 @@ const uint PowerSupply5VControl = 4;
|
||||
const uint RelayOffControl = 2;
|
||||
const uint RelayOnControl = 3;
|
||||
|
||||
// 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.
|
||||
// We're going to use a region 512k from the start of flash as non volatile storage for our settings.
|
||||
// We can access this at XIP_BASE + 512k.
|
||||
#define FLASH_TARGET_OFFSET (512 * 1024)
|
||||
|
||||
const uint8_t *flash_target_contents = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET);
|
||||
@@ -158,6 +160,7 @@ void setup(void)
|
||||
ReadSettingsFromFlash();
|
||||
|
||||
startRadio();
|
||||
|
||||
}
|
||||
|
||||
void print_help(void)
|
||||
@@ -176,10 +179,35 @@ void print_help(void)
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads a string and converts it to its 32 bit value if it contains a number,
|
||||
* else it returns 0xFFFFFFFF
|
||||
*/
|
||||
uint32_t ConvertStringToValue(char string[])
|
||||
{
|
||||
uint16_t position = 0;
|
||||
uint32_t value = 0;
|
||||
|
||||
// Extract value from string (if present)
|
||||
while( string[position] != 0 )
|
||||
{
|
||||
// Is character a number?
|
||||
if (string[position] >= 48 && string[position] <= 57) {
|
||||
value = 10*value + string[position]-48;
|
||||
} else {
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
position++;
|
||||
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void ProcessSerialInput(char string[])
|
||||
{
|
||||
uint8_t cnt;
|
||||
uint8_t position=0;
|
||||
uint32_t tmp = 0;
|
||||
|
||||
char command[100];
|
||||
char parameter[100];
|
||||
@@ -308,6 +336,83 @@ void ProcessSerialInput(char string[])
|
||||
log_out("Destination set to %s.\n", AprsSettings.Destination);
|
||||
}
|
||||
}
|
||||
// Set lora frequency (limited between 420MHz and 450MHz)
|
||||
else if (strcmp(command, "freq") == 0) {
|
||||
tmp = ConvertStringToValue(parameter);
|
||||
if (tmp == 0xFFFFFFFF || tmp < 420000000 || tmp > 450000000)
|
||||
log_out("ERROR: that is not a valid value.\n");
|
||||
else {
|
||||
AprsSettings.loraFrequency = tmp;
|
||||
log_out("LoRa frequency set to %u.\n", AprsSettings.loraFrequency);
|
||||
}
|
||||
}
|
||||
// Set lora spreading factor (can be between 6 and 12)
|
||||
else if (strcmp(command, "spread") == 0) {
|
||||
tmp = ConvertStringToValue(parameter);
|
||||
if (tmp == 0xFFFFFFFF || tmp < 6 || tmp > 12)
|
||||
log_out("ERROR: that is not a valid value.\n");
|
||||
else {
|
||||
AprsSettings.loraSpreadingFactor = (uint16_t)tmp;
|
||||
log_out("LoRa spreading factor set to %u.\n", AprsSettings.loraSpreadingFactor);
|
||||
}
|
||||
}
|
||||
// Set lora preamble (can be between 6 and 0xFFFF)
|
||||
else if (strcmp(command, "pre") == 0) {
|
||||
tmp = ConvertStringToValue(parameter);
|
||||
if (tmp == 0xFFFFFFFF || tmp < 6 || tmp > 0xFFFF)
|
||||
log_out("ERROR: that is not a valid value.\n");
|
||||
else {
|
||||
AprsSettings.loraPreamble = (uint16_t)tmp;
|
||||
log_out("LoRa preamble set to %u.\n", AprsSettings.loraPreamble);
|
||||
}
|
||||
}
|
||||
// Set lora coding rate (can be between 5 and 8)
|
||||
else if (strcmp(command, "rate") == 0) {
|
||||
tmp = ConvertStringToValue(parameter);
|
||||
if (tmp == 0xFFFFFFFF || tmp < 5 || tmp > 8)
|
||||
log_out("ERROR: that is not a valid value.\n");
|
||||
else {
|
||||
AprsSettings.loraCodingRate = (uint16_t)tmp;
|
||||
log_out("LoRa coding rate set to %u.\n", AprsSettings.loraCodingRate);
|
||||
}
|
||||
}
|
||||
// Set lora tx power (can be between 2 and 17)
|
||||
else if (strcmp(command, "power") == 0) {
|
||||
tmp = ConvertStringToValue(parameter);
|
||||
if (tmp == 0xFFFFFFFF || tmp < 2 || tmp > 17)
|
||||
log_out("ERROR: that is not a valid value.\n");
|
||||
else {
|
||||
AprsSettings.loraTxPower = (uint16_t)tmp;
|
||||
log_out("LoRa tx power set to %u.\n", AprsSettings.loraTxPower);
|
||||
}
|
||||
}
|
||||
// Set lora bandwidth (can be between 7800 and 500000)
|
||||
else if (strcmp(command, "band") == 0) {
|
||||
tmp = ConvertStringToValue(parameter);
|
||||
if (tmp == 0xFFFFFFFF || tmp < 7800 || tmp > 5000000)
|
||||
log_out("ERROR: that is not a valid value.\n");
|
||||
else {
|
||||
AprsSettings.loraBandwidth = tmp;
|
||||
log_out("LoRa bandwidth set to %u.\n", AprsSettings.loraBandwidth);
|
||||
}
|
||||
}
|
||||
// Set lora pa to +20dBm (can be either 0 or 1)
|
||||
else if (strcmp(command, "pa") == 0) {
|
||||
tmp = ConvertStringToValue(parameter);
|
||||
if (tmp != 0 && tmp != 1)
|
||||
log_out("ERROR: that is not a valid value.\n");
|
||||
else {
|
||||
AprsSettings.loraPaSelect = (uint16_t)tmp;
|
||||
log_out("LoRa PA set to %u.\n", AprsSettings.loraPaSelect);
|
||||
}
|
||||
}
|
||||
// Restart radio
|
||||
else if (strcmp(command, "restart") == 0)
|
||||
if (strcmp(parameter, "lora") == 0) {
|
||||
log_out("Re-");
|
||||
startRadio();
|
||||
}
|
||||
|
||||
else {
|
||||
print_help();
|
||||
}
|
||||
@@ -335,6 +440,7 @@ void ReadUSBSerial(void)
|
||||
strg[lp-1] = 0; //terminate string by overwriting <CR> with NULL
|
||||
//log_out("You wrote - %s\n", strg);
|
||||
lp = 0; //reset string buffer pointer
|
||||
log_out("\n");
|
||||
|
||||
ProcessSerialInput(strg);
|
||||
|
||||
|
Reference in New Issue
Block a user