Wilson Tang
/
HSP_RPC_GUI
Fork of the offical HSP_RPC_GUI firmware
Fork of MAXREFDES100 firmware for MAX32620HSP
HSP/RpcServer/RpcServer.cpp@1:9490836294ea, 2017-04-21 (annotated)
- Committer:
- jbradshaw
- Date:
- Fri Apr 21 12:12:30 2017 -0500
- Revision:
- 1:9490836294ea
- Parent:
- 0:e4a10ed6eb92
- Child:
- 3:8e9b9f5818aa
Flash device is now fully utilized for datalog of sensor data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbradshaw | 0:e4a10ed6eb92 | 1 | /******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
jbradshaw | 0:e4a10ed6eb92 | 3 | * |
jbradshaw | 0:e4a10ed6eb92 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
jbradshaw | 0:e4a10ed6eb92 | 5 | * copy of this software and associated documentation files (the "Software"), |
jbradshaw | 0:e4a10ed6eb92 | 6 | * to deal in the Software without restriction, including without limitation |
jbradshaw | 0:e4a10ed6eb92 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
jbradshaw | 0:e4a10ed6eb92 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
jbradshaw | 0:e4a10ed6eb92 | 9 | * Software is furnished to do so, subject to the following conditions: |
jbradshaw | 0:e4a10ed6eb92 | 10 | * |
jbradshaw | 0:e4a10ed6eb92 | 11 | * The above copyright notice and this permission notice shall be included |
jbradshaw | 0:e4a10ed6eb92 | 12 | * in all copies or substantial portions of the Software. |
jbradshaw | 0:e4a10ed6eb92 | 13 | * |
jbradshaw | 0:e4a10ed6eb92 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
jbradshaw | 0:e4a10ed6eb92 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
jbradshaw | 0:e4a10ed6eb92 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
jbradshaw | 0:e4a10ed6eb92 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
jbradshaw | 0:e4a10ed6eb92 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
jbradshaw | 0:e4a10ed6eb92 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
jbradshaw | 0:e4a10ed6eb92 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
jbradshaw | 0:e4a10ed6eb92 | 21 | * |
jbradshaw | 0:e4a10ed6eb92 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 24 | * Products, Inc. Branding Policy. |
jbradshaw | 0:e4a10ed6eb92 | 25 | * |
jbradshaw | 0:e4a10ed6eb92 | 26 | * The mere transfer of this software does not imply any licenses |
jbradshaw | 0:e4a10ed6eb92 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
jbradshaw | 0:e4a10ed6eb92 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
jbradshaw | 0:e4a10ed6eb92 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
jbradshaw | 0:e4a10ed6eb92 | 30 | * ownership rights. |
jbradshaw | 0:e4a10ed6eb92 | 31 | ******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 32 | */ |
jbradshaw | 0:e4a10ed6eb92 | 33 | #include "RpcServer.h" |
jbradshaw | 0:e4a10ed6eb92 | 34 | #include "StringInOut.h" |
jbradshaw | 0:e4a10ed6eb92 | 35 | #include "StringHelper.h" |
jbradshaw | 0:e4a10ed6eb92 | 36 | #include "MAX30001_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 37 | #include "MAX30101_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 38 | #include "LIS2DH_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 39 | #include "Logging_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 40 | #include "Peripherals.h" |
jbradshaw | 0:e4a10ed6eb92 | 41 | #include "I2C_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 42 | #include "BMP280_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 43 | #include "MAX30205_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 44 | #include "HspLed_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 45 | #include "S25FS512_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 46 | #include "Testing_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 47 | #include "MAX14720_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 48 | #include "RpcDeclarations.h" |
jbradshaw | 0:e4a10ed6eb92 | 49 | #include "Device_Logging.h" |
jbradshaw | 0:e4a10ed6eb92 | 50 | |
jbradshaw | 0:e4a10ed6eb92 | 51 | /// define the version string that is reported with a RPC "ReadVer" command |
jbradshaw | 1:9490836294ea | 52 | #define FW_VERSION_STRING "HSP FW Version 3.0.1 4/21/16" |
jbradshaw | 0:e4a10ed6eb92 | 53 | |
jbradshaw | 0:e4a10ed6eb92 | 54 | char args[32][32]; |
jbradshaw | 0:e4a10ed6eb92 | 55 | char results[32][32]; |
jbradshaw | 0:e4a10ed6eb92 | 56 | |
jbradshaw | 0:e4a10ed6eb92 | 57 | /// define a fifo for incoming USB data |
jbradshaw | 0:e4a10ed6eb92 | 58 | static fifo_t fifo; |
jbradshaw | 0:e4a10ed6eb92 | 59 | /// define a buffer for incoming USB data |
jbradshaw | 0:e4a10ed6eb92 | 60 | static uint8_t fifoBuffer[128]; |
jbradshaw | 0:e4a10ed6eb92 | 61 | /// define stream out fifo |
jbradshaw | 0:e4a10ed6eb92 | 62 | static fifo_t fifoStreamOut; |
jbradshaw | 0:e4a10ed6eb92 | 63 | /// allocate a large fifo buffer for streaming out |
jbradshaw | 0:e4a10ed6eb92 | 64 | static uint32_t streamOutBuffer[0xC000 / 4]; |
jbradshaw | 0:e4a10ed6eb92 | 65 | |
jbradshaw | 0:e4a10ed6eb92 | 66 | /// define a device log for the BMP280, keeps track of mission and loggin status |
jbradshaw | 0:e4a10ed6eb92 | 67 | Device_Logging *bmp280_Logging; |
jbradshaw | 0:e4a10ed6eb92 | 68 | /// define a device log for the MAX30205 (instance 0), keeps track of mission |
jbradshaw | 0:e4a10ed6eb92 | 69 | /// and loggin status |
jbradshaw | 0:e4a10ed6eb92 | 70 | Device_Logging *MAX30205_0_Logging; |
jbradshaw | 0:e4a10ed6eb92 | 71 | /// define a device log for the MAX30205 (instance 1), keeps track of mission |
jbradshaw | 0:e4a10ed6eb92 | 72 | /// and loggin status |
jbradshaw | 0:e4a10ed6eb92 | 73 | Device_Logging *MAX30205_1_Logging; |
jbradshaw | 0:e4a10ed6eb92 | 74 | |
jbradshaw | 0:e4a10ed6eb92 | 75 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 76 | fifo_t *GetUSBIncomingFifo(void) { return &fifo; } |
jbradshaw | 0:e4a10ed6eb92 | 77 | |
jbradshaw | 0:e4a10ed6eb92 | 78 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 79 | fifo_t *GetStreamOutFifo(void) { return &fifoStreamOut; } |
jbradshaw | 0:e4a10ed6eb92 | 80 | |
jbradshaw | 0:e4a10ed6eb92 | 81 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 82 | int System_ReadVer(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 83 | strcpy(replyStrs[0], FW_VERSION_STRING); |
jbradshaw | 0:e4a10ed6eb92 | 84 | strcpy(replyStrs[1], "\0"); |
jbradshaw | 0:e4a10ed6eb92 | 85 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 86 | } |
jbradshaw | 0:e4a10ed6eb92 | 87 | |
jbradshaw | 0:e4a10ed6eb92 | 88 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 89 | int System_ReadBuildTime(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 90 | // strcpy(replyStrs[0],buildTime); |
jbradshaw | 0:e4a10ed6eb92 | 91 | // strcpy(replyStrs[1],"\0"); |
jbradshaw | 0:e4a10ed6eb92 | 92 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 93 | } |
jbradshaw | 0:e4a10ed6eb92 | 94 | |
jbradshaw | 0:e4a10ed6eb92 | 95 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 96 | int System_SystemCoreClock(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 1:9490836294ea | 97 | sprintf(replyStrs[0], "SystemCoreClock = %d", (unsigned int)SystemCoreClock); |
jbradshaw | 0:e4a10ed6eb92 | 98 | strcpy(replyStrs[1], "\0"); |
jbradshaw | 0:e4a10ed6eb92 | 99 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 100 | } |
jbradshaw | 0:e4a10ed6eb92 | 101 | |
jbradshaw | 0:e4a10ed6eb92 | 102 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 103 | int System_GetTimestamp(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 104 | sprintf(replyStrs[0], "GetTimestamp = %d", 0); |
jbradshaw | 0:e4a10ed6eb92 | 105 | strcpy(replyStrs[1], "\0"); |
jbradshaw | 0:e4a10ed6eb92 | 106 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 107 | } |
jbradshaw | 0:e4a10ed6eb92 | 108 | |
jbradshaw | 0:e4a10ed6eb92 | 109 | static struct RPC_Object RPC_Procedures = {NULL, NULL}; |
jbradshaw | 0:e4a10ed6eb92 | 110 | |
jbradshaw | 0:e4a10ed6eb92 | 111 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 112 | void RPC_addProcedure(struct RPC_registeredProcedure *procedure) { |
jbradshaw | 0:e4a10ed6eb92 | 113 | struct RPC_Object *obj = &RPC_Procedures; |
jbradshaw | 0:e4a10ed6eb92 | 114 | if (obj->last != NULL) { |
jbradshaw | 0:e4a10ed6eb92 | 115 | obj->last->next = procedure; |
jbradshaw | 0:e4a10ed6eb92 | 116 | } |
jbradshaw | 0:e4a10ed6eb92 | 117 | if (obj->head == NULL) { |
jbradshaw | 0:e4a10ed6eb92 | 118 | obj->head = procedure; |
jbradshaw | 0:e4a10ed6eb92 | 119 | } |
jbradshaw | 0:e4a10ed6eb92 | 120 | procedure->next = NULL; |
jbradshaw | 0:e4a10ed6eb92 | 121 | obj->last = procedure; |
jbradshaw | 0:e4a10ed6eb92 | 122 | } |
jbradshaw | 0:e4a10ed6eb92 | 123 | |
jbradshaw | 0:e4a10ed6eb92 | 124 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 125 | void RPC_init(void) { |
jbradshaw | 0:e4a10ed6eb92 | 126 | bmp280_Logging = new Device_Logging(); |
jbradshaw | 0:e4a10ed6eb92 | 127 | MAX30205_0_Logging = new Device_Logging(); |
jbradshaw | 0:e4a10ed6eb92 | 128 | MAX30205_1_Logging = new Device_Logging(); |
jbradshaw | 0:e4a10ed6eb92 | 129 | |
jbradshaw | 0:e4a10ed6eb92 | 130 | fifo_init(&fifo, fifoBuffer, sizeof(fifoBuffer)); |
jbradshaw | 0:e4a10ed6eb92 | 131 | fifo_init(&fifoStreamOut, streamOutBuffer, |
jbradshaw | 0:e4a10ed6eb92 | 132 | sizeof(streamOutBuffer) / sizeof(uint32_t)); |
jbradshaw | 0:e4a10ed6eb92 | 133 | |
jbradshaw | 0:e4a10ed6eb92 | 134 | // I2c |
jbradshaw | 0:e4a10ed6eb92 | 135 | RPC_addProcedure(&Define_I2c_WriteRead); |
jbradshaw | 0:e4a10ed6eb92 | 136 | |
jbradshaw | 0:e4a10ed6eb92 | 137 | // MAX30101 |
jbradshaw | 0:e4a10ed6eb92 | 138 | RPC_addProcedure(&Define_MAX30101_WriteReg); |
jbradshaw | 0:e4a10ed6eb92 | 139 | RPC_addProcedure(&Define_MAX30101_ReadReg); |
jbradshaw | 0:e4a10ed6eb92 | 140 | RPC_addProcedure(&Define_MAX30101_SpO2mode_Init); |
jbradshaw | 0:e4a10ed6eb92 | 141 | RPC_addProcedure(&Define_MAX30101_HRmode_Init); |
jbradshaw | 0:e4a10ed6eb92 | 142 | RPC_addProcedure(&Define_MAX30101_Multimode_init); |
jbradshaw | 0:e4a10ed6eb92 | 143 | RPC_addProcedure(&Define_MAX30101_SpO2mode_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 144 | RPC_addProcedure(&Define_MAX30101_HRmode_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 145 | RPC_addProcedure(&Define_MAX30101_Multimode_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 146 | RPC_addProcedure(&Define_MAX30101_SpO2mode_stop); |
jbradshaw | 0:e4a10ed6eb92 | 147 | RPC_addProcedure(&Define_MAX30101_HRmode_stop); |
jbradshaw | 0:e4a10ed6eb92 | 148 | RPC_addProcedure(&Define_MAX30101_Multimode_stop); |
jbradshaw | 0:e4a10ed6eb92 | 149 | |
jbradshaw | 0:e4a10ed6eb92 | 150 | // MAX30001 |
jbradshaw | 0:e4a10ed6eb92 | 151 | RPC_addProcedure(&Define_MAX30001_WriteReg); |
jbradshaw | 0:e4a10ed6eb92 | 152 | RPC_addProcedure(&Define_MAX30001_ReadReg); |
jbradshaw | 0:e4a10ed6eb92 | 153 | RPC_addProcedure(&Define_MAX30001_Start); |
jbradshaw | 0:e4a10ed6eb92 | 154 | RPC_addProcedure(&Define_MAX30001_Stop); |
jbradshaw | 0:e4a10ed6eb92 | 155 | RPC_addProcedure(&Define_MAX30001_Enable_ECG_LeadON); |
jbradshaw | 0:e4a10ed6eb92 | 156 | RPC_addProcedure(&Define_MAX30001_Enable_BIOZ_LeadON); |
jbradshaw | 0:e4a10ed6eb92 | 157 | RPC_addProcedure(&Define_MAX30001_Read_LeadON); |
jbradshaw | 0:e4a10ed6eb92 | 158 | RPC_addProcedure(&Define_MAX30001_StartTest); |
jbradshaw | 0:e4a10ed6eb92 | 159 | RPC_addProcedure(&Define_MAX30001_INT_assignment); |
jbradshaw | 0:e4a10ed6eb92 | 160 | RPC_addProcedure(&Define_MAX30001_Rbias_FMSTR_Init); |
jbradshaw | 0:e4a10ed6eb92 | 161 | RPC_addProcedure(&Define_MAX30001_CAL_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 162 | RPC_addProcedure(&Define_MAX30001_ECG_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 163 | RPC_addProcedure(&Define_MAX30001_ECGFast_Init); |
jbradshaw | 0:e4a10ed6eb92 | 164 | RPC_addProcedure(&Define_MAX30001_PACE_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 165 | RPC_addProcedure(&Define_MAX30001_BIOZ_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 166 | RPC_addProcedure(&Define_MAX30001_RtoR_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 167 | RPC_addProcedure(&Define_MAX30001_Stop_ECG); |
jbradshaw | 0:e4a10ed6eb92 | 168 | RPC_addProcedure(&Define_MAX30001_Stop_PACE); |
jbradshaw | 0:e4a10ed6eb92 | 169 | RPC_addProcedure(&Define_MAX30001_Stop_BIOZ); |
jbradshaw | 0:e4a10ed6eb92 | 170 | RPC_addProcedure(&Define_MAX30001_Stop_RtoR); |
jbradshaw | 0:e4a10ed6eb92 | 171 | RPC_addProcedure(&Define_MAX30001_Stop_Cal); |
jbradshaw | 0:e4a10ed6eb92 | 172 | |
jbradshaw | 0:e4a10ed6eb92 | 173 | // Logging |
jbradshaw | 0:e4a10ed6eb92 | 174 | RPC_addProcedure(&Define_Logging_StartMissionDefine); |
jbradshaw | 0:e4a10ed6eb92 | 175 | RPC_addProcedure(&Define_Logging_AppendMissionCmd); |
jbradshaw | 0:e4a10ed6eb92 | 176 | RPC_addProcedure(&Define_Logging_EndMissionDefine); |
jbradshaw | 0:e4a10ed6eb92 | 177 | RPC_addProcedure(&Define_Logging_WriteMission); |
jbradshaw | 0:e4a10ed6eb92 | 178 | RPC_addProcedure(&Define_Logging_ReadMission); |
jbradshaw | 0:e4a10ed6eb92 | 179 | RPC_addProcedure(&Define_Logging_EraseMission); |
jbradshaw | 0:e4a10ed6eb92 | 180 | RPC_addProcedure(&Define_Logging_EraseWrittenSectors); |
jbradshaw | 0:e4a10ed6eb92 | 181 | RPC_addProcedure(&Define_Logging_StartLoggingUsb); |
jbradshaw | 0:e4a10ed6eb92 | 182 | RPC_addProcedure(&Define_Logging_StartLoggingFlash); |
jbradshaw | 0:e4a10ed6eb92 | 183 | RPC_addProcedure(&Define_Logging_GetLastWrittenPage); |
jbradshaw | 0:e4a10ed6eb92 | 184 | RPC_addProcedure(&Define_Logging_Start); |
jbradshaw | 0:e4a10ed6eb92 | 185 | |
jbradshaw | 0:e4a10ed6eb92 | 186 | // LIS2HD |
jbradshaw | 0:e4a10ed6eb92 | 187 | RPC_addProcedure(&Define_LIS2DH_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 188 | RPC_addProcedure(&Define_LIS2DH_ReadReg); |
jbradshaw | 0:e4a10ed6eb92 | 189 | RPC_addProcedure(&Define_LIS2DH_WriteReg); |
jbradshaw | 0:e4a10ed6eb92 | 190 | RPC_addProcedure(&Define_LIS2DH_Stop); |
jbradshaw | 0:e4a10ed6eb92 | 191 | |
jbradshaw | 0:e4a10ed6eb92 | 192 | // BMP280 |
jbradshaw | 0:e4a10ed6eb92 | 193 | RPC_addProcedure(&Define_BMP280_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 194 | |
jbradshaw | 0:e4a10ed6eb92 | 195 | // MAX30205 and MAX31725 Alias |
jbradshaw | 0:e4a10ed6eb92 | 196 | RPC_addProcedure(&Define_MAX30205_1_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 197 | RPC_addProcedure(&Define_MAX30205_2_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 198 | RPC_addProcedure(&Define_MAX31725_1_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 199 | RPC_addProcedure(&Define_MAX31725_2_InitStart); |
jbradshaw | 0:e4a10ed6eb92 | 200 | |
jbradshaw | 0:e4a10ed6eb92 | 201 | // led |
jbradshaw | 0:e4a10ed6eb92 | 202 | RPC_addProcedure(&Define_Led_On); |
jbradshaw | 0:e4a10ed6eb92 | 203 | RPC_addProcedure(&Define_Led_Off); |
jbradshaw | 0:e4a10ed6eb92 | 204 | RPC_addProcedure(&Define_Led_BlinkHz); |
jbradshaw | 0:e4a10ed6eb92 | 205 | RPC_addProcedure(&Define_Led_BlinkPattern); |
jbradshaw | 0:e4a10ed6eb92 | 206 | |
jbradshaw | 0:e4a10ed6eb92 | 207 | // S25FS512 |
jbradshaw | 0:e4a10ed6eb92 | 208 | RPC_addProcedure(&Define_S25FS512_ReadId); |
jbradshaw | 0:e4a10ed6eb92 | 209 | RPC_addProcedure(&Define_S25FS512_ReadPagesBinary); |
jbradshaw | 0:e4a10ed6eb92 | 210 | RPC_addProcedure(&Define_S25FS512_Reset); |
jbradshaw | 0:e4a10ed6eb92 | 211 | RPC_addProcedure(&Define_S25FS512_EnableHWReset); |
jbradshaw | 0:e4a10ed6eb92 | 212 | RPC_addProcedure(&Define_S25FS512_SpiWriteRead); |
jbradshaw | 0:e4a10ed6eb92 | 213 | RPC_addProcedure(&Define_S25FS512_SpiWriteRead4Wire); |
jbradshaw | 0:e4a10ed6eb92 | 214 | |
jbradshaw | 0:e4a10ed6eb92 | 215 | // Testing |
jbradshaw | 0:e4a10ed6eb92 | 216 | RPC_addProcedure(&Define_Testing_Test_S25FS512); |
jbradshaw | 0:e4a10ed6eb92 | 217 | RPC_addProcedure(&Define_Testing_Test_BMP280); |
jbradshaw | 0:e4a10ed6eb92 | 218 | RPC_addProcedure(&Define_Testing_Test_LIS2DH); |
jbradshaw | 0:e4a10ed6eb92 | 219 | RPC_addProcedure(&Define_Testing_Test_LSM6DS3); |
jbradshaw | 0:e4a10ed6eb92 | 220 | RPC_addProcedure(&Define_Testing_Test_MAX30205_1); |
jbradshaw | 0:e4a10ed6eb92 | 221 | RPC_addProcedure(&Define_Testing_Test_MAX30205_2); |
jbradshaw | 0:e4a10ed6eb92 | 222 | RPC_addProcedure(&Define_Testing_Test_MAX30101); |
jbradshaw | 0:e4a10ed6eb92 | 223 | RPC_addProcedure(&Define_Testing_Test_MAX30001); |
jbradshaw | 0:e4a10ed6eb92 | 224 | RPC_addProcedure(&Define_Testing_Test_EM9301); |
jbradshaw | 0:e4a10ed6eb92 | 225 | |
jbradshaw | 0:e4a10ed6eb92 | 226 | // System |
jbradshaw | 0:e4a10ed6eb92 | 227 | RPC_addProcedure(&Define_System_ReadVer); |
jbradshaw | 0:e4a10ed6eb92 | 228 | RPC_addProcedure(&Define_System_ReadBuildTime); |
jbradshaw | 0:e4a10ed6eb92 | 229 | |
jbradshaw | 0:e4a10ed6eb92 | 230 | // MAX14720 |
jbradshaw | 0:e4a10ed6eb92 | 231 | RPC_addProcedure(&Define_MAX14720_ReadBoostVSet); |
jbradshaw | 0:e4a10ed6eb92 | 232 | RPC_addProcedure(&Define_MAX14720_WriteBoostVSet); |
jbradshaw | 0:e4a10ed6eb92 | 233 | RPC_addProcedure(&Define_MAX14720_ReadReg); |
jbradshaw | 0:e4a10ed6eb92 | 234 | RPC_addProcedure(&Define_MAX14720_WriteReg); |
jbradshaw | 0:e4a10ed6eb92 | 235 | } |
jbradshaw | 0:e4a10ed6eb92 | 236 | |
jbradshaw | 0:e4a10ed6eb92 | 237 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 238 | struct RPC_registeredProcedure *RPC_lookup(char *objectName, char *methodName) { |
jbradshaw | 0:e4a10ed6eb92 | 239 | struct RPC_registeredProcedure *ptr; |
jbradshaw | 0:e4a10ed6eb92 | 240 | // lookup all registered methods |
jbradshaw | 0:e4a10ed6eb92 | 241 | ptr = RPC_Procedures.head; |
jbradshaw | 0:e4a10ed6eb92 | 242 | while (ptr != NULL) { |
jbradshaw | 0:e4a10ed6eb92 | 243 | if (strcmp(ptr->objectName, objectName) == 0 && |
jbradshaw | 0:e4a10ed6eb92 | 244 | strcmp(ptr->methodName, methodName) == 0) { |
jbradshaw | 0:e4a10ed6eb92 | 245 | // we found a match... return with it |
jbradshaw | 0:e4a10ed6eb92 | 246 | return ptr; |
jbradshaw | 0:e4a10ed6eb92 | 247 | } |
jbradshaw | 0:e4a10ed6eb92 | 248 | ptr = ptr->next; |
jbradshaw | 0:e4a10ed6eb92 | 249 | } |
jbradshaw | 0:e4a10ed6eb92 | 250 | return NULL; |
jbradshaw | 0:e4a10ed6eb92 | 251 | } |
jbradshaw | 0:e4a10ed6eb92 | 252 | |
jbradshaw | 0:e4a10ed6eb92 | 253 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 254 | char *GetToken(char *inStr, char *outStr, int start, char ch) { |
jbradshaw | 0:e4a10ed6eb92 | 255 | int i; |
jbradshaw | 0:e4a10ed6eb92 | 256 | int index = 0; |
jbradshaw | 0:e4a10ed6eb92 | 257 | int length = strlen(inStr); |
jbradshaw | 0:e4a10ed6eb92 | 258 | for (i = start; i < length; i++) { |
jbradshaw | 0:e4a10ed6eb92 | 259 | if (inStr[i] != ch) { |
jbradshaw | 0:e4a10ed6eb92 | 260 | outStr[index++] = inStr[i]; |
jbradshaw | 0:e4a10ed6eb92 | 261 | } else { |
jbradshaw | 0:e4a10ed6eb92 | 262 | break; |
jbradshaw | 0:e4a10ed6eb92 | 263 | } |
jbradshaw | 0:e4a10ed6eb92 | 264 | } |
jbradshaw | 0:e4a10ed6eb92 | 265 | outStr[index++] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 266 | return outStr; |
jbradshaw | 0:e4a10ed6eb92 | 267 | } |
jbradshaw | 0:e4a10ed6eb92 | 268 | |
jbradshaw | 0:e4a10ed6eb92 | 269 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 270 | void SendCommandList(char *reply) { |
jbradshaw | 0:e4a10ed6eb92 | 271 | struct RPC_registeredProcedure *ptr; |
jbradshaw | 0:e4a10ed6eb92 | 272 | reply[0] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 273 | ptr = RPC_Procedures.head; |
jbradshaw | 0:e4a10ed6eb92 | 274 | while (ptr != NULL) { |
jbradshaw | 0:e4a10ed6eb92 | 275 | strcat(reply, "/"); |
jbradshaw | 0:e4a10ed6eb92 | 276 | strcat(reply, ptr->objectName); |
jbradshaw | 0:e4a10ed6eb92 | 277 | strcat(reply, "/"); |
jbradshaw | 0:e4a10ed6eb92 | 278 | strcat(reply, ptr->methodName); |
jbradshaw | 0:e4a10ed6eb92 | 279 | strcat(reply, ","); |
jbradshaw | 0:e4a10ed6eb92 | 280 | ptr = ptr->next; |
jbradshaw | 0:e4a10ed6eb92 | 281 | } |
jbradshaw | 0:e4a10ed6eb92 | 282 | strcat(reply, "\r\n"); |
jbradshaw | 0:e4a10ed6eb92 | 283 | } |
jbradshaw | 0:e4a10ed6eb92 | 284 | |
jbradshaw | 0:e4a10ed6eb92 | 285 | //****************************************************************************** |
jbradshaw | 1:9490836294ea | 286 | int CheckForDoubleQuote(const char *str) { |
jbradshaw | 0:e4a10ed6eb92 | 287 | int doubleQuoteFound; |
jbradshaw | 0:e4a10ed6eb92 | 288 | // scan through arguments, see if there is a double quote for a string |
jbradshaw | 0:e4a10ed6eb92 | 289 | // argument |
jbradshaw | 0:e4a10ed6eb92 | 290 | doubleQuoteFound = 0; |
jbradshaw | 0:e4a10ed6eb92 | 291 | while (*str != 0) { |
jbradshaw | 0:e4a10ed6eb92 | 292 | if (*str == '\"') { |
jbradshaw | 0:e4a10ed6eb92 | 293 | doubleQuoteFound = 1; |
jbradshaw | 0:e4a10ed6eb92 | 294 | break; |
jbradshaw | 0:e4a10ed6eb92 | 295 | } |
jbradshaw | 0:e4a10ed6eb92 | 296 | str++; |
jbradshaw | 0:e4a10ed6eb92 | 297 | } |
jbradshaw | 0:e4a10ed6eb92 | 298 | return doubleQuoteFound; |
jbradshaw | 0:e4a10ed6eb92 | 299 | } |
jbradshaw | 0:e4a10ed6eb92 | 300 | |
jbradshaw | 0:e4a10ed6eb92 | 301 | //****************************************************************************** |
jbradshaw | 1:9490836294ea | 302 | void ExtractDoubleQuoteStr(const char *src, char *dst) { |
jbradshaw | 0:e4a10ed6eb92 | 303 | int start; |
jbradshaw | 0:e4a10ed6eb92 | 304 | |
jbradshaw | 0:e4a10ed6eb92 | 305 | dst[0] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 306 | start = 0; |
jbradshaw | 0:e4a10ed6eb92 | 307 | while (*src != 0) { |
jbradshaw | 0:e4a10ed6eb92 | 308 | // look for start |
jbradshaw | 0:e4a10ed6eb92 | 309 | if ((*src == '\"') && (start == 0)) { |
jbradshaw | 0:e4a10ed6eb92 | 310 | start = 1; |
jbradshaw | 0:e4a10ed6eb92 | 311 | src++; |
jbradshaw | 0:e4a10ed6eb92 | 312 | continue; |
jbradshaw | 0:e4a10ed6eb92 | 313 | } |
jbradshaw | 0:e4a10ed6eb92 | 314 | // look for end |
jbradshaw | 0:e4a10ed6eb92 | 315 | if ((*src == '\"') && (start == 1)) { |
jbradshaw | 0:e4a10ed6eb92 | 316 | *dst = 0; // terminate the string |
jbradshaw | 0:e4a10ed6eb92 | 317 | break; |
jbradshaw | 0:e4a10ed6eb92 | 318 | } |
jbradshaw | 0:e4a10ed6eb92 | 319 | if (start == 1) { |
jbradshaw | 0:e4a10ed6eb92 | 320 | *dst = *src; |
jbradshaw | 0:e4a10ed6eb92 | 321 | dst++; |
jbradshaw | 0:e4a10ed6eb92 | 322 | } |
jbradshaw | 0:e4a10ed6eb92 | 323 | src++; |
jbradshaw | 0:e4a10ed6eb92 | 324 | } |
jbradshaw | 0:e4a10ed6eb92 | 325 | } |
jbradshaw | 0:e4a10ed6eb92 | 326 | |
jbradshaw | 0:e4a10ed6eb92 | 327 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 328 | void RPC_call_test(void) { |
jbradshaw | 0:e4a10ed6eb92 | 329 | int doubleQuoteFound; |
jbradshaw | 0:e4a10ed6eb92 | 330 | char doubleQuoteStr[64]; |
jbradshaw | 1:9490836294ea | 331 | const char *request = "/Logging/AppendMissionCmd \"BMP280 InitStart 1\""; |
jbradshaw | 0:e4a10ed6eb92 | 332 | |
jbradshaw | 0:e4a10ed6eb92 | 333 | // scan through arguments, see if there is a double quote for a string |
jbradshaw | 0:e4a10ed6eb92 | 334 | // argument |
jbradshaw | 0:e4a10ed6eb92 | 335 | doubleQuoteFound = CheckForDoubleQuote(request); |
jbradshaw | 0:e4a10ed6eb92 | 336 | if (doubleQuoteFound) { |
jbradshaw | 0:e4a10ed6eb92 | 337 | ExtractDoubleQuoteStr(request, doubleQuoteStr); |
jbradshaw | 0:e4a10ed6eb92 | 338 | } |
jbradshaw | 0:e4a10ed6eb92 | 339 | } |
jbradshaw | 0:e4a10ed6eb92 | 340 | |
jbradshaw | 0:e4a10ed6eb92 | 341 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 342 | void RPC_call(char *request, char *reply) { |
jbradshaw | 0:e4a10ed6eb92 | 343 | const char slash[2] = "/"; |
jbradshaw | 0:e4a10ed6eb92 | 344 | const char space[2] = " "; |
jbradshaw | 0:e4a10ed6eb92 | 345 | char *objectName; |
jbradshaw | 0:e4a10ed6eb92 | 346 | char *methodName; |
jbradshaw | 0:e4a10ed6eb92 | 347 | char doubleQuoteStr[64]; |
jbradshaw | 0:e4a10ed6eb92 | 348 | char requestCpy[128]; |
jbradshaw | 0:e4a10ed6eb92 | 349 | char *token; |
jbradshaw | 0:e4a10ed6eb92 | 350 | int argIndex; |
jbradshaw | 0:e4a10ed6eb92 | 351 | int resultIndex; |
jbradshaw | 0:e4a10ed6eb92 | 352 | int doubleQuoteFound; |
jbradshaw | 0:e4a10ed6eb92 | 353 | struct RPC_registeredProcedure *procedurePtr; |
jbradshaw | 1:9490836294ea | 354 | int callResult; |
jbradshaw | 0:e4a10ed6eb92 | 355 | |
jbradshaw | 0:e4a10ed6eb92 | 356 | // clear out the reply |
jbradshaw | 0:e4a10ed6eb92 | 357 | reply[0] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 358 | // copy the request for scanning and extraction later |
jbradshaw | 0:e4a10ed6eb92 | 359 | strcpy(requestCpy, request); |
jbradshaw | 0:e4a10ed6eb92 | 360 | // check for beginning forward slash |
jbradshaw | 0:e4a10ed6eb92 | 361 | if (request[0] != '/') { |
jbradshaw | 0:e4a10ed6eb92 | 362 | return; |
jbradshaw | 0:e4a10ed6eb92 | 363 | } |
jbradshaw | 0:e4a10ed6eb92 | 364 | // check for only a forward slash |
jbradshaw | 0:e4a10ed6eb92 | 365 | if (request[0] == '/' && request[1] == 0) { |
jbradshaw | 0:e4a10ed6eb92 | 366 | SendCommandList(reply); |
jbradshaw | 0:e4a10ed6eb92 | 367 | return; |
jbradshaw | 0:e4a10ed6eb92 | 368 | } |
jbradshaw | 0:e4a10ed6eb92 | 369 | strcat(request, " "); |
jbradshaw | 0:e4a10ed6eb92 | 370 | // get the object name |
jbradshaw | 0:e4a10ed6eb92 | 371 | token = strtok(request, slash); |
jbradshaw | 0:e4a10ed6eb92 | 372 | // token = GetToken(request, tokenBuffer, 1, '/'); |
jbradshaw | 0:e4a10ed6eb92 | 373 | objectName = token; |
jbradshaw | 0:e4a10ed6eb92 | 374 | if (objectName == NULL) |
jbradshaw | 0:e4a10ed6eb92 | 375 | return; // must have an object name |
jbradshaw | 0:e4a10ed6eb92 | 376 | // get the method name |
jbradshaw | 0:e4a10ed6eb92 | 377 | token = strtok(NULL, space); |
jbradshaw | 0:e4a10ed6eb92 | 378 | methodName = token; |
jbradshaw | 0:e4a10ed6eb92 | 379 | if (methodName == NULL) |
jbradshaw | 0:e4a10ed6eb92 | 380 | return; // must have a method name |
jbradshaw | 0:e4a10ed6eb92 | 381 | |
jbradshaw | 0:e4a10ed6eb92 | 382 | // scan through arguments, see if there is a double quote for a string |
jbradshaw | 0:e4a10ed6eb92 | 383 | // argument |
jbradshaw | 0:e4a10ed6eb92 | 384 | doubleQuoteFound = CheckForDoubleQuote(requestCpy); |
jbradshaw | 0:e4a10ed6eb92 | 385 | |
jbradshaw | 0:e4a10ed6eb92 | 386 | if (doubleQuoteFound == 0) { |
jbradshaw | 0:e4a10ed6eb92 | 387 | // walk through arguments |
jbradshaw | 0:e4a10ed6eb92 | 388 | argIndex = 0; |
jbradshaw | 0:e4a10ed6eb92 | 389 | token = strtok(NULL, space); |
jbradshaw | 0:e4a10ed6eb92 | 390 | while (token != NULL) { |
jbradshaw | 0:e4a10ed6eb92 | 391 | // save this arg in array |
jbradshaw | 0:e4a10ed6eb92 | 392 | strcpy(args[argIndex++], token); |
jbradshaw | 0:e4a10ed6eb92 | 393 | // read next token arg if any |
jbradshaw | 0:e4a10ed6eb92 | 394 | token = strtok(NULL, space); |
jbradshaw | 0:e4a10ed6eb92 | 395 | } |
jbradshaw | 0:e4a10ed6eb92 | 396 | // terminate the end of the string array with an empty string |
jbradshaw | 0:e4a10ed6eb92 | 397 | strcpy(args[argIndex], "\0"); |
jbradshaw | 0:e4a10ed6eb92 | 398 | strcpy(results[0], "\0"); |
jbradshaw | 0:e4a10ed6eb92 | 399 | } else { |
jbradshaw | 0:e4a10ed6eb92 | 400 | // grab out the double quote string |
jbradshaw | 0:e4a10ed6eb92 | 401 | ExtractDoubleQuoteStr(requestCpy, doubleQuoteStr); |
jbradshaw | 0:e4a10ed6eb92 | 402 | argIndex = 0; |
jbradshaw | 0:e4a10ed6eb92 | 403 | // token = strtok(NULL, quote); |
jbradshaw | 0:e4a10ed6eb92 | 404 | strcpy(args[argIndex++], doubleQuoteStr); |
jbradshaw | 0:e4a10ed6eb92 | 405 | } |
jbradshaw | 0:e4a10ed6eb92 | 406 | |
jbradshaw | 0:e4a10ed6eb92 | 407 | // |
jbradshaw | 0:e4a10ed6eb92 | 408 | // alias the MAX30001 and MAX30003 names |
jbradshaw | 0:e4a10ed6eb92 | 409 | // |
jbradshaw | 0:e4a10ed6eb92 | 410 | if (strcmp(objectName, MAX30003_NAME) == 0) { |
jbradshaw | 0:e4a10ed6eb92 | 411 | strcpy(objectName, MAX30001_NAME); |
jbradshaw | 0:e4a10ed6eb92 | 412 | } |
jbradshaw | 0:e4a10ed6eb92 | 413 | |
jbradshaw | 1:9490836294ea | 414 | callResult = 0; |
jbradshaw | 0:e4a10ed6eb92 | 415 | procedurePtr = RPC_lookup(objectName, methodName); |
jbradshaw | 0:e4a10ed6eb92 | 416 | if (procedurePtr != NULL) { |
jbradshaw | 0:e4a10ed6eb92 | 417 | // printf("RPC_call: %s processing\n",requestCpy); |
jbradshaw | 1:9490836294ea | 418 | callResult = procedurePtr->func(args, results); |
jbradshaw | 0:e4a10ed6eb92 | 419 | } else { |
jbradshaw | 0:e4a10ed6eb92 | 420 | printf("RPC_call: %s not found\n", requestCpy); |
jbradshaw | 0:e4a10ed6eb92 | 421 | // printf("Unable to lookup %s %s", objectName, methodName); |
jbradshaw | 0:e4a10ed6eb92 | 422 | } |
jbradshaw | 0:e4a10ed6eb92 | 423 | |
jbradshaw | 0:e4a10ed6eb92 | 424 | // loop while (if) there are results to return |
jbradshaw | 0:e4a10ed6eb92 | 425 | resultIndex = 0; |
jbradshaw | 0:e4a10ed6eb92 | 426 | strcpy(reply, "\0"); |
jbradshaw | 1:9490836294ea | 427 | if (callResult != RPC_SKIP_CRLF) { |
jbradshaw | 1:9490836294ea | 428 | while (results[resultIndex][0] != '\0') { |
jbradshaw | 1:9490836294ea | 429 | strcat(reply, results[resultIndex++]); |
jbradshaw | 1:9490836294ea | 430 | strcat(reply, " "); |
jbradshaw | 1:9490836294ea | 431 | } |
jbradshaw | 1:9490836294ea | 432 | strcat(reply, "\r\n"); |
jbradshaw | 0:e4a10ed6eb92 | 433 | } |
jbradshaw | 0:e4a10ed6eb92 | 434 | } |
jbradshaw | 0:e4a10ed6eb92 | 435 | |
jbradshaw | 0:e4a10ed6eb92 | 436 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 437 | void RPC_ProcessCmds(char *cmds) { |
jbradshaw | 0:e4a10ed6eb92 | 438 | char cmd[32 * 32]; |
jbradshaw | 0:e4a10ed6eb92 | 439 | char *ptrCmds; |
jbradshaw | 0:e4a10ed6eb92 | 440 | char reply[512]; |
jbradshaw | 0:e4a10ed6eb92 | 441 | ptrCmds = cmds; |
jbradshaw | 0:e4a10ed6eb92 | 442 | |
jbradshaw | 0:e4a10ed6eb92 | 443 | while (*ptrCmds != 0) { |
jbradshaw | 0:e4a10ed6eb92 | 444 | ptrCmds = ParseUntilCRLF(ptrCmds, cmd, sizeof(cmd)); |
jbradshaw | 0:e4a10ed6eb92 | 445 | if (*cmd != 0) { |
jbradshaw | 0:e4a10ed6eb92 | 446 | RPC_call(cmd, reply); |
jbradshaw | 0:e4a10ed6eb92 | 447 | } |
jbradshaw | 0:e4a10ed6eb92 | 448 | } |
jbradshaw | 0:e4a10ed6eb92 | 449 | } |