Changes done in ECG and BT

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of merged_code2_20sept_2017_4th_oct_2017 by nikita teggi

Committer:
nikitateggi
Date:
Fri Jun 23 07:25:24 2017 +0000
Revision:
22:ffa88619551d
Parent:
19:1650bbc923cc
Child:
24:d992ee8369f4
Code with Battery monitoring(commented), glc modified, bt modified, pid modified

Who changed what in which revision?

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