diff options
author | FreeArtMan <dos21h@gmail.com> | 2017-07-16 11:23:34 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2017-07-16 11:23:34 +0100 |
commit | c7449c1a905f9bffddd374016fcc7bf30e0e8ad0 (patch) | |
tree | 751204c4031c398cc7f25416f211d8f2565adc5a | |
parent | 309b670b9b8778f314076b0606d6578ab031ad16 (diff) | |
download | agni-c7449c1a905f9bffddd374016fcc7bf30e0e8ad0.tar.gz agni-c7449c1a905f9bffddd374016fcc7bf30e0e8ad0.zip |
New command SPI added
-rw-r--r-- | cmd/cmd_spi.c | 118 | ||||
-rw-r--r-- | cmd/cmd_spi.h | 18 | ||||
-rw-r--r-- | config_all_cmds.h | 3 | ||||
-rw-r--r-- | config_cmds.h | 1 |
4 files changed, 139 insertions, 1 deletions
diff --git a/cmd/cmd_spi.c b/cmd/cmd_spi.c new file mode 100644 index 0000000..bfda27c --- /dev/null +++ b/cmd/cmd_spi.c @@ -0,0 +1,118 @@ +#include "cmd_spi.h" + +/* +SPI command shows some info about SPI protocol +HELP - shows all params +MISO,MOSI,SCK,HOLD,CS shows meaning of them +MODES - shows SPI modes avaliable +SPI - show diagram of spi +MASTER - show master connection +SLAVE - show slave connection +*/ + +//TODO multiline output =[ +char _spi_str_spi[]="""\ +--------\n\ +| MISO |\n\ +| MOSI |\n\ +| SCK |\n\ +| CS |\n\ +--------\n\ +"""; + +char _spi_str_slave[]="""\ +slave\n\ +--------\n\ +| MISO |>-\n\ +| MOSI |<-\n\ +| SCK |<-\n\ +| CS |<-\n\ +--------\n\ +"""; + +char _spi_str_master[]="""\ +master\n\ +--------\n\ +| MISO |<-\n\ +| MOSI |>-\n\ +| SCK |>-\n\ +| CS |>-\n\ +--------\n\ +"""; + +char *_spi_help_table[] = +{ + "help" ,"MODES,SPI,SLAVE,MASTER,MISO,MOSI,SCK,HOLD,CS", + "MODES" ,"QUAD(4-wires),DOUBLE(3-wires),SINGLE(2-wires)", + "SPI" ,_spi_str_spi, + "SLAVE" ,_spi_str_slave, + "MASTER",_spi_str_master, + "MISO" ,"(M)aster(I)nput(S)lave(O)utput", + "MOSI" ,"(M)aster(O)utput(S)lave(I)nput", + "SCK" ,"Serial Clockrate", + "HOLD" ,"HOLD operation for some time", + "CS" ,"(C)hip(S)elect", + NULL,NULL +}; + +char *__cmd_spi_iter(char **table, char *cmp) +{ + int iter = 0; + char *ret = NULL; + + //yea thats hack mate + iter = 0; + while (table[iter]!=NULL) + { + printf("%s\n",table[iter]); + if (strncmp(table[iter],cmp,strlen(table[iter]))==0) + { + ret = table[iter+1]; + } + iter += 2; + } + return ret; +} + +void *cmd_spi(void *data) +{ + char *ret = NULL; + char *match = NULL; + + int count=-1; + sds params; + sds *tokens=NULL; + + printf("SPI\n"); + + if (data == NULL) + { + ret = alloc_new_str("SPI protocol info!"); + } else + { + params = sdsnew(data); + tokens = sdssplitargs(params, &count); + + //maybe useless thing but who knows + if (count < 1) + { + ret = alloc_new_str("None args"); + } + + match = __cmd_spi_iter(_spi_help_table, tokens[0]); + if (match) + { + ret = alloc_new_str(match); + } else + { + ret = alloc_new_str("None such commund"); + } + + sdsfree(params); + sdsfreesplitres(tokens, count); + + } + + return ret; +} + diff --git a/cmd/cmd_spi.h b/cmd/cmd_spi.h new file mode 100644 index 0000000..818fb1a --- /dev/null +++ b/cmd/cmd_spi.h @@ -0,0 +1,18 @@ +#ifndef __CMD_SPI_H +#define __CMD_SPI_H + +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> +#include <time.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include "util.h" +#include "debug.h" +#include "sds.h" + +void *cmd_spi(void *data); + +#endif
\ No newline at end of file diff --git a/config_all_cmds.h b/config_all_cmds.h index 1170e5f..435a24b 100644 --- a/config_all_cmds.h +++ b/config_all_cmds.h @@ -1,6 +1,7 @@ #ifndef __CONFIG_CMD_HEADERS_H #define __CONFIG_CMD_HEADERS_H #include "cmd/cmd_rand.h" +#include "cmd/cmd_spi.h" #include "cmd/cmd_cmd.h" #include "cmd/cmd_rusage.h" #include "cmd/cmd_version.h" @@ -10,8 +11,8 @@ #include "cmd/cmd_loadavg.h" #include "cmd/cmd_uptime.h" #include "cmd/cmd_rand_libc.h" -#include "cmd/cmd_botu.h" #include "cmd/cmd_ping.h" +#include "cmd/cmd_botu.h" #include "cmd/cmd_fir.h" #include "cmd/cmd_sum.h" #include "cmd/cmd_help.h" diff --git a/config_cmds.h b/config_cmds.h index 76c721a..e3ce369 100644 --- a/config_cmds.h +++ b/config_cmds.h @@ -30,6 +30,7 @@ single_cmd_def confgi_cmd_list[] = {"RANDC",cmd_rand_libc}, {"FIR",cmd_fir}, {"HELP",cmd_help}, + {"SPI",cmd_spi}, {NULL,NULL} }; |