Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
bt.cpp@27:907f8ce0025e, 2017-07-08 (annotated)
- Committer:
- nikitateggi
- Date:
- Sat Jul 08 04:19:45 2017 +0000
- Revision:
- 27:907f8ce0025e
- Parent:
- 24:d992ee8369f4
- Child:
- 28:65f2d80b7eb7
with file_track bluetooth
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikitateggi | 22:ffa88619551d | 1 | |
nikitateggi | 19:1650bbc923cc | 2 | #include "mbed.h" |
nikitateggi | 19:1650bbc923cc | 3 | #include "sdcard.h" |
nikitateggi | 19:1650bbc923cc | 4 | #include "struct.h" |
nikitateggi | 22:ffa88619551d | 5 | #define ACK 0x00 /// changed //16/06 #define all the values removing structure |
nikitateggi | 22:ffa88619551d | 6 | #define start_of_file 0x01 |
nikitateggi | 22:ffa88619551d | 7 | #define end_of_file 0x02 |
nikitateggi | 22:ffa88619551d | 8 | #define data_trfr 0x03 |
nikitateggi | 22:ffa88619551d | 9 | #define NACK 0xFF |
nikitateggi | 22:ffa88619551d | 10 | #define sos 0xc0 |
nikitateggi | 22:ffa88619551d | 11 | #define eos 0xc0 |
nikitateggi | 27:907f8ce0025e | 12 | #define no_of_samples 1500 |
nikitateggi | 27:907f8ce0025e | 13 | #include "eeprom_pgm.h" |
nikitateggi | 22:ffa88619551d | 14 | //#define len 6000 |
nikitateggi | 19:1650bbc923cc | 15 | |
nikitateggi | 22:ffa88619551d | 16 | BLEMsg_info *bt_file; |
nikitateggi | 22:ffa88619551d | 17 | Point *myBleMsg; |
nikitateggi | 27:907f8ce0025e | 18 | |
nikitateggi | 27:907f8ce0025e | 19 | Serial mc(USBTX,USBRX); // serial terminal |
nikitateggi | 27:907f8ce0025e | 20 | Serial blue(PTC4,PTC3); // communicating bluetooth through serial |
nikitateggi | 27:907f8ce0025e | 21 | |
nikitateggi | 19:1650bbc923cc | 22 | uint32_t total_samples=0; // variable to hold total number of samples |
nikitateggi | 19:1650bbc923cc | 23 | uint8_t ack_rx; // varibale to receive ack from the bluetooth |
nikitateggi | 19:1650bbc923cc | 24 | Point b; // structure copy |
nikitateggi | 19:1650bbc923cc | 25 | BLEMsg_info bt_file1; // structure copy |
nikitateggi | 27:907f8ce0025e | 26 | uint32_t total_file_size=0; // to determine the size of the file |
nikitateggi | 27:907f8ce0025e | 27 | uint32_t total_file_read=0; |
nikitateggi | 22:ffa88619551d | 28 | uint32_t file_start=0; // variable for 'for loop' |
nikitateggi | 19:1650bbc923cc | 29 | uint32_t j=0; |
nikitateggi | 27:907f8ce0025e | 30 | uint8_t count_send=0; |
nikitateggi | 19:1650bbc923cc | 31 | uint32_t file_pointer_position=0; |
nikitateggi | 27:907f8ce0025e | 32 | int32_t bt_file_tosend=0; // file to send on bluetooth |
nikitateggi | 27:907f8ce0025e | 33 | int32_t current_file=0; // file of the test done for the current pid |
nikitateggi | 27:907f8ce0025e | 34 | uint32_t counter=0; |
nikitateggi | 27:907f8ce0025e | 35 | uint8_t file=0; |
nikitateggi | 19:1650bbc923cc | 36 | |
nikitateggi | 19:1650bbc923cc | 37 | |
nikitateggi | 19:1650bbc923cc | 38 | uint8_t bt_send(uint8_t state_tx) |
nikitateggi | 19:1650bbc923cc | 39 | { |
nikitateggi | 27:907f8ce0025e | 40 | uint32_t v1[no_of_samples]; |
nikitateggi | 24:d992ee8369f4 | 41 | blue.baud(115200); // baud rate of bluetooth |
nikitateggi | 19:1650bbc923cc | 42 | bt_file=&bt_file1; |
nikitateggi | 19:1650bbc923cc | 43 | myBleMsg=&b; |
nikitateggi | 22:ffa88619551d | 44 | int8_t check_sum=0; |
nikitateggi | 27:907f8ce0025e | 45 | uint8_t state_rx =0; |
nikitateggi | 27:907f8ce0025e | 46 | |
nikitateggi | 27:907f8ce0025e | 47 | |
nikitateggi | 27:907f8ce0025e | 48 | |
nikitateggi | 19:1650bbc923cc | 49 | |
nikitateggi | 19:1650bbc923cc | 50 | |
nikitateggi | 19:1650bbc923cc | 51 | switch(state_tx) |
nikitateggi | 19:1650bbc923cc | 52 | { |
nikitateggi | 19:1650bbc923cc | 53 | |
nikitateggi | 27:907f8ce0025e | 54 | case 1: |
nikitateggi | 27:907f8ce0025e | 55 | //blue.printf("\n"); |
nikitateggi | 27:907f8ce0025e | 56 | state_tx =0; |
nikitateggi | 27:907f8ce0025e | 57 | counter=0; |
nikitateggi | 27:907f8ce0025e | 58 | total_file_read=0; |
nikitateggi | 27:907f8ce0025e | 59 | file_start=0; |
nikitateggi | 27:907f8ce0025e | 60 | j=0; count_send=0; total_samples=0; |
nikitateggi | 27:907f8ce0025e | 61 | file_pointer_position=0; |
nikitateggi | 27:907f8ce0025e | 62 | bt_file_tosend=eprom_read(6); // reading the file number(pid) from eeprom which has to be sent to bluetooth |
nikitateggi | 27:907f8ce0025e | 63 | current_file=eprom_read(1); |
nikitateggi | 27:907f8ce0025e | 64 | bt_file_tosend=bt_file_tosend+1; |
nikitateggi | 27:907f8ce0025e | 65 | eprom_write(6,bt_file_tosend); // read the current pid |
nikitateggi | 27:907f8ce0025e | 66 | mc.printf("eeprom file=%d",bt_file_tosend); |
nikitateggi | 27:907f8ce0025e | 67 | mc.printf("currentfile=%d",current_file); |
nikitateggi | 27:907f8ce0025e | 68 | if (bt_file_tosend>current_file) // if the file sent to bluetooth and current file are same, |
nikitateggi | 27:907f8ce0025e | 69 | { // then there is no new file to send |
nikitateggi | 27:907f8ce0025e | 70 | state_rx =6; |
nikitateggi | 27:907f8ce0025e | 71 | } |
nikitateggi | 27:907f8ce0025e | 72 | else |
nikitateggi | 27:907f8ce0025e | 73 | { |
nikitateggi | 27:907f8ce0025e | 74 | file=sd_open_read(bt_file_tosend); |
nikitateggi | 27:907f8ce0025e | 75 | if(file==0) |
nikitateggi | 27:907f8ce0025e | 76 | { |
nikitateggi | 27:907f8ce0025e | 77 | state_tx =6; |
nikitateggi | 27:907f8ce0025e | 78 | } |
nikitateggi | 27:907f8ce0025e | 79 | else |
nikitateggi | 27:907f8ce0025e | 80 | { |
nikitateggi | 27:907f8ce0025e | 81 | sendinit(); |
nikitateggi | 27:907f8ce0025e | 82 | total_file_size=file_size() ; // determined the file size |
nikitateggi | 27:907f8ce0025e | 83 | state_rx =1; |
nikitateggi | 27:907f8ce0025e | 84 | blue.printf("\n"); |
nikitateggi | 27:907f8ce0025e | 85 | } |
nikitateggi | 27:907f8ce0025e | 86 | } |
nikitateggi | 27:907f8ce0025e | 87 | |
nikitateggi | 27:907f8ce0025e | 88 | break; |
nikitateggi | 19:1650bbc923cc | 89 | |
nikitateggi | 19:1650bbc923cc | 90 | |
nikitateggi | 19:1650bbc923cc | 91 | case 2: total_samples=0; |
nikitateggi | 19:1650bbc923cc | 92 | sd_read1(bt_file1); // read the sd card file |
nikitateggi | 19:1650bbc923cc | 93 | myBleMsg->bt_msg=bt_file1; //copy the contents to the structure |
nikitateggi | 22:ffa88619551d | 94 | send(); // send the initial string |
nikitateggi | 24:d992ee8369f4 | 95 | blue.printf("\n"); |
nikitateggi | 27:907f8ce0025e | 96 | total_samples= myBleMsg->bt_msg.num_samples.num_sample_ppg_dummy+myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp; |
nikitateggi | 22:ffa88619551d | 97 | |
nikitateggi | 19:1650bbc923cc | 98 | state_tx =0; |
nikitateggi | 19:1650bbc923cc | 99 | state_rx =2; |
nikitateggi | 27:907f8ce0025e | 100 | count_send=0; |
nikitateggi | 22:ffa88619551d | 101 | total_file_read=file_size1(); |
nikitateggi | 19:1650bbc923cc | 102 | break; |
nikitateggi | 19:1650bbc923cc | 103 | |
nikitateggi | 19:1650bbc923cc | 104 | |
nikitateggi | 27:907f8ce0025e | 105 | case 3: counter=0; |
nikitateggi | 27:907f8ce0025e | 106 | if(count_send<(total_samples/no_of_samples)) |
nikitateggi | 19:1650bbc923cc | 107 | { |
nikitateggi | 27:907f8ce0025e | 108 | sd_read(v1,no_of_samples); |
nikitateggi | 27:907f8ce0025e | 109 | counter=j+no_of_samples; //read 1500 samples |
nikitateggi | 27:907f8ce0025e | 110 | send_data_str1(); |
nikitateggi | 27:907f8ce0025e | 111 | for(file_start=j;file_start<(j+no_of_samples);file_start++) |
nikitateggi | 19:1650bbc923cc | 112 | { |
nikitateggi | 19:1650bbc923cc | 113 | |
nikitateggi | 24:d992ee8369f4 | 114 | blue.printf("%08x", v1[file_start]); |
nikitateggi | 27:907f8ce0025e | 115 | |
nikitateggi | 19:1650bbc923cc | 116 | } |
nikitateggi | 22:ffa88619551d | 117 | |
nikitateggi | 22:ffa88619551d | 118 | |
nikitateggi | 22:ffa88619551d | 119 | check_sum=checksum(v1); // calculating checksum |
nikitateggi | 27:907f8ce0025e | 120 | state_tx =0; |
nikitateggi | 27:907f8ce0025e | 121 | state_rx =3; |
nikitateggi | 27:907f8ce0025e | 122 | send_data_str2(check_sum); // send the remaining part of the string |
nikitateggi | 19:1650bbc923cc | 123 | |
nikitateggi | 19:1650bbc923cc | 124 | } |
nikitateggi | 19:1650bbc923cc | 125 | |
nikitateggi | 19:1650bbc923cc | 126 | else |
nikitateggi | 19:1650bbc923cc | 127 | { |
nikitateggi | 27:907f8ce0025e | 128 | for(int l=0;l<no_of_samples;l++) |
nikitateggi | 19:1650bbc923cc | 129 | { |
nikitateggi | 19:1650bbc923cc | 130 | v1[l]=NULL; |
nikitateggi | 19:1650bbc923cc | 131 | } |
nikitateggi | 27:907f8ce0025e | 132 | counter=(total_samples-( no_of_samples*count_send)); |
nikitateggi | 27:907f8ce0025e | 133 | send_data_str1(); |
nikitateggi | 27:907f8ce0025e | 134 | sd_read(v1,(total_samples-( no_of_samples*count_send))); |
nikitateggi | 27:907f8ce0025e | 135 | for(file_start=j;file_start<(total_samples-( no_of_samples*count_send));file_start++) |
nikitateggi | 19:1650bbc923cc | 136 | { |
nikitateggi | 24:d992ee8369f4 | 137 | blue.printf("%08x", v1[file_start]); |
nikitateggi | 27:907f8ce0025e | 138 | |
nikitateggi | 19:1650bbc923cc | 139 | } |
nikitateggi | 27:907f8ce0025e | 140 | |
nikitateggi | 19:1650bbc923cc | 141 | state_tx=0; |
nikitateggi | 19:1650bbc923cc | 142 | state_rx=4; |
nikitateggi | 22:ffa88619551d | 143 | send_data_str2(check_sum); |
nikitateggi | 19:1650bbc923cc | 144 | } |
nikitateggi | 19:1650bbc923cc | 145 | |
nikitateggi | 19:1650bbc923cc | 146 | total_file_read=file_size1(); |
nikitateggi | 27:907f8ce0025e | 147 | blue.printf("\n"); |
nikitateggi | 27:907f8ce0025e | 148 | break; |
nikitateggi | 19:1650bbc923cc | 149 | |
nikitateggi | 19:1650bbc923cc | 150 | |
nikitateggi | 19:1650bbc923cc | 151 | case 4: total_file_read=file_size1(); |
nikitateggi | 27:907f8ce0025e | 152 | if(total_file_read==total_file_size) // if the total file size is same as total file size |
nikitateggi | 27:907f8ce0025e | 153 | { // then there is no more data to send in that particular file |
nikitateggi | 19:1650bbc923cc | 154 | |
nikitateggi | 19:1650bbc923cc | 155 | state_rx=6; |
nikitateggi | 22:ffa88619551d | 156 | sendlast(); |
nikitateggi | 24:d992ee8369f4 | 157 | blue.printf("\n"); |
nikitateggi | 27:907f8ce0025e | 158 | // sd_close(); |
nikitateggi | 19:1650bbc923cc | 159 | } |
nikitateggi | 19:1650bbc923cc | 160 | else |
nikitateggi | 19:1650bbc923cc | 161 | { |
nikitateggi | 19:1650bbc923cc | 162 | state_rx=5; |
nikitateggi | 27:907f8ce0025e | 163 | total_file_read=file_size1(); |
nikitateggi | 19:1650bbc923cc | 164 | } |
nikitateggi | 19:1650bbc923cc | 165 | |
nikitateggi | 19:1650bbc923cc | 166 | |
nikitateggi | 27:907f8ce0025e | 167 | |
nikitateggi | 19:1650bbc923cc | 168 | |
nikitateggi | 19:1650bbc923cc | 169 | } |
nikitateggi | 27:907f8ce0025e | 170 | |
nikitateggi | 19:1650bbc923cc | 171 | return state_rx; |
nikitateggi | 19:1650bbc923cc | 172 | |
nikitateggi | 19:1650bbc923cc | 173 | } |
nikitateggi | 19:1650bbc923cc | 174 | |
nikitateggi | 19:1650bbc923cc | 175 | |
nikitateggi | 19:1650bbc923cc | 176 | |
nikitateggi | 19:1650bbc923cc | 177 | |
nikitateggi | 19:1650bbc923cc | 178 | uint8_t bt_receive (uint8_t state_rx) |
nikitateggi | 19:1650bbc923cc | 179 | { |
nikitateggi | 19:1650bbc923cc | 180 | |
nikitateggi | 27:907f8ce0025e | 181 | unsigned char state_tx =1; //state for transmitting |
nikitateggi | 19:1650bbc923cc | 182 | |
nikitateggi | 19:1650bbc923cc | 183 | Timer t; // timer |
nikitateggi | 19:1650bbc923cc | 184 | uint8_t ack_rx; // varibale to receive ack from the bluetooth |
nikitateggi | 27:907f8ce0025e | 185 | //Point b; // structure copy |
nikitateggi | 27:907f8ce0025e | 186 | //myBleMsg=&b; |
nikitateggi | 19:1650bbc923cc | 187 | t.start(); // timer start |
nikitateggi | 27:907f8ce0025e | 188 | uint8_t sos_rx=0; // sos received from app |
nikitateggi | 27:907f8ce0025e | 189 | uint8_t eos_rx=0; // eos received from app |
nikitateggi | 27:907f8ce0025e | 190 | uint8_t chksum_rx=0; // check sum received from app |
nikitateggi | 27:907f8ce0025e | 191 | |
nikitateggi | 19:1650bbc923cc | 192 | |
nikitateggi | 19:1650bbc923cc | 193 | switch(state_rx) |
nikitateggi | 19:1650bbc923cc | 194 | { |
nikitateggi | 19:1650bbc923cc | 195 | |
nikitateggi | 19:1650bbc923cc | 196 | case 1: // wait for the ack |
nikitateggi | 22:ffa88619551d | 197 | state_rx=0; |
nikitateggi | 19:1650bbc923cc | 198 | myBleMsg->proto=ACK; |
nikitateggi | 27:907f8ce0025e | 199 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 27:907f8ce0025e | 200 | |
nikitateggi | 22:ffa88619551d | 201 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 19:1650bbc923cc | 202 | { |
nikitateggi | 19:1650bbc923cc | 203 | |
nikitateggi | 19:1650bbc923cc | 204 | state_tx=2; |
nikitateggi | 19:1650bbc923cc | 205 | } |
nikitateggi | 19:1650bbc923cc | 206 | |
nikitateggi | 22:ffa88619551d | 207 | else |
nikitateggi | 19:1650bbc923cc | 208 | |
nikitateggi | 19:1650bbc923cc | 209 | { |
nikitateggi | 19:1650bbc923cc | 210 | |
nikitateggi | 19:1650bbc923cc | 211 | state_tx=1; |
nikitateggi | 19:1650bbc923cc | 212 | sd_close(); |
nikitateggi | 19:1650bbc923cc | 213 | } |
nikitateggi | 19:1650bbc923cc | 214 | break; |
nikitateggi | 19:1650bbc923cc | 215 | |
nikitateggi | 19:1650bbc923cc | 216 | case 2: state_rx =0; //wait for the ack |
nikitateggi | 19:1650bbc923cc | 217 | myBleMsg->proto=ACK; |
nikitateggi | 19:1650bbc923cc | 218 | |
nikitateggi | 27:907f8ce0025e | 219 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 19:1650bbc923cc | 220 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 19:1650bbc923cc | 221 | { |
nikitateggi | 19:1650bbc923cc | 222 | |
nikitateggi | 19:1650bbc923cc | 223 | state_tx=3; |
nikitateggi | 19:1650bbc923cc | 224 | file_pointer_position=total_file_read; |
nikitateggi | 19:1650bbc923cc | 225 | } |
nikitateggi | 19:1650bbc923cc | 226 | |
nikitateggi | 19:1650bbc923cc | 227 | else |
nikitateggi | 19:1650bbc923cc | 228 | |
nikitateggi | 19:1650bbc923cc | 229 | { |
nikitateggi | 19:1650bbc923cc | 230 | |
nikitateggi | 19:1650bbc923cc | 231 | state_tx=2; |
nikitateggi | 22:ffa88619551d | 232 | setpos1(file_pointer_position); |
nikitateggi | 27:907f8ce0025e | 233 | |
nikitateggi | 19:1650bbc923cc | 234 | } |
nikitateggi | 27:907f8ce0025e | 235 | //blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 19:1650bbc923cc | 236 | break; |
nikitateggi | 19:1650bbc923cc | 237 | |
nikitateggi | 19:1650bbc923cc | 238 | |
nikitateggi | 19:1650bbc923cc | 239 | case 3: |
nikitateggi | 19:1650bbc923cc | 240 | state_rx =0; |
nikitateggi | 19:1650bbc923cc | 241 | myBleMsg->proto=ACK; |
nikitateggi | 27:907f8ce0025e | 242 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 19:1650bbc923cc | 243 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 19:1650bbc923cc | 244 | { |
nikitateggi | 19:1650bbc923cc | 245 | |
nikitateggi | 19:1650bbc923cc | 246 | state_tx=3; |
nikitateggi | 27:907f8ce0025e | 247 | count_send=count_send+1; |
nikitateggi | 19:1650bbc923cc | 248 | file_pointer_position=total_file_read; |
nikitateggi | 19:1650bbc923cc | 249 | } |
nikitateggi | 19:1650bbc923cc | 250 | |
nikitateggi | 19:1650bbc923cc | 251 | else |
nikitateggi | 19:1650bbc923cc | 252 | |
nikitateggi | 19:1650bbc923cc | 253 | { |
nikitateggi | 19:1650bbc923cc | 254 | |
nikitateggi | 19:1650bbc923cc | 255 | state_tx=3; |
nikitateggi | 27:907f8ce0025e | 256 | file_start=file_start- no_of_samples; |
nikitateggi | 19:1650bbc923cc | 257 | setpos1(file_pointer_position); |
nikitateggi | 19:1650bbc923cc | 258 | } |
nikitateggi | 19:1650bbc923cc | 259 | |
nikitateggi | 19:1650bbc923cc | 260 | break; |
nikitateggi | 19:1650bbc923cc | 261 | |
nikitateggi | 19:1650bbc923cc | 262 | case 4: |
nikitateggi | 19:1650bbc923cc | 263 | state_rx =0; |
nikitateggi | 19:1650bbc923cc | 264 | myBleMsg->proto=ACK; |
nikitateggi | 27:907f8ce0025e | 265 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 19:1650bbc923cc | 266 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 19:1650bbc923cc | 267 | { |
nikitateggi | 19:1650bbc923cc | 268 | state_tx=4; |
nikitateggi | 27:907f8ce0025e | 269 | count_send=count_send+1; |
nikitateggi | 19:1650bbc923cc | 270 | file_pointer_position=total_file_read; |
nikitateggi | 19:1650bbc923cc | 271 | } |
nikitateggi | 19:1650bbc923cc | 272 | |
nikitateggi | 19:1650bbc923cc | 273 | else |
nikitateggi | 19:1650bbc923cc | 274 | |
nikitateggi | 19:1650bbc923cc | 275 | { |
nikitateggi | 27:907f8ce0025e | 276 | |
nikitateggi | 19:1650bbc923cc | 277 | state_tx=3; |
nikitateggi | 27:907f8ce0025e | 278 | file_start=file_start- no_of_samples; |
nikitateggi | 19:1650bbc923cc | 279 | setpos1(file_pointer_position); |
nikitateggi | 19:1650bbc923cc | 280 | } |
nikitateggi | 19:1650bbc923cc | 281 | break; |
nikitateggi | 19:1650bbc923cc | 282 | |
nikitateggi | 19:1650bbc923cc | 283 | case 5: state_tx=2; |
nikitateggi | 27:907f8ce0025e | 284 | break; |
nikitateggi | 22:ffa88619551d | 285 | |
nikitateggi | 27:907f8ce0025e | 286 | case 6: state_rx =0; |
nikitateggi | 27:907f8ce0025e | 287 | /*myBleMsg->proto=ACK; |
nikitateggi | 27:907f8ce0025e | 288 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 27:907f8ce0025e | 289 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 27:907f8ce0025e | 290 | {*/ |
nikitateggi | 27:907f8ce0025e | 291 | if (bt_file_tosend!=current_file) |
nikitateggi | 27:907f8ce0025e | 292 | { sd_close(); |
nikitateggi | 27:907f8ce0025e | 293 | // bt_file_tosend=bt_file_tosend+1; |
nikitateggi | 27:907f8ce0025e | 294 | // eprom_write(6,bt_file_tosend); |
nikitateggi | 27:907f8ce0025e | 295 | // sd_open_read(bt_file_tosend); |
nikitateggi | 27:907f8ce0025e | 296 | // total_file_size=file_size() ; |
nikitateggi | 27:907f8ce0025e | 297 | state_tx=1; |
nikitateggi | 27:907f8ce0025e | 298 | |
nikitateggi | 27:907f8ce0025e | 299 | mc.printf("next file"); |
nikitateggi | 27:907f8ce0025e | 300 | } |
nikitateggi | 27:907f8ce0025e | 301 | |
nikitateggi | 27:907f8ce0025e | 302 | else |
nikitateggi | 27:907f8ce0025e | 303 | { |
nikitateggi | 27:907f8ce0025e | 304 | state_tx=0; |
nikitateggi | 27:907f8ce0025e | 305 | mc.printf("out"); |
nikitateggi | 27:907f8ce0025e | 306 | } |
nikitateggi | 27:907f8ce0025e | 307 | |
nikitateggi | 27:907f8ce0025e | 308 | // } |
nikitateggi | 27:907f8ce0025e | 309 | |
nikitateggi | 27:907f8ce0025e | 310 | /* else |
nikitateggi | 27:907f8ce0025e | 311 | |
nikitateggi | 27:907f8ce0025e | 312 | { |
nikitateggi | 27:907f8ce0025e | 313 | |
nikitateggi | 27:907f8ce0025e | 314 | state_tx=4; |
nikitateggi | 27:907f8ce0025e | 315 | |
nikitateggi | 27:907f8ce0025e | 316 | } */ |
nikitateggi | 27:907f8ce0025e | 317 | |
nikitateggi | 19:1650bbc923cc | 318 | break; |
nikitateggi | 19:1650bbc923cc | 319 | |
nikitateggi | 19:1650bbc923cc | 320 | } |
nikitateggi | 27:907f8ce0025e | 321 | |
nikitateggi | 19:1650bbc923cc | 322 | return state_tx; |
nikitateggi | 19:1650bbc923cc | 323 | } |
nikitateggi | 19:1650bbc923cc | 324 | |
nikitateggi | 19:1650bbc923cc | 325 | |
nikitateggi | 19:1650bbc923cc | 326 | |
nikitateggi | 19:1650bbc923cc | 327 | |
nikitateggi | 19:1650bbc923cc | 328 | |
nikitateggi | 19:1650bbc923cc | 329 | |
nikitateggi | 19:1650bbc923cc | 330 | |
nikitateggi | 27:907f8ce0025e | 331 | void send() // function to send the structure to bluetooth |
nikitateggi | 19:1650bbc923cc | 332 | { |
nikitateggi | 22:ffa88619551d | 333 | myBleMsg->start_of_string=sos; |
nikitateggi | 22:ffa88619551d | 334 | myBleMsg->length_file=26; |
nikitateggi | 22:ffa88619551d | 335 | myBleMsg->proto=data_trfr; // data transfer mode |
nikitateggi | 24:d992ee8369f4 | 336 | blue.printf("%02x",myBleMsg->start_of_string); |
nikitateggi | 24:d992ee8369f4 | 337 | blue.printf("%02x",myBleMsg->proto); |
nikitateggi | 24:d992ee8369f4 | 338 | blue.printf("%08x",myBleMsg->length_file); //changed the sequence |
nikitateggi | 24:d992ee8369f4 | 339 | blue.printf("%08x",myBleMsg->bt_msg.length); |
nikitateggi | 24:d992ee8369f4 | 340 | blue.printf("%02x",myBleMsg->bt_msg.device_id); |
nikitateggi | 24:d992ee8369f4 | 341 | blue.printf("%08x",myBleMsg->bt_msg.patient_id); |
nikitateggi | 24:d992ee8369f4 | 342 | blue.printf("%02x",myBleMsg->bt_msg.date_time.date); |
nikitateggi | 24:d992ee8369f4 | 343 | blue.printf("%02x",myBleMsg->bt_msg.date_time.month); |
nikitateggi | 24:d992ee8369f4 | 344 | blue.printf("%02x",myBleMsg->bt_msg.date_time.year); |
nikitateggi | 24:d992ee8369f4 | 345 | blue.printf("%02x",myBleMsg->bt_msg.date_time.hour); |
nikitateggi | 24:d992ee8369f4 | 346 | blue.printf("%02x",myBleMsg->bt_msg.date_time.mins); |
nikitateggi | 24:d992ee8369f4 | 347 | blue.printf("%02x",myBleMsg->bt_msg.date_time.sec); |
nikitateggi | 24:d992ee8369f4 | 348 | blue.printf("%02x",myBleMsg->bt_msg.test_type); |
nikitateggi | 24:d992ee8369f4 | 349 | blue.printf("%04x",myBleMsg->bt_msg.sampling_freq); |
nikitateggi | 24:d992ee8369f4 | 350 | blue.printf("%04x",myBleMsg->bt_msg.num_samples. num_sample_ppg_dummy); |
nikitateggi | 24:d992ee8369f4 | 351 | blue.printf("%04x",myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp); |
nikitateggi | 24:d992ee8369f4 | 352 | blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_sbp_dummy); |
nikitateggi | 24:d992ee8369f4 | 353 | blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_dbp_OTtyp); |
nikitateggi | 22:ffa88619551d | 354 | myBleMsg->end_of_string=eos; |
nikitateggi | 22:ffa88619551d | 355 | myBleMsg->chk_sum=checksum_struct(); |
nikitateggi | 24:d992ee8369f4 | 356 | blue.printf("%02x",myBleMsg->end_of_string); |
nikitateggi | 24:d992ee8369f4 | 357 | blue.printf("%02x",myBleMsg->chk_sum); |
nikitateggi | 19:1650bbc923cc | 358 | |
nikitateggi | 19:1650bbc923cc | 359 | } |
nikitateggi | 19:1650bbc923cc | 360 | |
nikitateggi | 27:907f8ce0025e | 361 | void sendinit() // function to send the initial string at the start f communication to bluetooth |
nikitateggi | 22:ffa88619551d | 362 | { |
nikitateggi | 22:ffa88619551d | 363 | |
nikitateggi | 22:ffa88619551d | 364 | uint8_t sum_init=0 ; |
nikitateggi | 22:ffa88619551d | 365 | myBleMsg->start_of_string=sos; |
nikitateggi | 22:ffa88619551d | 366 | myBleMsg->length_file=0; |
nikitateggi | 19:1650bbc923cc | 367 | myBleMsg->proto=start_of_file; |
nikitateggi | 19:1650bbc923cc | 368 | // myBleMsg->bt_msg=NULL; |
nikitateggi | 22:ffa88619551d | 369 | sum_init=checksum_init(); |
nikitateggi | 22:ffa88619551d | 370 | myBleMsg->chk_sum=sum_init; |
nikitateggi | 24:d992ee8369f4 | 371 | blue.printf("%02x",myBleMsg->start_of_string); |
nikitateggi | 24:d992ee8369f4 | 372 | blue.printf("%02x",myBleMsg->proto); |
nikitateggi | 24:d992ee8369f4 | 373 | blue.printf("%08x",myBleMsg->length_file); // chnged |
nikitateggi | 22:ffa88619551d | 374 | myBleMsg->end_of_string=eos; |
nikitateggi | 24:d992ee8369f4 | 375 | blue.printf("%02x",myBleMsg->end_of_string); |
nikitateggi | 24:d992ee8369f4 | 376 | blue.printf("%02x",myBleMsg->chk_sum); |
nikitateggi | 19:1650bbc923cc | 377 | |
nikitateggi | 19:1650bbc923cc | 378 | } |
nikitateggi | 22:ffa88619551d | 379 | |
nikitateggi | 22:ffa88619551d | 380 | |
nikitateggi | 27:907f8ce0025e | 381 | uint8_t checksum_init() // function to calculate the checksum for the initial string |
nikitateggi | 22:ffa88619551d | 382 | { |
nikitateggi | 22:ffa88619551d | 383 | |
nikitateggi | 22:ffa88619551d | 384 | uint32_t sum=0; |
nikitateggi | 22:ffa88619551d | 385 | uint8_t chksum_init=0; |
nikitateggi | 22:ffa88619551d | 386 | sum=sos+eos+start_of_file; |
nikitateggi | 22:ffa88619551d | 387 | chksum_init=sum & 0x000000FF; |
nikitateggi | 22:ffa88619551d | 388 | return chksum_init; |
nikitateggi | 22:ffa88619551d | 389 | } |
nikitateggi | 22:ffa88619551d | 390 | |
nikitateggi | 27:907f8ce0025e | 391 | uint8_t checksum_last() // function to calculate the checksum for the last string |
nikitateggi | 22:ffa88619551d | 392 | { |
nikitateggi | 22:ffa88619551d | 393 | |
nikitateggi | 22:ffa88619551d | 394 | uint32_t sum=0; |
nikitateggi | 22:ffa88619551d | 395 | uint8_t chksum_last=0; |
nikitateggi | 22:ffa88619551d | 396 | sum=sos+eos+end_of_file; // changed //16/06 #define all the values removing structure |
nikitateggi | 22:ffa88619551d | 397 | chksum_last=sum & 0x000000FF; |
nikitateggi | 22:ffa88619551d | 398 | return chksum_last; |
nikitateggi | 22:ffa88619551d | 399 | } |
nikitateggi | 22:ffa88619551d | 400 | |
nikitateggi | 27:907f8ce0025e | 401 | void sendlast() // function to send the last string to the bluetooth // which determines the end of file |
nikitateggi | 22:ffa88619551d | 402 | { |
nikitateggi | 22:ffa88619551d | 403 | uint8_t sum_last=0; |
nikitateggi | 22:ffa88619551d | 404 | myBleMsg->start_of_string=sos; |
nikitateggi | 22:ffa88619551d | 405 | myBleMsg->length_file=0; |
nikitateggi | 22:ffa88619551d | 406 | myBleMsg->proto=end_of_file; |
nikitateggi | 22:ffa88619551d | 407 | // myBleMsg->bt_msg=NULL; |
nikitateggi | 22:ffa88619551d | 408 | sum_last=checksum_last(); |
nikitateggi | 22:ffa88619551d | 409 | myBleMsg->chk_sum=sum_last; |
nikitateggi | 24:d992ee8369f4 | 410 | blue.printf("%02x",myBleMsg->start_of_string); |
nikitateggi | 24:d992ee8369f4 | 411 | blue.printf("%02x",myBleMsg->proto); |
nikitateggi | 24:d992ee8369f4 | 412 | blue.printf("%08x",myBleMsg->length_file); // chnged |
nikitateggi | 22:ffa88619551d | 413 | myBleMsg->end_of_string=eos; |
nikitateggi | 24:d992ee8369f4 | 414 | blue.printf("%02x",myBleMsg->end_of_string); |
nikitateggi | 24:d992ee8369f4 | 415 | blue.printf("%02x",myBleMsg->chk_sum); |
nikitateggi | 22:ffa88619551d | 416 | |
nikitateggi | 22:ffa88619551d | 417 | } |
nikitateggi | 22:ffa88619551d | 418 | |
nikitateggi | 27:907f8ce0025e | 419 | void send_data_str1() // function to send a part of the structure // after this raw data is sent// |
nikitateggi | 22:ffa88619551d | 420 | { |
nikitateggi | 22:ffa88619551d | 421 | myBleMsg->start_of_string=sos; |
nikitateggi | 22:ffa88619551d | 422 | myBleMsg->length_file=(counter*4); |
nikitateggi | 22:ffa88619551d | 423 | myBleMsg->proto=data_trfr; |
nikitateggi | 24:d992ee8369f4 | 424 | blue.printf("%02x",myBleMsg->start_of_string); |
nikitateggi | 24:d992ee8369f4 | 425 | blue.printf("%02x",myBleMsg->proto); // chnaged |
nikitateggi | 24:d992ee8369f4 | 426 | blue.printf("%08x",myBleMsg->length_file); |
nikitateggi | 22:ffa88619551d | 427 | |
nikitateggi | 22:ffa88619551d | 428 | } |
nikitateggi | 19:1650bbc923cc | 429 | |
nikitateggi | 19:1650bbc923cc | 430 | |
nikitateggi | 19:1650bbc923cc | 431 | |
nikitateggi | 27:907f8ce0025e | 432 | void send_data_str2(uint8_t check_sum) // after raw data// this last part of structure is sent |
nikitateggi | 19:1650bbc923cc | 433 | { |
nikitateggi | 22:ffa88619551d | 434 | myBleMsg->chk_sum=check_sum; |
nikitateggi | 22:ffa88619551d | 435 | myBleMsg->end_of_string=eos; |
nikitateggi | 24:d992ee8369f4 | 436 | blue.printf("%02x",myBleMsg->end_of_string); |
nikitateggi | 24:d992ee8369f4 | 437 | blue.printf("%02x",myBleMsg->chk_sum); |
nikitateggi | 19:1650bbc923cc | 438 | } |
nikitateggi | 19:1650bbc923cc | 439 | |
nikitateggi | 27:907f8ce0025e | 440 | uint8_t checksum(uint32_t *v1) // this function to calculate the checksum for the raw data |
nikitateggi | 22:ffa88619551d | 441 | { |
nikitateggi | 22:ffa88619551d | 442 | |
nikitateggi | 22:ffa88619551d | 443 | uint32_t sum=0; |
nikitateggi | 22:ffa88619551d | 444 | uint8_t chksum_datatrfr=0; |
nikitateggi | 22:ffa88619551d | 445 | |
nikitateggi | 27:907f8ce0025e | 446 | for (int i=0;i< no_of_samples;i++) |
nikitateggi | 22:ffa88619551d | 447 | { |
nikitateggi | 22:ffa88619551d | 448 | sum=sum+v1[i]; |
nikitateggi | 22:ffa88619551d | 449 | } |
nikitateggi | 22:ffa88619551d | 450 | |
nikitateggi | 22:ffa88619551d | 451 | sum=sos+eos+sum+counter+data_trfr; |
nikitateggi | 22:ffa88619551d | 452 | chksum_datatrfr=sum & 0x000000FF; |
nikitateggi | 22:ffa88619551d | 453 | return chksum_datatrfr; |
nikitateggi | 22:ffa88619551d | 454 | } |
nikitateggi | 19:1650bbc923cc | 455 | |
nikitateggi | 19:1650bbc923cc | 456 | |
nikitateggi | 19:1650bbc923cc | 457 | |
nikitateggi | 22:ffa88619551d | 458 | |
nikitateggi | 22:ffa88619551d | 459 | |
nikitateggi | 27:907f8ce0025e | 460 | uint8_t checksum_struct() // calculating checksum for sending the file structure |
nikitateggi | 22:ffa88619551d | 461 | { |
nikitateggi | 22:ffa88619551d | 462 | |
nikitateggi | 22:ffa88619551d | 463 | uint32_t sum=0; |
nikitateggi | 22:ffa88619551d | 464 | uint8_t chksum_struct=0; |
nikitateggi | 22:ffa88619551d | 465 | |
nikitateggi | 22:ffa88619551d | 466 | sum=myBleMsg->start_of_string+myBleMsg->proto+myBleMsg->bt_msg.length+myBleMsg->bt_msg.device_id+myBleMsg->bt_msg.date_time.date+myBleMsg->bt_msg.date_time.month+myBleMsg->bt_msg.date_time.year+myBleMsg->bt_msg.date_time.hour+myBleMsg->bt_msg.date_time.mins+myBleMsg->bt_msg.date_time.sec+myBleMsg->bt_msg.test_type+myBleMsg->bt_msg.sampling_freq+myBleMsg->bt_msg.num_samples.num_sample_ppg_dummy+myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp+myBleMsg->bt_msg.cal_data.cal_sbp_dummy+myBleMsg->bt_msg.cal_data.cal_dbp_OTtyp+myBleMsg->end_of_string+myBleMsg->chk_sum; |
nikitateggi | 22:ffa88619551d | 467 | chksum_struct=sum & 0x000000FF; |
nikitateggi | 22:ffa88619551d | 468 | return chksum_struct; |
nikitateggi | 22:ffa88619551d | 469 | } |