designed for instruments control and setup
over RS-232 line
- Copyright (C) 2001 by Pavel Pisa pisa@cmp.felk.cvut.cz
- (C) 2002 by PiKRON Ltd. http://www.pikron.com
+ Copyright (C) 2001-2009 by Pavel Pisa pisa@cmp.felk.cvut.cz
+ (C) 2002-2009 by PiKRON Ltd. http://www.pikron.com
(C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
This file can be used and copied according to next
#ifndef _CMD_PROC_H_
#define _CMD_PROC_H_
+#define CMD_PROC_WITH_FILE
+
+#ifdef CMD_PROC_WITH_FILE
+#include <stdio.h>
+#endif
+
#define FL_ELB_ECHO 0x10 /* Read characters are echoed back */
#define FL_ELB_INSEND 0x20 /* The line is currently being sent */
#define FL_ELB_NOCRLF 0x40 /* CR and/or LF will not start the new line */
#define CMD_DES_INCLUDE_SUBLIST_ID ((cmd_des_t*)2)
#define CMD_DES_CONTINUE_AT(list) CMD_DES_CONTINUE_AT_ID,((cmd_des_t*)list)
#define CMD_DES_INCLUDE_SUBLIST(list) CMD_DES_INCLUDE_SUBLIST_ID,((cmd_des_t*)list)
-/* generic cmd_io tructure */
+
+/* generic cmd_io structure */
/* buffer for in/out line collection */
typedef struct{
long pos;
void *ptr;
} device;
+#ifdef CMD_PROC_WITH_FILE
+ struct {
+ FILE *in;
+ FILE *out;
+ } file;
+#endif /*CMD_PROC_WITH_FILE*/
+ struct {
+ int uartch;
+ } uart;
} priv;
} cmd_io_t;
#define CDESM_RD 0x01 /* Value read is possible */
#define CDESM_WR 0x02 /* Value write is possible */
#define CDESM_RW (CDESM_RD|CDESM_WR) /* Both */
-
+#define CDESM_SPACE_SEP 0x20 /* Whitespace separated params - replaces space with '\0' */
+
+/**
+ * Command descriptor.
+ *
+ * Command name may contain the following wildcards:
+ * - '?' stands for one alphanumeric character
+ * - '#' stands for one digit
+ * - '*' stands for any number of alphanumeric characters at the end of the command
+ *
+ * The fnc() function is passed the following information as the param array:
+ * - param[0] points to the command (the longest sequence of alphanumeric characters)
+ * If CDESM_OPCHR is specified in the command descriptor then
+ * - param[1] points to the first wildcard in the command or is NULL for commands without wildcard in the name
+ * - param[2] points to the operation character (':' or '?') and
+ * - param[3] points to the string after the operation character (after skipping whitespace)
+ * If CDESM_OPCHR is not specified then
+ * If the command name contains a wildcard,
+ * - param[1] points to the first wildcard in the command and
+ * If the command has any parameters
+ * - param[1] or param[2] (depending on the presence of a wildcard)
+ * points to the beginning of those parameters (after skipping
+ * whitespace)
+ *
+ * If CDESM_SPACE_SEP is specified in the command descriptor, then
+ * the command arguments are split at whitespace by '\0'
+ * characters and stored in the next unused param elements. Param
+ * array can contain up to 9 elements.
+ *
+ * The param elements are always terminated by NULL element.
+ */
typedef struct cmd_des{
- int code;
- int mode;
- char *name;
+ int code; /* Application specific code */
+ int mode; /* CDESM_* constants */
+ char *name; /* Name of the command with possible wildcards */
char *help;
int (*fnc)(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
char *info[];
#define CMDERR_BADSEP 14
#define CMDERR_BADCFG 15
#define CMDERR_NOMEM 16
+#define CMDERR_BADSUF 17
#define CMDERR_BADPAR 20
+#define CMDERR_VALOOR 21
#define CMDERR_BADREG 40
#define CMDERR_BSYREG 41
#define CMDERR_BADDIO 50
int cmd_opchar_check(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+int cmd_num_suffix(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[], unsigned *val);
+
int proc_cmd_line(cmd_io_t *cmd_io, cmd_des_t const **des_arr, char *line);
int i2str(char *s,long val,int len,int form);