kopia lustrzana https://github.com/pa3gsb/Radioberry-2.x
register radioberry added
rodzic
8291e3b98d
commit
9a9ee773b0
|
@ -277,6 +277,15 @@ int deinit_gateware_ftdi() {
|
|||
return 0;
|
||||
};
|
||||
|
||||
unsigned long getFirmwareVersion() {
|
||||
FT_STATUS ftStatus;
|
||||
unsigned long dwDriverVer = 0;
|
||||
|
||||
ftStatus = FT_GetDriverVersion(ftHandle,&dwDriverVer);
|
||||
|
||||
return dwDriverVer;
|
||||
}
|
||||
|
||||
int load_gateware_image_into_fpga() {
|
||||
|
||||
if (init_gateware_ftdi() < 0) return -1 ;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
The gateware is present in the radioberry.rbf file.
|
||||
|
||||
This file will be read and will be transferred via the usb bus, ft2232 chip into the FPGA.
|
||||
|
||||
|
||||
*/
|
||||
#ifndef __RADIOBERRY_GATEWARE_LOADER_H__
|
||||
|
@ -16,7 +15,6 @@
|
|||
#include "ftd2xx.h"
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
//#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -42,5 +40,6 @@
|
|||
|
||||
int load_gateware_image_into_fpga(void);
|
||||
|
||||
unsigned long getFirmwareVersion(void);
|
||||
|
||||
#endif
|
|
@ -12,17 +12,20 @@ PROGRAM=radioberry-juice
|
|||
SOURCES= \
|
||||
radioberry.c \
|
||||
gateware.c \
|
||||
stream.c
|
||||
stream.c \
|
||||
register.c
|
||||
|
||||
HEADERS= \
|
||||
radioberry.h \
|
||||
gateware.h \
|
||||
stream.h
|
||||
stream.h \
|
||||
register.h
|
||||
|
||||
OBJS= \
|
||||
radioberry.o \
|
||||
gateware.o \
|
||||
stream.o
|
||||
stream.o \
|
||||
register.o
|
||||
|
||||
all: prebuild $(PROGRAM) $(HEADERS) $(SOURCES)
|
||||
|
||||
|
|
|
@ -51,8 +51,13 @@ For more information, please refer to <http://unlicense.org/>
|
|||
#include "radioberry.h"
|
||||
#include "gateware.h"
|
||||
#include "stream.h"
|
||||
#include "register.h"
|
||||
|
||||
#define FIRMWAREVERSION "Juice version"
|
||||
#ifdef _WIN32
|
||||
#define FIRMWAREVERSION "W-J-2021-08-01"
|
||||
#else
|
||||
#define FIRMWAREVERSION "L-J-2021-08-01"
|
||||
#endif
|
||||
|
||||
void printIntroScreen() {
|
||||
fprintf(stderr,"\n");
|
||||
|
@ -89,8 +94,23 @@ int load_radioberry_gateware() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void *rb_register_thread(void *arg) {
|
||||
sprintf(gatewareversion,"%d.%d", gateware_major_version, gateware_minor_version);
|
||||
sprintf(firmwareversion,"%s", FIRMWAREVERSION);
|
||||
//major-minor-build of ftdi driver
|
||||
sprintf(driverversion,"%02x.%02x.%02x", ((driver_version >>16) & 0xFF), ((driver_version >>8) & 0xFF), (driver_version & 0xFF));
|
||||
gateware_fpga_type == 0 ? sprintf(fpgatype,"%s", "-") : gateware_fpga_type == 1 ? sprintf(fpgatype,"%s", "CL016") : sprintf(fpgatype,"%s", "CL025");
|
||||
registerRadioberry();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void start_rb_register_thread() {
|
||||
pthread_t pid1;
|
||||
pthread_create(&pid1, NULL, rb_register_thread, NULL);
|
||||
}
|
||||
|
||||
void getStreamAndSendPacket() {
|
||||
read_stream(hpsdrdata); // fetching 1032 bytes of ethernet packet.
|
||||
if (read_stream(hpsdrdata) < 0) return; // fetching 1032 bytes of ethernet packet.
|
||||
if (sock_TCP_Client >= 0) {
|
||||
if (sendto(sock_TCP_Client, (const char*) hpsdrdata, sizeof(hpsdrdata), 0, NULL, 0) != 1032) fprintf(stderr, "TCP send error");
|
||||
} else {
|
||||
|
@ -131,7 +151,7 @@ void *packetreader(void *arg) {
|
|||
bytes_read += size;
|
||||
bytes_left -= size;
|
||||
}
|
||||
if (bytes_read == 1032) handlePacket((unsigned char*) buffer); else fprintf(stderr, "tcp packet received; wrong length %d \n", bytes_read);
|
||||
if (bytes_read == 1032) handlePacket((unsigned char*) buffer); //else fprintf(stderr, "tcp packet received; wrong length %d \n", bytes_read);
|
||||
}
|
||||
else {
|
||||
// handle UDP protocol.
|
||||
|
@ -229,15 +249,19 @@ void handlePacket(unsigned char* buffer){
|
|||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
{
|
||||
printIntroScreen();
|
||||
|
||||
if (load_radioberry_gateware() < 0) {
|
||||
fprintf(stderr,"Radioberry; loading radioberry \n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
driver_version = getFirmwareVersion();
|
||||
//fprintf(stderr, "%06x\n", driver_version);
|
||||
|
||||
int ret;
|
||||
if (ret = init_stream() < 0) { return ret; }
|
||||
if (ret = init_stream() < 0) { return ret; }
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa;
|
||||
|
@ -261,10 +285,15 @@ int main(int argc, char **argv)
|
|||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = TIMEOUT_MS;
|
||||
int wtimeout = TIMEOUT_MS; //window time out // wellicht aanpassen for linux
|
||||
int wtimeout = TIMEOUT_MS;
|
||||
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,(char*)&wtimeout,sizeof(wtimeout)) < 0)
|
||||
#ifdef _WIN32
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&wtimeout,sizeof (int)) < 0)
|
||||
perror("setsockopt failed\n");
|
||||
#else
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,(char*)&timeout,sizeof(timeout)) < 0)
|
||||
perror("setsockopt failed\n");
|
||||
#endif
|
||||
|
||||
/* bind the socket to any valid IP address and a specific port */
|
||||
memset((char *)&myaddr, 0, sizeof(myaddr));
|
||||
|
@ -321,6 +350,8 @@ int main(int argc, char **argv)
|
|||
int flags = fcntl(sock_TCP_Server, F_GETFL, 0);
|
||||
fcntl(sock_TCP_Server, F_SETFL, flags | O_NONBLOCK);
|
||||
#endif
|
||||
|
||||
start_rb_register_thread();
|
||||
|
||||
signal(SIGINT, handle_sigint);
|
||||
|
||||
|
|
|
@ -49,6 +49,13 @@
|
|||
#define HERMESLITE 0x06
|
||||
|
||||
|
||||
char macaddress[24];
|
||||
char* radiocall;
|
||||
char* radiolocator;
|
||||
char gatewareversion[16];
|
||||
char driverversion[16];
|
||||
char firmwareversion[16];
|
||||
char fpgatype[16];
|
||||
|
||||
int fd_rb;
|
||||
|
||||
|
@ -66,6 +73,8 @@ int active = 0;
|
|||
static volatile int keepRunning = 1;
|
||||
unsigned char gateware_major_version = 73;
|
||||
unsigned char gateware_minor_version = 0;
|
||||
unsigned long driver_version = 0x00020406;
|
||||
int gateware_fpga_type = 2;
|
||||
unsigned char hpsdrdata[1032];
|
||||
unsigned char broadcastReply[60];
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
call=<your call>
|
||||
locator=<locator>
|
Plik binarny nie jest wyświetlany.
|
@ -0,0 +1,194 @@
|
|||
#include "register.h"
|
||||
|
||||
|
||||
#define SA struct sockaddr
|
||||
#define MAXLINE 4096
|
||||
#define MAXSUB 512
|
||||
|
||||
PROPERTY* properties=NULL;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
||||
#define IP_LOCALHOST 0x0100007F
|
||||
|
||||
int getMacAddress(void)
|
||||
{
|
||||
int found = 0;
|
||||
ULONG nSize = 0;
|
||||
MIB_IPADDRTABLE * ip_table = NULL;
|
||||
if (GetIpAddrTable(ip_table, &nSize, 0) == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
ip_table = (MIB_IPADDRTABLE *) malloc(nSize);
|
||||
if (GetIpAddrTable(ip_table, &nSize, 0) == NO_ERROR)
|
||||
{
|
||||
for (int i = 0; i < ip_table->dwNumEntries; ++i)
|
||||
{
|
||||
if (IP_LOCALHOST != ip_table->table[i].dwAddr)
|
||||
{
|
||||
MIB_IFROW iInfo;
|
||||
BYTE byMAC[6] = { 0, 0, 0, 0, 0, 0 };
|
||||
memset(&iInfo, 0, sizeof(MIB_IFROW));
|
||||
iInfo.dwIndex = ip_table->table[i].dwIndex;
|
||||
GetIfEntry(&iInfo);
|
||||
if (IF_TYPE_IEEE80211 == iInfo.dwType) {
|
||||
memcpy(&byMAC, iInfo.bPhysAddr, iInfo.dwPhysAddrLen);
|
||||
char *macstr = "%02X:%02X:%02X:%02X:%02X:%02X";
|
||||
sprintf(macaddress,macstr, byMAC[0],byMAC[1],byMAC[2], byMAC[3],byMAC[4],byMAC[5]);
|
||||
//printf("%s", macaddress);
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(ip_table);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int getMacAddress(void) {
|
||||
|
||||
struct ifaddrs *ifaddr=NULL;
|
||||
struct ifaddrs *ifa = NULL;
|
||||
int found = 0;
|
||||
|
||||
if (getifaddrs(&ifaddr) != -1) {
|
||||
for ( ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if ( (ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET) && !(ifa->ifa_flags & IFF_LOOPBACK) ) {
|
||||
struct sockaddr_ll *s = (struct sockaddr_ll*)ifa->ifa_addr;
|
||||
if ((strstr(ifa->ifa_name, "eth") != NULL) || (strstr(ifa->ifa_name, "wlan") != NULL) ) {
|
||||
char *macstr = "%02X:%02X:%02X:%02X:%02X:%02X";
|
||||
sprintf(macaddress,macstr, s->sll_addr[0], s->sll_addr[1], s->sll_addr[2], s->sll_addr[3], s->sll_addr[4], s->sll_addr[5]);
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
freeifaddrs(ifaddr);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void loadProperties(char* filename) {
|
||||
char string[80];
|
||||
char* name;
|
||||
char* value;
|
||||
FILE* f=fopen(filename,"r");
|
||||
PROPERTY* property;
|
||||
if(f) {
|
||||
while(fgets(string,sizeof(string),f)) {
|
||||
if(string[0]!='#') {
|
||||
name=strtok(string,"=");
|
||||
value=strtok(NULL,"\n");
|
||||
// Beware of "illegal" lines in corrupted files
|
||||
if (name != NULL && value != NULL) {
|
||||
property=(PROPERTY *)malloc(sizeof(PROPERTY));
|
||||
property->name=(char *)malloc(strlen(name)+1);
|
||||
strcpy(property->name,name);
|
||||
property->value=(char *)malloc(strlen(value)+1);
|
||||
strcpy(property->value,value);
|
||||
property->next_property=properties;
|
||||
properties=property;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
char* getProperty(char* name) {
|
||||
char* value=NULL;
|
||||
PROPERTY* property=properties;
|
||||
while(property) {
|
||||
if(strcmp(name,property->name)==0) {
|
||||
value=property->value;
|
||||
break;
|
||||
}
|
||||
property=property->next_property;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void loadRadioberryProps() {
|
||||
#ifndef _WIN32
|
||||
loadProperties("/home/pi/.radioberry/radioberry.props");
|
||||
#else
|
||||
loadProperties("./radioberry.props");
|
||||
#endif
|
||||
|
||||
radiocall = getProperty("call");
|
||||
if (radiocall==NULL) radiocall="-";
|
||||
if (strlen(radiocall) > 16) radiocall[16] = '\0';
|
||||
radiolocator = getProperty("locator");
|
||||
if (radiolocator==NULL) radiolocator="-";
|
||||
if (strlen(radiolocator) > 6) radiolocator[6] = '\0';
|
||||
//fprintf(stderr, "call = %s, locator = %s", radiocall, radiolocator);
|
||||
}
|
||||
|
||||
|
||||
ssize_t process_http(int sockfd, char *host, char *page, char *poststr)
|
||||
{
|
||||
char sendline[MAXLINE + 1], recvline[MAXLINE + 1];
|
||||
ssize_t n;
|
||||
snprintf(sendline, MAXSUB,
|
||||
"POST %s HTTP/1.0\r\n"
|
||||
"Host: %s\r\n"
|
||||
"Content-type: application/x-www-form-urlencoded\r\n"
|
||||
"Content-length: %d\r\n\r\n"
|
||||
"%s", page, host, strlen(poststr), poststr);
|
||||
send(sockfd, sendline, strlen(sendline), 0);
|
||||
//get response
|
||||
while ((n = recv(sockfd, recvline, MAXLINE, 0)) > 0) {
|
||||
recvline[n] = '\0';
|
||||
//printf("%s", recvline);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int postRadioberryConfiguration() {
|
||||
|
||||
int result = 0;
|
||||
int sockfd;
|
||||
struct sockaddr_in servaddr;
|
||||
|
||||
char **pptr;
|
||||
char *hname = "www.pa3gsb.nl";
|
||||
char *page = "/radioberry/api/write.php";
|
||||
char *poststr = "macaddress=%s&radiocall=%s&radiolocator=%s&gatewareversion=%s&driverversion=%s&firmwareversion=%s&fpgatype=%s\r\n";
|
||||
|
||||
// make message for registration.
|
||||
char post_message[4096];
|
||||
sprintf(post_message,poststr, macaddress, radiocall, radiolocator, gatewareversion, driverversion, firmwareversion, fpgatype);
|
||||
|
||||
char str[50];
|
||||
struct hostent *hptr;
|
||||
if ((hptr = gethostbyname(hname)) == NULL) return -1;
|
||||
if (hptr->h_addrtype == AF_INET && (pptr = hptr->h_addr_list) != NULL) inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str));
|
||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
bzero(&servaddr, sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons(80);
|
||||
inet_pton(AF_INET, str, &servaddr.sin_addr);
|
||||
if (connect(sockfd, (SA *) & servaddr, sizeof(servaddr)) >= 0) process_http(sockfd, hname, page, post_message); else result = -1;
|
||||
|
||||
#ifdef _WIN32
|
||||
closesocket(sockfd);
|
||||
#else
|
||||
if (sockfd != 0) close(sockfd);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void registerRadioberry() {
|
||||
if (!getMacAddress()) return;
|
||||
loadRadioberryProps();
|
||||
if (postRadioberryConfiguration()) fprintf(stderr, "Registering your Radioberry not registered.\n"); else fprintf(stderr, "Your Radioberry is registered: http://www.pa3gsb.nl/radioberry/api/read.php\n");
|
||||
}
|
||||
//end of source
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
#ifndef __RADIOBERRY_REGISTER_H__
|
||||
#define __RADIOBERRY_REGISTER_H__
|
||||
|
||||
#ifdef _WIN32
|
||||
#define TCP_MAXSEG 4
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#pragma comment(lib, "iphlpapi.lib")
|
||||
#pragma comment(lib,"ws2_32.lib") //Winsock Library
|
||||
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <linux/if.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <netpacket/packet.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef struct _PROPERTY PROPERTY;
|
||||
struct _PROPERTY {
|
||||
char* name;
|
||||
char* value;
|
||||
PROPERTY* next_property;
|
||||
};
|
||||
|
||||
extern char macaddress[24];
|
||||
extern char* radiocall;
|
||||
extern char* radiolocator;
|
||||
extern char gatewareversion[16];
|
||||
extern char driverversion[16];
|
||||
extern char firmwareversion[16];
|
||||
extern char fpgatype[16];
|
||||
|
||||
int getWindowsMacAddress(void);
|
||||
int getMacAddress(void);
|
||||
void loadProperties(char* filename);
|
||||
char* getProperty(char* name);
|
||||
void loadRadioberryProps(void);
|
||||
ssize_t process_http(int sockfd, char *host, char *page, char *poststr);
|
||||
int postRadioberryConfiguration(void);
|
||||
|
||||
extern void registerRadioberry(void);
|
||||
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
CXX = x86_64-w64-mingw32-g++
|
||||
CXX = x86_64-w64-mingw32-g++ -Wwrite-strings -fpermissive
|
||||
CXXFLAGS = -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00
|
||||
LDSTATIC = -lwsock32 -L"C:\dev\git\Radioberry-2.x\juice\firmware" -lftd2xx64 -lpthread
|
||||
LDSTATIC = -lwsock32 -lIphlpapi -lws2_32 -L"C:\dev\git\Radioberry-2.x\juice\firmware" -lftd2xx64 -lpthread
|
||||
|
||||
LINK = $(CXX)
|
||||
|
||||
|
@ -8,8 +8,8 @@ LINK = $(CXX)
|
|||
%.o: %.c %.h
|
||||
$(CXX) $(CXXFLAGS) -c $<
|
||||
|
||||
radioberry: radioberry.o gateware.o stream.o
|
||||
$(LINK) radioberry.o gateware.o stream.o $(LDSTATIC) -o radioberry-juice.exe
|
||||
radioberry: radioberry.o gateware.o stream.o register.o
|
||||
$(LINK) radioberry.o gateware.o stream.o register.o $(LDSTATIC) -o radioberry-juice.exe
|
||||
|
||||
clean:
|
||||
del *.o
|
||||
|
|
Ładowanie…
Reference in New Issue