aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTero Kontkanen <tero.kontkanen@granitedevices.fi>2017-08-19 18:18:00 +0300
committerTero Kontkanen <tero.kontkanen@granitedevices.fi>2017-08-19 18:18:00 +0300
commit98fc91e77907285c0c2f9d8f6209d2df004835e1 (patch)
treebce57d784f61999d06088cee152eabb4087e8c00
parent6ef9e8c44e29d270c64c22b73ae00508966b4892 (diff)
downloadSimpleMotionV2-98fc91e77907285c0c2f9d8f6209d2df004835e1.tar.gz
SimpleMotionV2-98fc91e77907285c0c2f9d8f6209d2df004835e1.zip
Reorganized drivers (move them to drivers subfolder)
-rw-r--r--SimpleMotionV2.pri14
-rw-r--r--busdevice.c116
-rw-r--r--drivers/serial/pcserialport.c (renamed from pcserialport.c)0
-rw-r--r--drivers/serial/pcserialport.h (renamed from pcserialport.h)0
-rw-r--r--drivers/tcpip/tcpclient.c (renamed from tcpclient.c)114
-rw-r--r--drivers/tcpip/tcpclient.h (renamed from tcpclient.h)6
6 files changed, 129 insertions, 121 deletions
diff --git a/SimpleMotionV2.pri b/SimpleMotionV2.pri
index 17aea23..c63c339 100644
--- a/SimpleMotionV2.pri
+++ b/SimpleMotionV2.pri
@@ -7,20 +7,20 @@ DEPENDPATH += $$PWD
DEFINES += SIMPLEMOTIONV2_LIBRARY
-SOURCES += $$PWD/sm_consts.c $$PWD/simplemotion.c $$PWD/busdevice.c $$PWD/pcserialport.c \
- $$PWD/bufferedmotion.c $$PWD/tcpclient.c $$PWD/devicedeployment.c
+SOURCES += $$PWD/sm_consts.c $$PWD/simplemotion.c $$PWD/busdevice.c $$PWD/drivers/serial/pcserialport.c \
+ $$PWD/bufferedmotion.c $$PWD/drivers/tcpip/tcpclient.c $$PWD/devicedeployment.c
HEADERS += $$PWD/simplemotion_private.h\
- $$PWD/pcserialport.h $$PWD/busdevice.h $$PWD/simplemotion.h $$PWD/sm485.h $$PWD/simplemotion_defs.h \
- $$PWD/bufferedmotion.h $$PWD/tcpclient.h $$PWD/devicedeployment.h
+ $$PWD/drivers/serial/pcserialport.h $$PWD/busdevice.h $$PWD/simplemotion.h $$PWD/sm485.h $$PWD/simplemotion_defs.h \
+ $$PWD/bufferedmotion.h $$PWD/drivers/tcpip/tcpclient.h $$PWD/devicedeployment.h
#If FTDI D2XX support is enabled
greaterThan(SUPPORT_FTDI_D2XX_DRIVER, 0+) {
SOURCES += $$PWD/drivers/ftdi_d2xx/sm_d2xx.c
- macx:LIBS +=
-# win32:LIBS += $$PWD/drivers/ftdi_d2xx/static_w32_i386_ftd2xx.lib
+ HEADERS += $$PWD/drivers/ftdi_d2xx/sm_d2xx.c
+ macx:LIBS += #tbd. mac will also needs some helper tool to make it work..
win32:LIBS += $$PWD/drivers/ftdi_d2xx/ftd2xx.lib
- linux:LIBS +=
+ linux:LIBS += #tbd
DEFINES += FTDI_D2XX_SUPPORT
}
diff --git a/busdevice.c b/busdevice.c
index 85a5b0e..7c42202 100644
--- a/busdevice.c
+++ b/busdevice.c
@@ -1,13 +1,12 @@
#include "busdevice.h"
-#include "pcserialport.h"
-#include "tcpclient.h"
+#include "drivers/serial/pcserialport.h"
+#include "drivers/tcpip/tcpclient.h"
#include "drivers/ftdi_d2xx/sm_d2xx.h"
#include <string.h>
#include <errno.h>
#include <stdlib.h>
-#include <ctype.h>
#define BD_NONE 0
#define BD_RS 1
@@ -53,117 +52,6 @@ void smBDinit()
bdInitialized=smtrue;
}
-//accepted TCP/IP address format is nnn.nnn.nnn.nnn:pppp where n is IP address numbers and p is port number
-static int validateIpAddress(const char *s, const char **pip_end,
- const char **pport_start)
-{
- int octets = 0;
- int ch = 0, prev = 0;
- int len = 0;
- const char *ip_end = NULL;
- const char *port_start = NULL;
-
- while (*s)
- {
- ch = *s;
-
- if (isdigit(ch))
- {
- ++len;
- // Octet len must be 1-3 digits
- if (len > 3)
- {
- return -1;
- }
- }
- else if (ch == '.' && isdigit(prev))
- {
- ++octets;
- len = 0;
- // No more than 4 octets please
- if (octets > 4)
- {
- return -1;
- }
- }
- else if (ch == ':' && isdigit(prev))
- {
- ++octets;
- // We want exactly 4 octets at this point
- if (octets != 4)
- {
- return -1;
- }
- ip_end = s;
- ++s;
- port_start = s;
- while (isdigit((ch = *s)))
- ++s;
- // After port we want the end of the string
- if (ch != '\0')
- return -1;
- // This will skip over the ++s below
- continue;
- }
- else
- {
- return -1;
- }
-
- prev = ch;
- ++s;
- }
-
- // We reached the end of the string and did not encounter the port
- if (*s == '\0' && ip_end == NULL)
- {
- ++octets;
- ip_end = s;
- }
-
- // Check that there are exactly 4 octets
- if (octets != 4)
- return -1;
-
- if (pip_end)
- *pip_end = ip_end;
-
- if (pport_start)
- *pport_start = port_start;
-
- return 0;
-}
-
-static int parseIpAddress(const char *s, char *ip, size_t ipsize, short *port)
-{
- const char *ip_end, *port_start;
-
- //ip_end and port_start are pointers to memory area of s, not offsets or indexes to s
- if (validateIpAddress(s, &ip_end, &port_start) == -1)
- return -1;
-
- // If ip=NULL, we just report that the parsing was ok
- if (!ip)
- return 0;
-
- if (ipsize < (size_t)(ip_end - s + 1))
- return -1;
-
- memcpy(ip, s, ip_end - s);
- ip[ip_end - s] = '\0';
-
- if (port_start)
- {
- *port = 0;
- while (*port_start)
- {
- *port = *port * 10 + (*port_start - '0');
- ++port_start;
- }
- }
-
- return 0;
-}
//ie "COM1" "VSD2USB"
//return -1 if fails, otherwise handle number
diff --git a/pcserialport.c b/drivers/serial/pcserialport.c
index 8cbe281..8cbe281 100644
--- a/pcserialport.c
+++ b/drivers/serial/pcserialport.c
diff --git a/pcserialport.h b/drivers/serial/pcserialport.h
index 832786d..832786d 100644
--- a/pcserialport.h
+++ b/drivers/serial/pcserialport.h
diff --git a/tcpclient.c b/drivers/tcpip/tcpclient.c
index 09d2426..458b77a 100644
--- a/tcpclient.c
+++ b/drivers/tcpip/tcpclient.c
@@ -1,6 +1,7 @@
#include "simplemotion_private.h"
#include "tcpclient.h"
#include <stdio.h>
+#include <ctype.h>
#if defined(_WIN32)
#if defined(CM_NONE)
@@ -187,3 +188,116 @@ void CloseTCPport(int sockfd)
WSACleanup();
#endif
}
+
+
+//accepted TCP/IP address format is nnn.nnn.nnn.nnn:pppp where n is IP address numbers and p is port number
+int validateIpAddress(const char *s, const char **pip_end,
+ const char **pport_start)
+{
+ int octets = 0;
+ int ch = 0, prev = 0;
+ int len = 0;
+ const char *ip_end = NULL;
+ const char *port_start = NULL;
+
+ while (*s)
+ {
+ ch = *s;
+
+ if (isdigit(ch))
+ {
+ ++len;
+ // Octet len must be 1-3 digits
+ if (len > 3)
+ {
+ return -1;
+ }
+ }
+ else if (ch == '.' && isdigit(prev))
+ {
+ ++octets;
+ len = 0;
+ // No more than 4 octets please
+ if (octets > 4)
+ {
+ return -1;
+ }
+ }
+ else if (ch == ':' && isdigit(prev))
+ {
+ ++octets;
+ // We want exactly 4 octets at this point
+ if (octets != 4)
+ {
+ return -1;
+ }
+ ip_end = s;
+ ++s;
+ port_start = s;
+ while (isdigit((ch = *s)))
+ ++s;
+ // After port we want the end of the string
+ if (ch != '\0')
+ return -1;
+ // This will skip over the ++s below
+ continue;
+ }
+ else
+ {
+ return -1;
+ }
+
+ prev = ch;
+ ++s;
+ }
+
+ // We reached the end of the string and did not encounter the port
+ if (*s == '\0' && ip_end == NULL)
+ {
+ ++octets;
+ ip_end = s;
+ }
+
+ // Check that there are exactly 4 octets
+ if (octets != 4)
+ return -1;
+
+ if (pip_end)
+ *pip_end = ip_end;
+
+ if (pport_start)
+ *pport_start = port_start;
+
+ return 0;
+}
+
+int parseIpAddress(const char *s, char *ip, size_t ipsize, short *port)
+{
+ const char *ip_end, *port_start;
+
+ //ip_end and port_start are pointers to memory area of s, not offsets or indexes to s
+ if (validateIpAddress(s, &ip_end, &port_start) == -1)
+ return -1;
+
+ // If ip=NULL, we just report that the parsing was ok
+ if (!ip)
+ return 0;
+
+ if (ipsize < (size_t)(ip_end - s + 1))
+ return -1;
+
+ memcpy(ip, s, ip_end - s);
+ ip[ip_end - s] = '\0';
+
+ if (port_start)
+ {
+ *port = 0;
+ while (*port_start)
+ {
+ *port = *port * 10 + (*port_start - '0');
+ ++port_start;
+ }
+ }
+
+ return 0;
+}
diff --git a/tcpclient.h b/drivers/tcpip/tcpclient.h
index ea02e42..5ed075a 100644
--- a/tcpclient.h
+++ b/drivers/tcpip/tcpclient.h
@@ -13,6 +13,12 @@ int SendTCPBuf(int, unsigned char *, int);
void CloseTCPport(int);
+//accepted TCP/IP address format is nnn.nnn.nnn.nnn:pppp where n is IP address numbers and p is port number
+int validateIpAddress(const char *s, const char **pip_end,
+ const char **pport_start);
+int parseIpAddress(const char *s, char *ip, size_t ipsize, short *port);
+
+
#ifdef __cplusplus
} /* extern "C" */
#endif