]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-dad.git/blob - sw/app/lx_dad/appl_cmds.c
Added commands to control echo mode and check commands FIFOs round-trip.
[fpga/lx-cpu1/lx-dad.git] / sw / app / lx_dad / appl_cmds.c
1 /*******************************************************************
2   Motion and Robotic System (MARS) aplication components
3
4   appl_cmds.c - application specific commands 
5
6   Copyright (C) 2001-2015 by Pavel Pisa - originator
7                           pisa@cmp.felk.cvut.cz
8             (C) 2001-2015 by PiKRON Ltd. - originator
9                     http://www.pikron.com
10
11   This file can be used and copied according to next
12   license alternatives
13    - GPL - GNU Public License
14    - other license provided by project originators
15
16  *******************************************************************/
17
18 #include <cpu_def.h>
19 #include <system_def.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <cmd_proc.h>
23 #include <utils.h>
24
25 #include "appl_defs.h"
26
27 #ifndef __STRINGIFY
28 #define __STRINGIFY(x)     #x              /* stringify without expanding x */
29 #endif
30 #ifndef STRINGIFY
31 #define STRINGIFY(x)    __STRINGIFY(x)        /* expand x, then stringify */
32 #endif
33
34 int cmd_do_ioecho(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
35 {
36   int val;
37   int opchar;
38
39   if((opchar=cmd_opchar_check(cmd_io, des, param))<0) return opchar;
40   if(opchar == ':') {
41     val = *param[3];
42     if (val == '0')
43       cmd_io->priv.ed_line.in->flg &= ~FL_ELB_ECHO;
44     else if(val == '1')
45       cmd_io->priv.ed_line.in->flg |= FL_ELB_ECHO;
46     else return -CMDERR_BADPAR;
47   }else{
48     cmd_io_write(cmd_io, param[0], param[2]-param[0]);
49     cmd_io_putc(cmd_io,'=');
50     cmd_io_putc(cmd_io,cmd_io->priv.ed_line.in->flg & FL_ELB_ECHO?'1':'0');
51   }
52   return 0;
53 }
54
55 const char software_ver[]="LX_DAD v"STRINGIFY(SW_VER_MAJOR)"."STRINGIFY(SW_VER_MINOR)
56            " build Pi "__DATE__" "__TIME__;
57
58 int cmd_do_ver(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
59 {
60   if(*param[2]!='?') return -CMDERR_OPCHAR;
61   cmd_io_write(cmd_io,param[0],param[2]-param[0]);
62   cmd_io_putc(cmd_io,'=');
63   cmd_io_write(cmd_io,software_ver,strlen(software_ver));
64   return 0;
65 }
66
67 cmd_des_t const cmd_des_stamp={0, CDESM_OPCHR,
68                         "STAMP","host communication stamp",
69                         cmd_do_stamp,{}};
70 cmd_des_t const cmd_des_echo={0, CDESM_OPCHR|CDESM_RW,
71                         "ECHO","enable echoing of received character",cmd_do_ioecho,{}};
72 cmd_des_t const cmd_des_ver={0, CDESM_OPCHR|CDESM_RD,
73                         "VER","software version",cmd_do_ver,{}};
74
75 cmd_des_t const *const cmd_appl_specific[]={
76   &cmd_des_stamp,
77   &cmd_des_echo,
78   &cmd_des_ver,
79   NULL
80 };