David Brooke 2015-10-07 19:34:32 +01:00
commit 32166c6bbd
20 zmienionych plików z 57 dodań i 60 usunięć

5
README.md 100755 → 100644
Wyświetl plik

@ -32,10 +32,7 @@ Enable SPI in raspi-config.
Install WiringPi:
1. cd ~
2. git clone git://git.drogon.net/wiringPi
3. cd wiringPi
4. ./build
sudo apt-get install wiringpi
Install the curl library:

10
base64.c 100755 → 100644
Wyświetl plik

@ -74,10 +74,10 @@ unsigned char *base64_decode(const char *data,
for (i = 0, j = 0; i < input_length;) {
uint32_t sextet_a = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
uint32_t sextet_b = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
uint32_t sextet_c = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
uint32_t sextet_d = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
uint32_t sextet_a = data[i] == '=' ? 0 & i++ : decoding_table[(unsigned char) data[i++]];
uint32_t sextet_b = data[i] == '=' ? 0 & i++ : decoding_table[(unsigned char) data[i++]];
uint32_t sextet_c = data[i] == '=' ? 0 & i++ : decoding_table[(unsigned char) data[i++]];
uint32_t sextet_d = data[i] == '=' ? 0 & i++ : decoding_table[(unsigned char) data[i++]];
uint32_t triple = (sextet_a << 3 * 6)
+ (sextet_b << 2 * 6)
@ -96,4 +96,4 @@ unsigned char *base64_decode(const char *data,
void base64_cleanup() {
free(decoding_table);
}
}

0
base64.h 100755 → 100644
Wyświetl plik

Wyświetl plik

@ -1,5 +0,0 @@
This file is placed here by pip to indicate the source was put
here by pip.
Once this package is successfully installed this source code will be
deleted (unless you remove this file).

3
ftp.c 100755 → 100644
Wyświetl plik

@ -59,7 +59,7 @@ void *FTPLoop(void *some_void_ptr)
dp = opendir(SSDVFolder);
if (dp != NULL)
{
while (ep = readdir (dp))
while ((ep = readdir (dp)))
{
if (strstr(ep->d_name, ".bin") != NULL)
{
@ -84,3 +84,4 @@ void *FTPLoop(void *some_void_ptr)
sleep(5);
}
}

0
ftp.h 100755 → 100644
Wyświetl plik

55
gateway.c 100755 → 100644
Wyświetl plik

@ -1,9 +1,10 @@
#include <stdio.h>
#include <stdio.h>
#include <curl/curl.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <strings.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -266,7 +267,6 @@ void setFrequency(int Channel, double Frequency)
void setLoRaMode(int Channel)
{
double Frequency;
unsigned long FrequencyValue;
// LogMessage("Setting LoRa Mode\n");
setMode(Channel, RF96_MODE_SLEEP);
@ -409,6 +409,8 @@ double FrequencyReference(int Channel)
case BANDWIDTH_250K: return 250000;
case BANDWIDTH_500K: return 500000;
}
return 0;
}
double FrequencyError(int Channel)
@ -512,7 +514,7 @@ static char *decode_callsign(char *callsign, uint32_t code)
return(callsign);
}
void ConvertStringToHex(unsigned char *Target, unsigned char *Source, int Length)
void ConvertStringToHex(char *Target, unsigned char *Source, int Length)
{
const char Hex[16] = "0123456789ABCDEF";
int i;
@ -923,9 +925,6 @@ void LoadPayloadFile(int ID)
{
FILE *fp;
char filename[16];
char Keyword[32];
int Channel, Temp;
char TempString[16];
sprintf(filename, "payload_%d.txt", ID);
@ -1008,20 +1007,18 @@ void CloseDisplay(WINDOW * mainwin)
void ProcessLine(int Channel, char *Line)
{
int FieldCount;
FieldCount = sscanf(Line+2, "%15[^,],%u,%8[^,],%lf,%lf,%u",
&(Config.LoRaDevices[Channel].Payload),
&(Config.LoRaDevices[Channel].Counter),
&(Config.LoRaDevices[Channel].Time),
&(Config.LoRaDevices[Channel].Latitude),
&(Config.LoRaDevices[Channel].Longitude),
&(Config.LoRaDevices[Channel].Altitude));
sscanf(Line+2, "%15[^,],%u,%8[^,],%lf,%lf,%u",
Config.LoRaDevices[Channel].Payload,
&Config.LoRaDevices[Channel].Counter,
Config.LoRaDevices[Channel].Time,
&Config.LoRaDevices[Channel].Latitude,
&Config.LoRaDevices[Channel].Longitude,
&Config.LoRaDevices[Channel].Altitude);
// HAB->HAB_status = FieldCount == 6;
}
void DoPositionCalcs(Channel)
void DoPositionCalcs(int Channel)
{
unsigned long Now;
struct tm tm;
@ -1052,11 +1049,10 @@ void DoPositionCalcs(Channel)
uint16_t CRC16(unsigned char *ptr)
{
uint16_t CRC, xPolynomial;
uint16_t CRC;
int j;
CRC = 0xffff; // Seed
xPolynomial = 0x1021;
for (; *ptr; ptr++)
{ // For speed, repeat calculation instead of looping for each bit
@ -1140,7 +1136,7 @@ void ProcessCallingMessage(int Channel, char *Message)
ChannelPrintf(Channel, 4, 1, "Calling message %d bytes ", strlen(Message));
if (sscanf(Message+2, "%15[^,],%lf,%d,%d,%d,%d,%d,%d",
if (sscanf(Message+2, "%15[^,],%lf,%d,%d,%d,%d,%d,%*d",
Payload,
&Frequency,
&ImplicitOrExplicit,
@ -1180,8 +1176,7 @@ void ProcessTelemetryMessage(int Channel, char *Message)
{
if (strlen(Message+1) < 150)
{
int i;
unsigned char *startmessage, *endmessage;
char *startmessage, *endmessage;
ChannelPrintf(Channel, 4, 1, "Telemetry %d bytes ", strlen(Message+1));
@ -1216,14 +1211,14 @@ void ProcessTelemetryMessage(int Channel, char *Message)
}
}
void ProcessSSDVMessage(int Channel, char *Message)
void ProcessSSDVMessage(int Channel, unsigned char *Message)
{
// SSDV packet
static uint32_t PreviousCallsignCode=0;
static int PreviousImageNumber=-1, PreviousPacketNumber=0;
uint32_t CallsignCode;
char Callsign[7], *FileMode, *EncodedCallsign, *EncodedEncoding, *Base64Data, *EncodedData, HexString[513], Command[1000];
int output_length, ImageNumber, PacketNumber;
char Callsign[7], *FileMode, *EncodedCallsign, *EncodedEncoding, *EncodedData, HexString[513];
int ImageNumber, PacketNumber;
char filename[100];
FILE *fp;
@ -1267,7 +1262,7 @@ void ProcessSSDVMessage(int Channel, char *Message)
sprintf(filename, "/tmp/%s_%d.bin", Callsign, ImageNumber);
if (fp = fopen(filename, FileMode))
if ((fp = fopen(filename, FileMode)))
{
fwrite(Message, 1, 256, fp);
fclose(fp);
@ -1348,7 +1343,7 @@ int prog_count(char* name)
int main(int argc, char **argv)
{
unsigned char Message[257], Command[200], Telemetry[100], *dest, *src;
unsigned char Message[257];
int Bytes, ch;
uint32_t LoopCount[2];
pthread_t SSDVThread, FTPThread, NetworkThread, HabitatThread, ServerThread;
@ -1469,15 +1464,15 @@ int main(int argc, char **argv)
if (Message[1] == '!')
{
ProcessUploadMessage(Channel, Message+1);
ProcessUploadMessage(Channel, (char *) Message+1);
}
else if (Message[1] == '^')
{
ProcessCallingMessage(Channel, Message+1);
ProcessCallingMessage(Channel, (char *) Message+1);
}
else if (Message[1] == '$')
{
ProcessTelemetryMessage(Channel, Message+1);
ProcessTelemetryMessage(Channel, (char *) Message+1);
}
else if (Message[1] == 0x66)
{

0
gateway.txt 100755 → 100644
Wyświetl plik

0
global.h 100755 → 100644
Wyświetl plik

0
habitat.c 100755 → 100644
Wyświetl plik

0
habitat.h 100755 → 100644
Wyświetl plik

26
makefile 100755 → 100644
Wyświetl plik

@ -1,27 +1,35 @@
CC=gcc
CFLAGS=-Wall -g -O2
LDFLAGS=-lm -lwiringPi -lwiringPiDev -lcurl -lncurses -lpthread
gateway: gateway.o urlencode.o base64.o habitat.o ssdv.o ftp.o network.o server.o
cc -o gateway gateway.o urlencode.o base64.o habitat.o ssdv.o ftp.o network.o server.o -lm -lwiringPi -lwiringPiDev -lcurl -lncurses -lpthread
$(CC) $(LDFLAGS) -o gateway gateway.o urlencode.o base64.o habitat.o ssdv.o ftp.o network.o server.o
gateway.o: gateway.c global.h
gcc -c gateway.c
$(CC) $(CFLAGS) -o gateway.o -c gateway.c
habitat.o: habitat.c habitat.h global.h
gcc -c habitat.c
$(CC) $(CFLAGS) -o habitat.o -c habitat.c
ssdv.o: ssdv.c ssdv.h global.h
gcc -c ssdv.c
$(CC) $(CFLAGS) -o ssdv.o -c ssdv.c
ftp.o: ftp.c ftp.h global.h
gcc -c ftp.c
$(CC) $(CFLAGS) -o ftp.o -c ftp.c
server.o: server.c server.h global.h
gcc -c server.c
$(CC) $(CFLAGS) -o server.o -c server.c
network.o: network.c network.h global.h
gcc -c network.c
$(CC) $(CFLAGS) -o network.o -c network.c
urlencode.o: urlencode.c
gcc -c urlencode.c
$(CC) $(CFLAGS) -o urlencode.o -c urlencode.c
base64.o: base64.c
gcc -c base64.c
$(CC) $(CFLAGS) -o base64.o -c base64.c
clean:
rm -rf *.o gateway

7
network.c 100755 → 100644
Wyświetl plik

@ -18,6 +18,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <wiringPi.h>
#include "network.h"
#include "global.h"
@ -58,14 +59,14 @@ int HaveAnIPAddress(void)
int CanSeeTheInternet(void)
{
struct addrinfo hints, *res, *p;
int status, sockfd, FoundInternet;
struct addrinfo hints, *res;
int sockfd, FoundInternet;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
hints.ai_socktype = SOCK_STREAM;
if ((status = getaddrinfo("google.com", "80", &hints, &res)) != 0)
if (getaddrinfo("google.com", "80", &hints, &res) != 0)
{
return 0;
}

0
network.h 100755 → 100644
Wyświetl plik

3
server.c 100755 → 100644
Wyświetl plik

@ -26,7 +26,6 @@ void *ServerLoop(void *some_void_ptr)
struct sockaddr_in serv_addr;
char sendBuff[1025];
time_t ticks;
listenfd = socket(AF_INET, SOCK_STREAM, 0);
memset(&serv_addr, '0', sizeof(serv_addr));
@ -80,4 +79,4 @@ void *ServerLoop(void *some_void_ptr)
close(connfd);
}
}
}

0
server.h 100755 → 100644
Wyświetl plik

0
ssdv.c 100755 → 100644
Wyświetl plik

0
ssdv.h 100755 → 100644
Wyświetl plik

3
urlencode.c 100755 → 100644
Wyświetl plik

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* Converts a hex character to its integer value */
@ -49,4 +50,4 @@ char *url_decode(char *str) {
}
*pbuf = '\0';
return buf;
}
}

0
urlencode.h 100755 → 100644
Wyświetl plik