kopia lustrzana https://github.com/lora-aprs/LoRa_APRS_Tracker
moving settings.h to json...
rodzic
1ad85c3147
commit
4c1f3fde78
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"callsign":"DF1OE-12",
|
||||
"beacon":
|
||||
{
|
||||
"message":"LoRa APRS Tracker Test",
|
||||
"position":
|
||||
{
|
||||
"latitude":52.390212,
|
||||
"longitude":9.745379
|
||||
},
|
||||
"timeout": 1,
|
||||
"symbol": "[",
|
||||
"overlay": "/"
|
||||
|
||||
},
|
||||
"wifi":
|
||||
{
|
||||
"active":true,
|
||||
"AP": [
|
||||
{ "SSID":"DF1OE@JO42UJ", "password":"40683742350238290821" },
|
||||
{ "SSID":"DF1OE-H48", "password":"hamRadio4all" },
|
||||
{ "SSID":"DF1OE/m", "password":"dataRadio#"}
|
||||
]
|
||||
},
|
||||
"lora":
|
||||
{
|
||||
"frequency_rx":433775000,
|
||||
"frequency_tx":433775000,
|
||||
"power":20,
|
||||
"spreading_factor":12,
|
||||
"signal_bandwidth":125000,
|
||||
"coding_rate4":5
|
||||
}
|
||||
}
|
|
@ -9,15 +9,21 @@
|
|||
#include "display.h"
|
||||
#include "pins.h"
|
||||
#include "power_management.h"
|
||||
#include "configuration.h"
|
||||
Configuration Config;
|
||||
|
||||
#include "power_management.h"
|
||||
PowerManagement powerManagement;
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
HardwareSerial ss(1);
|
||||
TinyGPSPlus gps;
|
||||
|
||||
void setup_lora();
|
||||
void setup_gps();
|
||||
void load_config();
|
||||
|
||||
String create_lat_aprs(RawDegrees lat);
|
||||
String create_long_aprs(RawDegrees lng);
|
||||
String createDateString(time_t t);
|
||||
|
@ -37,6 +43,7 @@ int lastTxTime = millis();
|
|||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
load_config();
|
||||
|
||||
#ifdef TTGO_T_Beam_V1_0
|
||||
Wire.begin(SDA, SCL);
|
||||
|
@ -61,7 +68,7 @@ void setup()
|
|||
|
||||
#ifdef SB_ACTIVE
|
||||
Serial.println("[INFO] Smart Beaconing Active");
|
||||
show_display("DJ1AN", "Smart Beaconing","Active", 1000);
|
||||
// show_display("DJ1AN", "Smart Beaconing","Active", 1000);
|
||||
#endif
|
||||
|
||||
setup_gps();
|
||||
|
@ -157,15 +164,15 @@ void loop()
|
|||
if(send_update && gps.location.isValid() && gps_loc_update)
|
||||
{
|
||||
powerManagement.deactivateMeasurement();
|
||||
nextBeaconTimeStamp = now() + (BEACON_TIMEOUT * SECS_PER_MIN);
|
||||
nextBeaconTimeStamp = now() + (Config.beacon.timeout * SECS_PER_MIN);
|
||||
send_update = false;
|
||||
|
||||
APRSMessage msg;
|
||||
msg.setSource(CALL);
|
||||
msg.setSource(Config.callsign);
|
||||
msg.setDestination("APLT0");
|
||||
String lat = create_lat_aprs(gps.location.rawLat());
|
||||
String lng = create_long_aprs(gps.location.rawLng());
|
||||
msg.getAPRSBody()->setData(String("=") + lat + SYMBOL_OVERLAY + lng + SYMBOL_CODE + BEACON_MESSAGE);
|
||||
msg.getAPRSBody()->setData(String("=") + lat + Config.beacon.overlay + lng + Config.beacon.symbol + Config.beacon.message);
|
||||
String data = msg.encode();
|
||||
Serial.println(data);
|
||||
show_display("<< TX >>", data);
|
||||
|
@ -196,7 +203,7 @@ void loop()
|
|||
String batteryChargeCurrent(powerManagement.getBatteryChargeDischargeCurrent(), 0);
|
||||
#endif
|
||||
|
||||
show_display(CALL,
|
||||
show_display(Config.callsign,
|
||||
createDateString(now()) + " " + createTimeString(now()),
|
||||
String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(),
|
||||
String("Nxt Bcn: ") + createTimeString(nextBeaconTimeStamp)
|
||||
|
@ -245,7 +252,7 @@ void setup_lora()
|
|||
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
|
||||
Serial.println("[INFO] Set LoRa pins!");
|
||||
|
||||
long freq = FREQ_SET;
|
||||
long freq = Config.lora.frequencyTx;
|
||||
Serial.print("[INFO] frequency: ");
|
||||
Serial.println(freq);
|
||||
if (!LoRa.begin(freq)) {
|
||||
|
@ -253,9 +260,9 @@ void setup_lora()
|
|||
show_display("ERROR", "Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(SF_SET);
|
||||
LoRa.setSignalBandwidth(BW_SET);
|
||||
LoRa.setCodingRate4(CR_SET);
|
||||
LoRa.setSpreadingFactor(Config.lora.spreadingFactor);
|
||||
LoRa.setSignalBandwidth(Config.lora.signalBandwidth);
|
||||
LoRa.setCodingRate4(Config.lora.codingRate4);
|
||||
LoRa.enableCrc();
|
||||
|
||||
LoRa.setTxPower(20);
|
||||
|
@ -268,6 +275,28 @@ void setup_gps()
|
|||
ss.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX);
|
||||
}
|
||||
|
||||
void load_config()
|
||||
{
|
||||
ConfigurationManagement confmg("/is-cfg.json");
|
||||
Config = confmg.readConfiguration();
|
||||
if(Config.callsign == "NOCALL-10")
|
||||
{
|
||||
logPrintlnE("You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!");
|
||||
show_display("ERROR", "You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!");
|
||||
while (true)
|
||||
{}
|
||||
}
|
||||
|
||||
#ifndef ETH_BOARD
|
||||
if(Config.aprs_is.active && !Config.wifi.active)
|
||||
{
|
||||
logPrintlnE("You have to activate Wifi for APRS IS to work, please check your settings!");
|
||||
show_display("ERROR", "You have to activate Wifi for APRS IS to work, please check your settings!");
|
||||
while (true)
|
||||
{}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
String create_lat_aprs(RawDegrees lat)
|
||||
{
|
||||
char str[20];
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
#include <SPIFFS.h>
|
||||
|
||||
#include "configuration.h"
|
||||
#include "logger.h"
|
||||
|
||||
ConfigurationManagement::ConfigurationManagement(String FilePath)
|
||||
: mFilePath(FilePath)
|
||||
{
|
||||
if(!SPIFFS.begin(true))
|
||||
{
|
||||
logPrintlnE("Mounting SPIFFS was not possible. Trying to format SPIFFS...");
|
||||
SPIFFS.format();
|
||||
if(!SPIFFS.begin())
|
||||
{
|
||||
logPrintlnE("Formating SPIFFS was not okay!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Configuration ConfigurationManagement::readConfiguration()
|
||||
{
|
||||
File file = SPIFFS.open(mFilePath);
|
||||
if(!file)
|
||||
{
|
||||
logPrintlnE("Failed to open file for reading...");
|
||||
return Configuration();
|
||||
}
|
||||
DynamicJsonDocument data(2048);
|
||||
DeserializationError error = deserializeJson(data, file);
|
||||
if(error)
|
||||
{
|
||||
logPrintlnW("Failed to read file, using default configuration.");
|
||||
}
|
||||
serializeJson(data, Serial);
|
||||
Serial.println();
|
||||
file.close();
|
||||
|
||||
Configuration conf;
|
||||
if(data.containsKey("callsign"))
|
||||
conf.callsign = data["callsign"].as<String>();
|
||||
|
||||
conf.wifi.active = data["wifi"]["active"] | false;
|
||||
JsonArray aps = data["wifi"]["AP"].as<JsonArray>();
|
||||
for(JsonVariant v : aps)
|
||||
{
|
||||
Configuration::Wifi::AP ap;
|
||||
ap.SSID = v["SSID"].as<String>();
|
||||
ap.password = v["password"].as<String>();
|
||||
conf.wifi.APs.push_back(ap);
|
||||
}
|
||||
if(data.containsKey("beacon") && data["beacon"].containsKey("message"))
|
||||
conf.beacon.message = data["beacon"]["message"].as<String>();
|
||||
conf.beacon.positionLatitude = data["beacon"]["position"]["latitude"] | 0.0;
|
||||
conf.beacon.positionLongitude = data["beacon"]["position"]["longitude"] | 0.0;
|
||||
conf.beacon.timeout = data["beacon"]["timeout"] | 1;
|
||||
conf.beacon.overlay = data["beacon"]["overlay"].as<String>();
|
||||
conf.beacon.symbol = data["beacon"]["overlay"] | "/";
|
||||
|
||||
conf.aprs_is.active = data["aprs_is"]["active"] | false;
|
||||
if(data.containsKey("aprs_is") && data["aprs_is"].containsKey("password"))
|
||||
conf.aprs_is.password = data["aprs_is"]["password"].as<String>();
|
||||
if(data.containsKey("aprs_is") && data["aprs_is"].containsKey("server"))
|
||||
conf.aprs_is.server = data["aprs_is"]["server"].as<String>();
|
||||
conf.aprs_is.port = data["aprs_is"]["port"] | 14580;
|
||||
conf.aprs_is.beacon = data["aprs_is"]["beacon"] | true;
|
||||
conf.aprs_is.beaconTimeout = data["aprs_is"]["beacon_timeout"] | 15;
|
||||
conf.digi.active = data["digi"]["active"] | false;
|
||||
conf.digi.forwardTimeout = data["digi"]["forward_timeout"] | 5;
|
||||
conf.digi.beacon = data["digi"]["beacon"] | true;
|
||||
conf.digi.beaconTimeout = data["digi"]["beacon_timeout"] | 30;
|
||||
|
||||
conf.lora.frequencyRx = data["lora"]["frequency_rx"] | 433775000;
|
||||
conf.lora.frequencyTx = data["lora"]["frequency_tx"] | 433775000;
|
||||
conf.lora.power = data["lora"]["power"] | 20;
|
||||
conf.lora.spreadingFactor = data["lora"]["spreading_factor"] | 12;
|
||||
conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"] | 125000;
|
||||
conf.lora.codingRate4 = data["lora"]["coding_rate4"] | 5;
|
||||
conf.display.alwaysOn = data["display"]["always_on"] | true;
|
||||
conf.display.timeout = data["display"]["timeout"] | 10;
|
||||
conf.display.overwritePin = data["display"]["overwrite_pin"] | 0;
|
||||
|
||||
conf.ftp.active = data["ftp"]["active"] | false;
|
||||
JsonArray users = data["ftp"]["user"].as<JsonArray>();
|
||||
for(JsonVariant u : users)
|
||||
{
|
||||
Configuration::Ftp::User us;
|
||||
us.name = u["name"].as<String>();
|
||||
us.password = u["password"].as<String>();
|
||||
conf.ftp.users.push_back(us);
|
||||
}
|
||||
if(conf.ftp.users.empty())
|
||||
{
|
||||
Configuration::Ftp::User us;
|
||||
us.name = "ftp";
|
||||
us.password = "ftp";
|
||||
conf.ftp.users.push_back(us);
|
||||
}
|
||||
|
||||
// update config in memory to get the new fields:
|
||||
writeConfiguration(conf);
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
void ConfigurationManagement::writeConfiguration(Configuration conf)
|
||||
{
|
||||
File file = SPIFFS.open(mFilePath, "w");
|
||||
if(!file)
|
||||
{
|
||||
logPrintlnE("Failed to open file for writing...");
|
||||
return;
|
||||
}
|
||||
DynamicJsonDocument data(2048);
|
||||
|
||||
data["callsign"] = conf.callsign;
|
||||
data["wifi"]["active"] = conf.wifi.active;
|
||||
JsonArray aps = data["wifi"].createNestedArray("AP");
|
||||
for(Configuration::Wifi::AP ap : conf.wifi.APs)
|
||||
{
|
||||
JsonObject v = aps.createNestedObject();
|
||||
v["SSID"] = ap.SSID;
|
||||
v["password"] = ap.password;
|
||||
}
|
||||
data["beacon"]["message"] = conf.beacon.message;
|
||||
data["beacon"]["position"]["latitude"] = conf.beacon.positionLatitude;
|
||||
data["beacon"]["position"]["longitude"] = conf.beacon.positionLongitude;
|
||||
data["aprs_is"]["active"] = conf.aprs_is.active;
|
||||
data["aprs_is"]["password"] = conf.aprs_is.password;
|
||||
data["aprs_is"]["server"] = conf.aprs_is.server;
|
||||
data["aprs_is"]["port"] = conf.aprs_is.port;
|
||||
data["aprs_is"]["beacon"] = conf.aprs_is.beacon;
|
||||
data["aprs_is"]["beacon_timeout"] = conf.aprs_is.beaconTimeout;
|
||||
data["digi"]["active"] = conf.digi.active;
|
||||
data["digi"]["forward_timeout"] = conf.digi.forwardTimeout;
|
||||
data["digi"]["beacon"] = conf.digi.beacon;
|
||||
data["digi"]["beacon_timeout"] = conf.digi.beaconTimeout;
|
||||
data["lora"]["frequency_rx"] = conf.lora.frequencyRx;
|
||||
data["lora"]["frequency_tx"] = conf.lora.frequencyTx;
|
||||
data["lora"]["power"] = conf.lora.power;
|
||||
data["lora"]["spreading_factor"] = conf.lora.spreadingFactor;
|
||||
data["lora"]["signal_bandwidth"] = conf.lora.signalBandwidth;
|
||||
data["lora"]["coding_rate4"] = conf.lora.codingRate4;
|
||||
data["display"]["always_on"] = conf.display.alwaysOn;
|
||||
data["display"]["timeout"] = conf.display.timeout;
|
||||
data["display"]["overwrite_pin"] = conf.display.overwritePin;
|
||||
data["ftp"]["active"] = conf.ftp.active;
|
||||
JsonArray users = data["ftp"].createNestedArray("user");
|
||||
for(Configuration::Ftp::User u : conf.ftp.users)
|
||||
{
|
||||
JsonObject v = users.createNestedObject();
|
||||
v["name"] = u.name;
|
||||
v["password"] = u.password;
|
||||
}
|
||||
|
||||
serializeJson(data, file);
|
||||
//serializeJson(data, Serial);
|
||||
//Serial.println();
|
||||
file.close();
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
#ifndef CONFIGURATION_H_
|
||||
#define CONFIGURATION_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include <Arduino.h>
|
||||
#ifndef CPPCHECK
|
||||
#include <ArduinoJson.h>
|
||||
#endif
|
||||
|
||||
class Configuration
|
||||
{
|
||||
public:
|
||||
class Wifi
|
||||
{
|
||||
public:
|
||||
class AP
|
||||
{
|
||||
public:
|
||||
String SSID;
|
||||
String password;
|
||||
};
|
||||
|
||||
Wifi() : active(false) {}
|
||||
|
||||
bool active;
|
||||
std::list<AP> APs;
|
||||
};
|
||||
|
||||
class Beacon
|
||||
{
|
||||
public:
|
||||
Beacon() : message("LoRa Tracker, Info: github.com/peterus/LoRa_APRS_Tracker"), positionLatitude(0.0), positionLongitude(0.0) {}
|
||||
|
||||
String message;
|
||||
int timeout = 1;
|
||||
String symbol = ">";
|
||||
String overlay = "/";
|
||||
double positionLatitude;
|
||||
double positionLongitude;
|
||||
};
|
||||
|
||||
class APRS_IS
|
||||
{
|
||||
public:
|
||||
APRS_IS() : active(false), server("euro.aprs2.net"), port(14580), beacon(true), beaconTimeout(15) {}
|
||||
|
||||
bool active;
|
||||
String password;
|
||||
String server;
|
||||
int port;
|
||||
bool beacon;
|
||||
int beaconTimeout;
|
||||
};
|
||||
|
||||
class Digi
|
||||
{
|
||||
public:
|
||||
Digi() : active(false), forwardTimeout(5), beacon(true), beaconTimeout(30) {}
|
||||
|
||||
bool active;
|
||||
int forwardTimeout;
|
||||
bool beacon;
|
||||
int beaconTimeout;
|
||||
};
|
||||
|
||||
class LoRa
|
||||
{
|
||||
public:
|
||||
LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {}
|
||||
|
||||
long frequencyRx;
|
||||
long frequencyTx;
|
||||
int power;
|
||||
int spreadingFactor;
|
||||
long signalBandwidth;
|
||||
int codingRate4;
|
||||
};
|
||||
|
||||
class Display
|
||||
{
|
||||
public:
|
||||
Display() : alwaysOn(true), timeout(10), overwritePin(0) {}
|
||||
|
||||
bool alwaysOn;
|
||||
int timeout;
|
||||
int overwritePin;
|
||||
};
|
||||
|
||||
class Ftp
|
||||
{
|
||||
public:
|
||||
class User
|
||||
{
|
||||
public:
|
||||
String name;
|
||||
String password;
|
||||
};
|
||||
|
||||
Ftp() : active(false) {}
|
||||
|
||||
bool active;
|
||||
std::list<User> users;
|
||||
};
|
||||
|
||||
Configuration() : callsign("NOCALL-10") {};
|
||||
|
||||
String callsign;
|
||||
Wifi wifi;
|
||||
Beacon beacon;
|
||||
APRS_IS aprs_is;
|
||||
Digi digi;
|
||||
LoRa lora;
|
||||
Display display;
|
||||
Ftp ftp;
|
||||
};
|
||||
|
||||
class ConfigurationManagement
|
||||
{
|
||||
public:
|
||||
explicit ConfigurationManagement(String FilePath);
|
||||
|
||||
Configuration readConfiguration();
|
||||
void writeConfiguration(Configuration conf);
|
||||
|
||||
private:
|
||||
const String mFilePath;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,248 @@
|
|||
#include "logger.h"
|
||||
|
||||
#undef LOG_RESET_COLOR
|
||||
#undef LOG_COLOR_E
|
||||
#undef LOG_COLOR_W
|
||||
#undef LOG_COLOR_I
|
||||
#undef LOG_COLOR_D
|
||||
#undef LOG_COLOR_V
|
||||
|
||||
#define LOG_COLOR_BLACK "30"
|
||||
#define LOG_COLOR_RED "31"
|
||||
#define LOG_COLOR_GREEN "32"
|
||||
#define LOG_COLOR_BROWN "33"
|
||||
#define LOG_COLOR_BLUE "34"
|
||||
#define LOG_COLOR_PURPLE "35"
|
||||
#define LOG_COLOR_CYAN "36"
|
||||
#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
|
||||
#define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
|
||||
#define LOG_RESET_COLOR "\033[0m"
|
||||
#define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
|
||||
#define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
|
||||
#define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
|
||||
#define LOG_COLOR_D LOG_COLOR(LOG_COLOR_BLUE)
|
||||
#define LOG_COLOR_V LOG_COLOR(LOG_COLOR_CYAN)
|
||||
|
||||
Logger::Logger()
|
||||
: _serial(Serial), _level(DEBUG_LEVEL_DEBUG), _printIsNewline(true)
|
||||
{
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::setSerial(const HardwareSerial & serial)
|
||||
{
|
||||
_serial = serial;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::setDebugLevel(debug_level_t level)
|
||||
{
|
||||
_level = level;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printA(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_NONE);
|
||||
printHeader(DEBUG_LEVEL_NONE, file, line, false);
|
||||
_serial.print(text);
|
||||
printEndColor(DEBUG_LEVEL_NONE);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printE(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_ERROR);
|
||||
printHeader(DEBUG_LEVEL_ERROR, file, line, false);
|
||||
_serial.print(text);
|
||||
printEndColor(DEBUG_LEVEL_ERROR);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printlnA(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_NONE);
|
||||
printHeader(DEBUG_LEVEL_NONE, file, line, true);
|
||||
_serial.println(text);
|
||||
printEndColor(DEBUG_LEVEL_NONE);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printlnE(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_ERROR);
|
||||
printHeader(DEBUG_LEVEL_ERROR, file, line, true);
|
||||
_serial.println(text);
|
||||
printEndColor(DEBUG_LEVEL_ERROR);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printV(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
if (_level >= DEBUG_LEVEL_VERBOSE)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_VERBOSE);
|
||||
printHeader(DEBUG_LEVEL_VERBOSE, file, line, false);
|
||||
_serial.print(text);
|
||||
printEndColor(DEBUG_LEVEL_VERBOSE);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printD(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
if (_level >= DEBUG_LEVEL_DEBUG)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_DEBUG);
|
||||
printHeader(DEBUG_LEVEL_DEBUG, file, line, false);
|
||||
_serial.print(text);
|
||||
printEndColor(DEBUG_LEVEL_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printI(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
if (_level >= DEBUG_LEVEL_INFO)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_INFO);
|
||||
printHeader(DEBUG_LEVEL_INFO, file, line, false);
|
||||
_serial.print(text);
|
||||
printEndColor(DEBUG_LEVEL_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printW(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
if (_level >= DEBUG_LEVEL_WARN)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_WARN);
|
||||
printHeader(DEBUG_LEVEL_WARN, file, line, false);
|
||||
_serial.print(text);
|
||||
printEndColor(DEBUG_LEVEL_WARN);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printlnV(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
if (_level >= DEBUG_LEVEL_VERBOSE)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_VERBOSE);
|
||||
printHeader(DEBUG_LEVEL_VERBOSE, file, line, true);
|
||||
_serial.println(text);
|
||||
printEndColor(DEBUG_LEVEL_VERBOSE);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printlnD(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
if (_level >= DEBUG_LEVEL_DEBUG)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_DEBUG);
|
||||
printHeader(DEBUG_LEVEL_DEBUG, file, line, true);
|
||||
_serial.println(text);
|
||||
printEndColor(DEBUG_LEVEL_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printlnI(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
if (_level >= DEBUG_LEVEL_INFO)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_INFO);
|
||||
printHeader(DEBUG_LEVEL_INFO, file, line, true);
|
||||
_serial.println(text);
|
||||
printEndColor(DEBUG_LEVEL_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Logger::printlnW(const String & text, const char * file, uint32_t line)
|
||||
{
|
||||
if (_level >= DEBUG_LEVEL_WARN)
|
||||
{
|
||||
printStartColor(DEBUG_LEVEL_WARN);
|
||||
printHeader(DEBUG_LEVEL_WARN, file, line, true);
|
||||
_serial.println(text);
|
||||
printEndColor(DEBUG_LEVEL_WARN);
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::printStartColor(debug_level_t level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case DEBUG_LEVEL_ERROR:
|
||||
_serial.print(LOG_COLOR_E);
|
||||
break;
|
||||
case DEBUG_LEVEL_WARN:
|
||||
_serial.print(LOG_COLOR_W);
|
||||
break;
|
||||
case DEBUG_LEVEL_INFO:
|
||||
_serial.print(LOG_COLOR_I);
|
||||
break;
|
||||
case DEBUG_LEVEL_DEBUG:
|
||||
_serial.print(LOG_COLOR_D);
|
||||
break;
|
||||
case DEBUG_LEVEL_VERBOSE:
|
||||
_serial.print(LOG_COLOR_V);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::printHeader(debug_level_t level, const char * file, uint32_t line, bool isln)
|
||||
{
|
||||
if (_printIsNewline)
|
||||
{
|
||||
Serial.printf("%c %25s %4d : ", levelToChar(level), file, line);
|
||||
if(!isln)
|
||||
{
|
||||
_printIsNewline = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_printIsNewline = isln;
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::printEndColor(debug_level_t level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case DEBUG_LEVEL_ERROR:
|
||||
case DEBUG_LEVEL_WARN:
|
||||
case DEBUG_LEVEL_INFO:
|
||||
case DEBUG_LEVEL_DEBUG:
|
||||
case DEBUG_LEVEL_VERBOSE:
|
||||
_serial.print(LOG_RESET_COLOR);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char Logger::levelToChar(debug_level_t level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case DEBUG_LEVEL_ERROR:
|
||||
return 'E';
|
||||
case DEBUG_LEVEL_WARN:
|
||||
return 'W';
|
||||
case DEBUG_LEVEL_INFO:
|
||||
return 'I';
|
||||
case DEBUG_LEVEL_DEBUG:
|
||||
return 'D';
|
||||
case DEBUG_LEVEL_VERBOSE:
|
||||
return 'V';
|
||||
default:
|
||||
return ' ';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
#ifndef _LOGGER_H_
|
||||
#define _LOGGER_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
enum debug_level_t {
|
||||
DEBUG_LEVEL_NONE, // No debug output
|
||||
DEBUG_LEVEL_ERROR, // Critical errors
|
||||
DEBUG_LEVEL_WARN, // Error conditions but not critical
|
||||
DEBUG_LEVEL_INFO, // Information messages
|
||||
DEBUG_LEVEL_DEBUG, // Extra information - default level (if not changed)
|
||||
DEBUG_LEVEL_VERBOSE, // More information than the usual
|
||||
DEBUG_LEVELS_SIZE
|
||||
};
|
||||
|
||||
static Logger & instance()
|
||||
{
|
||||
static Logger _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
~Logger() {}
|
||||
|
||||
void setSerial(const HardwareSerial & serial = Serial);
|
||||
void setDebugLevel(debug_level_t level);
|
||||
|
||||
// print always:
|
||||
void printA(const String & text, const char * file, uint32_t line); // always
|
||||
void printE(const String & text, const char * file, uint32_t line); // error
|
||||
void printlnA(const String & text, const char * file, uint32_t line); // always with new line
|
||||
void printlnE(const String & text, const char * file, uint32_t line); // error with new line
|
||||
|
||||
// depending on verbose level:
|
||||
void printV(const String & text, const char * file, uint32_t line); // verbose
|
||||
void printD(const String & text, const char * file, uint32_t line); // debug
|
||||
void printI(const String & text, const char * file, uint32_t line); // information
|
||||
void printW(const String & text, const char * file, uint32_t line); // warning
|
||||
|
||||
void printlnV(const String & text, const char * file, uint32_t line); // verbose with new line
|
||||
void printlnD(const String & text, const char * file, uint32_t line); // debug with new line
|
||||
void printlnI(const String & text, const char * file, uint32_t line); // information with new line
|
||||
void printlnW(const String & text, const char * file, uint32_t line); // warning with new line
|
||||
|
||||
private:
|
||||
HardwareSerial & _serial;
|
||||
debug_level_t _level;
|
||||
bool _printIsNewline;
|
||||
|
||||
void printStartColor(debug_level_t level);
|
||||
void printHeader(debug_level_t level, const char * file, uint32_t line, bool isln);
|
||||
void printEndColor(debug_level_t level);
|
||||
char levelToChar(debug_level_t level);
|
||||
|
||||
Logger();
|
||||
Logger(const Logger &);
|
||||
Logger & operator = (const Logger &);
|
||||
};
|
||||
|
||||
#define logPrintA(text) Logger::instance().printA(text, __FILE__, __LINE__)
|
||||
#define logPrintE(text) Logger::instance().printE(text, __FILE__, __LINE__)
|
||||
#define logPrintlnA(text) Logger::instance().printlnA(text, __FILE__, __LINE__)
|
||||
#define logPrintlnE(text) Logger::instance().printlnE(text, __FILE__, __LINE__)
|
||||
#define logPrintV(text) Logger::instance().printV(text, __FILE__, __LINE__)
|
||||
#define logPrintD(text) Logger::instance().printD(text, __FILE__, __LINE__)
|
||||
#define logPrintI(text) Logger::instance().printI(text, __FILE__, __LINE__)
|
||||
#define logPrintW(text) Logger::instance().printW(text, __FILE__, __LINE__)
|
||||
#define logPrintlnV(text) Logger::instance().printlnV(text, __FILE__, __LINE__)
|
||||
#define logPrintlnD(text) Logger::instance().printlnD(text, __FILE__, __LINE__)
|
||||
#define logPrintlnI(text) Logger::instance().printlnI(text, __FILE__, __LINE__)
|
||||
#define logPrintlnW(text) Logger::instance().printlnW(text, __FILE__, __LINE__)
|
||||
|
||||
#endif
|
|
@ -2,17 +2,17 @@
|
|||
#ifndef SETTINGS_H_
|
||||
#define SETTINGS_H_
|
||||
|
||||
#define CALL "OE5BPA-7"
|
||||
#define BEACON_MESSAGE "LoRa APRS SB Tracker test"
|
||||
#define BEACON_TIMEOUT 1 // Beacon interval in Minutes. Will be overwritten by SB_ACTIVE
|
||||
#define SYMBOL_CODE ">"
|
||||
#define SYMBOL_OVERLAY "/"
|
||||
//#define CALL "DF1OE-12"
|
||||
//#define BEACON_MESSAGE "LoRa APRS SB Tracker test"
|
||||
//#define BEACON_TIMEOUT 1 // Beacon interval in Minutes. Will be overwritten by SB_ACTIVE
|
||||
//#define SYMBOL_CODE "["
|
||||
//#define SYMBOL_OVERLAY "/"
|
||||
|
||||
// Freq and Mode Setup - 2021-02-17 YC1HVZ
|
||||
#define FREQ_SET 433775E3 //set freq in KHz XxxXxxE3 6 digit. E3 is KHz
|
||||
#define SF_SET 12 //Spreading Factor
|
||||
#define CR_SET 5 //Coding Rate
|
||||
#define BW_SET 125E3 //Bandwith -> E3 is khz
|
||||
// #define FREQ_SET 433775E3 //set freq in KHz XxxXxxE3 6 digit. E3 is KHz
|
||||
// #define SF_SET 12 //Spreading Factor
|
||||
// #define CR_SET 5 //Coding Rate
|
||||
// #define BW_SET 125E3 //Bandwith -> E3 is khz
|
||||
|
||||
// SMART BEACONING PARAMETERS - 2020-11-22 DJ1AN
|
||||
#define SB_ACTIVE // uncomment to enable Smart Beaconing
|
||||
|
|
Ładowanie…
Reference in New Issue