/*******************************************************************
Components for embedded applications builded for
- laboratory and medical instruments firmware
-
+ laboratory and medical instruments firmware
+
cmd_proc.h - text line command processor
designed for instruments control and setup
over RS-232 line
-
+
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>
#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 FL_ELB_NOCRLF 0x40 /* CR and/or LF will not start a new
+ * line (used for out buffers to store
+ * more than a single line) */
#define CMD_DES_CONTINUE_AT_ID ((cmd_des_t*)1)
#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)
int (*read)(struct cmd_io *cmd_io,void *buf,int count);
union {
struct {
- ed_line_buf_t *in;
- ed_line_buf_t *out;
+ ed_line_buf_t *in; /* Buffer for storing the read command line */
+ ed_line_buf_t *out; /* Temporarily stores characters to be sent
+ * out (until the send operation is
+ * finished). This is not used for echo
+ * handling. */
struct cmd_io *io_stack;
} ed_line;
struct {
/* Local Variables: */
/* c-basic-offset: 2 */
-/* End */
+/* End: */
/*******************************************************************
Components for embedded applications builded for
- laboratory and medical instruments firmware
-
+ laboratory and medical instruments firmware
+
cmd_proc.c - text command processor
enables to define multilevel tables of commands
which can be received from more inputs and send reply
to respective I/O stream output
-
+
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>
* @param cmd_io I/O stack
* @param des_arr Pointer to the command descriptors.
* @param line Command line to process.
- *
+ *
* @return Zero if no command was given in line, -CMDERR_BADCMD if
* command is not known or has no function assigned to it. If a
* command is executed, then the return value of the command function
int arr_stack_sp=0;
char *param[10];
short cmd_len;
- int res, i, parcnt;
+ int res, i, parcnt;
param[0]=p=skip_white(p);
if(!*p) return 0;
/* Determine the name of the command */
cmd_len=p-param[0];
}
param[1]=param[2]=skip_white(p);
-
+
/* Find the command in des_arr */
while(1){
des=*(des_arr++);
break;
}
i=1; /* Signal no match */
- break;
+ break;
}
if(i!=0) continue; /* Try next command */
/* Setup parameters */
* if the opchar is not ':' or '?'.
*/
int cmd_opchar_check(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
+{
int opchar=*param[2];
if(opchar==':'){
if(!(des->mode&CDESM_WR)){
p++;
}while(*p && !strchr(" :?=",*p));
*pval=val;
- return 0;
+ return 0;
}
cmd_io_write(cmd_io,param[0],param[2]-param[0]);
cmd_io_putc(cmd_io,'=');
cmd_io_write(cmd_io,param[3],strlen(param[3]));
- return 0;
+ return 0;
}
/**
}else{
return cmd_opchar_replong(cmd_io, param, (long)*ptr, 0, 0);
}
- return 0;
+ return 0;
}
/**
}else{
return cmd_opchar_replong(cmd_io, param, (long)*ptr, 0, 0);
}
- return 0;
+ return 0;
}
}else{
return cmd_opchar_replong(cmd_io, param, (long)*ptr, 0, 0);
}
- return 0;
+ return 0;
}
/**
/* Local Variables: */
/* c-basic-offset: 2 */
-/* End */
+/* End: */
/*******************************************************************
Components for embedded applications builded for
- laboratory and medical instruments firmware
-
+ laboratory and medical instruments firmware
+
cmd_proc.h - text line command processor
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
(C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
/* cmd_io line editor */
-/**
+/**
* Adds new characters to an edit line buffer.
- *
+ *
* @param elb Edit line buffer.
* @param ch character to add.
- *
- * @return 1 in case of end of line, 0 otherwise.
+ *
+ * @return 1 in case of end of line, -1 if called at inaproprate time, 0 otherwise.
*/
int cmd_ed_line_buf(ed_line_buf_t *elb, int ch)
{
if(!lastch){
elb->inbuf=0; /* Start new line */
}
+ if(ch == '\b') { /* backspace */
+ if (elb->inbuf > 0)
+ elb->inbuf--;
+ return 0;
+ }
if((!(elb->flg&FL_ELB_NOCRLF))&&((ch=='\n')||(ch=='\r'))){
if((lastch=='\n')&&(ch=='\r')) /* Empty line, ignore it. */
return 0;
elb->buf[elb->inbuf]=0;
return 1;
}
- if(elb->inbuf>=elb->alloc-1){
+ if(elb->inbuf>=elb->alloc-1){
/* try to reallocate buffer len not implemented */
return 0;
}
- elb->buf[elb->inbuf++]=ch;
+ elb->buf[elb->inbuf++]=ch;
return 0;
}
{
cmd_io_t* io_stack=cmd_io->priv.ed_line.io_stack;
ed_line_buf_t* ed_line_out=cmd_io->priv.ed_line.out;
-
+
if(!ed_line_out->inbuf) return 0;
if(!io_stack)
return -1;
-
+
if(!(ed_line_out->flg&FL_ELB_INSEND)){
ed_line_out->flg|=FL_ELB_INSEND;
ed_line_out->lastch=0;
return 1;
}
-/* process input */
+/* process input & perform echo if requested */
int cmd_io_line_in(cmd_io_t *cmd_io)
{
int ch;
while((ch=cmd_io_getc(io_stack))>=0){
// DPRINT("Added %c (%d)\n", ch, ch);
int eol = cmd_ed_line_buf(ed_line_in,ch);
+ if (eol == -1)
+ return -1;
if(eol){
if(ed_line_in->flg&FL_ELB_ECHO){
while(cmd_io_putc(io_stack,'\r')<0);
}
return 1;
}
- else
+ else
if(ed_line_in->flg&FL_ELB_ECHO) {
while(cmd_io_putc(io_stack,ch)<0);
}
/* Local Variables: */
/* c-basic-offset: 2 */
-/* End */
+/* End: */
/*******************************************************************
Components for embedded applications builded for
- laboratory and medical instruments firmware
-
+ laboratory and medical instruments firmware
+
cmd_proc.c - text command processor
enables to define multilevel tables of commands
which can be received from more inputs and send reply
to respective I/O stream output
-
+
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>
/* Local Variables: */
/* c-basic-offset: 2 */
-/* End */
+/* End: */