Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: USBMSD_BD max32630fthr USBDevice
Streaming.cpp
00001 /******************************************************************************* 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 ******************************************************************************* 00032 */ 00033 #include "mbed.h" 00034 #include "USBMSD_BD.h" 00035 #include "SDBlockDevice.h" 00036 #include "HeapBlockDevice.h" 00037 #include "FATFileSystem.h" 00038 00039 #include "RpcServer.h" 00040 #include "RpcFifo.h" 00041 #include "Streaming.h" 00042 #include "Peripherals.h" 00043 #include "MAX30001.h" 00044 #include "Test_MAX30001.h" 00045 #include "Peripherals.h" 00046 00047 //Another define the FAT File system and SD Card 00048 extern SDBlockDevice sd; 00049 extern FATFileSystem fs; 00050 00051 00052 bool streaming = FALSE; 00053 bool dataLogging = FALSE; 00054 00055 extern uint32_t ECG_Data[5120]; 00056 extern uint32_t BIOZ_Data[1280]; 00057 extern uint32_t PACE_Data[1280]; 00058 extern uint32_t RTOR_Data[1280]; 00059 00060 extern uint32_t ECG_Data_Size; 00061 extern uint32_t BIOZ_Data_Size; 00062 extern uint32_t PACE_Data_Size; 00063 extern uint32_t RTOR_Data_Size; 00064 00065 /** 00066 * @brief Encodes a 0x55 0xAA signature and a simple checksum to the id byte in 00067 * the 32 bit field 00068 * @param id Streaming ID 00069 */ 00070 uint32_t StreamIdChecksumCalculate(uint32_t id) { 00071 uint32_t sum; 00072 uint32_t calculated; 00073 sum = 0x55; 00074 sum += 0xAA; 00075 sum += id; 00076 sum &= 0xFF; 00077 sum = sum << 8; 00078 calculated = 0x55AA0000 + sum + id; 00079 return calculated; 00080 } 00081 00082 /** 00083 * @brief Creates a packet that will be streamed via USB or saved into flash 00084 * datalog memory 00085 * @brief the packet created will be inserted into a fifo to be streamed at a 00086 * later time 00087 * @param id Streaming ID 00088 * @param buffer Pointer to a uint32 array that contains the data to include in 00089 * the packet 00090 * @param number Number of elements in the buffer 00091 */ 00092 void StreamPacketUint32(uint32_t id, uint32_t *buffer, uint32_t number) { 00093 uint32_t checksumId; 00094 int i; 00095 if (streaming == TRUE || dataLogging == TRUE) { 00096 checksumId = StreamIdChecksumCalculate(id); 00097 StreamFifoId(checksumId); 00098 StreamFifoTimeStamp(); 00099 StreamFifoLength(number); 00100 StreamFifoUint32Array(buffer, number); 00101 } 00102 /* 00103 if (testing_max30001 == 1) { 00104 if (id == MAX30001_DATA_ECG) 00105 testing_ecg_flags[TESTING_ECG_FLAG] = 1; 00106 if (id == MAX30001_DATA_BIOZ) 00107 testing_ecg_flags[TESTING_BIOZ_FLAG] = 1; 00108 if (id == MAX30001_DATA_PACE) 00109 testing_ecg_flags[TESTING_PACE_FLAG] = 1; 00110 if (id == MAX30001_DATA_RTOR) 00111 testing_ecg_flags[TESTING_RTOR_FLAG] = 1; 00112 } 00113 */ 00114 //printf("streaming \n"); 00115 /* 00116 FILE *fp = fopen("/sd/myfile888.txt", "a"); 00117 fprintf(fp, "%s %d %s","Hello World!!!!", i, "\n"); 00118 fclose(fp); printf("id=%d num=%d\n", id, number); 00119 */ 00120 // printf("id1=%x \n", id); 00121 00122 if(id == 0x30) 00123 { 00124 for(i=0; i<number; i++) 00125 { 00126 ECG_Data[ECG_Data_Size+i] = buffer[i]>>6; 00127 00128 } 00129 ECG_Data_Size = ECG_Data_Size + number; 00130 00131 } 00132 // printf("E_S1 = %d \n", ECG_Data_Size); 00133 00134 if(id == 0x33) 00135 { 00136 for(i=0; i<number; i++) 00137 { 00138 BIOZ_Data[BIOZ_Data_Size+i] = buffer[i]*4+5; 00139 00140 } 00141 BIOZ_Data_Size = BIOZ_Data_Size + number; 00142 // printf("Get BIOZ_Data \n"); 00143 } 00144 // printf("B_S1 = %d \n", BIOZ_Data_Size); 00145 00146 /* 00147 if(id == 0x31) 00148 { 00149 FILE *fp = fopen("/sd/PACE.txt", "a"); 00150 for(i=0 ; i<number ; i++){ 00151 fprintf(fp, "%s %d %s","PACE", buffer[i], "\n"); 00152 } 00153 fclose(fp); 00154 printf("Save PACE \n"); 00155 } 00156 if(id == 0x32) 00157 { 00158 FILE *fp = fopen("/sd/RTOR.txt", "a"); 00159 for(i=0 ; i<number ; i++){ 00160 fprintf(fp, "%s %d %s","RTOR", buffer[i], "\n"); 00161 } 00162 fclose(fp); 00163 printf("Save RTOR \n"); 00164 } 00165 if(id == 0x33) 00166 { 00167 FILE *fp = fopen("/sd/BIOZ.txt", "a"); 00168 for(i=0 ; i<number ; i++){ 00169 fprintf(fp, "%s %d %s","BIOZ", buffer[i], "\n"); 00170 } 00171 fclose(fp); 00172 printf("Save BIOZ \n"); 00173 } 00174 */ 00175 } 00176 00177 /** 00178 * @brief Insert a buffer into the out going fifo 00179 * @param buffer Array of uint32 to send to the fifo 00180 * @param len Length of the array 00181 */ 00182 int StreamFifoUint32Array(uint32_t buffer[], uint32_t len) { 00183 int status; 00184 uint32_t i; 00185 for (i = 0; i < len; i++) { 00186 status = fifo_put32(GetStreamOutFifo(), buffer[i]); 00187 if (status == -1) { 00188 printf("FIFO_OF!"); 00189 fflush(stdout); 00190 while (1) 00191 ; 00192 } 00193 } 00194 return 0; 00195 } 00196 00197 /** 00198 * @brief Insert a timestamp into the out going fifo 00199 */ 00200 int StreamFifoTimeStamp(void) { 00201 int status; 00202 // uint32_t timer = timestamp_GetCurrent(); //RTC_GetVal(); 00203 uint32_t timer = (uint32_t)Peripherals::timestampTimer()->read_us(); 00204 status = fifo_put32(GetStreamOutFifo(), timer); 00205 if (status == -1) { 00206 printf("FIFO_OF!"); 00207 fflush(stdout); 00208 while (1) 00209 ; 00210 } 00211 return 0; 00212 } 00213 00214 /** 00215 * @brief Insert a packet id into the out going fifo 00216 * @param id The uint32 packet id 00217 */ 00218 int StreamFifoId(uint32_t id) { 00219 int status; 00220 status = fifo_put32(GetStreamOutFifo(), id); 00221 if (status == -1) { 00222 printf("FIFO_OF!"); 00223 fflush(stdout); 00224 while (1) 00225 ; 00226 } 00227 return 0; 00228 } 00229 00230 /** 00231 * @brief Insert a length value into the out going fifo 00232 * @param length A uint32 number representing a length 00233 */ 00234 int StreamFifoLength(uint32_t length) { 00235 int status; 00236 status = fifo_put32(GetStreamOutFifo(), length); 00237 if (status == -1) { 00238 printf("FIFO_OF!"); 00239 fflush(stdout); 00240 while (1) 00241 ; 00242 } 00243 return 0; 00244 } 00245 00246 /** 00247 * @brief Return a value that indicates if the system is streaming data 00248 * @returns Returns a one or zero value 00249 */ 00250 uint8_t IsStreaming(void) { return streaming; } 00251 00252 /** 00253 * @brief Set a flag to indicate if streaming is enabled 00254 * @param state A one or zero value 00255 */ 00256 void SetStreaming(uint8_t state) { streaming = state; } 00257 00258 /** 00259 * @brief Set a flag to indicate if datalogging is enabled 00260 * @param state A one or zero value 00261 */ 00262 void SetDataLoggingStream(uint8_t state) { dataLogging = state; } 00263
Generated on Tue Jul 12 2022 13:19:19 by
1.7.2