ME11C Sample Code in Maxim Integrated Team
Dependencies: BMI160 max32630hsp3 MemoryLCD USBDevice
Fork of Host_Software_MAX32664GWEC_SpO2_HR-_EXTE by
cmdUI/cmdInterface.cpp@2:3b5d2467e6c7, 2019-03-25 (annotated)
- Committer:
- seyhmuscacina
- Date:
- Mon Mar 25 07:56:34 2019 +0000
- Revision:
- 2:3b5d2467e6c7
- Parent:
- 0:b259fd1a88f5
Fork the repository
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seyhmus.cacina | 0:b259fd1a88f5 | 1 | /* |
seyhmus.cacina | 0:b259fd1a88f5 | 2 | * cmdInterface.cpp |
seyhmus.cacina | 0:b259fd1a88f5 | 3 | * |
seyhmus.cacina | 0:b259fd1a88f5 | 4 | * Created on: Jan 30, 2019 |
seyhmus.cacina | 0:b259fd1a88f5 | 5 | * Author: Yagmur.Gok |
seyhmus.cacina | 0:b259fd1a88f5 | 6 | */ |
seyhmus.cacina | 0:b259fd1a88f5 | 7 | |
seyhmus.cacina | 0:b259fd1a88f5 | 8 | #include <mbed.h> |
seyhmus.cacina | 0:b259fd1a88f5 | 9 | #include "cmdInterface.h" |
seyhmus.cacina | 0:b259fd1a88f5 | 10 | #include "SH_Max8614x_BareMetal.h" |
seyhmus.cacina | 0:b259fd1a88f5 | 11 | #include "bootldrAPI.h" |
seyhmus.cacina | 0:b259fd1a88f5 | 12 | #include "SHComm.h" |
seyhmus.cacina | 0:b259fd1a88f5 | 13 | #include "demoDefinitions.h" |
seyhmus.cacina | 0:b259fd1a88f5 | 14 | |
seyhmus.cacina | 0:b259fd1a88f5 | 15 | static uint8_t hostOperatingMode = HOSTMODEAPPLICATION; |
seyhmus.cacina | 0:b259fd1a88f5 | 16 | |
seyhmus.cacina | 0:b259fd1a88f5 | 17 | |
seyhmus.cacina | 0:b259fd1a88f5 | 18 | static int get_host_operating_mode(const char* arg){ |
seyhmus.cacina | 0:b259fd1a88f5 | 19 | |
seyhmus.cacina | 0:b259fd1a88f5 | 20 | int status = 0x00; |
seyhmus.cacina | 0:b259fd1a88f5 | 21 | SERIALOUT("\r\n%s host_operating_mode=%s\r\n", "get_host_mode", (hostOperatingMode ==HOSTMODEAPPLICATION)? "APPMODE":"BOOTLOADERMODE" ); |
seyhmus.cacina | 0:b259fd1a88f5 | 22 | return status; |
seyhmus.cacina | 0:b259fd1a88f5 | 23 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 24 | |
seyhmus.cacina | 0:b259fd1a88f5 | 25 | static int set_host_operating_mode(const char* arg){ |
seyhmus.cacina | 0:b259fd1a88f5 | 26 | |
seyhmus.cacina | 0:b259fd1a88f5 | 27 | int status = -1; |
seyhmus.cacina | 0:b259fd1a88f5 | 28 | uint32_t val; |
seyhmus.cacina | 0:b259fd1a88f5 | 29 | if( sscanf(arg, "%*s %x", &val) == 1 ){ |
seyhmus.cacina | 0:b259fd1a88f5 | 30 | hostOperatingMode = ( val > 0 )? HOSTMODEBOOTLOADER:HOSTMODEAPPLICATION; |
seyhmus.cacina | 0:b259fd1a88f5 | 31 | |
seyhmus.cacina | 0:b259fd1a88f5 | 32 | status = 0x00; |
seyhmus.cacina | 0:b259fd1a88f5 | 33 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 34 | SERIALOUT("\r\n%s err=%d\r\n", "set_host_opmode", status); |
seyhmus.cacina | 0:b259fd1a88f5 | 35 | return status; |
seyhmus.cacina | 0:b259fd1a88f5 | 36 | |
seyhmus.cacina | 0:b259fd1a88f5 | 37 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 38 | |
seyhmus.cacina | 0:b259fd1a88f5 | 39 | |
seyhmus.cacina | 0:b259fd1a88f5 | 40 | |
seyhmus.cacina | 0:b259fd1a88f5 | 41 | static int get_hub_operating_mode(const char* arg){ |
seyhmus.cacina | 0:b259fd1a88f5 | 42 | |
seyhmus.cacina | 0:b259fd1a88f5 | 43 | uint8_t hubMode; |
seyhmus.cacina | 0:b259fd1a88f5 | 44 | int status = sh_get_sensorhub_operating_mode(&hubMode); |
seyhmus.cacina | 0:b259fd1a88f5 | 45 | if( status == 0x00) |
seyhmus.cacina | 0:b259fd1a88f5 | 46 | SERIALOUT("\r\n hub_operating_mode=%s\r\n", (hubMode == 0x00)? "APPMODE":"BOOTLOADERMODE" ); |
seyhmus.cacina | 0:b259fd1a88f5 | 47 | else |
seyhmus.cacina | 0:b259fd1a88f5 | 48 | SERIALOUT("\r\n%s err=%d\r\n", "get_sensorhub_opmode", status); |
seyhmus.cacina | 0:b259fd1a88f5 | 49 | |
seyhmus.cacina | 0:b259fd1a88f5 | 50 | return status; |
seyhmus.cacina | 0:b259fd1a88f5 | 51 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 52 | |
seyhmus.cacina | 0:b259fd1a88f5 | 53 | uint8_t get_internal_operating_mode(void){ |
seyhmus.cacina | 0:b259fd1a88f5 | 54 | |
seyhmus.cacina | 0:b259fd1a88f5 | 55 | return hostOperatingMode; |
seyhmus.cacina | 0:b259fd1a88f5 | 56 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 57 | |
seyhmus.cacina | 0:b259fd1a88f5 | 58 | |
seyhmus.cacina | 0:b259fd1a88f5 | 59 | cmd_interface_t setHostModeCMD = {"set_host_opmode" , set_host_operating_mode , "sets mode of host to app or bootloader"}; |
seyhmus.cacina | 0:b259fd1a88f5 | 60 | cmd_interface_t getHostModeCMD = {"get_host_opmode" , get_host_operating_mode , "gets mode of host app or bootloader"}; |
seyhmus.cacina | 0:b259fd1a88f5 | 61 | cmd_interface_t getHubModeCMD = {"get_sensorhub_opmode", get_hub_operating_mode , "gets mode of host app or bootloader"}; |
seyhmus.cacina | 0:b259fd1a88f5 | 62 | |
seyhmus.cacina | 0:b259fd1a88f5 | 63 | |
seyhmus.cacina | 0:b259fd1a88f5 | 64 | static bool starts_with(const char* str1, const char* str2) |
seyhmus.cacina | 0:b259fd1a88f5 | 65 | { |
seyhmus.cacina | 0:b259fd1a88f5 | 66 | while (*str1 && *str2) { |
seyhmus.cacina | 0:b259fd1a88f5 | 67 | if (*str1 != *str2) |
seyhmus.cacina | 0:b259fd1a88f5 | 68 | return false; |
seyhmus.cacina | 0:b259fd1a88f5 | 69 | str1++; |
seyhmus.cacina | 0:b259fd1a88f5 | 70 | str2++; |
seyhmus.cacina | 0:b259fd1a88f5 | 71 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 72 | |
seyhmus.cacina | 0:b259fd1a88f5 | 73 | if (*str2) |
seyhmus.cacina | 0:b259fd1a88f5 | 74 | return false; |
seyhmus.cacina | 0:b259fd1a88f5 | 75 | |
seyhmus.cacina | 0:b259fd1a88f5 | 76 | return true; |
seyhmus.cacina | 0:b259fd1a88f5 | 77 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 78 | |
seyhmus.cacina | 0:b259fd1a88f5 | 79 | //MYG DEBUG: |
seyhmus.cacina | 0:b259fd1a88f5 | 80 | |
seyhmus.cacina | 0:b259fd1a88f5 | 81 | int parse_execute_command( const char *cmd_str) |
seyhmus.cacina | 0:b259fd1a88f5 | 82 | { |
seyhmus.cacina | 0:b259fd1a88f5 | 83 | |
seyhmus.cacina | 0:b259fd1a88f5 | 84 | int found = 0; |
seyhmus.cacina | 0:b259fd1a88f5 | 85 | int tableIdx; |
seyhmus.cacina | 0:b259fd1a88f5 | 86 | if( starts_with(&cmd_str[0], setHostModeCMD.cmdStr)) { |
seyhmus.cacina | 0:b259fd1a88f5 | 87 | int status = setHostModeCMD.execute(cmd_str); |
seyhmus.cacina | 0:b259fd1a88f5 | 88 | if( status != 0x00){ |
seyhmus.cacina | 0:b259fd1a88f5 | 89 | SERIALOUT("\r\n%s err=%d\r\n", "set_host_mode", COMM_INVALID_PARAM); |
seyhmus.cacina | 0:b259fd1a88f5 | 90 | hostOperatingMode = 0; |
seyhmus.cacina | 0:b259fd1a88f5 | 91 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 92 | found = 1; |
seyhmus.cacina | 0:b259fd1a88f5 | 93 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 94 | |
seyhmus.cacina | 0:b259fd1a88f5 | 95 | if( starts_with(&cmd_str[0], getHostModeCMD.cmdStr)) { |
seyhmus.cacina | 0:b259fd1a88f5 | 96 | int status = getHostModeCMD.execute(cmd_str); |
seyhmus.cacina | 0:b259fd1a88f5 | 97 | found = 1; |
seyhmus.cacina | 0:b259fd1a88f5 | 98 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 99 | |
seyhmus.cacina | 0:b259fd1a88f5 | 100 | if( starts_with(&cmd_str[0], getHubModeCMD.cmdStr)) { |
seyhmus.cacina | 0:b259fd1a88f5 | 101 | int status = getHubModeCMD.execute(cmd_str); |
seyhmus.cacina | 0:b259fd1a88f5 | 102 | found = 1; |
seyhmus.cacina | 0:b259fd1a88f5 | 103 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 104 | |
seyhmus.cacina | 0:b259fd1a88f5 | 105 | if( hostOperatingMode == HOSTMODEAPPLICATION) { |
seyhmus.cacina | 0:b259fd1a88f5 | 106 | |
seyhmus.cacina | 0:b259fd1a88f5 | 107 | tableIdx = NUMCMDS8614X; |
seyhmus.cacina | 0:b259fd1a88f5 | 108 | do{ |
seyhmus.cacina | 0:b259fd1a88f5 | 109 | tableIdx -= 1; |
seyhmus.cacina | 0:b259fd1a88f5 | 110 | if (starts_with(&cmd_str[0], CMDTABLE8614x[tableIdx].cmdStr)){ |
seyhmus.cacina | 0:b259fd1a88f5 | 111 | |
seyhmus.cacina | 0:b259fd1a88f5 | 112 | CMDTABLE8614x[tableIdx].execute(cmd_str); |
seyhmus.cacina | 0:b259fd1a88f5 | 113 | /*MYG DEBUG8*/// SERIALPRINT("___SELECTED COMMAND IDX IS: %d \r\n", tableIdx); |
seyhmus.cacina | 0:b259fd1a88f5 | 114 | SERIALOUT(" \r\n"); // Here is needed due to a bug on mbed serial! |
seyhmus.cacina | 0:b259fd1a88f5 | 115 | found = 1; |
seyhmus.cacina | 0:b259fd1a88f5 | 116 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 117 | |
seyhmus.cacina | 0:b259fd1a88f5 | 118 | }while(tableIdx && found == 0 ); |
seyhmus.cacina | 0:b259fd1a88f5 | 119 | |
seyhmus.cacina | 0:b259fd1a88f5 | 120 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 121 | |
seyhmus.cacina | 0:b259fd1a88f5 | 122 | if( hostOperatingMode == HOSTMODEBOOTLOADER) { |
seyhmus.cacina | 0:b259fd1a88f5 | 123 | |
seyhmus.cacina | 0:b259fd1a88f5 | 124 | |
seyhmus.cacina | 0:b259fd1a88f5 | 125 | tableIdx = NUMCMDSBOOTLDRAPI; |
seyhmus.cacina | 0:b259fd1a88f5 | 126 | do{ |
seyhmus.cacina | 0:b259fd1a88f5 | 127 | tableIdx -= 1; |
seyhmus.cacina | 0:b259fd1a88f5 | 128 | if (starts_with(&cmd_str[0], CMDTABLEBOOTLDR[tableIdx].cmdStr)){ |
seyhmus.cacina | 0:b259fd1a88f5 | 129 | |
seyhmus.cacina | 0:b259fd1a88f5 | 130 | CMDTABLEBOOTLDR[tableIdx].execute(cmd_str); |
seyhmus.cacina | 0:b259fd1a88f5 | 131 | /*MYG DEBUG8*/// SERIALPRINT("___SELECTED COMMAND IDX IS: %d \r\n", tableIdx); |
seyhmus.cacina | 0:b259fd1a88f5 | 132 | SERIALOUT(" \r\n"); // Here is needed due to a bug on mbed serial! |
seyhmus.cacina | 0:b259fd1a88f5 | 133 | found = 1; |
seyhmus.cacina | 0:b259fd1a88f5 | 134 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 135 | |
seyhmus.cacina | 0:b259fd1a88f5 | 136 | }while(tableIdx && found == 0 ); |
seyhmus.cacina | 0:b259fd1a88f5 | 137 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 138 | |
seyhmus.cacina | 0:b259fd1a88f5 | 139 | return found; |
seyhmus.cacina | 0:b259fd1a88f5 | 140 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 141 | |
seyhmus.cacina | 0:b259fd1a88f5 | 142 | |
seyhmus.cacina | 0:b259fd1a88f5 | 143 | void cmdIntf_build_command(char ch) |
seyhmus.cacina | 0:b259fd1a88f5 | 144 | { |
seyhmus.cacina | 0:b259fd1a88f5 | 145 | static char cmd_str[1024]; |
seyhmus.cacina | 0:b259fd1a88f5 | 146 | static int cmd_idx = 0; |
seyhmus.cacina | 0:b259fd1a88f5 | 147 | int status; |
seyhmus.cacina | 0:b259fd1a88f5 | 148 | |
seyhmus.cacina | 0:b259fd1a88f5 | 149 | if (ch == 0x00) { |
seyhmus.cacina | 0:b259fd1a88f5 | 150 | return; |
seyhmus.cacina | 0:b259fd1a88f5 | 151 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 152 | |
seyhmus.cacina | 0:b259fd1a88f5 | 153 | if ((ch == '\n') || (ch == '\r')) { |
seyhmus.cacina | 0:b259fd1a88f5 | 154 | if (cmd_idx < 1024) |
seyhmus.cacina | 0:b259fd1a88f5 | 155 | cmd_str[cmd_idx++] = '\0'; |
seyhmus.cacina | 0:b259fd1a88f5 | 156 | status = parse_execute_command(cmd_str); |
seyhmus.cacina | 0:b259fd1a88f5 | 157 | |
seyhmus.cacina | 0:b259fd1a88f5 | 158 | //Clear cmd_str |
seyhmus.cacina | 0:b259fd1a88f5 | 159 | while (cmd_idx > 0) |
seyhmus.cacina | 0:b259fd1a88f5 | 160 | cmd_str[--cmd_idx] = '\0'; |
seyhmus.cacina | 0:b259fd1a88f5 | 161 | |
seyhmus.cacina | 0:b259fd1a88f5 | 162 | } else if ((ch == 0x08 || ch == 0x7F) && cmd_idx > 0) { |
seyhmus.cacina | 0:b259fd1a88f5 | 163 | //Backspace character |
seyhmus.cacina | 0:b259fd1a88f5 | 164 | if (cmd_idx > 0) |
seyhmus.cacina | 0:b259fd1a88f5 | 165 | cmd_str[--cmd_idx] = '\0'; |
seyhmus.cacina | 0:b259fd1a88f5 | 166 | } else { |
seyhmus.cacina | 0:b259fd1a88f5 | 167 | |
seyhmus.cacina | 0:b259fd1a88f5 | 168 | if (cmd_idx < 1024) |
seyhmus.cacina | 0:b259fd1a88f5 | 169 | cmd_str[cmd_idx++] = ch; |
seyhmus.cacina | 0:b259fd1a88f5 | 170 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 171 | |
seyhmus.cacina | 0:b259fd1a88f5 | 172 | } |
seyhmus.cacina | 0:b259fd1a88f5 | 173 | |
seyhmus.cacina | 0:b259fd1a88f5 | 174 | |
seyhmus.cacina | 0:b259fd1a88f5 | 175 |