ME11B Sample Code in Maxim Integrated Team
Dependencies: BMI160 max32630hsp3 MemoryLCD USBDevice
Fork of Host_Software_MAX32664GWEB_HR_EXTENDED by
cmdUI/cmdInterface.cpp@0:ac4dea3e2894, 2019-03-18 (annotated)
- Committer:
- seyhmus.cacina
- Date:
- Mon Mar 18 10:21:53 2019 +0300
- Revision:
- 0:ac4dea3e2894
ME11B Sample Code First Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seyhmus.cacina | 0:ac4dea3e2894 | 1 | /* |
seyhmus.cacina | 0:ac4dea3e2894 | 2 | * cmdInterface.cpp |
seyhmus.cacina | 0:ac4dea3e2894 | 3 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 4 | * Created on: Jan 30, 2019 |
seyhmus.cacina | 0:ac4dea3e2894 | 5 | * Author: Yagmur.Gok |
seyhmus.cacina | 0:ac4dea3e2894 | 6 | */ |
seyhmus.cacina | 0:ac4dea3e2894 | 7 | |
seyhmus.cacina | 0:ac4dea3e2894 | 8 | #include <mbed.h> |
seyhmus.cacina | 0:ac4dea3e2894 | 9 | #include "cmdInterface.h" |
seyhmus.cacina | 0:ac4dea3e2894 | 10 | #include "SH_Max8614x_BareMetal.h" |
seyhmus.cacina | 0:ac4dea3e2894 | 11 | #include "bootldrAPI.h" |
seyhmus.cacina | 0:ac4dea3e2894 | 12 | #include "SHComm.h" |
seyhmus.cacina | 0:ac4dea3e2894 | 13 | #include "demoDefinitions.h" |
seyhmus.cacina | 0:ac4dea3e2894 | 14 | |
seyhmus.cacina | 0:ac4dea3e2894 | 15 | static uint8_t hostOperatingMode = HOSTMODEAPPLICATION; |
seyhmus.cacina | 0:ac4dea3e2894 | 16 | static uint8_t hostCommEchoMode = HOSTCOMMMODE_ECHO_OFF; |
seyhmus.cacina | 0:ac4dea3e2894 | 17 | |
seyhmus.cacina | 0:ac4dea3e2894 | 18 | /* @brief function to get the current operating mode of HOST: "APPMODE" or "BOOTLOADERMODE" |
seyhmus.cacina | 0:ac4dea3e2894 | 19 | * associated with command: "get_host_opmode". |
seyhmus.cacina | 0:ac4dea3e2894 | 20 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 21 | * @param[in] arg : NULL string, just to match the form of command table function pointer type |
seyhmus.cacina | 0:ac4dea3e2894 | 22 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 23 | * */ |
seyhmus.cacina | 0:ac4dea3e2894 | 24 | static int get_host_operating_mode(const char* arg){ |
seyhmus.cacina | 0:ac4dea3e2894 | 25 | |
seyhmus.cacina | 0:ac4dea3e2894 | 26 | int status = 0x00; |
seyhmus.cacina | 0:ac4dea3e2894 | 27 | SERIALOUT("\r\n%s host_operating_mode=%s\r\n", "get_host_mode", (hostOperatingMode ==HOSTMODEAPPLICATION)? "APPMODE":"BOOTLOADERMODE" ); |
seyhmus.cacina | 0:ac4dea3e2894 | 28 | return status; |
seyhmus.cacina | 0:ac4dea3e2894 | 29 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 30 | |
seyhmus.cacina | 0:ac4dea3e2894 | 31 | /* @brief function to set the current operating mode of HOST: "APPMODE" or "BOOTLOADERMODE" |
seyhmus.cacina | 0:ac4dea3e2894 | 32 | * associated with command: "set_host_opmode". |
seyhmus.cacina | 0:ac4dea3e2894 | 33 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 34 | * @param[in] arg: whole command string with argument included: "set_host_opmode X", X: 1 or 0 |
seyhmus.cacina | 0:ac4dea3e2894 | 35 | * 0 : APPMODE |
seyhmus.cacina | 0:ac4dea3e2894 | 36 | * 1 : BOOTLOADERMODE |
seyhmus.cacina | 0:ac4dea3e2894 | 37 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 38 | * */ |
seyhmus.cacina | 0:ac4dea3e2894 | 39 | static int set_host_operating_mode(const char* arg){ |
seyhmus.cacina | 0:ac4dea3e2894 | 40 | |
seyhmus.cacina | 0:ac4dea3e2894 | 41 | int status = -1; |
seyhmus.cacina | 0:ac4dea3e2894 | 42 | uint32_t val; |
seyhmus.cacina | 0:ac4dea3e2894 | 43 | if( sscanf(arg, "%*s %x", &val) == 1 ){ |
seyhmus.cacina | 0:ac4dea3e2894 | 44 | hostOperatingMode = ( val > 0 )? HOSTMODEBOOTLOADER:HOSTMODEAPPLICATION; |
seyhmus.cacina | 0:ac4dea3e2894 | 45 | |
seyhmus.cacina | 0:ac4dea3e2894 | 46 | status = 0x00; |
seyhmus.cacina | 0:ac4dea3e2894 | 47 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 48 | SERIALOUT("\r\n%s err=%d\r\n", "set_host_opmode", status); |
seyhmus.cacina | 0:ac4dea3e2894 | 49 | return status; |
seyhmus.cacina | 0:ac4dea3e2894 | 50 | |
seyhmus.cacina | 0:ac4dea3e2894 | 51 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 52 | |
seyhmus.cacina | 0:ac4dea3e2894 | 53 | |
seyhmus.cacina | 0:ac4dea3e2894 | 54 | /* @brief function to get the current firmware version of Sensor Hub". |
seyhmus.cacina | 0:ac4dea3e2894 | 55 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 56 | * @param[in] arg : NULL string, just to match the form of command table function pointer type |
seyhmus.cacina | 0:ac4dea3e2894 | 57 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 58 | * */ |
seyhmus.cacina | 0:ac4dea3e2894 | 59 | static int get_hub_firmware_version(const char* arg){ |
seyhmus.cacina | 0:ac4dea3e2894 | 60 | |
seyhmus.cacina | 0:ac4dea3e2894 | 61 | int idx; |
seyhmus.cacina | 0:ac4dea3e2894 | 62 | int status = -1; |
seyhmus.cacina | 0:ac4dea3e2894 | 63 | static const int MAXFWDESCSIZE = 5; |
seyhmus.cacina | 0:ac4dea3e2894 | 64 | uint8_t descArray[MAXFWDESCSIZE]; |
seyhmus.cacina | 0:ac4dea3e2894 | 65 | uint8_t descSz; |
seyhmus.cacina | 0:ac4dea3e2894 | 66 | |
seyhmus.cacina | 0:ac4dea3e2894 | 67 | status = sh_get_ss_fw_version( &descArray[0] , &descSz); |
seyhmus.cacina | 0:ac4dea3e2894 | 68 | if(status == 0x00 && descSz > 0 && descSz < MAXFWDESCSIZE){ |
seyhmus.cacina | 0:ac4dea3e2894 | 69 | SERIALOUT("\r\n Firmware Version of Sensor Hub is = "); |
seyhmus.cacina | 0:ac4dea3e2894 | 70 | for(idx = 0 ; idx != descSz ; idx++) |
seyhmus.cacina | 0:ac4dea3e2894 | 71 | SERIALOUT("%d.", descArray[idx]); |
seyhmus.cacina | 0:ac4dea3e2894 | 72 | SERIALOUT("\r\n"); |
seyhmus.cacina | 0:ac4dea3e2894 | 73 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 74 | |
seyhmus.cacina | 0:ac4dea3e2894 | 75 | |
seyhmus.cacina | 0:ac4dea3e2894 | 76 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 77 | |
seyhmus.cacina | 0:ac4dea3e2894 | 78 | static int set_host_comm_echomode(const char* arg){ |
seyhmus.cacina | 0:ac4dea3e2894 | 79 | |
seyhmus.cacina | 0:ac4dea3e2894 | 80 | int status = -1; |
seyhmus.cacina | 0:ac4dea3e2894 | 81 | uint32_t val; |
seyhmus.cacina | 0:ac4dea3e2894 | 82 | if( sscanf(arg, "%*s %x", &val) == 1 ){ |
seyhmus.cacina | 0:ac4dea3e2894 | 83 | hostCommEchoMode = ( val > 0 )? HOSTCOMMMODE_ECHO_ON:HOSTCOMMMODE_ECHO_OFF; |
seyhmus.cacina | 0:ac4dea3e2894 | 84 | |
seyhmus.cacina | 0:ac4dea3e2894 | 85 | status = 0x00; |
seyhmus.cacina | 0:ac4dea3e2894 | 86 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 87 | SERIALOUT("\r\n%s err=%d\r\n", "set_host_comm_echomode", status); |
seyhmus.cacina | 0:ac4dea3e2894 | 88 | return status; |
seyhmus.cacina | 0:ac4dea3e2894 | 89 | |
seyhmus.cacina | 0:ac4dea3e2894 | 90 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 91 | |
seyhmus.cacina | 0:ac4dea3e2894 | 92 | /* |
seyhmus.cacina | 0:ac4dea3e2894 | 93 | static int get_hub_operating_mode(const char* arg){ |
seyhmus.cacina | 0:ac4dea3e2894 | 94 | |
seyhmus.cacina | 0:ac4dea3e2894 | 95 | uint8_t hubMode; |
seyhmus.cacina | 0:ac4dea3e2894 | 96 | int status = sh_get_sensorhub_operating_mode(&hubMode); |
seyhmus.cacina | 0:ac4dea3e2894 | 97 | if( status == 0x00) |
seyhmus.cacina | 0:ac4dea3e2894 | 98 | SERIALOUT("\r\n hub_operating_mode=%s\r\n", (hubMode == 0x00)? "APPMODE":"BOOTLOADERMODE" ); |
seyhmus.cacina | 0:ac4dea3e2894 | 99 | else |
seyhmus.cacina | 0:ac4dea3e2894 | 100 | SERIALOUT("\r\n%s err=%d\r\n", "get_sensorhub_opmode", status); |
seyhmus.cacina | 0:ac4dea3e2894 | 101 | |
seyhmus.cacina | 0:ac4dea3e2894 | 102 | return status; |
seyhmus.cacina | 0:ac4dea3e2894 | 103 | }*/ |
seyhmus.cacina | 0:ac4dea3e2894 | 104 | |
seyhmus.cacina | 0:ac4dea3e2894 | 105 | //__attribute__((__always_inline__)) |
seyhmus.cacina | 0:ac4dea3e2894 | 106 | uint8_t get_internal_operating_mode(void) { |
seyhmus.cacina | 0:ac4dea3e2894 | 107 | |
seyhmus.cacina | 0:ac4dea3e2894 | 108 | return hostOperatingMode; |
seyhmus.cacina | 0:ac4dea3e2894 | 109 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 110 | |
seyhmus.cacina | 0:ac4dea3e2894 | 111 | |
seyhmus.cacina | 0:ac4dea3e2894 | 112 | /* HOST MCU related mode functions inoredr to keep application&bootloader side modular: |
seyhmus.cacina | 0:ac4dea3e2894 | 113 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 114 | * 1. in app mode Host accepts commnands related to algo/ppg applications ( command table in SH_Max8614x_BareMetal.h) |
seyhmus.cacina | 0:ac4dea3e2894 | 115 | * and does not check/relpy to bootloder related commnads |
seyhmus.cacina | 0:ac4dea3e2894 | 116 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 117 | * 2. in bootloader mode Host accepts commands related to bootloader ( command table in bootldrAPI.h) only. |
seyhmus.cacina | 0:ac4dea3e2894 | 118 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 119 | * */ |
seyhmus.cacina | 0:ac4dea3e2894 | 120 | cmd_interface_t setCommEchoModeCMD = {"set_host_echomode" , set_host_comm_echomode , "enables/disables echoing of command console commands"}; |
seyhmus.cacina | 0:ac4dea3e2894 | 121 | cmd_interface_t setHostModeCMD = {"set_host_opmode" , set_host_operating_mode , "sets mode of host to app or bootloader"}; |
seyhmus.cacina | 0:ac4dea3e2894 | 122 | cmd_interface_t getHostModeCMD = {"get_host_opmode" , get_host_operating_mode , "gets mode of host app or bootloader"}; |
seyhmus.cacina | 0:ac4dea3e2894 | 123 | cmd_interface_t getHubFwVersionCMD = {"get_hub_fwversion" , get_hub_firmware_version , "gets mode of host app or bootloader"}; |
seyhmus.cacina | 0:ac4dea3e2894 | 124 | //cmd_interface_t getHubModeCMD = {"get_sensorhub_opmode", get_hub_operating_mode , "gets mode of host app or bootloader"}; |
seyhmus.cacina | 0:ac4dea3e2894 | 125 | |
seyhmus.cacina | 0:ac4dea3e2894 | 126 | /* @brief Compares two string to check whether they match. |
seyhmus.cacina | 0:ac4dea3e2894 | 127 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 128 | * @param[in] str1, str2 : strings to compare |
seyhmus.cacina | 0:ac4dea3e2894 | 129 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 130 | * */ |
seyhmus.cacina | 0:ac4dea3e2894 | 131 | |
seyhmus.cacina | 0:ac4dea3e2894 | 132 | static bool starts_with(const char* str1, const char* str2) |
seyhmus.cacina | 0:ac4dea3e2894 | 133 | { |
seyhmus.cacina | 0:ac4dea3e2894 | 134 | while (*str1 && *str2) { |
seyhmus.cacina | 0:ac4dea3e2894 | 135 | if (*str1 != *str2) |
seyhmus.cacina | 0:ac4dea3e2894 | 136 | return false; |
seyhmus.cacina | 0:ac4dea3e2894 | 137 | str1++; |
seyhmus.cacina | 0:ac4dea3e2894 | 138 | str2++; |
seyhmus.cacina | 0:ac4dea3e2894 | 139 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 140 | |
seyhmus.cacina | 0:ac4dea3e2894 | 141 | if (*str2) |
seyhmus.cacina | 0:ac4dea3e2894 | 142 | return false; |
seyhmus.cacina | 0:ac4dea3e2894 | 143 | |
seyhmus.cacina | 0:ac4dea3e2894 | 144 | return true; |
seyhmus.cacina | 0:ac4dea3e2894 | 145 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 146 | |
seyhmus.cacina | 0:ac4dea3e2894 | 147 | |
seyhmus.cacina | 0:ac4dea3e2894 | 148 | |
seyhmus.cacina | 0:ac4dea3e2894 | 149 | /** |
seyhmus.cacina | 0:ac4dea3e2894 | 150 | * @brief Command parser and executer for user input commands |
seyhmus.cacina | 0:ac4dea3e2894 | 151 | * @details Gets the command string from command builder, compares with the commands of defined command tables of 8614x and bootloader |
seyhmus.cacina | 0:ac4dea3e2894 | 152 | * if found calls the function associated with the command, passsing the whole command string with arguments to the called |
seyhmus.cacina | 0:ac4dea3e2894 | 153 | * function |
seyhmus.cacina | 0:ac4dea3e2894 | 154 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 155 | * @param[in] cmd_str Input commnad from user. |
seyhmus.cacina | 0:ac4dea3e2894 | 156 | */ |
seyhmus.cacina | 0:ac4dea3e2894 | 157 | |
seyhmus.cacina | 0:ac4dea3e2894 | 158 | int parse_execute_command( const char *cmd_str) |
seyhmus.cacina | 0:ac4dea3e2894 | 159 | { |
seyhmus.cacina | 0:ac4dea3e2894 | 160 | |
seyhmus.cacina | 0:ac4dea3e2894 | 161 | int found = 0; |
seyhmus.cacina | 0:ac4dea3e2894 | 162 | int tableIdx; |
seyhmus.cacina | 0:ac4dea3e2894 | 163 | |
seyhmus.cacina | 0:ac4dea3e2894 | 164 | if( starts_with(&cmd_str[0], setCommEchoModeCMD.cmdStr)) { |
seyhmus.cacina | 0:ac4dea3e2894 | 165 | int status = setCommEchoModeCMD.execute(cmd_str); |
seyhmus.cacina | 0:ac4dea3e2894 | 166 | if( status != 0x00){ |
seyhmus.cacina | 0:ac4dea3e2894 | 167 | SERIALOUT("\r\n%s err=%d\r\n", "set_host_mode", COMM_INVALID_PARAM); |
seyhmus.cacina | 0:ac4dea3e2894 | 168 | hostCommEchoMode = HOSTCOMMMODE_ECHO_OFF; |
seyhmus.cacina | 0:ac4dea3e2894 | 169 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 170 | found = 1; |
seyhmus.cacina | 0:ac4dea3e2894 | 171 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 172 | |
seyhmus.cacina | 0:ac4dea3e2894 | 173 | if( starts_with(&cmd_str[0], setHostModeCMD.cmdStr)) { |
seyhmus.cacina | 0:ac4dea3e2894 | 174 | int status = setHostModeCMD.execute(cmd_str); |
seyhmus.cacina | 0:ac4dea3e2894 | 175 | if( status != 0x00){ |
seyhmus.cacina | 0:ac4dea3e2894 | 176 | SERIALOUT("\r\n%s err=%d\r\n", "set_host_mode", COMM_INVALID_PARAM); |
seyhmus.cacina | 0:ac4dea3e2894 | 177 | hostOperatingMode = HOSTMODEAPPLICATION; |
seyhmus.cacina | 0:ac4dea3e2894 | 178 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 179 | found = 1; |
seyhmus.cacina | 0:ac4dea3e2894 | 180 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 181 | |
seyhmus.cacina | 0:ac4dea3e2894 | 182 | if( starts_with(&cmd_str[0], getHostModeCMD.cmdStr)) { |
seyhmus.cacina | 0:ac4dea3e2894 | 183 | int status = getHostModeCMD.execute(cmd_str); |
seyhmus.cacina | 0:ac4dea3e2894 | 184 | found = 1; |
seyhmus.cacina | 0:ac4dea3e2894 | 185 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 186 | |
seyhmus.cacina | 0:ac4dea3e2894 | 187 | if( starts_with(&cmd_str[0], getHubFwVersionCMD.cmdStr)) { |
seyhmus.cacina | 0:ac4dea3e2894 | 188 | int status = getHubFwVersionCMD.execute(cmd_str); |
seyhmus.cacina | 0:ac4dea3e2894 | 189 | found = 1; |
seyhmus.cacina | 0:ac4dea3e2894 | 190 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 191 | |
seyhmus.cacina | 0:ac4dea3e2894 | 192 | /* if( starts_with(&cmd_str[0], getHubModeCMD.cmdStr)) { |
seyhmus.cacina | 0:ac4dea3e2894 | 193 | int status = getHubModeCMD.execute(cmd_str); |
seyhmus.cacina | 0:ac4dea3e2894 | 194 | found = 1; |
seyhmus.cacina | 0:ac4dea3e2894 | 195 | }*/ |
seyhmus.cacina | 0:ac4dea3e2894 | 196 | |
seyhmus.cacina | 0:ac4dea3e2894 | 197 | if( hostOperatingMode == HOSTMODEAPPLICATION) { |
seyhmus.cacina | 0:ac4dea3e2894 | 198 | |
seyhmus.cacina | 0:ac4dea3e2894 | 199 | tableIdx = NUMCMDS8614X; |
seyhmus.cacina | 0:ac4dea3e2894 | 200 | do{ |
seyhmus.cacina | 0:ac4dea3e2894 | 201 | tableIdx -= 1; |
seyhmus.cacina | 0:ac4dea3e2894 | 202 | if (starts_with(&cmd_str[0], CMDTABLE8614x[tableIdx].cmdStr)){ |
seyhmus.cacina | 0:ac4dea3e2894 | 203 | |
seyhmus.cacina | 0:ac4dea3e2894 | 204 | CMDTABLE8614x[tableIdx].execute(cmd_str); |
seyhmus.cacina | 0:ac4dea3e2894 | 205 | /*MYG DEBUG8*/// SERIALPRINT("___SELECTED COMMAND IDX IS: %d \r\n", tableIdx); |
seyhmus.cacina | 0:ac4dea3e2894 | 206 | SERIALOUT(" \r\n"); // Here is needed due to a bug on mbed serial! |
seyhmus.cacina | 0:ac4dea3e2894 | 207 | found = 1; |
seyhmus.cacina | 0:ac4dea3e2894 | 208 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 209 | |
seyhmus.cacina | 0:ac4dea3e2894 | 210 | }while(tableIdx && found == 0 ); |
seyhmus.cacina | 0:ac4dea3e2894 | 211 | |
seyhmus.cacina | 0:ac4dea3e2894 | 212 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 213 | |
seyhmus.cacina | 0:ac4dea3e2894 | 214 | if( hostOperatingMode == HOSTMODEBOOTLOADER) { |
seyhmus.cacina | 0:ac4dea3e2894 | 215 | |
seyhmus.cacina | 0:ac4dea3e2894 | 216 | |
seyhmus.cacina | 0:ac4dea3e2894 | 217 | tableIdx = NUMCMDSBOOTLDRAPI; |
seyhmus.cacina | 0:ac4dea3e2894 | 218 | do{ |
seyhmus.cacina | 0:ac4dea3e2894 | 219 | tableIdx -= 1; |
seyhmus.cacina | 0:ac4dea3e2894 | 220 | if (starts_with(&cmd_str[0], CMDTABLEBOOTLDR[tableIdx].cmdStr)){ |
seyhmus.cacina | 0:ac4dea3e2894 | 221 | |
seyhmus.cacina | 0:ac4dea3e2894 | 222 | CMDTABLEBOOTLDR[tableIdx].execute(cmd_str); |
seyhmus.cacina | 0:ac4dea3e2894 | 223 | /*MYG DEBUG8*/// SERIALPRINT("___SELECTED COMMAND IDX IS: %d \r\n", tableIdx); |
seyhmus.cacina | 0:ac4dea3e2894 | 224 | SERIALOUT(" \r\n"); // Here is needed due to a bug on mbed serial! |
seyhmus.cacina | 0:ac4dea3e2894 | 225 | found = 1; |
seyhmus.cacina | 0:ac4dea3e2894 | 226 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 227 | |
seyhmus.cacina | 0:ac4dea3e2894 | 228 | }while(tableIdx && found == 0 ); |
seyhmus.cacina | 0:ac4dea3e2894 | 229 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 230 | |
seyhmus.cacina | 0:ac4dea3e2894 | 231 | return found; |
seyhmus.cacina | 0:ac4dea3e2894 | 232 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 233 | |
seyhmus.cacina | 0:ac4dea3e2894 | 234 | |
seyhmus.cacina | 0:ac4dea3e2894 | 235 | /** |
seyhmus.cacina | 0:ac4dea3e2894 | 236 | * @brief Command builder from serial i/o device. |
seyhmus.cacina | 0:ac4dea3e2894 | 237 | * @details Reads character and builds commands for application. |
seyhmus.cacina | 0:ac4dea3e2894 | 238 | * |
seyhmus.cacina | 0:ac4dea3e2894 | 239 | * @param[in] ch Input character from i/o device. |
seyhmus.cacina | 0:ac4dea3e2894 | 240 | */ |
seyhmus.cacina | 0:ac4dea3e2894 | 241 | //__attribute__((__always_inline__)) |
seyhmus.cacina | 0:ac4dea3e2894 | 242 | void cmdIntf_build_command(char ch) |
seyhmus.cacina | 0:ac4dea3e2894 | 243 | { |
seyhmus.cacina | 0:ac4dea3e2894 | 244 | static char cmd_str[1024]; |
seyhmus.cacina | 0:ac4dea3e2894 | 245 | static int cmd_idx = 0; |
seyhmus.cacina | 0:ac4dea3e2894 | 246 | int status; |
seyhmus.cacina | 0:ac4dea3e2894 | 247 | |
seyhmus.cacina | 0:ac4dea3e2894 | 248 | if(hostCommEchoMode == HOSTCOMMMODE_ECHO_ON) |
seyhmus.cacina | 0:ac4dea3e2894 | 249 | SERIALOUT("%c", ch); |
seyhmus.cacina | 0:ac4dea3e2894 | 250 | |
seyhmus.cacina | 0:ac4dea3e2894 | 251 | if (ch == 0x00) { |
seyhmus.cacina | 0:ac4dea3e2894 | 252 | return; |
seyhmus.cacina | 0:ac4dea3e2894 | 253 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 254 | |
seyhmus.cacina | 0:ac4dea3e2894 | 255 | if ((ch == '\n') || (ch == '\r')) { |
seyhmus.cacina | 0:ac4dea3e2894 | 256 | if (cmd_idx < 1024) |
seyhmus.cacina | 0:ac4dea3e2894 | 257 | cmd_str[cmd_idx++] = '\0'; |
seyhmus.cacina | 0:ac4dea3e2894 | 258 | status = parse_execute_command(cmd_str); |
seyhmus.cacina | 0:ac4dea3e2894 | 259 | |
seyhmus.cacina | 0:ac4dea3e2894 | 260 | //Clear cmd_str |
seyhmus.cacina | 0:ac4dea3e2894 | 261 | while (cmd_idx > 0) |
seyhmus.cacina | 0:ac4dea3e2894 | 262 | cmd_str[--cmd_idx] = '\0'; |
seyhmus.cacina | 0:ac4dea3e2894 | 263 | |
seyhmus.cacina | 0:ac4dea3e2894 | 264 | } else if ((ch == 0x08 || ch == 0x7F) && cmd_idx > 0) { |
seyhmus.cacina | 0:ac4dea3e2894 | 265 | //Backspace character |
seyhmus.cacina | 0:ac4dea3e2894 | 266 | if (cmd_idx > 0) |
seyhmus.cacina | 0:ac4dea3e2894 | 267 | cmd_str[--cmd_idx] = '\0'; |
seyhmus.cacina | 0:ac4dea3e2894 | 268 | } else { |
seyhmus.cacina | 0:ac4dea3e2894 | 269 | |
seyhmus.cacina | 0:ac4dea3e2894 | 270 | if (cmd_idx < 1024) |
seyhmus.cacina | 0:ac4dea3e2894 | 271 | cmd_str[cmd_idx++] = ch; |
seyhmus.cacina | 0:ac4dea3e2894 | 272 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 273 | |
seyhmus.cacina | 0:ac4dea3e2894 | 274 | } |
seyhmus.cacina | 0:ac4dea3e2894 | 275 | |
seyhmus.cacina | 0:ac4dea3e2894 | 276 | |
seyhmus.cacina | 0:ac4dea3e2894 | 277 |