repo time
Dependencies: mbed MAX14720 MAX30205 USBDevice
e4a10ed6eb92/HSP/RpcServer/Streaming.cpp@20:6d2af70c92ab, 2021-04-06 (annotated)
- Committer:
- darienf
- Date:
- Tue Apr 06 06:41:40 2021 +0000
- Revision:
- 20:6d2af70c92ab
another repo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
darienf | 20:6d2af70c92ab | 1 | /******************************************************************************* |
darienf | 20:6d2af70c92ab | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
darienf | 20:6d2af70c92ab | 3 | * |
darienf | 20:6d2af70c92ab | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
darienf | 20:6d2af70c92ab | 5 | * copy of this software and associated documentation files (the "Software"), |
darienf | 20:6d2af70c92ab | 6 | * to deal in the Software without restriction, including without limitation |
darienf | 20:6d2af70c92ab | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
darienf | 20:6d2af70c92ab | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
darienf | 20:6d2af70c92ab | 9 | * Software is furnished to do so, subject to the following conditions: |
darienf | 20:6d2af70c92ab | 10 | * |
darienf | 20:6d2af70c92ab | 11 | * The above copyright notice and this permission notice shall be included |
darienf | 20:6d2af70c92ab | 12 | * in all copies or substantial portions of the Software. |
darienf | 20:6d2af70c92ab | 13 | * |
darienf | 20:6d2af70c92ab | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
darienf | 20:6d2af70c92ab | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
darienf | 20:6d2af70c92ab | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
darienf | 20:6d2af70c92ab | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
darienf | 20:6d2af70c92ab | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
darienf | 20:6d2af70c92ab | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
darienf | 20:6d2af70c92ab | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
darienf | 20:6d2af70c92ab | 21 | * |
darienf | 20:6d2af70c92ab | 22 | * Except as contained in this notice, the name of Maxim Integrated |
darienf | 20:6d2af70c92ab | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
darienf | 20:6d2af70c92ab | 24 | * Products, Inc. Branding Policy. |
darienf | 20:6d2af70c92ab | 25 | * |
darienf | 20:6d2af70c92ab | 26 | * The mere transfer of this software does not imply any licenses |
darienf | 20:6d2af70c92ab | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
darienf | 20:6d2af70c92ab | 28 | * trademarks, maskwork rights, or any other form of intellectual |
darienf | 20:6d2af70c92ab | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
darienf | 20:6d2af70c92ab | 30 | * ownership rights. |
darienf | 20:6d2af70c92ab | 31 | ******************************************************************************* |
darienf | 20:6d2af70c92ab | 32 | */ |
darienf | 20:6d2af70c92ab | 33 | #include "RpcServer.h" |
darienf | 20:6d2af70c92ab | 34 | #include "RpcFifo.h" |
darienf | 20:6d2af70c92ab | 35 | #include "Streaming.h" |
darienf | 20:6d2af70c92ab | 36 | #include "Peripherals.h" |
darienf | 20:6d2af70c92ab | 37 | #include "Test_MAX30101.h" |
darienf | 20:6d2af70c92ab | 38 | #include "Test_MAX30001.h" |
darienf | 20:6d2af70c92ab | 39 | #include "MAX30001.h" |
darienf | 20:6d2af70c92ab | 40 | #include "MAX30101.h" |
darienf | 20:6d2af70c92ab | 41 | #include "Peripherals.h" |
darienf | 20:6d2af70c92ab | 42 | |
darienf | 20:6d2af70c92ab | 43 | bool streaming = FALSE; |
darienf | 20:6d2af70c92ab | 44 | bool dataLogging = FALSE; |
darienf | 20:6d2af70c92ab | 45 | |
darienf | 20:6d2af70c92ab | 46 | /** |
darienf | 20:6d2af70c92ab | 47 | * @brief Encodes a 0x55 0xAA signature and a simple checksum to the id byte in |
darienf | 20:6d2af70c92ab | 48 | * the 32 bit field |
darienf | 20:6d2af70c92ab | 49 | * @param id Streaming ID |
darienf | 20:6d2af70c92ab | 50 | */ |
darienf | 20:6d2af70c92ab | 51 | uint32_t StreamIdChecksumCalculate(uint32_t id) { |
darienf | 20:6d2af70c92ab | 52 | uint32_t sum; |
darienf | 20:6d2af70c92ab | 53 | uint32_t calculated; |
darienf | 20:6d2af70c92ab | 54 | sum = 0x55; |
darienf | 20:6d2af70c92ab | 55 | sum += 0xAA; |
darienf | 20:6d2af70c92ab | 56 | sum += id; |
darienf | 20:6d2af70c92ab | 57 | sum &= 0xFF; |
darienf | 20:6d2af70c92ab | 58 | sum = sum << 8; |
darienf | 20:6d2af70c92ab | 59 | calculated = 0x55AA0000 + sum + id; |
darienf | 20:6d2af70c92ab | 60 | return calculated; |
darienf | 20:6d2af70c92ab | 61 | } |
darienf | 20:6d2af70c92ab | 62 | |
darienf | 20:6d2af70c92ab | 63 | /** |
darienf | 20:6d2af70c92ab | 64 | * @brief Creates a packet that will be streamed via USB or saved into flash |
darienf | 20:6d2af70c92ab | 65 | * datalog memory |
darienf | 20:6d2af70c92ab | 66 | * @brief the packet created will be inserted into a fifo to be streamed at a |
darienf | 20:6d2af70c92ab | 67 | * later time |
darienf | 20:6d2af70c92ab | 68 | * @param id Streaming ID |
darienf | 20:6d2af70c92ab | 69 | * @param buffer Pointer to a uint32 array that contains the data to include in |
darienf | 20:6d2af70c92ab | 70 | * the packet |
darienf | 20:6d2af70c92ab | 71 | * @param number Number of elements in the buffer |
darienf | 20:6d2af70c92ab | 72 | */ |
darienf | 20:6d2af70c92ab | 73 | void StreamPacketUint32(uint32_t id, uint32_t *buffer, uint32_t number) { |
darienf | 20:6d2af70c92ab | 74 | uint32_t checksumId; |
darienf | 20:6d2af70c92ab | 75 | if (streaming == TRUE || dataLogging == TRUE) { |
darienf | 20:6d2af70c92ab | 76 | checksumId = StreamIdChecksumCalculate(id); |
darienf | 20:6d2af70c92ab | 77 | StreamFifoId(checksumId); |
darienf | 20:6d2af70c92ab | 78 | StreamFifoTimeStamp(); |
darienf | 20:6d2af70c92ab | 79 | StreamFifoLength(number); |
darienf | 20:6d2af70c92ab | 80 | StreamFifoUint32Array(buffer, number); |
darienf | 20:6d2af70c92ab | 81 | } |
darienf | 20:6d2af70c92ab | 82 | if (testing_max30001 == 1) { |
darienf | 20:6d2af70c92ab | 83 | if (id == MAX30001_DATA_ECG) |
darienf | 20:6d2af70c92ab | 84 | testing_ecg_flags[TESTING_ECG_FLAG] = 1; |
darienf | 20:6d2af70c92ab | 85 | if (id == MAX30001_DATA_BIOZ) |
darienf | 20:6d2af70c92ab | 86 | testing_ecg_flags[TESTING_BIOZ_FLAG] = 1; |
darienf | 20:6d2af70c92ab | 87 | if (id == MAX30001_DATA_PACE) |
darienf | 20:6d2af70c92ab | 88 | testing_ecg_flags[TESTING_PACE_FLAG] = 1; |
darienf | 20:6d2af70c92ab | 89 | if (id == MAX30001_DATA_RTOR) |
darienf | 20:6d2af70c92ab | 90 | testing_ecg_flags[TESTING_RTOR_FLAG] = 1; |
darienf | 20:6d2af70c92ab | 91 | } |
darienf | 20:6d2af70c92ab | 92 | if (testing_max30101 == 1) { |
darienf | 20:6d2af70c92ab | 93 | if (id == (MAX30101_OXIMETER_DATA + 1)) |
darienf | 20:6d2af70c92ab | 94 | testing_max30101_flags[TESTING_HR_FLAG] = 1; |
darienf | 20:6d2af70c92ab | 95 | if (id == (MAX30101_OXIMETER_DATA + 2)) |
darienf | 20:6d2af70c92ab | 96 | testing_max30101_flags[TESTING_SPO2_FLAG] = 1; |
darienf | 20:6d2af70c92ab | 97 | if (id == (MAX30101_OXIMETER_DATA + 3)) |
darienf | 20:6d2af70c92ab | 98 | testing_max30101_flags[TESTING_MULTI_FLAG] = 1; |
darienf | 20:6d2af70c92ab | 99 | } |
darienf | 20:6d2af70c92ab | 100 | } |
darienf | 20:6d2af70c92ab | 101 | |
darienf | 20:6d2af70c92ab | 102 | /** |
darienf | 20:6d2af70c92ab | 103 | * @brief Insert a buffer into the out going fifo |
darienf | 20:6d2af70c92ab | 104 | * @param buffer Array of uint32 to send to the fifo |
darienf | 20:6d2af70c92ab | 105 | * @param len Length of the array |
darienf | 20:6d2af70c92ab | 106 | */ |
darienf | 20:6d2af70c92ab | 107 | int StreamFifoUint32Array(uint32_t buffer[], uint32_t len) { |
darienf | 20:6d2af70c92ab | 108 | int status; |
darienf | 20:6d2af70c92ab | 109 | uint32_t i; |
darienf | 20:6d2af70c92ab | 110 | for (i = 0; i < len; i++) { |
darienf | 20:6d2af70c92ab | 111 | status = fifo_put32(GetStreamOutFifo(), buffer[i]); |
darienf | 20:6d2af70c92ab | 112 | if (status == -1) { |
darienf | 20:6d2af70c92ab | 113 | printf("FIFO_OF!"); |
darienf | 20:6d2af70c92ab | 114 | fflush(stdout); |
darienf | 20:6d2af70c92ab | 115 | while (1) |
darienf | 20:6d2af70c92ab | 116 | ; |
darienf | 20:6d2af70c92ab | 117 | } |
darienf | 20:6d2af70c92ab | 118 | } |
darienf | 20:6d2af70c92ab | 119 | return 0; |
darienf | 20:6d2af70c92ab | 120 | } |
darienf | 20:6d2af70c92ab | 121 | |
darienf | 20:6d2af70c92ab | 122 | /** |
darienf | 20:6d2af70c92ab | 123 | * @brief Insert a timestamp into the out going fifo |
darienf | 20:6d2af70c92ab | 124 | */ |
darienf | 20:6d2af70c92ab | 125 | int StreamFifoTimeStamp(void) { |
darienf | 20:6d2af70c92ab | 126 | int status; |
darienf | 20:6d2af70c92ab | 127 | // uint32_t timer = timestamp_GetCurrent(); //RTC_GetVal(); |
darienf | 20:6d2af70c92ab | 128 | uint32_t timer = (uint32_t)Peripherals::timestampTimer()->read_us(); |
darienf | 20:6d2af70c92ab | 129 | status = fifo_put32(GetStreamOutFifo(), timer); |
darienf | 20:6d2af70c92ab | 130 | if (status == -1) { |
darienf | 20:6d2af70c92ab | 131 | printf("FIFO_OF!"); |
darienf | 20:6d2af70c92ab | 132 | fflush(stdout); |
darienf | 20:6d2af70c92ab | 133 | while (1) |
darienf | 20:6d2af70c92ab | 134 | ; |
darienf | 20:6d2af70c92ab | 135 | } |
darienf | 20:6d2af70c92ab | 136 | return 0; |
darienf | 20:6d2af70c92ab | 137 | } |
darienf | 20:6d2af70c92ab | 138 | |
darienf | 20:6d2af70c92ab | 139 | /** |
darienf | 20:6d2af70c92ab | 140 | * @brief Insert a packet id into the out going fifo |
darienf | 20:6d2af70c92ab | 141 | * @param id The uint32 packet id |
darienf | 20:6d2af70c92ab | 142 | */ |
darienf | 20:6d2af70c92ab | 143 | int StreamFifoId(uint32_t id) { |
darienf | 20:6d2af70c92ab | 144 | int status; |
darienf | 20:6d2af70c92ab | 145 | status = fifo_put32(GetStreamOutFifo(), id); |
darienf | 20:6d2af70c92ab | 146 | if (status == -1) { |
darienf | 20:6d2af70c92ab | 147 | printf("FIFO_OF!"); |
darienf | 20:6d2af70c92ab | 148 | fflush(stdout); |
darienf | 20:6d2af70c92ab | 149 | while (1) |
darienf | 20:6d2af70c92ab | 150 | ; |
darienf | 20:6d2af70c92ab | 151 | } |
darienf | 20:6d2af70c92ab | 152 | return 0; |
darienf | 20:6d2af70c92ab | 153 | } |
darienf | 20:6d2af70c92ab | 154 | |
darienf | 20:6d2af70c92ab | 155 | /** |
darienf | 20:6d2af70c92ab | 156 | * @brief Insert a length value into the out going fifo |
darienf | 20:6d2af70c92ab | 157 | * @param length A uint32 number representing a length |
darienf | 20:6d2af70c92ab | 158 | */ |
darienf | 20:6d2af70c92ab | 159 | int StreamFifoLength(uint32_t length) { |
darienf | 20:6d2af70c92ab | 160 | int status; |
darienf | 20:6d2af70c92ab | 161 | status = fifo_put32(GetStreamOutFifo(), length); |
darienf | 20:6d2af70c92ab | 162 | if (status == -1) { |
darienf | 20:6d2af70c92ab | 163 | printf("FIFO_OF!"); |
darienf | 20:6d2af70c92ab | 164 | fflush(stdout); |
darienf | 20:6d2af70c92ab | 165 | while (1) |
darienf | 20:6d2af70c92ab | 166 | ; |
darienf | 20:6d2af70c92ab | 167 | } |
darienf | 20:6d2af70c92ab | 168 | return 0; |
darienf | 20:6d2af70c92ab | 169 | } |
darienf | 20:6d2af70c92ab | 170 | |
darienf | 20:6d2af70c92ab | 171 | /** |
darienf | 20:6d2af70c92ab | 172 | * @brief Return a value that indicates if the system is streaming data |
darienf | 20:6d2af70c92ab | 173 | * @returns Returns a one or zero value |
darienf | 20:6d2af70c92ab | 174 | */ |
darienf | 20:6d2af70c92ab | 175 | uint8_t IsStreaming(void) { return streaming; } |
darienf | 20:6d2af70c92ab | 176 | |
darienf | 20:6d2af70c92ab | 177 | /** |
darienf | 20:6d2af70c92ab | 178 | * @brief Set a flag to indicate if streaming is enabled |
darienf | 20:6d2af70c92ab | 179 | * @param state A one or zero value |
darienf | 20:6d2af70c92ab | 180 | */ |
darienf | 20:6d2af70c92ab | 181 | void SetStreaming(uint8_t state) { streaming = state; } |
darienf | 20:6d2af70c92ab | 182 | |
darienf | 20:6d2af70c92ab | 183 | /** |
darienf | 20:6d2af70c92ab | 184 | * @brief Set a flag to indicate if datalogging is enabled |
darienf | 20:6d2af70c92ab | 185 | * @param state A one or zero value |
darienf | 20:6d2af70c92ab | 186 | */ |
darienf | 20:6d2af70c92ab | 187 | void SetDataLoggingStream(uint8_t state) { dataLogging = state; } |