V1.8.18 - Reprogram LoRa module when relevant settings are changed via JSON port

pull/48/head
Dave Akerman 2018-04-10 23:18:23 +00:00
rodzic 75a5748d63
commit e26c4fd441
7 zmienionych plików z 101 dodań i 148 usunięć

Wyświetl plik

@ -228,10 +228,20 @@ Change History
==============
11/04/2018 - V1.8.18
--------------------
JSON port now sends packet SNR, RSSI and frequency error
Implemented callbacks for when settings are changed
Reprogram LoRa module when frequency, bandwidth etc are changed via JSON port
Update display when frequency, bandwidth, AFC etc are changed via JSON port
10/04/2018 - V1.8.17
--------------------
JSON port only sends telemetry as it is received, instead of repeatedly
JSON port now sends current RSSI
Append \r\n to sentences sent to data port
JSON port now accepts commands split over multiple packets (e.g. typed commands)
When saving to gateway.txt, permissions are set to RW/RW/RW, and owner/group are maintained

Wyświetl plik

@ -91,7 +91,7 @@ int RegisterConfigDouble(int SectionIndex, int Index, char *Name, double *Double
strcpy(Settings[SettingIndex].ValueName, Name);
Settings[SettingIndex].SettingType = stDouble;
Settings[SettingIndex].DoubleValuePtr = DoubleValuePtr;
// Settings[SettingIndex].Callback = Callback;
Settings[SettingIndex].Callback = Callback;
ReadConfigValue(SettingIndex);
}
@ -113,7 +113,7 @@ int RegisterConfigInteger(int SectionIndex, int Index, char *Name, int *IntValue
strcpy(Settings[SettingIndex].ValueName, Name);
Settings[SettingIndex].SettingType = stInteger;
Settings[SettingIndex].IntValuePtr = IntValuePtr;
// Settings[SettingIndex].Callback = Callback;
Settings[SettingIndex].Callback = Callback;
return ReadConfigValue(SettingIndex);
}
@ -135,7 +135,7 @@ int RegisterConfigBoolean(int SectionIndex, int Index, char *Name, int *BoolValu
strcpy(Settings[SettingIndex].ValueName, Name);
Settings[SettingIndex].SettingType = stBoolean;
Settings[SettingIndex].IntValuePtr = BoolValuePtr;
// Settings[SettingIndex].Callback = Callback;
Settings[SettingIndex].Callback = Callback;
return ReadConfigValue(SettingIndex);
}
@ -144,7 +144,7 @@ int RegisterConfigBoolean(int SectionIndex, int Index, char *Name, int *BoolValu
return 0;
}
int RegisterConfigString(int SectionIndex, int Index, char *Name, char *StringValuePtr, int MaxValueLength, void (Callback)(int))
int RegisterConfigString(int SectionIndex, int Index, char *Name, char *StringValuePtr, int MaxValueLength, void (*Callback)(int))
{
if ((SectionIndex >= 0) && (SectionIndex < SectionCount))
{
@ -158,7 +158,7 @@ int RegisterConfigString(int SectionIndex, int Index, char *Name, char *StringVa
Settings[SettingIndex].SettingType = stString;
Settings[SettingIndex].StringValuePtr = StringValuePtr;
Settings[SettingIndex].MaxValueLength = MaxValueLength;
// Settings[SettingIndex].Callback = Callback;
Settings[SettingIndex].Callback = Callback;
return ReadConfigValue(SettingIndex);
}
@ -362,6 +362,11 @@ void SetConfigValue(char *Setting, char *Value)
case stNone:
break;
}
if (Settings[SettingIndex].Callback != NULL)
{
Settings[SettingIndex].Callback(Settings[SettingIndex].Index);
}
}
}
@ -401,4 +406,5 @@ int SettingAsString(int SettingIndex, char *SettingName, int SettingNameSize, ch
}
return 0;
}
}

Wyświetl plik

@ -10,7 +10,7 @@ struct TSetting
int *IntValuePtr;
double *DoubleValuePtr;
int MaxValueLength;
// void (Callback)(int);
void (*Callback)(int);
};
void RegisterConfigFile(char *Filename);
@ -20,6 +20,7 @@ int RegisterConfigInteger(int SectionIndex, int Index, char *Name, int *IntValue
int RegisterConfigDouble(int SectionIndex, int Index, char *Name, double *DoubleValuePtr, void (Callback)(int));
int RegisterConfigBoolean(int SectionIndex, int Index, char *Name, int *BoolValuePtr, void (Callback)(int));
int ReadConfigValue(int SettingIndex);
int ConfigSettingChannel(int SettingIndex);
void SetConfigValue(char *Setting, char *Value);
int SettingAsString(int SettingIndex, char *SettingName, int SettingNameSize, char *SettingValue, int SettingValueSize);
void SaveConfigFile(void);

Wyświetl plik

@ -38,7 +38,7 @@
#include "listener.h"
#include "udpclient.h"
#define VERSION "V1.8.17"
#define VERSION "V1.8.18"
bool run = TRUE;
// RFM98
@ -490,13 +490,11 @@ void displayFrequency ( int Channel, double Frequency )
void setLoRaMode( int Channel )
{
// LogMessage("Setting LoRa Mode\n");
setMode( Channel, RF98_MODE_SLEEP );
writeRegister( Channel, REG_OPMODE, 0x80 );
setMode( Channel, RF98_MODE_SLEEP );
// LogMessage("Set Default Frequency\n");
setFrequency( Channel, Config.LoRaDevices[Channel].Frequency);
}
@ -1438,6 +1436,10 @@ receiveMessage( int Channel, char *message, rx_metadata_t *Metadata )
FreqError = FrequencyError( Channel ) / 1000;
ChannelPrintf( Channel, 11, 1, "Freq. Error = %5.1lfkHz ", FreqError);
Config.LoRaDevices[Channel].PacketSNR = Metadata->SNR;
Config.LoRaDevices[Channel].PacketRSSI = Metadata->RSSI;
Config.LoRaDevices[Channel].FrequencyError = FreqError;
writeRegister( Channel, REG_FIFO_ADDR_PTR, currentAddr );
@ -1498,6 +1500,20 @@ void RemoveTrailingSlash(char *Value)
}
}
void LoRaCallback(int Index)
{
setLoRaMode(Index);
SetDefaultLoRaParameters(Index);
startReceiving(Index);
}
void MiscCallback(int Index)
{
displayChannel(Index);
}
void LoadConfigFile(void)
{
FILE *fp;
@ -1621,7 +1637,7 @@ void LoadConfigFile(void)
for (Channel = 0; Channel <= 1; Channel++)
{
RegisterConfigDouble(MainSection, Channel, "frequency", &Config.LoRaDevices[Channel].Frequency, NULL);
RegisterConfigDouble(MainSection, Channel, "frequency", &Config.LoRaDevices[Channel].Frequency, LoRaCallback);
if (Config.LoRaDevices[Channel].Frequency > 100)
{
// Defaults
@ -1697,26 +1713,26 @@ void LoadConfigFile(void)
Config.LoRaDevices[Channel].LowDataRateOptimize = LowOptToInt(LoRaModes[Config.LoRaDevices[Channel].SpeedMode].LowDataRateOptimize);
// Overrides
if (RegisterConfigInteger(MainSection, Channel, "sf", &Config.LoRaDevices[Channel].SpreadingFactor, NULL))
if (RegisterConfigInteger(MainSection, Channel, "sf", &Config.LoRaDevices[Channel].SpreadingFactor, LoRaCallback))
{
LogMessage( "Setting SF=%d\n", Config.LoRaDevices[Channel].SpreadingFactor);
}
if (RegisterConfigDouble(MainSection, Channel, "bandwidth", &Config.LoRaDevices[Channel].Bandwidth, NULL))
if (RegisterConfigDouble(MainSection, Channel, "bandwidth", &Config.LoRaDevices[Channel].Bandwidth, LoRaCallback))
{
LogMessage( "Setting Bandwidth=%.2lfkHz\n", Config.LoRaDevices[Channel].Bandwidth);
}
RegisterConfigBoolean(MainSection, Channel, "implicit", &Config.LoRaDevices[Channel].ImplicitOrExplicit, NULL);
RegisterConfigBoolean(MainSection, Channel, "implicit", &Config.LoRaDevices[Channel].ImplicitOrExplicit, LoRaCallback);
if (RegisterConfigInteger(MainSection, Channel, "coding", &Config.LoRaDevices[Channel].ErrorCoding, NULL))
if (RegisterConfigInteger(MainSection, Channel, "coding", &Config.LoRaDevices[Channel].ErrorCoding, LoRaCallback))
{
LogMessage( "Setting Error Coding=%d\n", Config.LoRaDevices[Channel].ErrorCoding);
}
RegisterConfigBoolean(MainSection, Channel, "lowopt", &Config.LoRaDevices[Channel].LowDataRateOptimize, NULL);
RegisterConfigBoolean(MainSection, Channel, "lowopt", &Config.LoRaDevices[Channel].LowDataRateOptimize, LoRaCallback);
RegisterConfigBoolean(MainSection, Channel, "AFC", &Config.LoRaDevices[Channel].AFC, NULL);
RegisterConfigBoolean(MainSection, Channel, "AFC", &Config.LoRaDevices[Channel].AFC, MiscCallback);
if (Config.LoRaDevices[Channel].AFC)
{
ChannelPrintf( Channel, 11, 24, "AFC" );
@ -2357,11 +2373,12 @@ int main( int argc, char **argv )
for (Channel=0; Channel<=1; Channel++)
{
if ( Config.LoRaDevices[Channel].InUse )
if (Config.LoRaDevices[Channel].InUse)
{
ShowPacketCounts( Channel );
ChannelPrintf( Channel, 12, 1, "Current RSSI = %4d ", CurrentRSSI(Channel));
Config.LoRaDevices[Channel].CurrentRSSI = CurrentRSSI(Channel);
ChannelPrintf( Channel, 12, 1, "Current RSSI = %4d ", Config.LoRaDevices[Channel].CurrentRSSI);
// Calling mode timeout?
if ( Config.LoRaDevices[Channel].InCallingMode

Wyświetl plik

@ -1,110 +0,0 @@
tracker=M0RPI
EnableHabitat=N
EnableSSDV=N
JPGFolder=ssdv
LogTelemetry=Y
CallingTimeout=60
ServerPort=6004
DataPort=6006
UDPPort=55671
OziPort=55672
# Telnet settings
# HABPort=6005
# HABChannel=1
Latitude=51.950230
Longitude=-2.544500
Antenna=Sigma X-30
#SMSFolder=./
# UplinkCode=DAVE
#NetworkLED=21
#InternetLED=22
#ActivityLED_0=23
#ActivityLED_1=24
#----------------- HARDWARE
DIO0_0=31
DIO5_0=26
DIO0_1=6
DIO5_1=5
#----------------- CHANNEL 0
# Standard Fast SSDV
# frequency_0=869.850
mode_0=3
AFC_0=N
# UplinkTime_0=1
# UplinkCycle_0=60
# UplinkFrequency_0=869.5
# UplinkMode_0=2
# Power_0=143
# SSDVUplink_0=Y
# ----------------- CHANNEL 1
# BUZZ
# frequency_1=434.450
# mode_1=2
# AFC_1=N
# RTLS1
frequency_1=434.450000
mode_1=2
SF_1=7
AFC_1=N
# RTLS2 / 3
# frequency_1=434.225
# mode_1=2
# AFC_1=N
# BRUCE
# frequency_1=434.231
# mode_1=1
# AFC_1=Y
# X0
# frequency_1=434.410
# mode_1=0
# WB-L
# frequency_1=434.454
# mode_1=1
# AFC_1=Y
# Testing
# frequency_1=434.455
# mode_1=1
# TDM settings
# frequency_1=433.705
# mode_1=2
# UplinkTime_1=0
# UplinkCycle_1=10
# IdleUplink_1=Y
# SSDV Repeating settings
# frequency_1=434.231
# mode_1=8
# Telnet settings
# frequency_1=434.228
# mode_1=7
# RTLS settings
# frequency_1=434.228
# mode_1=2
# BOUY settings
# frequency_1=434.4543
# mode_1=1
#AFC_1=N
#UplinkTime_1=0
#UplinkCycle_1=10
#SSDVUplink=Y

Wyświetl plik

@ -24,7 +24,7 @@ struct TPayload
double Longitude, Latitude;
unsigned int Altitude, PreviousAltitude;
float AscentRate;
unsigned long LastPositionAt;
unsigned long LastPositionAt;
}; struct TLoRaDevice {
double Frequency;
double Bandwidth;
@ -81,6 +81,11 @@ struct TPayload
// Local data packets
int LocalDataCount;
char LocalDataBuffer[255];
// Status
int CurrentRSSI;
int PacketSNR, PacketRSSI;
double FrequencyError;
};
struct TConfig { char Tracker[16]; // Callsign or name of receiver
double latitude, longitude; // Receiver's location

Wyświetl plik

@ -21,6 +21,7 @@
#include "server.h"
#include "config.h"
#include "global.h"
#include "gateway.h"
extern bool run;
@ -121,40 +122,63 @@ void ProcessJSONClientLine(int connfd, char *line)
int SendJSON(int connfd)
{
int PayloadIndex, port_closed;
char sendBuff[1025];
int Channel, PayloadIndex, port_closed;
char sendBuff[4000], line[400];
port_closed = 0;
memset( sendBuff, '0', sizeof( sendBuff ) );
sendBuff[0] = '\0';
// Send any packets that we've not sent yet
for (PayloadIndex=0; PayloadIndex<MAX_PAYLOADS; PayloadIndex++)
{
if (Config.Payloads[PayloadIndex].InUse && Config.Payloads[PayloadIndex].SendToClients)
{
sprintf(sendBuff, "{\"class\":\"POSN\",\"index\":%d,\"channel\":%d,\"payload\":\"%s\",\"time\":\"%s\",\"lat\":%.5lf,\"lon\":%.5lf,\"alt\":%d,\"rate\":%.1lf,\"sentence\":\"%s\"}\r\n",
Channel = Config.Payloads[PayloadIndex].Channel;
sprintf(line, "{\"class\":\"POSN\",\"index\":%d,\"channel\":%d,\"payload\":\"%s\",\"time\":\"%s\",\"lat\":%.5lf,\"lon\":%.5lf,\"alt\":%d,\"rate\":%.1lf,\"snr\":%d,\"rssi\":%d,\"ferr\":%.1lf,\"sentence\":\"%s\"}\r\n",
PayloadIndex,
Config.Payloads[PayloadIndex].Channel,
Channel,
Config.Payloads[PayloadIndex].Payload,
Config.Payloads[PayloadIndex].Time,
Config.Payloads[PayloadIndex].Latitude,
Config.Payloads[PayloadIndex].Longitude,
Config.Payloads[PayloadIndex].Altitude,
Config.Payloads[PayloadIndex].AscentRate,
Config.LoRaDevices[Channel].PacketSNR,
Config.LoRaDevices[Channel].PacketRSSI,
Config.LoRaDevices[Channel].FrequencyError,
Config.Payloads[PayloadIndex].Telemetry);
if (!run)
{
port_closed = 1;
}
else if (send(connfd, sendBuff, strlen(sendBuff), MSG_NOSIGNAL ) <= 0)
{
LogMessage( "Disconnected from client\n" );
port_closed = 1;
}
else
{
Config.Payloads[PayloadIndex].SendToClients = 0;
}
strcat(sendBuff, line);
Config.Payloads[PayloadIndex].SendToClients = 0;
}
}
// Send Channel Status (RSSI only at present)
for (Channel=0; Channel<=1; Channel++)
{
if (Config.LoRaDevices[Channel].InUse)
{
sprintf(line, "{\"class\":\"STATS\",\"index\":%d,\"rssi\":%d}\r\n",
Channel,
Config.LoRaDevices[Channel].CurrentRSSI);
strcat(sendBuff, line);
}
}
if (!run)
{
port_closed = 1;
}
else if (sendBuff[0])
{
if (send(connfd, sendBuff, strlen(sendBuff), MSG_NOSIGNAL ) <= 0)
{
LogMessage( "Disconnected from client\n" );
port_closed = 1;
}
}