Add multicastserver test

Fix compile warnings on mingw
pull/1289/head
Mike Black W9MDB 2023-05-07 17:17:50 -05:00
rodzic 2a758b96ab
commit 62b9a12e89
5 zmienionych plików z 52 dodań i 9 usunięć

Wyświetl plik

@ -37,6 +37,11 @@
#include <inttypes.h>
#include <time.h>
// to stop warnings about including winsock2.h before windows.h
#if defined(_WIN32)
#include <winsock2.h>
#endif
// For MSVC install the NUGet pthread package
#if defined(_MSC_VER)
#define HAVE_STRUCT_TIMESPEC
@ -2477,10 +2482,10 @@ struct multicast_s
int seqnumber;
int runflag; // = 0;
pthread_t threadid;
#ifdef HAVE_ARPA_INET_H
//#ifdef HAVE_ARPA_INET_H
struct ip_mreq mreq; // = {0};
struct sockaddr_in dest_addr; // = {0};
#endif
//#endif
};
/**

Wyświetl plik

@ -206,7 +206,7 @@ static int multicast_send_json(RIG *rig)
json_add_vfoA(rig, msg);
// send the thing
multicast_send(rig, (unsigned char *)msg, strlen(msg));
multicast_send(rig, msg, strlen(msg));
return 0;
}
@ -269,7 +269,7 @@ int multicast_init(RIG *rig, char *addr, int port)
// Set the SO_REUSEADDR option to allow multiple processes to use the same address
int optval = 1;
if (setsockopt(rig->state.multicast->sock, SOL_SOCKET, SO_REUSEADDR, &optval,
if (setsockopt(rig->state.multicast->sock, SOL_SOCKET, SO_REUSEADDR, (char*)&optval,
sizeof(optval)) < 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: setsockopt: %s\n", __func__, strerror(errno));
@ -295,7 +295,7 @@ int multicast_init(RIG *rig, char *addr, int port)
rig->state.multicast->mreq.imr_interface.s_addr = htonl(INADDR_ANY);
// Set the multicast TTL (time-to-live) to limit the scope of the packets
unsigned char ttl = 1;
char ttl = 1;
if (setsockopt(rig->state.multicast->sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
sizeof(ttl)) < 0)
@ -322,7 +322,7 @@ int multicast_init(RIG *rig, char *addr, int port)
rig->state.multicast->runflag = 1;
pthread_create(&rig->state.multicast->threadid, NULL, multicast_thread,
(void *)rig);
printf("threadid=%ld\n", rig->state.multicast->threadid);
//printf("threadid=%ld\n", rig->state.multicast->threadid);
rig->state.multicast->multicast_running = 1;
return RIG_OK;
}
@ -348,7 +348,7 @@ void multicast_close(RIG *rig)
}
// if msglen=0 msg is assumed to be a string
int multicast_send(RIG *rig, unsigned char *msg, int msglen)
int multicast_send(RIG *rig, const char *msg, int msglen)
{
// Construct the message to send
if (msglen == 0) { msglen = strlen((char *)msg); }

Wyświetl plik

@ -8,6 +8,10 @@
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
@ -53,5 +57,5 @@ struct multicast_broadcast
// returns # of bytes sent
int multicast_init(RIG *rig, char *addr, int port);
int multicast_send(RIG *rig, unsigned char *msg, int msglen);
int multicast_send(RIG *rig, const char *msg, int msglen);
#endif //MULTICAST_H

Wyświetl plik

@ -14,7 +14,7 @@ endif
DISTCLEANFILES = rigctl.log rigctl.sum testbcd.log testbcd.sum
bin_PROGRAMS = rigctl rigctld rigmem rigsmtr rigswr rotctl rotctld rigctlcom rigctltcp rigctlsync ampctl ampctld multicastclient $(TESTLIBUSB)
bin_PROGRAMS = rigctl rigctld rigmem rigsmtr rigswr rotctl rotctld rigctlcom rigctltcp rigctlsync ampctl ampctld multicastclient multicastserver $(TESTLIBUSB)
#check_PROGRAMS = dumpmem testrig testrigopen testrigcaps testtrn testbcd testfreq listrigs testloc rig_bench testcache cachetest cachetest2 testcookie testgrid testsecurity
check_PROGRAMS = dumpmem testrig testrigopen testrigcaps testtrn testbcd testfreq listrigs testloc rig_bench testcache cachetest cachetest2 testcookie testgrid hamlibmodels

Wyświetl plik

@ -0,0 +1,34 @@
#include <stdlib.h>
#include <hamlib/rig.h>
#define TEST
#ifdef TEST
int main(int argc, char *argv[])
{
RIG *rig;
rig_model_t myrig_model;
rig_set_debug_level(RIG_DEBUG_NONE);
if (argc > 1) { myrig_model = atoi(argv[1]); }
else
{
myrig_model = 1035;
}
rig = rig_init(myrig_model);
if (rig == NULL)
{
}
strncpy(rig->state.rigport.pathname, "/dev/ttyUSB0", HAMLIB_FILPATHLEN - 1);
rig->state.rigport.parm.serial.rate = 38400;
rig_open(rig);
multicast_init(rig, "224.0.0.1", 4532);
pthread_join(rig->state.multicast->threadid, NULL);
pthread_exit(NULL);
return 0;
}
#endif