Bumped the version to 2.40 - correctly this time, I hope.

Added fixed for a few minor things. pin driver for rht03/dht type
sensors. Network stuff is experimental - for now.
This commit is contained in:
Gordon Henderson
2017-02-27 19:51:32 +00:00
parent e687f3f2c6
commit 70fa99a127
28 changed files with 2069 additions and 87 deletions

View File

@@ -55,10 +55,13 @@
#include "ads1115.h"
#include "sn3218.h"
#include "drcSerial.h"
#include "drcNet.h"
#include "../wiringPiD/drcNetCmd.h"
#include "pseudoPins.h"
#include "bmp180.h"
#include "htu21d.h"
#include "ds18b20.h"
#include "rht03.h"
#include "wpiExtensions.h"
@@ -134,12 +137,16 @@ static char *extractInt (char *progName, char *p, int *num)
/*
* extractStr:
* Check & return a string at the given location (prefixed by a :)
* Note: The string can be enclosed in []'s to escape colons. This is
* so we can handle IPv6 addresses which contain colons and the []'s is
* a common way to prepresent them.
*********************************************************************************
*/
static char *extractStr (char *progName, char *p, char **str)
{
char *q, *r ;
int quoted = FALSE ;
if (*p != ':')
{
@@ -149,21 +156,38 @@ static char *extractStr (char *progName, char *p, char **str)
++p ;
if (!isprint (*p))
if (*p == '[')
{
quoted = TRUE ;
++p ;
}
if (!isprint (*p)) // Is this needed?
{
verbError ("%s: character expected", progName) ;
return NULL ;
}
q = p ;
while ((*q != 0) && (*q != ':'))
++q ;
if (quoted)
{
while ((*q != 0) && (*q != ']'))
++q ;
}
else
{
while ((*q != 0) && (*q != ':'))
++q ;
}
*str = r = calloc (q - p + 2, 1) ; // Zeros it
while (p != q)
*r++ = *p++ ;
if (quoted) // Skip over the ] to the :
++p ;
return p ;
}
@@ -495,6 +519,24 @@ static int doExtensionDs18b20 (char *progName, int pinBase, char *params)
}
/*
* doExtensionRht03:
* Maxdetect 1-Wire Temperature & Humidity
* rht03:base:piPin
*********************************************************************************
*/
static int doExtensionRht03 (char *progName, int pinBase, char *params)
{
int piPin ;
if ((params = extractInt (progName, params, &piPin)) == NULL)
return FALSE ;
return rht03Setup (pinBase, piPin) ;
}
/*
* doExtensionMax31855:
* Analog IO
@@ -698,9 +740,9 @@ static int doExtensionDrcS (char *progName, int pinBase, char *params)
if ((params = extractInt (progName, params, &pins)) == NULL)
return FALSE ;
if ((pins < 1) || (pins > 100))
if ((pins < 1) || (pins > 1000))
{
verbError ("%s: pins (%d) out of range (2-100)", progName, pins) ;
verbError ("%s: pins (%d) out of range (2-1000)", progName, pins) ;
return FALSE ;
}
@@ -728,6 +770,59 @@ static int doExtensionDrcS (char *progName, int pinBase, char *params)
}
/*
* doExtensionDrcNet:
* Interface to a DRC Network system
* drcn:base:pins:ipAddress:port:password
*********************************************************************************
*/
static int doExtensionDrcNet (char *progName, int pinBase, char *params)
{
int pins ;
char *ipAddress, *port, *password ;
char pPort [1024] ;
if ((params = extractInt (progName, params, &pins)) == NULL)
return FALSE ;
if ((pins < 1) || (pins > 1000))
{
verbError ("%s: pins (%d) out of range (2-1000)", progName, pins) ;
return FALSE ;
}
if ((params = extractStr (progName, params, &ipAddress)) == NULL)
return FALSE ;
if (strlen (ipAddress) == 0)
{
verbError ("%s: ipAddress required", progName) ;
return FALSE ;
}
if ((params = extractStr (progName, params, &port)) == NULL)
return FALSE ;
if (strlen (port) == 0)
{
sprintf (pPort, "%d", DEFAULT_SERVER_PORT) ;
port = pPort ;
}
if ((params = extractStr (progName, params, &password)) == NULL)
return FALSE ;
if (strlen (password) == 0)
{
verbError ("%s: password required", progName) ;
return FALSE ;
}
return drcSetupNet (pinBase, pins, ipAddress, port, password) ;
}
/*
* Function list
@@ -748,6 +843,7 @@ static struct extensionFunctionStruct extensionFunctions [] =
{ "pseudoPins", &doExtensionPseudoPins },
{ "htu21d", &doExtensionHtu21d },
{ "ds18b20", &doExtensionDs18b20 },
{ "rht03", &doExtensionRht03 },
{ "mcp3002", &doExtensionMcp3002 },
{ "mcp3004", &doExtensionMcp3004 },
{ "mcp4802", &doExtensionMcp4802 },
@@ -757,6 +853,7 @@ static struct extensionFunctionStruct extensionFunctions [] =
{ "max5322", &doExtensionMax5322 },
{ "sn3218", &doExtensionSn3218 },
{ "drcs", &doExtensionDrcS },
{ "drcn", &doExtensionDrcNet },
{ NULL, NULL },
} ;
@@ -826,6 +923,6 @@ int loadWPiExtension (char *progName, char *extensionData, int printErrors)
return extensionFn->function (progName, pinBase, p) ;
}
verbError ("%s: extension %s not found", progName, extension) ;
fprintf (stderr, "%s: extension %s not found", progName, extension) ;
return FALSE ;
}