-
Notifications
You must be signed in to change notification settings - Fork 6
/
ssdv.ino
93 lines (78 loc) · 2.86 KB
/
ssdv.ino
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
/***********************************************************************************
* SSDV related stuff
***********************************************************************************/
#define SSDV_MAX_CALLSIGN (6) /* Maximum number of characters in a callsign */
// Struct to hold LoRA settings
struct TSSDVSettings
{
char callsign[SSDV_MAX_CALLSIGN+1];
uint8_t imageID;
uint16_t packetID;
} SSDVSettings;
/***********************************************************************************
* Process the received SSDV packet
***********************************************************************************/
void processSSDVPacket(byte *buf)
{
uint32_t callsign_code;
// Decode the callsign, which should be bytes 1, 2, 3 and 4 in BASE40 format.
callsign_code = (buf[1] * 256 * 256 * 256) + (buf[2] * 256 * 256) + (buf[3] * 256) + buf[4];
decode_callsign(SSDVSettings.callsign, callsign_code);
Telemetry.payload_callsign = SSDVSettings.callsign;
// Decode the image ID
SSDVSettings.imageID = buf[5];
SSDVSettings.packetID = buf[6]*256 + buf[7];
Telemetry.raw = "SSDV packet - callsign: ";
Telemetry.raw += SSDVSettings.callsign;
Telemetry.raw += " image ID: ";
Telemetry.raw += SSDVSettings.imageID;
Telemetry.raw += " packet ID: ";
Telemetry.raw += SSDVSettings.packetID;
Serial.println(Telemetry.raw);
}
/***********************************************************************************
* Decodes the callsign in the packet. BASE40 decode
***********************************************************************************/
static char *decode_callsign(char *callsign, uint32_t code)
{
char *c, s;
*callsign = '\0';
/* Is callsign valid? */
if(code > 0xF423FFFF) return(callsign);
for(c = callsign; code; c++)
{
s = code % 40;
if(s == 0) *c = '-';
else if(s < 11) *c = '0' + s - 1;
else if(s < 14) *c = '-';
else *c = 'A' + s - 14;
code /= 40;
}
*c = '\0';
return(callsign);
}
/************************************************************************************
// Put the SSDV packet into the SSDV queue
************************************************************************************/
void postSSDVinQueue( byte* buf)
{
char packetBuf[256]; // Contains the hex encoded packet
// Put the received SSDV packet into a temporary buffer and add a sync byte
packetBuf[0] = 0x55; // Sync Byte;
for (int i = 1; i < 256; i++)
{
packetBuf[i] = buf[i-1];
}
// Add the packet to the queue. do not wait if thge queue is full
if (ssdv_Queue != NULL)
{
if (xQueueSend(ssdv_Queue, packetBuf, 0) == pdPASS)
{
Telemetry.uploadResult = "Packet added to upload queue.";
}
else
{
Telemetry.uploadResult = "Could not upload. Queue is full.";
}
}
}