kopia lustrzana https://github.com/PiInTheSky/lora-gateway
Skip extra $'s at start of telemetry; work with missing LF from end of telemetry
rodzic
fdda19099d
commit
a9ca0103d8
39
gateway.c
39
gateway.c
|
@ -35,7 +35,7 @@
|
|||
#include "config.h"
|
||||
#include "gui.h"
|
||||
|
||||
#define VERSION "V1.8.7"
|
||||
#define VERSION "V1.8.8"
|
||||
bool run = TRUE;
|
||||
|
||||
// RFM98
|
||||
|
@ -941,7 +941,6 @@ void ProcessTelemetryMessage(int Channel, char *Message)
|
|||
if (strlen(Message + 1) < 250)
|
||||
{
|
||||
char *startmessage, *endmessage;
|
||||
|
||||
char telem[40];
|
||||
char buffer[40];
|
||||
|
||||
|
@ -951,8 +950,9 @@ void ProcessTelemetryMessage(int Channel, char *Message)
|
|||
sprintf(buffer,"%-37s", telem );
|
||||
ChannelPrintf( Channel, 3, 1, buffer);
|
||||
|
||||
startmessage = Message;
|
||||
startmessage = Message + strspn(Message, "$") - 2;
|
||||
endmessage = strchr( startmessage, '\n' );
|
||||
if (endmessage == NULL) endmessage = strchr(startmessage, 0);
|
||||
|
||||
while ( endmessage != NULL )
|
||||
{
|
||||
|
@ -1593,6 +1593,8 @@ void LoadConfigFile(void)
|
|||
Config.LoRaDevices[Channel].AFC = FALSE;
|
||||
Config.LoRaDevices[Channel].Power = PA_MAX_UK;
|
||||
Config.LoRaDevices[Channel].UplinkMode = -1;
|
||||
Config.LoRaDevices[Channel].UplinkTime = -1;
|
||||
Config.LoRaDevices[Channel].UplinkCycle = -1;
|
||||
|
||||
LogMessage( "Channel %d frequency set to %.3lfMHz\n", Channel, Config.LoRaDevices[Channel].Frequency);
|
||||
Config.LoRaDevices[Channel].InUse = 1;
|
||||
|
@ -1606,16 +1608,19 @@ void LoadConfigFile(void)
|
|||
// Uplink
|
||||
RegisterConfigInteger(MainSection, Channel, "UplinkTime", &Config.LoRaDevices[Channel].UplinkTime, NULL);
|
||||
RegisterConfigInteger(MainSection, Channel, "UplinkCycle", &Config.LoRaDevices[Channel].UplinkCycle, NULL);
|
||||
if ((Config.LoRaDevices[Channel].UplinkTime > 0) && (Config.LoRaDevices[Channel].UplinkCycle))
|
||||
if ((Config.LoRaDevices[Channel].UplinkTime >= 0) && (Config.LoRaDevices[Channel].UplinkCycle > Config.LoRaDevices[Channel].UplinkTime))
|
||||
{
|
||||
LogMessage( "Channel %d UplinkTime %d Uplink Cycle %d\n", Channel, Config.LoRaDevices[Channel].UplinkTime, Config.LoRaDevices[Channel].UplinkCycle);
|
||||
|
||||
|
||||
RegisterConfigInteger(MainSection, Channel, "Power", &Config.LoRaDevices[Channel].Power, NULL);
|
||||
|
||||
|
||||
LogMessage( "Channel %d power set to %02Xh\n", Channel, Config.LoRaDevices[Channel].Power );
|
||||
RegisterConfigBoolean(MainSection, Channel, "SSDVUplink", &Config.LoRaDevices[Channel].SSDVUplink, NULL);
|
||||
}
|
||||
|
||||
RegisterConfigInteger(MainSection, Channel, "Power", &Config.LoRaDevices[Channel].Power, NULL);
|
||||
if ((Config.LoRaDevices[Channel].UplinkTime > 0) && (Config.LoRaDevices[Channel].UplinkCycle))
|
||||
{
|
||||
LogMessage( "Channel %d power set to %02Xh\n", Channel, Config.LoRaDevices[Channel].Power );
|
||||
}
|
||||
|
||||
RegisterConfigInteger(MainSection, Channel, "UplinkMode", &Config.LoRaDevices[Channel].UplinkMode, NULL);
|
||||
if (Config.LoRaDevices[Channel].UplinkMode >= 0)
|
||||
|
@ -1950,20 +1955,13 @@ GetExternalListOfMissingSSDVPackets( int Channel, char *Message )
|
|||
// First, create request file
|
||||
FILE *fp;
|
||||
|
||||
// LogMessage("GetExternalListOfMissingSSDVPackets()\n");
|
||||
|
||||
// if ((fp = fopen("get_list.txt", "wt")) != NULL)
|
||||
if (Config.LoRaDevices[Channel].SSDVUplink)
|
||||
{
|
||||
int i;
|
||||
|
||||
// fprintf(fp, "No Message\n");
|
||||
// fclose(fp);
|
||||
|
||||
// LogMessage("File created\n");
|
||||
|
||||
// Now wait for uplink.txt file to appear.
|
||||
// Timeout before the end of our Tx slot if no file appears
|
||||
|
||||
|
||||
for ( i = 0; i < 20; i++ )
|
||||
{
|
||||
if ( ( fp = fopen( "uplink.txt", "r" ) ) )
|
||||
|
@ -1997,7 +1995,12 @@ void SendUplinkMessage( int Channel )
|
|||
char Message[512];
|
||||
|
||||
// Decide what type of message we need to send
|
||||
if ( GetTextMessageToUpload( Channel, Message ) )
|
||||
if (*Config.LoRaDevices[Channel].UplinkMessage)
|
||||
{
|
||||
SendLoRaData(Channel, Config.LoRaDevices[Channel].UplinkMessage, strlen(Config.LoRaDevices[Channel].UplinkMessage)+1);
|
||||
*Config.LoRaDevices[Channel].UplinkMessage = 0;
|
||||
}
|
||||
else if ( GetTextMessageToUpload( Channel, Message ) )
|
||||
{
|
||||
SendLoRaData( Channel, Message, 255 );
|
||||
}
|
||||
|
|
5
global.h
5
global.h
|
@ -54,7 +54,9 @@ struct TPayload
|
|||
|
||||
// Normal (non TDM) uplink
|
||||
int UplinkTime;
|
||||
int UplinkCycle;
|
||||
int UplinkCycle;
|
||||
int SSDVUplink;
|
||||
char UplinkMessage[256];
|
||||
};
|
||||
struct TConfig
{
char Tracker[16]; // Callsign or name of receiver
|
||||
double latitude, longitude; // Receiver's location
|
||||
|
@ -76,6 +78,7 @@ struct TPayload
|
|||
char SMSFolder[64];
|
||||
char antenna[64];
|
||||
int EnableDev;
|
||||
char UplinkCode[64];
|
||||
};
|
||||
typedef struct {
|
||||
int parent_status;
|
||||
|
|
79
server.c
79
server.c
|
@ -24,15 +24,62 @@
|
|||
|
||||
extern bool run;
|
||||
|
||||
void EncryptMessage(char *Code, char *Message)
|
||||
{
|
||||
int i, Len;
|
||||
|
||||
Len = strlen(Code);
|
||||
|
||||
if (Len > 0)
|
||||
{
|
||||
i = 0;
|
||||
while (*Message)
|
||||
{
|
||||
*Message = (*Message ^ Code[i]) | 0x80;
|
||||
Message++;
|
||||
i = (i + 1) % Len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessJSONClientLine(int connfd, char *line)
|
||||
{
|
||||
line[strcspn(line, "\r\n")] = '\0'; // Get rid of CR LF
|
||||
|
||||
LogMessage("Received %s from JSON client\n", line);
|
||||
LogMessage("Received '%s' from JSON client\n", line);
|
||||
|
||||
if (strchr(line, '=') == NULL)
|
||||
if (strchr(line, '=') != NULL)
|
||||
{
|
||||
// Request or command
|
||||
// Setting
|
||||
char *setting, *value, *saveptr;
|
||||
|
||||
setting = strtok_r(line, "=", &saveptr);
|
||||
value = strtok_r( NULL, "\n", &saveptr);
|
||||
|
||||
SetConfigValue(setting, value);
|
||||
}
|
||||
else if (strchr(line, ':') != NULL)
|
||||
{
|
||||
// Command with parameters
|
||||
char *command, *value, *saveptr;
|
||||
|
||||
command = strtok_r(line, ":", &saveptr);
|
||||
value = strtok_r(NULL, "\n", &saveptr);
|
||||
|
||||
if (strcasecmp(command, "send") == 0)
|
||||
{
|
||||
LogMessage("Message '%s' to send\n", value);
|
||||
|
||||
EncryptMessage(Config.UplinkCode, value+1); // +1 so we don't encode the key byt at the start of the message
|
||||
|
||||
strcpy(Config.LoRaDevices[1].UplinkMessage, value);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
// single-word request
|
||||
|
||||
|
||||
if (strcasecmp(line, "settings") == 0)
|
||||
{
|
||||
|
@ -66,18 +113,19 @@ void ProcessJSONClientLine(int connfd, char *line)
|
|||
SaveConfigFile();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Setting
|
||||
char *setting, *value, *saveptr;
|
||||
|
||||
setting = strtok_r(line, "=", &saveptr);
|
||||
value = strtok_r( NULL, "\n", &saveptr);
|
||||
|
||||
SetConfigValue(setting, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int SendJSON(int connfd)
|
||||
{
|
||||
int PayloadIndex, port_closed;
|
||||
|
@ -90,7 +138,7 @@ int SendJSON(int connfd)
|
|||
{
|
||||
if (Config.Payloads[PayloadIndex].InUse)
|
||||
{
|
||||
sprintf(sendBuff, "{\"class\":\"POSN\",\"index\":%d,\"channel\":%d,\"payload\":\"%s\",\"time\":\"%s\",\"lat\":%.5lf,\"lon\":%.5lf,\"alt\":%d,\"rate\":%.1lf}\r\n",
|
||||
sprintf(sendBuff, "{\"class\":\"POSN\",\"index\":%d,\"channel\":%d,\"payload\":\"%s\",\"time\":\"%s\",\"lat\":%.5lf,\"lon\":%.5lf,\"alt\":%d,\"rate\":%.1lf,\"sentence\":\"%s\"}\r\n",
|
||||
PayloadIndex,
|
||||
Config.Payloads[PayloadIndex].Channel,
|
||||
Config.Payloads[PayloadIndex].Payload,
|
||||
|
@ -98,7 +146,8 @@ int SendJSON(int connfd)
|
|||
Config.Payloads[PayloadIndex].Latitude,
|
||||
Config.Payloads[PayloadIndex].Longitude,
|
||||
Config.Payloads[PayloadIndex].Altitude,
|
||||
Config.Payloads[PayloadIndex].AscentRate);
|
||||
Config.Payloads[PayloadIndex].AscentRate,
|
||||
Config.Payloads[PayloadIndex].Telemetry);
|
||||
|
||||
if ( !run )
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@ def get_list_of_missing_packets(PayloadID, Minutes):
|
|||
result = ''
|
||||
|
||||
time_limit = datetime.utcnow() - timedelta(0,Minutes*60) # n minutes ago
|
||||
url = 'http://ssdv.habhub.org/api/v0/images?callsign=' + PayloadID + '&from=' + time_limit.strftime('%Y-%m-%dT%H:%M:%SZ') + '&missing_packets'
|
||||
url = 'http://ssdv.habhub.org/api/v0/images?callsign=' + PayloadID + '&from=' + time_limit.strftime('%Y-%m-%dT%H:%M:%SZ') + '&missing_packets=true'
|
||||
|
||||
print("url", url)
|
||||
|
||||
|
@ -31,7 +31,7 @@ def get_list_of_missing_packets(PayloadID, Minutes):
|
|||
if len(item['missing_packets']) > 0:
|
||||
print(item['id'], item['image_id'], len(item['missing_packets']))
|
||||
print(item['missing_packets'])
|
||||
pl = item['packets']
|
||||
# pl = item['packets']
|
||||
# print("highest_packet_id = ", item['last_packet'])
|
||||
first_missing_packet = -1
|
||||
last_missing_packet = -1
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
!3:278=134,269
|
||||
|
Ładowanie…
Reference in New Issue