Created
September 17, 2017 02:55
-
-
Save N0NB/750720786b9d3f93fd038eb7b8378f46 to your computer and use it in GitHub Desktop.
Changes to attempt to build microham support with MinGW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/iofunc.c b/src/iofunc.c | |
index 2c117b21..07966984 100644 | |
--- a/src/iofunc.c | |
+++ b/src/iofunc.c | |
@@ -237,6 +237,7 @@ static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count) | |
{ | |
int i; | |
ssize_t ret; | |
+ extern int uh_radio_fd; | |
/* | |
* Since WIN32 does its special serial read, we have | |
diff --git a/src/microham.c b/src/microham.c | |
index 56e2ec49..27559181 100644 | |
--- a/src/microham.c | |
+++ b/src/microham.c | |
@@ -5,22 +5,24 @@ | |
// | |
#ifdef HAVE_CONFIG_H | |
-# include "config.h" | |
+# include "config.h" | |
#endif | |
- | |
+ | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/stat.h> | |
-#include <glob.h> | |
#include <fcntl.h> | |
-#include <sys/select.h> | |
#include <time.h> | |
-#include <sys/errno.h> | |
#include <limits.h> | |
-#include <sys/socket.h> | |
+#if !(defined (WIN32) || defined (WIN64)) | |
+# include <glob.h> | |
+# include <sys/select.h> | |
+# include <sys/errno.h> | |
+# include <sys/socket.h> | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
//#define FRAME(s, ...) printf(s, ##__VA_ARGS__) | |
//#define DEBUG(s, ...) printf(s, ##__VA_ARGS__) | |
@@ -28,25 +30,28 @@ | |
//#define ERROR(s, ...) printf(s, ##__VA_ARGS__) | |
#ifndef FRAME | |
-#define FRAME(s, ...) | |
+# define FRAME(s, ...) | |
#endif | |
#ifndef DEBUG | |
-#define DEBUG(s, ...) | |
+# define DEBUG(s, ...) | |
#endif | |
#ifndef TRACE | |
-#define TRACE(s, ...) | |
+# define TRACE(s, ...) | |
#endif | |
#ifndef ERROR | |
-#define ERROR(s, ...) | |
+# define ERROR(s, ...) | |
#endif | |
#ifndef PATH_MAX | |
// should not happen, should be defined in limits.h | |
// but better paranoia than a code that does not work | |
-#define PATH_MAX 256 | |
+# define PATH_MAX 256 | |
#endif | |
+#if !(defined (WIN32) || defined (WIN64)) | |
static char uh_device_path[PATH_MAX]; // use PATH_MAX since udev names can be VERY long! | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
+ | |
static int uh_device_fd=-1; | |
static int uh_is_initialized=0; | |
@@ -62,22 +67,27 @@ static int statusbyte=0; | |
#ifdef HAVE_PTHREAD | |
-#include <pthread.h> | |
+# include <pthread.h> | |
+#if !(defined(WIN32) || defined (WIN64)) | |
static pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER; | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
+ | |
static pthread_t readthread; | |
-#define getlock() if (pthread_mutex_lock(&mutex)) perror("GETLOCK:") | |
-#define freelock() if (pthread_mutex_unlock(&mutex)) perror("FREELOCK:") | |
+# define getlock() if (pthread_mutex_lock(&mutex)) perror("GETLOCK:") | |
+# define freelock() if (pthread_mutex_unlock(&mutex)) perror("FREELOCK:") | |
#else | |
-#define getlock() | |
-#define freelock() | |
+# define getlock() | |
+# define freelock() | |
#endif | |
+#if !(defined (WIN32) || defined (WIN64)) | |
// | |
// time of last heartbeat. Updated by heartbeat() | |
// | |
static time_t lastbeat=0; | |
static time_t starttime; | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
#define TIME ((int) (time(NULL) - starttime)) | |
@@ -133,14 +143,14 @@ static void close_microham() | |
close_all_files(); | |
} | |
-#if defined(WIN32) | |
+#if (defined(WIN32) || defined (WIN64)) | |
/* | |
* On Windows, this is not really needed since we have uhrouter.exe | |
* creating virtual COM ports | |
* | |
* I do now know how to "find" a microham device under Windows, | |
* and serial I/O may also be Windows-specific. | |
- * | |
+ * | |
* Therefore, a dummy version of finddevices() is included such that it compiles | |
* well on WIN32. Since the dummy version does not find anything, no reading thread | |
* and no sockets are created. | |
@@ -151,9 +161,9 @@ static void close_microham() | |
* number begins with MK, M2, CK, DK, D2, 2R, 2P or UR. Then, open the serial | |
* line and put a valid fd into uh_device_fd. | |
*/ | |
-static void finddevices() | |
-{ | |
-} | |
+//static void finddevices() | |
+//{ | |
+//} | |
#else | |
/* | |
@@ -187,13 +197,13 @@ static void finddevices() | |
* even disclosed. | |
*/ | |
-#define NUMUHTYPES 8 | |
+# define NUMUHTYPES 8 | |
static struct uhtypes { | |
const char *name; | |
const char *device; | |
} uhtypes[NUMUHTYPES] = { | |
-#ifdef __APPLE__ | |
+# ifdef __APPLE__ | |
{ "microKeyer", "/dev/tty.usbserial-MK*"}, | |
{ "microKeyer-II", "/dev/tty.usbserial-M2*"}, | |
{ "CW Keyer", "/dev/tty.usbserial-CK*"}, | |
@@ -202,7 +212,7 @@ static struct uhtypes { | |
{ "micorKeyer-IIR", "/dev/tty.usbserial-2R*"}, | |
{ "microKeyer-IIR+", "/dev/tty.usbserial-2P*"}, | |
{ "microKeyer-U2R", "/dev/tty.usbserial-UR*"}, | |
-#else | |
+# else | |
{ "microKeyer", "/dev/serial/by-id/*microHAM*_MK*"}, | |
{ "microKeyer-II", "/dev/serial/by-id/*microHAM*_M2*"}, | |
{ "CW Keyer", "/dev/serial/by-id/*microHAM*_CK*"}, | |
@@ -211,7 +221,7 @@ static struct uhtypes { | |
{ "micorKeyer-IIR", "/dev/serial/by-id/*microHAM*_2R*"}, | |
{ "microKeyer-IIR+", "/dev/serial/by-id/*microHAM*_2P*"}, | |
{ "microKeyer-U2R", "/dev/serial/by-id/*microHAM*_UR*"}, | |
-#endif | |
+# endif | |
}; | |
// | |
@@ -219,7 +229,7 @@ static struct uhtypes { | |
// file has a name from which we can tell this is a microHam device | |
// This is the case for MacOS and LINUX (for LINUX: use udev) | |
// | |
-#include <termios.h> | |
+# include <termios.h> | |
static void finddevices() | |
{ | |
struct stat st; | |
@@ -232,7 +242,7 @@ static void finddevices() | |
// | |
// Check ALL device special files that might be relevant, | |
- // | |
+ // | |
for (i=0; i<NUMUHTYPES; i++) { | |
DEBUG("Checking for %s device\n", uhtypes[i].device); | |
glob(uhtypes[i].device, 0, NULL, &gbuf); | |
@@ -314,11 +324,14 @@ static void finddevices() | |
// once a complete frame has been received | |
// Send Radio and Winkey bytes received to the client sockets. | |
// | |
+#if !(defined(WIN32) || defined (WIN64)) | |
static int frameseq=0; | |
static int incontrol=0; | |
static unsigned char controlstring[256]; | |
static int numcontrolbytes=0; | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
+#if !(defined(WIN32) || defined (WIN64)) | |
static void parseFrame(unsigned char *frame) | |
{ | |
int i; | |
@@ -360,7 +373,7 @@ static void parseFrame(unsigned char *frame) | |
if (frame[0] & 0x01) { | |
byte |= 0x80; | |
} | |
- | |
+ | |
switch (frameseq) { | |
case 0: | |
DEBUG("%10d:RCV: Flags=%02x\n", TIME, byte); | |
@@ -377,7 +390,7 @@ static void parseFrame(unsigned char *frame) | |
if ((frame[0] & 0x08) == 0 && incontrol) { | |
// end of a control sequence | |
controlstring[numcontrolbytes++]=byte; | |
- DEBUG("%10d:FromControl:",TIME); | |
+ DEBUG("%10d:FromControl:",TIME); | |
for (i=0; i<numcontrolbytes; i++) DEBUG(" %02x",controlstring[i]); | |
DEBUG(".\n"); | |
incontrol=0; | |
@@ -399,10 +412,12 @@ static void parseFrame(unsigned char *frame) | |
} | |
} | |
} | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
// | |
// Send radio bytes to keyer | |
// | |
+#if !(defined(WIN32) || defined (WIN64)) | |
static void writeRadio(unsigned char *bytes, int len) | |
{ | |
unsigned char seq[4]; | |
@@ -433,12 +448,14 @@ static void writeRadio(unsigned char *bytes, int len) | |
} | |
freelock(); | |
} | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
// | |
// send statusbyte to keyer | |
// | |
static void writeFlags() | |
{ | |
+#if !(defined(WIN32) || defined (WIN64)) | |
unsigned char seq[4]; | |
int ret; | |
@@ -458,10 +475,12 @@ static void writeFlags() | |
} | |
} | |
freelock(); | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
} | |
// | |
// Send bytes to the WinKeyer | |
// | |
+#if !(defined(WIN32) || defined (WIN64)) | |
static void writeWkey(unsigned char *bytes, int len) | |
{ | |
unsigned char seq[12]; | |
@@ -500,11 +519,15 @@ static void writeWkey(unsigned char *bytes, int len) | |
} | |
freelock(); | |
} | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
+ | |
+ | |
// | |
// Write a string to the control channel | |
// | |
static void writeControl(unsigned char *data, int len) | |
{ | |
+#if !(defined(WIN32) || defined (WIN64)) | |
int i, ret; | |
unsigned char seq[8]; | |
@@ -542,10 +565,14 @@ static void writeControl(unsigned char *data, int len) | |
} | |
} | |
freelock(); | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
} | |
+ | |
+ | |
// | |
// send a heartbeat and record time. | |
// | |
+#if !(defined(WIN32) || defined (WIN64)) | |
static void heartbeat() | |
{ | |
unsigned char seq[2]; | |
@@ -555,12 +582,16 @@ static void heartbeat() | |
writeControl(seq, 2); | |
lastbeat=time(NULL); | |
} | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
+ | |
+ | |
// | |
// This thread reads from the microHam device and puts data on the sockets | |
// it also issues periodic heartbeat messages | |
// it also reads the sockets if data is available | |
// | |
-static void* read_device(void *p) | |
+#if !(defined(WIN32) || defined (WIN64)) | |
+static void * read_device(void *p) | |
{ | |
unsigned char frame[4]; | |
int framepos=0; | |
@@ -569,7 +600,7 @@ static void* read_device(void *p) | |
fd_set fds; | |
struct timeval tv; | |
int maxdev; | |
- | |
+ | |
// the bytes from the microHam decive come in "frames" | |
// a frame is a four-byte sequence. The first byte has the MSB unset, | |
@@ -666,11 +697,16 @@ static void* read_device(void *p) | |
} | |
} | |
} | |
+//#if (defined(WIN32) || defined (WIN64)) | |
+// return NULL; | |
+//#endif // !(defined(WIN32) || defined (WIN64)) | |
} | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
+ | |
/* | |
* If we do not have pthreads, we cannot use the microham device. | |
- * This is so because we have to digest unsolicited messages | |
+ * This is so because we have to digest unsolicited messages | |
* (e.g. voltage change) and since we have to send periodic | |
* Nevertheless, the program should compile well even we we do not | |
@@ -679,6 +715,7 @@ static void* read_device(void *p) | |
*/ | |
static void start_thread() | |
{ | |
+#if !(defined(WIN32) || defined (WIN64)) | |
#ifdef HAVE_PTHREAD | |
/* | |
* Find a microHam device and open serial port to it. | |
@@ -801,6 +838,7 @@ static void start_thread() | |
TRACE("Started daemonized thread reading microHam\n"); | |
#endif | |
// if we do not have pthreads, this function does nothing. | |
+#endif // !(defined(WIN32) || defined (WIN64)) | |
} | |
/* | |
@@ -814,7 +852,7 @@ static void start_thread() | |
* Note that it is not intended that any I/O is done via the PTT sockets | |
* but hamlib needs a valid file descriptor! | |
- * | |
+ * | |
*/ | |
/* | |
diff --git a/src/microham.h b/src/microham.h | |
index 36008fa0..36521d08 100644 | |
--- a/src/microham.h | |
+++ b/src/microham.h | |
@@ -5,8 +5,11 @@ | |
// whether we are working on a "real" serial interface or on a socket | |
// | |
+#ifndef _MICROHAM_H | |
+#define _MICROHAM_H 1 | |
+ | |
int uh_ptt_fd = -1; // PUBLIC! must be visible in iofunc.c in WIN32 case | |
-int uh_radio_fd = -1; // PUBLIC! must be visible in iofunc.c in WIN32 case | |
+int uh_radio_fd; // PUBLIC! must be visible in iofunc.c in WIN32 case | |
extern int uh_open_radio(int baud, int databits, int stopbits, int rtscts); | |
extern int uh_open_ptt(); | |
@@ -15,3 +18,4 @@ extern int uh_get_ptt(); | |
extern void uh_close_radio(); | |
extern void uh_close_ptt(); | |
+#endif // _MICROHAM_H | |
diff --git a/src/serial.c b/src/serial.c | |
index e7713527..35cfb974 100644 | |
--- a/src/serial.c | |
+++ b/src/serial.c | |
@@ -94,6 +94,7 @@ int HAMLIB_API serial_open(hamlib_port_t *rp) | |
int fd; /* File descriptor for the port */ | |
int err; | |
+ int uh_radio_fd = -1; | |
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment