pigpiod.o: pigpiod.c pigpio.h
pigpiod_if.o: pigpiod_if.c pigpio.h pigpiod_if.h command.h
pigpiod_if2.o: pigpiod_if2.c pigpio.h pigpiod_if2.h command.h
-pigs.o: pigs.c pigpio.h command.h
+pigs.o: pigs.c pigpio.h command.h pigs.h
pig2vcd.o: pig2vcd.c pigpio.h
pigpiod.o: pigpiod.c pigpio.h
-pigs.o: pigs.c pigpio.h command.h
+pigs.o: pigs.c pigpio.h command.h pigs.h
x_pigpio.o: x_pigpio.c pigpio.h
x_pigpiod_if.o: x_pigpiod_if.c pigpiod_if.h pigpio.h
x_pigpiod_if2.o: x_pigpiod_if2.c pigpiod_if2.h pigpio.h
o the header file (pigpio.h) in /usr/local/include
o the header file (pigpiod_if.h) in /usr/local/include
o the header file (pigpiod_if2.h) in /usr/local/include
+o the header file (pigs.h) in /usr/local/include
o the daemon (pigpiod) in /usr/local/bin
o the socket interface (pigs) in /usr/local/bin
o the utility pig2vcd in /usr/local/bin
* *
* All the tests make extensive use of gpio 25 (pin 22). *
* Ensure that either nothing or just a LED is connected to *
-* gpio 4 before running any of the tests. *
+* gpio 25 before running any of the tests. *
* *
* Some tests are statistical in nature and so may on *
* occasion fail. Repeated failures on the same test or *
#include <stdint.h>
#include <pthread.h>
-#define PIGPIO_VERSION 6701
+#define PIGPIO_VERSION 6702
/*TEXT
.br
pigs will show the result of the command on screen.
+.br
+The pigs process returns an exit status (which can be displayed with
+the command echo $?).
+
+.br
+
+.EX
+PIGS_OK 0
+.br
+PIGS_CONNECT_ERR 255
+.br
+PIGS_OPTION_ERR 254
+.br
+PIGS_SCRIPT_ERR 253
+.br
+.br
+.br
+
+.EE
+
.br
The results of /dev/pigpio commands need to be read from /dev/pigout,
e.g. cat /dev/pigout (try cat /dev/pigout& so that all subsequent
*/
/*
-This version is for pigpio version 56+
+This version is for pigpio version 67+
*/
#include <stdio.h>
#include "pigpio.h"
#include "command.h"
+#include "pigs.h"
/*
This program provides a socket interface to some of
int printFlags = 0;
+int status = PIGS_OK;
+
#define SOCKET_OPEN_FAILED -1
#define PRINT_HEX 1
#define PRINT_ASCII 2
-void fatal(char *fmt, ...)
+void report(int err, char *fmt, ...)
{
char buf[128];
va_list ap;
+ if (err > status) status = err;
+
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
{
int opt, args;
+ opterr = 0;
+
args = 1;
while ((opt = getopt(argc, argv, "ax")) != -1)
printFlags |= PRINT_HEX;
args++;
break;
- }
+
+ default:
+ args++;
+ report(PIGS_OPTION_ERR, "ERROR: bad option %c", optopt);
+ }
}
return args;
}
if (r < 0)
{
printf("%d\n", r);
- fatal("ERROR: %s", cmdErrStr(r));
+ report(PIGS_SCRIPT_ERR, "ERROR: %s", cmdErrStr(r));
}
break;
case 2:
printf("%d\n", r);
- if (r < 0) fatal("ERROR: %s", cmdErrStr(r));
+ if (r < 0) report(PIGS_SCRIPT_ERR, "ERROR: %s", cmdErrStr(r));
break;
case 3:
I2CZ SERR SLR SPIX SPIR
*/
printf("%d", r);
- if (r < 0) fatal("ERROR: %s", cmdErrStr(r));
+ if (r < 0) report(PIGS_SCRIPT_ERR, "ERROR: %s", cmdErrStr(r));
if (r > 0)
{
if (printFlags == PRINT_ASCII) printf(" ");
if (r != (4 + (4*PI_MAX_SCRIPT_PARAMS)))
{
printf("%d", r);
- fatal("ERROR: %s", cmdErrStr(r));
+ report(PIGS_SCRIPT_ERR, "ERROR: %s", cmdErrStr(r));
}
else
{
if (r < 0)
{
printf("%d", r);
- fatal("ERROR: %s", cmdErrStr(r));
+ report(PIGS_SCRIPT_ERR, "ERROR: %s", cmdErrStr(r));
}
p = (uint32_t *)response_buf;
print_result(sock, cmdInfo[idx].rv, cmd);
}
- else fatal("socket receive failed");
+ else report(PIGS_CONNECT_ERR, "socket receive failed");
}
- else fatal("socket send failed");
+ else report(PIGS_CONNECT_ERR, "socket send failed");
}
- else fatal("socket connect failed");
+ else report(PIGS_CONNECT_ERR, "socket connect failed");
}
}
- else fatal("%s only allowed within a script", cmdInfo[idx].name);
+ else report(PIGS_SCRIPT_ERR,
+ "%s only allowed within a script", cmdInfo[idx].name);
}
else
{
if (idx == CMD_UNKNOWN_CMD)
- fatal("%s? unknown command, pigs h for help", cmdStr());
+ report(PIGS_SCRIPT_ERR,
+ "%s? unknown command, pigs h for help", cmdStr());
else
- fatal("%s: bad parameter, pigs h for help", cmdStr());
+ report(PIGS_SCRIPT_ERR,
+ "%s: bad parameter, pigs h for help", cmdStr());
}
}
if (sock >= 0) close(sock);
- return 0;
+ return status;
}
--- /dev/null
+/*
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
+*/
+
+/*
+This version is for pigpio version 67+
+*/
+
+#ifndef PIGS_H
+#define PIGS_H
+
+#define PIGS_OK 0
+#define PIGS_CONNECT_ERR 255
+#define PIGS_OPTION_ERR 254
+#define PIGS_SCRIPT_ERR 253
+
+#endif
+