-
Notifications
You must be signed in to change notification settings - Fork 69
/
global.h
257 lines (224 loc) · 5.84 KB
/
global.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#ifndef _H_Global
#define _H_Global
#include <curses.h>
#define RUNNING 1 // The main program is running
#define STOPPED 0 // The main program has stopped
#define MAX_PAYLOADS 32
struct TPayload
{
int InUse;
int SendToClients;
int Channel;
time_t LastPacketAt;
char Telemetry[256];
char Payload[32];
char Time[12];
unsigned int Counter, LastCounter;
double Longitude, Latitude;
int Altitude, PreviousAltitude;
float AscentRate;
unsigned long LastPositionAt;
int PacketSNR, PacketRSSI;
double Frequency;
};
struct TLoRaDevice
{
int Enabled;
double Frequency;
double PPM;
double FrequencyOffset;
double Bandwidth;
double CurrentBandwidth;
int InUse;
int DIO0;
int DIO5;
int AFC; // Enable Automatic Frequency Control
double MaxAFCStep; // Maximum adjustment, in kHz, per packet
int AFCTimeout; // Revert to original frequency if no packets for this period (in seconds)
int SpeedMode;
int Power;
int PayloadLength;
int ImplicitOrExplicit;
int ErrorCoding;
int SpreadingFactor;
int LowDataRateOptimize;
WINDOW * Window;
unsigned int TelemetryCount, SSDVCount, BadCRCCount, UnknownCount;
int Sending;
// unsigned long Seconds;
// double PredictedLongitude, PredictedLatitude;
// unsigned int Satellites;
time_t LastSSDVPacketAt, LastTelemetryPacketAt;
time_t ReturnToCallingModeAt;
time_t ReturnToOriginalFrequencyAt;
int InCallingMode;
int ActivityLED;
double UplinkFrequency;
int UplinkMode;
// Normal (non TDM) uplink
int UplinkTime;
int UplinkCycle;
int IdleUplink;
int SSDVUplink;
char UplinkMessage[256];
// Telnet uplink
char Telemetry[256];
unsigned char PacketID;
int TimeSinceLastTx;
int HABAck; // Received message ACKd our last Tx
int HABConnected; // 1 if HAB has telnet connection
char ToTelnetBuffer[256]; // Buffer for data Telnet --> LoRa
int ToTelnetBufferCount;
char FromTelnetBuffer[256]; // Buffer for data LoRa --> Telnet
int FromTelnetBufferCount;
char HABUplink[256];
int HABUplinkCount;
int GotHABReply;
int GotReply;
// Chat uplink
int ChatMode;
char ChatPayloadID[32];
int TxMessageID;
char TxChatMessage[200];
int RxMessageID;
char RxChatMessage[200];
// 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, altitude; // Receiver's location
int EnableSSDV;
int EnableSondehub;
int EnableTelemetryLogging;
int EnablePacketLogging;
int CallingTimeout;
char SSDVJpegFolder[100];
char ftpServer[100];
char ftpUser[32];
char ftpPassword[32];
char ftpFolder[64];
struct TLoRaDevice LoRaDevices[2];
struct TPayload Payloads[MAX_PAYLOADS];
int NetworkLED;
int InternetLED;
int ServerPort; // JSON port for telemetry, settings
int ChatPort; // Chat port
int UDPPort; // UDP Broadcast port for raw received data packets
int OziPlotterPort; // UDP Broadcast port for OziPlotter formatted packets
int OziMuxPort; // UDP Broadcast port for OziMux formatted packets
int HABPort; // Telnet style port for comms with HAB
int HABTimeout; // Timeout in ms for telnet uplink
int HABChannel; // LoRa Channel for uplink
int DataPort; // Raw received data packet port
char SMSFolder[64];
char radio[64];
char antenna[64];
int EnableDev;
char UplinkCode[64];
char Version[16];
int DumpBuffer;
char DumpFile[64];
int EnableMQTT;
char MQTTHost[128];
char MQTTPort[8];
char MQTTUser[16];
char MQTTPass[32];
char MQTTTopic[128];
};
typedef struct {
int parent_status;
unsigned long packet_count;
} thread_shared_vars_t;
typedef struct {
/* Rx Metadata */
short int Channel;
time_t Timestamp;
double Frequency;
double FrequencyError;
int ImplicitOrExplicit;
double Bandwidth;
int ErrorCoding;
int SpreadingFactor;
int LowDataRateOptimize;
int SNR;
int RSSI;
} rx_metadata_t;
/* HABpack Telemetry Storage */
typedef enum { HB_VALUE_INTEGER, HB_VALUE_REAL, HB_VALUE_STRING } HB_Value_Type;
typedef struct habpack_telem_linklist_entry {
uint32_t type;
char name[32];
HB_Value_Type value_type;
union {
int64_t integer;
double real;
char *string;
} value;
struct habpack_telem_linklist_entry *next;
} habpack_telem_linklist_entry_t;
typedef struct {
/* Core Telemetry */
char Callsign[32];
uint64_t SentenceId;
uint64_t Time;
char TimeString[9];
double Latitude;
double Longitude;
int64_t Altitude;
/* Calling Beacon Values */
uint64_t DownlinkFrequency;
int64_t DownlinkLoraMode;
int DownlinkLoraImplicit;
int DownlinkLoraErrorCoding;
double DownlinkLoraBandwidth;
int DownlinkLoraSpreadingFactor;
int DownlinkLoraLowDatarateOptimise;
/* Linked list of additional telem fields */
habpack_telem_linklist_entry_t *habpack_extra;
} rx_telemetry_t;
#define Message_length 257
#define UKHASstring_length 257
typedef struct {
char Message[Message_length];
int Bytes;
/* UKHAS ASCII Telemetry String for habitat upload */
char UKHASstring[UKHASstring_length];
char HabitatString[UKHASstring_length];
bool isCallingBeacon;
double AscentRate;
/* Telemetry values */
rx_telemetry_t Telemetry;
rx_metadata_t Metadata;
} received_t;
typedef struct {
short int Channel;
char SSDV_Packet[257];
int Packet_Number;
} ssdv_t;
typedef struct {
char host[128];
char port[8];
char user[16];
char pass[32];
char clientId[16];
char topic[128];
} mqtt_connect_t;
struct TServerInfo
{
int Port;
int Connected;
int ServerIndex;
int sockfd;
};
extern struct TConfig Config;
extern int SSDVSendArrayIndex;
extern pthread_mutex_t ssdv_mutex;
void LogMessage( const char *format, ... );
#endif /* _H_Global */