diff --git a/README.md b/README.md index 028ec6b..8c635de 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ The global options are: EnableSSDV=. Enables uploading of SSDV image packets to the SSDV server. + EnableHABLink=. Enables uploading of telemetry packets to the hab.link server. + JPGFolder=. Tells the gateway where to save local JPEG files built from incoming SSDV packets. LogTelemetry=. Enables logging of telemetry packets (ASCII only at present) to telemetry.txt. diff --git a/gateway.c b/gateway.c index bbe5a31..bc7e864 100644 --- a/gateway.c +++ b/gateway.c @@ -33,6 +33,7 @@ #include "ssdv.h" #include "ftp.h" #include "habitat.h" +#include "hablink.h" #include "network.h" #include "network.h" #include "global.h" @@ -45,7 +46,7 @@ #include "udpclient.h" #include "lifo_buffer.h" -#define VERSION "V1.8.29" +#define VERSION "V1.8.30" bool run = TRUE; // RFM98 @@ -1059,6 +1060,11 @@ int ProcessTelemetryMessage(int Channel, received_t *Received) } } + if (Config.EnableHablink) + { + SetHablinkSentence(startmessage); + } + tm = localtime( &Received->Metadata.Timestamp ); LogMessage("%02d:%02d:%02d Ch%d: %s%s\n", tm->tm_hour, tm->tm_min, tm->tm_sec, Channel, startmessage, Repeated ? " (repeated)" : ""); @@ -1902,6 +1908,7 @@ void LoadConfigFile(void) // Enable uploads RegisterConfigBoolean(MainSection, -1, "EnableHabitat", &Config.EnableHabitat, NULL); RegisterConfigBoolean(MainSection, -1, "EnableSSDV", &Config.EnableSSDV, NULL); + RegisterConfigBoolean(MainSection, -1, "EnableHablink", &Config.EnableHablink, NULL); // Enable telemetry logging RegisterConfigBoolean(MainSection, -1, "LogTelemetry", &Config.EnableTelemetryLogging, NULL); @@ -2478,7 +2485,7 @@ int main( int argc, char **argv ) int ch; int LoopPeriod, MSPerLoop; int Channel; - pthread_t SSDVThread, FTPThread, NetworkThread, HabitatThread, ServerThread, TelnetThread, ListenerThread, DataportThread, ChatportThread; + pthread_t SSDVThread, FTPThread, NetworkThread, HabitatThread, HablinkThread, ServerThread, TelnetThread, ListenerThread, DataportThread, ChatportThread; struct TServerInfo JSONInfo, TelnetInfo, DataportInfo, ChatportInfo; atexit(bye); @@ -2573,6 +2580,15 @@ int main( int argc, char **argv ) return 1; } } + + if (Config.EnableHablink) + { + if (pthread_create (&HablinkThread, NULL, HablinkLoop, NULL)) + { + fprintf( stderr, "Error creating Hablink thread\n" ); + return 1; + } + } if (Config.ServerPort > 0) { @@ -2763,7 +2779,7 @@ int main( int argc, char **argv ) char Message[200]; Seconds = 0; - sprintf(Message, "GATEWAY:HOST=%s,IP=%s,VER=%s%s\n", Hostname(), GetIPAddress(), VERSION, ChannelInfo()); + sprintf(Message, "GATEWAY:HOST=%s,IP=%s,VER=%s,CALLSIGN=%s%s\n", Hostname(), GetIPAddress(), VERSION, Config.Tracker, ChannelInfo()); UDPSend(Message, Config.UDPPort); } } diff --git a/global.h b/global.h index 0b2256e..79e4a5c 100644 --- a/global.h +++ b/global.h @@ -112,6 +112,7 @@ struct TConfig int EnableHabitat; int EnableSSDV; + int EnableHablink; int EnableTelemetryLogging; int EnablePacketLogging; int CallingTimeout; diff --git a/gra b/gra deleted file mode 100755 index e69de29..0000000 diff --git a/hablink.c b/hablink.c new file mode 100644 index 0000000..e28b13d --- /dev/null +++ b/hablink.c @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hablink.h" +#include "global.h" + +char HablinkSentence[256]; + +void SetHablinkSentence(char *tmp) +{ + strcpy(HablinkSentence, tmp); +} + +void UploadSentence(int sockfd, char *Sentence) +{ + char Message[300]; + + // Create message to upload + sprintf(Message, "POSITION:CALLSIGN=%s,SENTENCE=%s\n", Config.Tracker, Sentence); + + write(sockfd, Message, strlen(Message)); +} + + +int ConnectSocket(char *Host, int Port) +{ + int sockfd; + struct sockaddr_in serv_addr; + + if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + { + return -1; + } + + memset(&serv_addr, '0', sizeof(serv_addr)); + + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(Port); + + if (inet_pton(AF_INET, Host, &serv_addr.sin_addr) <=0) + { + return -1; + } + + if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) + { + return -1; + } + + fcntl(sockfd, F_SETFL, O_NONBLOCK); + + return sockfd; +} + +int StillConnected(int sockfd) +{ + char buf[1]; + int Count; + + Count = read(sockfd, buf, 1); + + return Count != 0; +} + +void *HablinkLoop( void *vars ) +{ + int sockfd; + + sockfd = -1; + + while (1) + { + if (sockfd < 0) + { + LogMessage("Connecting to hab.link ...\n"); + + while (sockfd < 0) + { + sockfd = ConnectSocket("52.56.152.45", 8887); + + if (sockfd >= 0) + { + LogMessage("Connected to hab.link\n"); + } + else + { + sleep(1); + } + } + } + + // Check still connected + if (!StillConnected(sockfd)) + { + LogMessage("Disconnected from hab.link\n"); + close(sockfd); + sockfd = -1; + } + + if ((sockfd >= 0) && HablinkSentence[0]) + { + UploadSentence(sockfd, HablinkSentence); + HablinkSentence[0] = '\0'; + } + + usleep(100000); + } +} diff --git a/hablink.h b/hablink.h new file mode 100644 index 0000000..d57d8f9 --- /dev/null +++ b/hablink.h @@ -0,0 +1,2 @@ +void *HablinkLoop( void *some_void_ptr ); +void SetHablinkSentence(char *tmp); diff --git a/network.c b/network.c index 36d483c..3b8a274 100644 --- a/network.c +++ b/network.c @@ -115,6 +115,6 @@ NetworkLoop( void *some_void_ptr ) // LogMessage("No network :-(\n"); } - sleep( 5 ); + sleep(5); } }