00001 /* 00002 This is free and unencumbered software released into the public domain. 00003 00004 Anyone is free to copy, modify, publish, use, compile, sell, or 00005 distribute this software, either in source code form or as a compiled 00006 binary, for any purpose, commercial or non-commercial, and by any 00007 means. 00008 00009 In jurisdictions that recognize copyright laws, the author or authors 00010 of this software dedicate any and all copyright interest in the 00011 software to the public domain. We make this dedication for the benefit 00012 of the public at large and to the detriment of our heirs and 00013 successors. We intend this dedication to be an overt act of 00014 relinquishment in perpetuity of all present and future rights to this 00015 software under copyright law. 00016 00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00018 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00019 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00020 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00021 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00022 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00023 OTHER DEALINGS IN THE SOFTWARE. 00024 00025 For more information, please refer to <http://unlicense.org/> 00026 */ 00027 00028 /* 00029 This version is for pigpio version 57+ 00030 */ 00031 00032 #ifndef COMMAND_H 00033 #define COMMAND_H 00034 00035 #include <stdio.h> 00036 #include <string.h> 00037 00038 #include "pigpio.h" 00039 00040 #define CMD_MAX_PARAM 512 00041 #define CMD_MAX_EXTENSION (1<<16) 00042 00043 #define CMD_UNKNOWN_CMD -1 00044 #define CMD_BAD_PARAMETER -2 00045 #define CMD_EXT_TOO_SMALL -3 00046 00047 #define CMD_P_ARR 10 00048 #define CMD_V_ARR 10 00049 00050 #define CMD_NUMERIC 1 00051 #define CMD_VAR 2 00052 #define CMD_PAR 3 00053 00054 typedef struct 00055 { 00056 uint32_t cmd; 00057 uint32_t p1; 00058 uint32_t p2; 00059 union 00060 { 00061 uint32_t p3; 00062 uint32_t ext_len; 00063 uint32_t res; 00064 }; 00065 } cmdCmd_t; 00066 00067 typedef struct 00068 { 00069 int eaten; 00070 int8_t opt[4]; 00071 } cmdCtlParse_t; 00072 00073 typedef struct 00074 { 00075 int cmd; /* command number */ 00076 char *name; /* command name */ 00077 int vt; /* command verification type */ 00078 int rv; /* command return value type */ 00079 } cmdInfo_t; 00080 00081 typedef struct 00082 { 00083 uint32_t tag; 00084 int step; 00085 } cmdTagStep_t; 00086 00087 typedef struct 00088 { 00089 uint32_t p[5]; 00090 int8_t opt[4]; 00091 } cmdInstr_t; 00092 00093 typedef struct 00094 { 00095 /* 00096 +-----------+---------+---------+----------------+ 00097 | PARAMS... | VARS... | CMDS... | STRING AREA... | 00098 +-----------+---------+---------+----------------+ 00099 */ 00100 int *par; 00101 int *var; 00102 cmdInstr_t *instr; 00103 int instrs; 00104 char *str_area; 00105 int str_area_len; 00106 int str_area_pos; 00107 } cmdScript_t; 00108 00109 extern cmdInfo_t cmdInfo[]; 00110 00111 extern char *cmdUsage; 00112 00113 int cmdParse(char *buf, uint32_t *p, unsigned ext_len, char *ext, cmdCtlParse_t *ctl); 00114 00115 int cmdParseScript(char *script, cmdScript_t *s, int diags); 00116 00117 char *cmdErrStr(int error); 00118 00119 char *cmdStr(void); 00120 00121 #endif 00122