|
【TI首届低功耗设计大赛】为LaunchPad添加AT指令解析
[复制链接]
相关代码和介绍可以参考我之前的贴子,这里只是简单的说明修改的地方和一个测试AT指令,当然这里的AT回显部分未做,是直接在命令行中echo的。测试支持两个AT+H和AT+MODE,分别是帮助和LED运行模式控制
argv和argc解析函数
- /**
- * @brief make_argv
- * @note ARGV执行
- * @param none
- * @retval none
- */
- int
- make_argv (char *cmdline, char *argv[])
- {
- char argvTAB;
- int argc, i, in_text;
-
- /*
- * Break cmdline into strings and argv
- * It is permissible for argv to be NULL, in which case
- * the purpose of this routine becomes to count args
- */
- i = 0;
- argc = 0;
- in_text = FALSE;
-
- /* getline() must place 0x00 on end */
- while (cmdline[i] != '\0') {
- if (argc == 1) {
- argvTAB = '=';
- } else {
- argvTAB = ',';
- }
- if ( (cmdline[i] == argvTAB) || (cmdline[i] == '\t') ) {
- if (in_text) {
- /* end of command line argument */
- cmdline[i] = '\0';
- in_text = FALSE;
- } else {
- /* still looking for next argument */
-
- }
- } else {
- /* got non-whitespace character */
- if (in_text){
- } else {
- /* start of an argument */
- in_text = TRUE;
- if (argc < UIF_MAX_ARGS) {
- if (argv != NULL) {
- argv[argc] = &cmdline[i];
- }
- argc++;
- } else {
- /*return argc;*/
- break;
- }
- }
-
- }
- /* proceed to next character */
- i++;
- }
- if (argv != NULL) {
- argv[argc] = NULL;
- }
- return argc;
- }
复制代码
AT+MODE实现
- /**
- * @brief uif_cmd_mode
- * @note MODE命令
- * @param none
- * @retval none
- */
- void
- uif_cmd_mode (int argc, char **argv)
- {
- char runMode[10];
- char runFreq[10];
-
- if (argc == 1) {
- if (ledMode == 0){
- strcpy(runMode,"off");
- } else if (ledMode == 1){
- strcpy(runMode,"on");
- } else if (ledMode == 2){
- strcpy(runMode,"toggle");
- } else {
- return;
- }
- _itoa(ledFreq, runFreq, 10);
- printf("+ok=%s,%s\r\n\r\n", runMode, runFreq);
- return;
- }
-
- if (argc != 3) {
- printf("Error: Invalid argument list\r\n");
- printf("\r\n");
- return;
- }
- if ( ((argc-1-1) >= UIF_CMDTAB[1].min_args) && ((argc-1-1) <= UIF_CMDTAB[1].max_args) ) {
- if (argv[1] != NULL) {
- if (strcasecmp("off", argv[1]) == 0){
- ledMode = 0;
- } else if(strcasecmp("on", argv[1]) == 0){
- ledMode = 1;
- } else if(strcasecmp("toggle", argv[1]) == 0){
- ledMode = 2;
- } else {
- printf(INVOPT, argv[1]);
- printf("\r\n");
- return;
- }
- }
- if(argv[2] != NULL){
- ledFreq = _atoi((char*)argv[2], 10);
- if (ledFreq > 50) {
- ledFreq = 50;
- printf(INVOPT, argv[2]);
- printf("\r\n");
- return;
- }
- }
- printf("+ok\r\n\r\n");
- return;
- } else {
- printf(INVARG, argv[0]);
- printf("\r\n");
- return;
- }
- }
复制代码
测试命令行:
相关功耗测试/功耗模式配置查询等AT指令待实现
|
|