Fork of the offical HSP_RPC_GUI firmware

Dependencies:   USBDevice

Fork of MAXREFDES100 firmware for MAX32620HSP

Committer:
wt8008
Date:
Tue Jan 28 20:22:16 2020 +0000
Revision:
4:18155622d30a
Parent:
3:8e9b9f5818aa
Update Maxim's USBDevice project to the latest version

Who changed what in which revision?

UserRevisionLine numberNew 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 3:8e9b9f5818aa 75 ///Defines a timer to detect if a series of binary pages are being transfered via RPC
jbradshaw 3:8e9b9f5818aa 76 Timer rpcFlashPagesTransferTimer;
jbradshaw 3:8e9b9f5818aa 77 bool rpcFlashPagesTransferTimer_running;
jbradshaw 3:8e9b9f5818aa 78
jbradshaw 0:e4a10ed6eb92 79 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 80 fifo_t *GetUSBIncomingFifo(void) { return &fifo; }
jbradshaw 0:e4a10ed6eb92 81
jbradshaw 0:e4a10ed6eb92 82 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 83 fifo_t *GetStreamOutFifo(void) { return &fifoStreamOut; }
jbradshaw 0:e4a10ed6eb92 84
jbradshaw 0:e4a10ed6eb92 85 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 86 int System_ReadVer(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 87 strcpy(replyStrs[0], FW_VERSION_STRING);
jbradshaw 0:e4a10ed6eb92 88 strcpy(replyStrs[1], "\0");
jbradshaw 0:e4a10ed6eb92 89 return 0;
jbradshaw 0:e4a10ed6eb92 90 }
jbradshaw 0:e4a10ed6eb92 91
jbradshaw 0:e4a10ed6eb92 92 //******************************************************************************
jbradshaw 3:8e9b9f5818aa 93 bool RPC_IsTransferingFlashPages(void) {
jbradshaw 3:8e9b9f5818aa 94 if (rpcFlashPagesTransferTimer_running == true) {
jbradshaw 3:8e9b9f5818aa 95 if (rpcFlashPagesTransferTimer.read_ms() < 200) {
jbradshaw 3:8e9b9f5818aa 96 return true;
jbradshaw 3:8e9b9f5818aa 97 } else {
jbradshaw 3:8e9b9f5818aa 98 rpcFlashPagesTransferTimer.stop();
jbradshaw 3:8e9b9f5818aa 99 rpcFlashPagesTransferTimer_running = false;
jbradshaw 3:8e9b9f5818aa 100 }
jbradshaw 3:8e9b9f5818aa 101 }
jbradshaw 3:8e9b9f5818aa 102 return false;
jbradshaw 3:8e9b9f5818aa 103 }
jbradshaw 3:8e9b9f5818aa 104
jbradshaw 3:8e9b9f5818aa 105 //******************************************************************************
jbradshaw 3:8e9b9f5818aa 106 void RPC_TransferingFlashPages(void) {
jbradshaw 3:8e9b9f5818aa 107 if (rpcFlashPagesTransferTimer_running == false) {
jbradshaw 3:8e9b9f5818aa 108 rpcFlashPagesTransferTimer.start();
jbradshaw 3:8e9b9f5818aa 109 rpcFlashPagesTransferTimer_running = true;
jbradshaw 3:8e9b9f5818aa 110 }
jbradshaw 3:8e9b9f5818aa 111 rpcFlashPagesTransferTimer.reset();
jbradshaw 3:8e9b9f5818aa 112 }
jbradshaw 3:8e9b9f5818aa 113
jbradshaw 3:8e9b9f5818aa 114 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 115 int System_ReadBuildTime(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 116 // strcpy(replyStrs[0],buildTime);
jbradshaw 0:e4a10ed6eb92 117 // strcpy(replyStrs[1],"\0");
jbradshaw 0:e4a10ed6eb92 118 return 0;
jbradshaw 0:e4a10ed6eb92 119 }
jbradshaw 0:e4a10ed6eb92 120
jbradshaw 0:e4a10ed6eb92 121 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 122 int System_SystemCoreClock(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 1:9490836294ea 123 sprintf(replyStrs[0], "SystemCoreClock = %d", (unsigned int)SystemCoreClock);
jbradshaw 0:e4a10ed6eb92 124 strcpy(replyStrs[1], "\0");
jbradshaw 0:e4a10ed6eb92 125 return 0;
jbradshaw 0:e4a10ed6eb92 126 }
jbradshaw 0:e4a10ed6eb92 127
jbradshaw 0:e4a10ed6eb92 128 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 129 int System_GetTimestamp(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 130 sprintf(replyStrs[0], "GetTimestamp = %d", 0);
jbradshaw 0:e4a10ed6eb92 131 strcpy(replyStrs[1], "\0");
jbradshaw 0:e4a10ed6eb92 132 return 0;
jbradshaw 0:e4a10ed6eb92 133 }
jbradshaw 0:e4a10ed6eb92 134
jbradshaw 0:e4a10ed6eb92 135 static struct RPC_Object RPC_Procedures = {NULL, NULL};
jbradshaw 0:e4a10ed6eb92 136
jbradshaw 0:e4a10ed6eb92 137 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 138 void RPC_addProcedure(struct RPC_registeredProcedure *procedure) {
jbradshaw 0:e4a10ed6eb92 139 struct RPC_Object *obj = &RPC_Procedures;
jbradshaw 0:e4a10ed6eb92 140 if (obj->last != NULL) {
jbradshaw 0:e4a10ed6eb92 141 obj->last->next = procedure;
jbradshaw 0:e4a10ed6eb92 142 }
jbradshaw 0:e4a10ed6eb92 143 if (obj->head == NULL) {
jbradshaw 0:e4a10ed6eb92 144 obj->head = procedure;
jbradshaw 0:e4a10ed6eb92 145 }
jbradshaw 0:e4a10ed6eb92 146 procedure->next = NULL;
jbradshaw 0:e4a10ed6eb92 147 obj->last = procedure;
jbradshaw 0:e4a10ed6eb92 148 }
jbradshaw 0:e4a10ed6eb92 149
jbradshaw 0:e4a10ed6eb92 150 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 151 void RPC_init(void) {
jbradshaw 0:e4a10ed6eb92 152 bmp280_Logging = new Device_Logging();
jbradshaw 0:e4a10ed6eb92 153 MAX30205_0_Logging = new Device_Logging();
jbradshaw 0:e4a10ed6eb92 154 MAX30205_1_Logging = new Device_Logging();
jbradshaw 0:e4a10ed6eb92 155
jbradshaw 3:8e9b9f5818aa 156 rpcFlashPagesTransferTimer_running = false;
jbradshaw 3:8e9b9f5818aa 157
jbradshaw 0:e4a10ed6eb92 158 fifo_init(&fifo, fifoBuffer, sizeof(fifoBuffer));
jbradshaw 0:e4a10ed6eb92 159 fifo_init(&fifoStreamOut, streamOutBuffer,
jbradshaw 0:e4a10ed6eb92 160 sizeof(streamOutBuffer) / sizeof(uint32_t));
jbradshaw 0:e4a10ed6eb92 161
jbradshaw 0:e4a10ed6eb92 162 // I2c
jbradshaw 0:e4a10ed6eb92 163 RPC_addProcedure(&Define_I2c_WriteRead);
jbradshaw 0:e4a10ed6eb92 164
jbradshaw 0:e4a10ed6eb92 165 // MAX30101
jbradshaw 0:e4a10ed6eb92 166 RPC_addProcedure(&Define_MAX30101_WriteReg);
jbradshaw 0:e4a10ed6eb92 167 RPC_addProcedure(&Define_MAX30101_ReadReg);
jbradshaw 0:e4a10ed6eb92 168 RPC_addProcedure(&Define_MAX30101_SpO2mode_Init);
jbradshaw 0:e4a10ed6eb92 169 RPC_addProcedure(&Define_MAX30101_HRmode_Init);
jbradshaw 0:e4a10ed6eb92 170 RPC_addProcedure(&Define_MAX30101_Multimode_init);
jbradshaw 0:e4a10ed6eb92 171 RPC_addProcedure(&Define_MAX30101_SpO2mode_InitStart);
jbradshaw 0:e4a10ed6eb92 172 RPC_addProcedure(&Define_MAX30101_HRmode_InitStart);
jbradshaw 0:e4a10ed6eb92 173 RPC_addProcedure(&Define_MAX30101_Multimode_InitStart);
jbradshaw 0:e4a10ed6eb92 174 RPC_addProcedure(&Define_MAX30101_SpO2mode_stop);
jbradshaw 0:e4a10ed6eb92 175 RPC_addProcedure(&Define_MAX30101_HRmode_stop);
jbradshaw 0:e4a10ed6eb92 176 RPC_addProcedure(&Define_MAX30101_Multimode_stop);
jbradshaw 0:e4a10ed6eb92 177
jbradshaw 0:e4a10ed6eb92 178 // MAX30001
jbradshaw 0:e4a10ed6eb92 179 RPC_addProcedure(&Define_MAX30001_WriteReg);
jbradshaw 0:e4a10ed6eb92 180 RPC_addProcedure(&Define_MAX30001_ReadReg);
jbradshaw 0:e4a10ed6eb92 181 RPC_addProcedure(&Define_MAX30001_Start);
jbradshaw 0:e4a10ed6eb92 182 RPC_addProcedure(&Define_MAX30001_Stop);
jbradshaw 0:e4a10ed6eb92 183 RPC_addProcedure(&Define_MAX30001_Enable_ECG_LeadON);
jbradshaw 0:e4a10ed6eb92 184 RPC_addProcedure(&Define_MAX30001_Enable_BIOZ_LeadON);
jbradshaw 0:e4a10ed6eb92 185 RPC_addProcedure(&Define_MAX30001_Read_LeadON);
jbradshaw 0:e4a10ed6eb92 186 RPC_addProcedure(&Define_MAX30001_StartTest);
jbradshaw 0:e4a10ed6eb92 187 RPC_addProcedure(&Define_MAX30001_INT_assignment);
jbradshaw 0:e4a10ed6eb92 188 RPC_addProcedure(&Define_MAX30001_Rbias_FMSTR_Init);
jbradshaw 0:e4a10ed6eb92 189 RPC_addProcedure(&Define_MAX30001_CAL_InitStart);
jbradshaw 0:e4a10ed6eb92 190 RPC_addProcedure(&Define_MAX30001_ECG_InitStart);
jbradshaw 0:e4a10ed6eb92 191 RPC_addProcedure(&Define_MAX30001_ECGFast_Init);
jbradshaw 0:e4a10ed6eb92 192 RPC_addProcedure(&Define_MAX30001_PACE_InitStart);
jbradshaw 0:e4a10ed6eb92 193 RPC_addProcedure(&Define_MAX30001_BIOZ_InitStart);
jbradshaw 0:e4a10ed6eb92 194 RPC_addProcedure(&Define_MAX30001_RtoR_InitStart);
jbradshaw 0:e4a10ed6eb92 195 RPC_addProcedure(&Define_MAX30001_Stop_ECG);
jbradshaw 0:e4a10ed6eb92 196 RPC_addProcedure(&Define_MAX30001_Stop_PACE);
jbradshaw 0:e4a10ed6eb92 197 RPC_addProcedure(&Define_MAX30001_Stop_BIOZ);
jbradshaw 0:e4a10ed6eb92 198 RPC_addProcedure(&Define_MAX30001_Stop_RtoR);
jbradshaw 0:e4a10ed6eb92 199 RPC_addProcedure(&Define_MAX30001_Stop_Cal);
jbradshaw 0:e4a10ed6eb92 200
jbradshaw 0:e4a10ed6eb92 201 // Logging
jbradshaw 0:e4a10ed6eb92 202 RPC_addProcedure(&Define_Logging_StartMissionDefine);
jbradshaw 0:e4a10ed6eb92 203 RPC_addProcedure(&Define_Logging_AppendMissionCmd);
jbradshaw 0:e4a10ed6eb92 204 RPC_addProcedure(&Define_Logging_EndMissionDefine);
jbradshaw 0:e4a10ed6eb92 205 RPC_addProcedure(&Define_Logging_WriteMission);
jbradshaw 0:e4a10ed6eb92 206 RPC_addProcedure(&Define_Logging_ReadMission);
jbradshaw 0:e4a10ed6eb92 207 RPC_addProcedure(&Define_Logging_EraseMission);
jbradshaw 0:e4a10ed6eb92 208 RPC_addProcedure(&Define_Logging_EraseWrittenSectors);
jbradshaw 0:e4a10ed6eb92 209 RPC_addProcedure(&Define_Logging_StartLoggingUsb);
jbradshaw 0:e4a10ed6eb92 210 RPC_addProcedure(&Define_Logging_StartLoggingFlash);
jbradshaw 0:e4a10ed6eb92 211 RPC_addProcedure(&Define_Logging_GetLastWrittenPage);
jbradshaw 0:e4a10ed6eb92 212 RPC_addProcedure(&Define_Logging_Start);
jbradshaw 0:e4a10ed6eb92 213
jbradshaw 0:e4a10ed6eb92 214 // LIS2HD
jbradshaw 0:e4a10ed6eb92 215 RPC_addProcedure(&Define_LIS2DH_InitStart);
jbradshaw 0:e4a10ed6eb92 216 RPC_addProcedure(&Define_LIS2DH_ReadReg);
jbradshaw 0:e4a10ed6eb92 217 RPC_addProcedure(&Define_LIS2DH_WriteReg);
jbradshaw 0:e4a10ed6eb92 218 RPC_addProcedure(&Define_LIS2DH_Stop);
jbradshaw 0:e4a10ed6eb92 219
jbradshaw 0:e4a10ed6eb92 220 // BMP280
jbradshaw 0:e4a10ed6eb92 221 RPC_addProcedure(&Define_BMP280_InitStart);
jbradshaw 0:e4a10ed6eb92 222
jbradshaw 0:e4a10ed6eb92 223 // MAX30205 and MAX31725 Alias
jbradshaw 0:e4a10ed6eb92 224 RPC_addProcedure(&Define_MAX30205_1_InitStart);
jbradshaw 0:e4a10ed6eb92 225 RPC_addProcedure(&Define_MAX30205_2_InitStart);
jbradshaw 0:e4a10ed6eb92 226 RPC_addProcedure(&Define_MAX31725_1_InitStart);
jbradshaw 0:e4a10ed6eb92 227 RPC_addProcedure(&Define_MAX31725_2_InitStart);
jbradshaw 0:e4a10ed6eb92 228
jbradshaw 0:e4a10ed6eb92 229 // led
jbradshaw 0:e4a10ed6eb92 230 RPC_addProcedure(&Define_Led_On);
jbradshaw 0:e4a10ed6eb92 231 RPC_addProcedure(&Define_Led_Off);
jbradshaw 0:e4a10ed6eb92 232 RPC_addProcedure(&Define_Led_BlinkHz);
jbradshaw 0:e4a10ed6eb92 233 RPC_addProcedure(&Define_Led_BlinkPattern);
jbradshaw 0:e4a10ed6eb92 234
jbradshaw 0:e4a10ed6eb92 235 // S25FS512
jbradshaw 0:e4a10ed6eb92 236 RPC_addProcedure(&Define_S25FS512_ReadId);
jbradshaw 0:e4a10ed6eb92 237 RPC_addProcedure(&Define_S25FS512_ReadPagesBinary);
jbradshaw 0:e4a10ed6eb92 238 RPC_addProcedure(&Define_S25FS512_Reset);
jbradshaw 0:e4a10ed6eb92 239 RPC_addProcedure(&Define_S25FS512_EnableHWReset);
jbradshaw 0:e4a10ed6eb92 240 RPC_addProcedure(&Define_S25FS512_SpiWriteRead);
jbradshaw 0:e4a10ed6eb92 241 RPC_addProcedure(&Define_S25FS512_SpiWriteRead4Wire);
jbradshaw 0:e4a10ed6eb92 242
jbradshaw 0:e4a10ed6eb92 243 // Testing
jbradshaw 0:e4a10ed6eb92 244 RPC_addProcedure(&Define_Testing_Test_S25FS512);
jbradshaw 0:e4a10ed6eb92 245 RPC_addProcedure(&Define_Testing_Test_BMP280);
jbradshaw 0:e4a10ed6eb92 246 RPC_addProcedure(&Define_Testing_Test_LIS2DH);
jbradshaw 0:e4a10ed6eb92 247 RPC_addProcedure(&Define_Testing_Test_LSM6DS3);
jbradshaw 0:e4a10ed6eb92 248 RPC_addProcedure(&Define_Testing_Test_MAX30205_1);
jbradshaw 0:e4a10ed6eb92 249 RPC_addProcedure(&Define_Testing_Test_MAX30205_2);
jbradshaw 0:e4a10ed6eb92 250 RPC_addProcedure(&Define_Testing_Test_MAX30101);
jbradshaw 0:e4a10ed6eb92 251 RPC_addProcedure(&Define_Testing_Test_MAX30001);
jbradshaw 0:e4a10ed6eb92 252 RPC_addProcedure(&Define_Testing_Test_EM9301);
jbradshaw 0:e4a10ed6eb92 253
jbradshaw 0:e4a10ed6eb92 254 // System
jbradshaw 0:e4a10ed6eb92 255 RPC_addProcedure(&Define_System_ReadVer);
jbradshaw 0:e4a10ed6eb92 256 RPC_addProcedure(&Define_System_ReadBuildTime);
jbradshaw 0:e4a10ed6eb92 257
jbradshaw 0:e4a10ed6eb92 258 // MAX14720
jbradshaw 0:e4a10ed6eb92 259 RPC_addProcedure(&Define_MAX14720_ReadBoostVSet);
jbradshaw 0:e4a10ed6eb92 260 RPC_addProcedure(&Define_MAX14720_WriteBoostVSet);
jbradshaw 0:e4a10ed6eb92 261 RPC_addProcedure(&Define_MAX14720_ReadReg);
jbradshaw 0:e4a10ed6eb92 262 RPC_addProcedure(&Define_MAX14720_WriteReg);
jbradshaw 0:e4a10ed6eb92 263 }
jbradshaw 0:e4a10ed6eb92 264
jbradshaw 0:e4a10ed6eb92 265 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 266 struct RPC_registeredProcedure *RPC_lookup(char *objectName, char *methodName) {
jbradshaw 0:e4a10ed6eb92 267 struct RPC_registeredProcedure *ptr;
jbradshaw 0:e4a10ed6eb92 268 // lookup all registered methods
jbradshaw 0:e4a10ed6eb92 269 ptr = RPC_Procedures.head;
jbradshaw 0:e4a10ed6eb92 270 while (ptr != NULL) {
jbradshaw 0:e4a10ed6eb92 271 if (strcmp(ptr->objectName, objectName) == 0 &&
jbradshaw 0:e4a10ed6eb92 272 strcmp(ptr->methodName, methodName) == 0) {
jbradshaw 0:e4a10ed6eb92 273 // we found a match... return with it
jbradshaw 0:e4a10ed6eb92 274 return ptr;
jbradshaw 0:e4a10ed6eb92 275 }
jbradshaw 0:e4a10ed6eb92 276 ptr = ptr->next;
jbradshaw 0:e4a10ed6eb92 277 }
jbradshaw 0:e4a10ed6eb92 278 return NULL;
jbradshaw 0:e4a10ed6eb92 279 }
jbradshaw 0:e4a10ed6eb92 280
jbradshaw 0:e4a10ed6eb92 281 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 282 char *GetToken(char *inStr, char *outStr, int start, char ch) {
jbradshaw 0:e4a10ed6eb92 283 int i;
jbradshaw 0:e4a10ed6eb92 284 int index = 0;
jbradshaw 0:e4a10ed6eb92 285 int length = strlen(inStr);
jbradshaw 0:e4a10ed6eb92 286 for (i = start; i < length; i++) {
jbradshaw 0:e4a10ed6eb92 287 if (inStr[i] != ch) {
jbradshaw 0:e4a10ed6eb92 288 outStr[index++] = inStr[i];
jbradshaw 0:e4a10ed6eb92 289 } else {
jbradshaw 0:e4a10ed6eb92 290 break;
jbradshaw 0:e4a10ed6eb92 291 }
jbradshaw 0:e4a10ed6eb92 292 }
jbradshaw 0:e4a10ed6eb92 293 outStr[index++] = 0;
jbradshaw 0:e4a10ed6eb92 294 return outStr;
jbradshaw 0:e4a10ed6eb92 295 }
jbradshaw 0:e4a10ed6eb92 296
jbradshaw 0:e4a10ed6eb92 297 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 298 void SendCommandList(char *reply) {
jbradshaw 0:e4a10ed6eb92 299 struct RPC_registeredProcedure *ptr;
jbradshaw 0:e4a10ed6eb92 300 reply[0] = 0;
jbradshaw 0:e4a10ed6eb92 301 ptr = RPC_Procedures.head;
jbradshaw 0:e4a10ed6eb92 302 while (ptr != NULL) {
jbradshaw 0:e4a10ed6eb92 303 strcat(reply, "/");
jbradshaw 0:e4a10ed6eb92 304 strcat(reply, ptr->objectName);
jbradshaw 0:e4a10ed6eb92 305 strcat(reply, "/");
jbradshaw 0:e4a10ed6eb92 306 strcat(reply, ptr->methodName);
jbradshaw 0:e4a10ed6eb92 307 strcat(reply, ",");
jbradshaw 0:e4a10ed6eb92 308 ptr = ptr->next;
jbradshaw 0:e4a10ed6eb92 309 }
jbradshaw 0:e4a10ed6eb92 310 strcat(reply, "\r\n");
jbradshaw 0:e4a10ed6eb92 311 }
jbradshaw 0:e4a10ed6eb92 312
jbradshaw 0:e4a10ed6eb92 313 //******************************************************************************
jbradshaw 1:9490836294ea 314 int CheckForDoubleQuote(const char *str) {
jbradshaw 0:e4a10ed6eb92 315 int doubleQuoteFound;
jbradshaw 0:e4a10ed6eb92 316 // scan through arguments, see if there is a double quote for a string
jbradshaw 0:e4a10ed6eb92 317 // argument
jbradshaw 0:e4a10ed6eb92 318 doubleQuoteFound = 0;
jbradshaw 0:e4a10ed6eb92 319 while (*str != 0) {
jbradshaw 0:e4a10ed6eb92 320 if (*str == '\"') {
jbradshaw 0:e4a10ed6eb92 321 doubleQuoteFound = 1;
jbradshaw 0:e4a10ed6eb92 322 break;
jbradshaw 0:e4a10ed6eb92 323 }
jbradshaw 0:e4a10ed6eb92 324 str++;
jbradshaw 0:e4a10ed6eb92 325 }
jbradshaw 0:e4a10ed6eb92 326 return doubleQuoteFound;
jbradshaw 0:e4a10ed6eb92 327 }
jbradshaw 0:e4a10ed6eb92 328
jbradshaw 0:e4a10ed6eb92 329 //******************************************************************************
jbradshaw 1:9490836294ea 330 void ExtractDoubleQuoteStr(const char *src, char *dst) {
jbradshaw 0:e4a10ed6eb92 331 int start;
jbradshaw 0:e4a10ed6eb92 332
jbradshaw 0:e4a10ed6eb92 333 dst[0] = 0;
jbradshaw 0:e4a10ed6eb92 334 start = 0;
jbradshaw 0:e4a10ed6eb92 335 while (*src != 0) {
jbradshaw 0:e4a10ed6eb92 336 // look for start
jbradshaw 0:e4a10ed6eb92 337 if ((*src == '\"') && (start == 0)) {
jbradshaw 0:e4a10ed6eb92 338 start = 1;
jbradshaw 0:e4a10ed6eb92 339 src++;
jbradshaw 0:e4a10ed6eb92 340 continue;
jbradshaw 0:e4a10ed6eb92 341 }
jbradshaw 0:e4a10ed6eb92 342 // look for end
jbradshaw 0:e4a10ed6eb92 343 if ((*src == '\"') && (start == 1)) {
jbradshaw 0:e4a10ed6eb92 344 *dst = 0; // terminate the string
jbradshaw 0:e4a10ed6eb92 345 break;
jbradshaw 0:e4a10ed6eb92 346 }
jbradshaw 0:e4a10ed6eb92 347 if (start == 1) {
jbradshaw 0:e4a10ed6eb92 348 *dst = *src;
jbradshaw 0:e4a10ed6eb92 349 dst++;
jbradshaw 0:e4a10ed6eb92 350 }
jbradshaw 0:e4a10ed6eb92 351 src++;
jbradshaw 0:e4a10ed6eb92 352 }
jbradshaw 0:e4a10ed6eb92 353 }
jbradshaw 0:e4a10ed6eb92 354
jbradshaw 0:e4a10ed6eb92 355 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 356 void RPC_call_test(void) {
jbradshaw 0:e4a10ed6eb92 357 int doubleQuoteFound;
jbradshaw 0:e4a10ed6eb92 358 char doubleQuoteStr[64];
jbradshaw 1:9490836294ea 359 const char *request = "/Logging/AppendMissionCmd \"BMP280 InitStart 1\"";
jbradshaw 0:e4a10ed6eb92 360
jbradshaw 0:e4a10ed6eb92 361 // scan through arguments, see if there is a double quote for a string
jbradshaw 0:e4a10ed6eb92 362 // argument
jbradshaw 0:e4a10ed6eb92 363 doubleQuoteFound = CheckForDoubleQuote(request);
jbradshaw 0:e4a10ed6eb92 364 if (doubleQuoteFound) {
jbradshaw 0:e4a10ed6eb92 365 ExtractDoubleQuoteStr(request, doubleQuoteStr);
jbradshaw 0:e4a10ed6eb92 366 }
jbradshaw 0:e4a10ed6eb92 367 }
jbradshaw 0:e4a10ed6eb92 368
jbradshaw 0:e4a10ed6eb92 369 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 370 void RPC_call(char *request, char *reply) {
jbradshaw 0:e4a10ed6eb92 371 const char slash[2] = "/";
jbradshaw 0:e4a10ed6eb92 372 const char space[2] = " ";
jbradshaw 0:e4a10ed6eb92 373 char *objectName;
jbradshaw 0:e4a10ed6eb92 374 char *methodName;
jbradshaw 0:e4a10ed6eb92 375 char doubleQuoteStr[64];
jbradshaw 0:e4a10ed6eb92 376 char requestCpy[128];
jbradshaw 0:e4a10ed6eb92 377 char *token;
jbradshaw 0:e4a10ed6eb92 378 int argIndex;
jbradshaw 0:e4a10ed6eb92 379 int resultIndex;
jbradshaw 0:e4a10ed6eb92 380 int doubleQuoteFound;
jbradshaw 0:e4a10ed6eb92 381 struct RPC_registeredProcedure *procedurePtr;
jbradshaw 1:9490836294ea 382 int callResult;
jbradshaw 0:e4a10ed6eb92 383
jbradshaw 0:e4a10ed6eb92 384 // clear out the reply
jbradshaw 0:e4a10ed6eb92 385 reply[0] = 0;
jbradshaw 0:e4a10ed6eb92 386 // copy the request for scanning and extraction later
jbradshaw 0:e4a10ed6eb92 387 strcpy(requestCpy, request);
jbradshaw 0:e4a10ed6eb92 388 // check for beginning forward slash
jbradshaw 0:e4a10ed6eb92 389 if (request[0] != '/') {
jbradshaw 0:e4a10ed6eb92 390 return;
jbradshaw 0:e4a10ed6eb92 391 }
jbradshaw 0:e4a10ed6eb92 392 // check for only a forward slash
jbradshaw 0:e4a10ed6eb92 393 if (request[0] == '/' && request[1] == 0) {
jbradshaw 0:e4a10ed6eb92 394 SendCommandList(reply);
jbradshaw 0:e4a10ed6eb92 395 return;
jbradshaw 0:e4a10ed6eb92 396 }
jbradshaw 0:e4a10ed6eb92 397 strcat(request, " ");
jbradshaw 0:e4a10ed6eb92 398 // get the object name
jbradshaw 0:e4a10ed6eb92 399 token = strtok(request, slash);
jbradshaw 0:e4a10ed6eb92 400 // token = GetToken(request, tokenBuffer, 1, '/');
jbradshaw 0:e4a10ed6eb92 401 objectName = token;
jbradshaw 0:e4a10ed6eb92 402 if (objectName == NULL)
jbradshaw 0:e4a10ed6eb92 403 return; // must have an object name
jbradshaw 0:e4a10ed6eb92 404 // get the method name
jbradshaw 0:e4a10ed6eb92 405 token = strtok(NULL, space);
jbradshaw 0:e4a10ed6eb92 406 methodName = token;
jbradshaw 0:e4a10ed6eb92 407 if (methodName == NULL)
jbradshaw 0:e4a10ed6eb92 408 return; // must have a method name
jbradshaw 0:e4a10ed6eb92 409
jbradshaw 0:e4a10ed6eb92 410 // scan through arguments, see if there is a double quote for a string
jbradshaw 0:e4a10ed6eb92 411 // argument
jbradshaw 0:e4a10ed6eb92 412 doubleQuoteFound = CheckForDoubleQuote(requestCpy);
jbradshaw 0:e4a10ed6eb92 413
jbradshaw 0:e4a10ed6eb92 414 if (doubleQuoteFound == 0) {
jbradshaw 0:e4a10ed6eb92 415 // walk through arguments
jbradshaw 0:e4a10ed6eb92 416 argIndex = 0;
jbradshaw 0:e4a10ed6eb92 417 token = strtok(NULL, space);
jbradshaw 0:e4a10ed6eb92 418 while (token != NULL) {
jbradshaw 0:e4a10ed6eb92 419 // save this arg in array
jbradshaw 0:e4a10ed6eb92 420 strcpy(args[argIndex++], token);
jbradshaw 0:e4a10ed6eb92 421 // read next token arg if any
jbradshaw 0:e4a10ed6eb92 422 token = strtok(NULL, space);
jbradshaw 0:e4a10ed6eb92 423 }
jbradshaw 0:e4a10ed6eb92 424 // terminate the end of the string array with an empty string
jbradshaw 0:e4a10ed6eb92 425 strcpy(args[argIndex], "\0");
jbradshaw 0:e4a10ed6eb92 426 strcpy(results[0], "\0");
jbradshaw 0:e4a10ed6eb92 427 } else {
jbradshaw 0:e4a10ed6eb92 428 // grab out the double quote string
jbradshaw 0:e4a10ed6eb92 429 ExtractDoubleQuoteStr(requestCpy, doubleQuoteStr);
jbradshaw 0:e4a10ed6eb92 430 argIndex = 0;
jbradshaw 0:e4a10ed6eb92 431 // token = strtok(NULL, quote);
jbradshaw 0:e4a10ed6eb92 432 strcpy(args[argIndex++], doubleQuoteStr);
jbradshaw 0:e4a10ed6eb92 433 }
jbradshaw 0:e4a10ed6eb92 434
jbradshaw 0:e4a10ed6eb92 435 //
jbradshaw 0:e4a10ed6eb92 436 // alias the MAX30001 and MAX30003 names
jbradshaw 0:e4a10ed6eb92 437 //
jbradshaw 0:e4a10ed6eb92 438 if (strcmp(objectName, MAX30003_NAME) == 0) {
jbradshaw 0:e4a10ed6eb92 439 strcpy(objectName, MAX30001_NAME);
jbradshaw 0:e4a10ed6eb92 440 }
jbradshaw 0:e4a10ed6eb92 441
jbradshaw 1:9490836294ea 442 callResult = 0;
jbradshaw 0:e4a10ed6eb92 443 procedurePtr = RPC_lookup(objectName, methodName);
jbradshaw 0:e4a10ed6eb92 444 if (procedurePtr != NULL) {
jbradshaw 0:e4a10ed6eb92 445 // printf("RPC_call: %s processing\n",requestCpy);
jbradshaw 1:9490836294ea 446 callResult = procedurePtr->func(args, results);
jbradshaw 0:e4a10ed6eb92 447 } else {
jbradshaw 0:e4a10ed6eb92 448 printf("RPC_call: %s not found\n", requestCpy);
jbradshaw 0:e4a10ed6eb92 449 // printf("Unable to lookup %s %s", objectName, methodName);
jbradshaw 0:e4a10ed6eb92 450 }
jbradshaw 0:e4a10ed6eb92 451
jbradshaw 0:e4a10ed6eb92 452 // loop while (if) there are results to return
jbradshaw 0:e4a10ed6eb92 453 resultIndex = 0;
jbradshaw 0:e4a10ed6eb92 454 strcpy(reply, "\0");
jbradshaw 1:9490836294ea 455 if (callResult != RPC_SKIP_CRLF) {
jbradshaw 1:9490836294ea 456 while (results[resultIndex][0] != '\0') {
jbradshaw 1:9490836294ea 457 strcat(reply, results[resultIndex++]);
jbradshaw 1:9490836294ea 458 strcat(reply, " ");
jbradshaw 1:9490836294ea 459 }
jbradshaw 1:9490836294ea 460 strcat(reply, "\r\n");
jbradshaw 0:e4a10ed6eb92 461 }
jbradshaw 0:e4a10ed6eb92 462 }
jbradshaw 0:e4a10ed6eb92 463
jbradshaw 0:e4a10ed6eb92 464 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 465 void RPC_ProcessCmds(char *cmds) {
jbradshaw 0:e4a10ed6eb92 466 char cmd[32 * 32];
jbradshaw 0:e4a10ed6eb92 467 char *ptrCmds;
jbradshaw 0:e4a10ed6eb92 468 char reply[512];
jbradshaw 0:e4a10ed6eb92 469 ptrCmds = cmds;
jbradshaw 0:e4a10ed6eb92 470
jbradshaw 0:e4a10ed6eb92 471 while (*ptrCmds != 0) {
jbradshaw 0:e4a10ed6eb92 472 ptrCmds = ParseUntilCRLF(ptrCmds, cmd, sizeof(cmd));
jbradshaw 0:e4a10ed6eb92 473 if (*cmd != 0) {
jbradshaw 0:e4a10ed6eb92 474 RPC_call(cmd, reply);
jbradshaw 0:e4a10ed6eb92 475 }
jbradshaw 0:e4a10ed6eb92 476 }
jbradshaw 0:e4a10ed6eb92 477 }