Command all jmCLIG modules from serial port

Committer:
jm
Date:
Sat Feb 12 16:50:25 2011 +0000
Revision:
0:9112e09912db
jmAll Command Line Interface Module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jm 0:9112e09912db 1 /*************************************************************************
jm 0:9112e09912db 2 * @file jmMessages.c
jm 0:9112e09912db 3 * @brief Control System Messages
jm 0:9112e09912db 4 *
jm 0:9112e09912db 5 * @date December 27,2010
jm 0:9112e09912db 6 */
jm 0:9112e09912db 7
jm 0:9112e09912db 8 #include "jmCommands.h"
jm 0:9112e09912db 9 #include "jmRingBuffer.h"
jm 0:9112e09912db 10 #include "stdio.h"
jm 0:9112e09912db 11 #include "jmMessages.h"
jm 0:9112e09912db 12 #include "stdint.h"
jm 0:9112e09912db 13
jm 0:9112e09912db 14 uint8_t Help;
jm 0:9112e09912db 15 uint8_t Feedback;
jm 0:9112e09912db 16 uint8_t Echo;
jm 0:9112e09912db 17
jm 0:9112e09912db 18
jm 0:9112e09912db 19 /** @brief Enable only help messages
jm 0:9112e09912db 20 * @param none
jm 0:9112e09912db 21 * @returns none
jm 0:9112e09912db 22 */
jm 0:9112e09912db 23 void InitMessages(void){
jm 0:9112e09912db 24 Help = 1;
jm 0:9112e09912db 25 Echo = 0;
jm 0:9112e09912db 26 Feedback = 0;
jm 0:9112e09912db 27 }
jm 0:9112e09912db 28
jm 0:9112e09912db 29 /** @brief Send all command names in a project
jm 0:9112e09912db 30 * @param none
jm 0:9112e09912db 31 * @returns none
jm 0:9112e09912db 32 */
jm 0:9112e09912db 33 void cli_list(void){
jm 0:9112e09912db 34 int i,j;
jm 0:9112e09912db 35 printf("Commands:\n");
jm 0:9112e09912db 36 printf(".......................\n");
jm 0:9112e09912db 37 // for each command
jm 0:9112e09912db 38 for(i=0,j=0; i<nbCommands; i++,j++){
jm 0:9112e09912db 39 // print name
jm 0:9112e09912db 40 while(cmdNames[j]) printf("%c",cmdNames[j++]);
jm 0:9112e09912db 41 printf("\n");
jm 0:9112e09912db 42 }
jm 0:9112e09912db 43 printf("........................\n");
jm 0:9112e09912db 44 }
jm 0:9112e09912db 45
jm 0:9112e09912db 46 /** @brief Send Message Unknown Command from interpreter
jm 0:9112e09912db 47 * @param none
jm 0:9112e09912db 48 * @returns none
jm 0:9112e09912db 49 */
jm 0:9112e09912db 50 void UnknownCommand(void){
jm 0:9112e09912db 51 printf("\n?\n");
jm 0:9112e09912db 52 }
jm 0:9112e09912db 53
jm 0:9112e09912db 54 /** @brief Send Build Version Message
jm 0:9112e09912db 55 * @param none
jm 0:9112e09912db 56 * @returns none
jm 0:9112e09912db 57 */
jm 0:9112e09912db 58 void cli_version(void){
jm 0:9112e09912db 59 printf(jmCLIG);
jm 0:9112e09912db 60 }
jm 0:9112e09912db 61
jm 0:9112e09912db 62 /** @brief Help Command Line Control.
jm 0:9112e09912db 63 * Enable/disable help messages
jm 0:9112e09912db 64 * When enabled, Typing name only prints Command Format
jm 0:9112e09912db 65 * @param none
jm 0:9112e09912db 66 * @returns none
jm 0:9112e09912db 67 */
jm 0:9112e09912db 68 void cli_help(void){
jm 0:9112e09912db 69 unsigned int value;
jm 0:9112e09912db 70 if(ExtractUInteger(pLine,&value,0,1)){
jm 0:9112e09912db 71 if(value == 1) printf("Help Enabled ! type command name to print its format\n");
jm 0:9112e09912db 72 else printf("Help Disabled !\n");
jm 0:9112e09912db 73
jm 0:9112e09912db 74 Help = (uint8_t) value; // save status
jm 0:9112e09912db 75 return;
jm 0:9112e09912db 76 }
jm 0:9112e09912db 77 // Error on input, show format
jm 0:9112e09912db 78 if(Help)printf("help (value)0..1\n");
jm 0:9112e09912db 79 // Ignore pending command line
jm 0:9112e09912db 80 NextCommand(nl,pLine);
jm 0:9112e09912db 81 }
jm 0:9112e09912db 82
jm 0:9112e09912db 83 /** @brief Feedback Command Line Control.
jm 0:9112e09912db 84 * Enable/disable feedback messages
jm 0:9112e09912db 85 * When enabled, feedback from user input commands are returned
jm 0:9112e09912db 86 * @param none
jm 0:9112e09912db 87 * @returns none
jm 0:9112e09912db 88 */
jm 0:9112e09912db 89 void cli_feedback(void){
jm 0:9112e09912db 90 unsigned int value;
jm 0:9112e09912db 91 if(ExtractUInteger(pLine,&value,0,1)){
jm 0:9112e09912db 92 if(value == 1) printf("Feedback Enabled !\n");
jm 0:9112e09912db 93 else printf("Feedback Disabled !\n");
jm 0:9112e09912db 94
jm 0:9112e09912db 95 Feedback = (uint8_t)value; // save status
jm 0:9112e09912db 96 return;
jm 0:9112e09912db 97 }
jm 0:9112e09912db 98
jm 0:9112e09912db 99 // Error on input, show format
jm 0:9112e09912db 100 if(Help)printf("feedback (value)0..1\n");
jm 0:9112e09912db 101 // Ignore pending command line
jm 0:9112e09912db 102 NextCommand(nl,pLine);
jm 0:9112e09912db 103 }
jm 0:9112e09912db 104
jm 0:9112e09912db 105 /** @brief Echo Command Line Control.
jm 0:9112e09912db 106 * Enable/disable communication echoes
jm 0:9112e09912db 107 * When enabled, user inputs are echoed back
jm 0:9112e09912db 108 * @param none
jm 0:9112e09912db 109 * @returns none
jm 0:9112e09912db 110 */
jm 0:9112e09912db 111 void cli_echo(void){
jm 0:9112e09912db 112 unsigned int value;
jm 0:9112e09912db 113 if(ExtractUInteger(pLine,&value,0,1)){
jm 0:9112e09912db 114 if(value == 1) printf("Echo Enabled !\n");
jm 0:9112e09912db 115 else printf("Echo Disabled !\n");
jm 0:9112e09912db 116
jm 0:9112e09912db 117 Echo = (uint8_t)value; // save status
jm 0:9112e09912db 118 return;
jm 0:9112e09912db 119 }
jm 0:9112e09912db 120
jm 0:9112e09912db 121 // Error on input, show format
jm 0:9112e09912db 122 if(Help)printf("echo (value)0..1\n");
jm 0:9112e09912db 123 // Ignore pending command line
jm 0:9112e09912db 124 NextCommand(nl,pLine);
jm 0:9112e09912db 125 }