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@36:00d96aa14658, 2017-07-29 (annotated)
- Committer:
- avp2417
- Date:
- Sat Jul 29 11:23:19 2017 +0000
- Revision:
- 36:00d96aa14658
- Parent:
- 33:a80eed071fdc
- Child:
- 44:05dbea558c9a
Added Suhasini's changes related to BP code and increase Bluetooth buffer from 150 samples to 600 Samples into 27th July 2017 code
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 |
avp2417 | 36:00d96aa14658 | 12 | #define no_of_samples 600 //changed the buffer size from 150- 22/7/17- suhasini |
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 | 28:65f2d80b7eb7 | 22 | static 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 | 28:65f2d80b7eb7 | 26 | static uint32_t total_file_size=0; // to determine the size of the file |
nikitateggi | 28:65f2d80b7eb7 | 27 | static uint32_t total_file_read=0; |
nikitateggi | 28:65f2d80b7eb7 | 28 | static uint32_t file_start=0; // variable for 'for loop' |
nikitateggi | 28:65f2d80b7eb7 | 29 | static uint32_t j=0; |
nikitateggi | 27:907f8ce0025e | 30 | uint8_t count_send=0; |
nikitateggi | 28:65f2d80b7eb7 | 31 | static uint32_t file_pointer_position=0; |
nikitateggi | 28:65f2d80b7eb7 | 32 | static int32_t bt_file_tosend=0; // file to send on bluetooth |
nikitateggi | 28:65f2d80b7eb7 | 33 | static int32_t current_file=0; // file of the test done for the current pid |
nikitateggi | 28:65f2d80b7eb7 | 34 | static uint32_t counter=0; |
nikitateggi | 27:907f8ce0025e | 35 | uint8_t file=0; |
nikitateggi | 32:76892fdf5e4c | 36 | static uint32_t v1[no_of_samples]; |
nikitateggi | 19:1650bbc923cc | 37 | |
nikitateggi | 19:1650bbc923cc | 38 | uint8_t bt_send(uint8_t state_tx) |
nikitateggi | 19:1650bbc923cc | 39 | { |
nikitateggi | 32:76892fdf5e4c | 40 | |
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 | 31:0f67acfc6236 | 64 | // current_file=2; |
nikitateggi | 31:0f67acfc6236 | 65 | //bt_file_tosend=bt_file_tosend+1; |
nikitateggi | 31:0f67acfc6236 | 66 | //eprom_write(6,bt_file_tosend); // read the current pid |
nikitateggi | 27:907f8ce0025e | 67 | mc.printf("eeprom file=%d",bt_file_tosend); |
nikitateggi | 27:907f8ce0025e | 68 | mc.printf("currentfile=%d",current_file); |
nikitateggi | 27:907f8ce0025e | 69 | if (bt_file_tosend>current_file) // if the file sent to bluetooth and current file are same, |
nikitateggi | 27:907f8ce0025e | 70 | { // then there is no new file to send |
nikitateggi | 27:907f8ce0025e | 71 | state_rx =6; |
nikitateggi | 27:907f8ce0025e | 72 | } |
nikitateggi | 27:907f8ce0025e | 73 | else |
nikitateggi | 27:907f8ce0025e | 74 | { |
nikitateggi | 27:907f8ce0025e | 75 | file=sd_open_read(bt_file_tosend); |
nikitateggi | 27:907f8ce0025e | 76 | if(file==0) |
nikitateggi | 27:907f8ce0025e | 77 | { |
nikitateggi | 31:0f67acfc6236 | 78 | state_rx =6; |
nikitateggi | 27:907f8ce0025e | 79 | } |
nikitateggi | 27:907f8ce0025e | 80 | else |
nikitateggi | 27:907f8ce0025e | 81 | { |
nikitateggi | 27:907f8ce0025e | 82 | sendinit(); |
nikitateggi | 27:907f8ce0025e | 83 | total_file_size=file_size() ; // determined the file size |
nikitateggi | 27:907f8ce0025e | 84 | state_rx =1; |
nikitateggi | 27:907f8ce0025e | 85 | blue.printf("\n"); |
nikitateggi | 27:907f8ce0025e | 86 | } |
nikitateggi | 27:907f8ce0025e | 87 | } |
nikitateggi | 27:907f8ce0025e | 88 | |
nikitateggi | 27:907f8ce0025e | 89 | break; |
nikitateggi | 19:1650bbc923cc | 90 | |
nikitateggi | 19:1650bbc923cc | 91 | |
nikitateggi | 19:1650bbc923cc | 92 | case 2: total_samples=0; |
nikitateggi | 19:1650bbc923cc | 93 | sd_read1(bt_file1); // read the sd card file |
avp2417 | 36:00d96aa14658 | 94 | mc.printf("sd file opened to read data in it\n"); |
nikitateggi | 19:1650bbc923cc | 95 | myBleMsg->bt_msg=bt_file1; //copy the contents to the structure |
nikitateggi | 22:ffa88619551d | 96 | send(); // send the initial string |
avp2417 | 36:00d96aa14658 | 97 | |
avp2417 | 36:00d96aa14658 | 98 | blue.printf("\n"); |
avp2417 | 36:00d96aa14658 | 99 | mc.printf("sent initial string\n"); |
nikitateggi | 27:907f8ce0025e | 100 | total_samples= myBleMsg->bt_msg.num_samples.num_sample_ppg_dummy+myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp; |
nikitateggi | 22:ffa88619551d | 101 | |
nikitateggi | 19:1650bbc923cc | 102 | state_tx =0; |
nikitateggi | 19:1650bbc923cc | 103 | state_rx =2; |
nikitateggi | 27:907f8ce0025e | 104 | count_send=0; |
nikitateggi | 22:ffa88619551d | 105 | total_file_read=file_size1(); |
nikitateggi | 19:1650bbc923cc | 106 | break; |
nikitateggi | 19:1650bbc923cc | 107 | |
nikitateggi | 19:1650bbc923cc | 108 | |
nikitateggi | 27:907f8ce0025e | 109 | case 3: counter=0; |
nikitateggi | 27:907f8ce0025e | 110 | if(count_send<(total_samples/no_of_samples)) |
nikitateggi | 19:1650bbc923cc | 111 | { |
nikitateggi | 27:907f8ce0025e | 112 | sd_read(v1,no_of_samples); |
nikitateggi | 27:907f8ce0025e | 113 | counter=j+no_of_samples; //read 1500 samples |
nikitateggi | 27:907f8ce0025e | 114 | send_data_str1(); |
avp2417 | 36:00d96aa14658 | 115 | |
nikitateggi | 27:907f8ce0025e | 116 | for(file_start=j;file_start<(j+no_of_samples);file_start++) |
nikitateggi | 19:1650bbc923cc | 117 | { |
nikitateggi | 19:1650bbc923cc | 118 | |
nikitateggi | 24:d992ee8369f4 | 119 | blue.printf("%08x", v1[file_start]); |
nikitateggi | 27:907f8ce0025e | 120 | |
nikitateggi | 19:1650bbc923cc | 121 | } |
avp2417 | 36:00d96aa14658 | 122 | |
nikitateggi | 31:0f67acfc6236 | 123 | check_sum=checksum((uint8_t *)v1,counter); // calculating checksum // calculating checksum |
nikitateggi | 27:907f8ce0025e | 124 | state_tx =0; |
nikitateggi | 27:907f8ce0025e | 125 | state_rx =3; |
nikitateggi | 27:907f8ce0025e | 126 | send_data_str2(check_sum); // send the remaining part of the string |
nikitateggi | 19:1650bbc923cc | 127 | |
nikitateggi | 19:1650bbc923cc | 128 | } |
nikitateggi | 19:1650bbc923cc | 129 | |
nikitateggi | 19:1650bbc923cc | 130 | else |
nikitateggi | 19:1650bbc923cc | 131 | { |
nikitateggi | 27:907f8ce0025e | 132 | for(int l=0;l<no_of_samples;l++) |
nikitateggi | 19:1650bbc923cc | 133 | { |
nikitateggi | 19:1650bbc923cc | 134 | v1[l]=NULL; |
nikitateggi | 19:1650bbc923cc | 135 | } |
nikitateggi | 27:907f8ce0025e | 136 | counter=(total_samples-( no_of_samples*count_send)); |
nikitateggi | 27:907f8ce0025e | 137 | send_data_str1(); |
nikitateggi | 27:907f8ce0025e | 138 | sd_read(v1,(total_samples-( no_of_samples*count_send))); |
nikitateggi | 27:907f8ce0025e | 139 | for(file_start=j;file_start<(total_samples-( no_of_samples*count_send));file_start++) |
nikitateggi | 19:1650bbc923cc | 140 | { |
nikitateggi | 24:d992ee8369f4 | 141 | blue.printf("%08x", v1[file_start]); |
nikitateggi | 27:907f8ce0025e | 142 | |
nikitateggi | 19:1650bbc923cc | 143 | } |
nikitateggi | 27:907f8ce0025e | 144 | |
nikitateggi | 19:1650bbc923cc | 145 | state_tx=0; |
nikitateggi | 19:1650bbc923cc | 146 | state_rx=4; |
nikitateggi | 31:0f67acfc6236 | 147 | check_sum=checksum((uint8_t *)v1,counter); // calculating checksum |
nikitateggi | 22:ffa88619551d | 148 | send_data_str2(check_sum); |
nikitateggi | 19:1650bbc923cc | 149 | } |
nikitateggi | 19:1650bbc923cc | 150 | |
nikitateggi | 19:1650bbc923cc | 151 | total_file_read=file_size1(); |
nikitateggi | 27:907f8ce0025e | 152 | blue.printf("\n"); |
nikitateggi | 27:907f8ce0025e | 153 | break; |
nikitateggi | 19:1650bbc923cc | 154 | |
nikitateggi | 19:1650bbc923cc | 155 | |
nikitateggi | 19:1650bbc923cc | 156 | case 4: total_file_read=file_size1(); |
nikitateggi | 27:907f8ce0025e | 157 | if(total_file_read==total_file_size) // if the total file size is same as total file size |
nikitateggi | 27:907f8ce0025e | 158 | { // then there is no more data to send in that particular file |
nikitateggi | 19:1650bbc923cc | 159 | |
nikitateggi | 19:1650bbc923cc | 160 | state_rx=6; |
nikitateggi | 22:ffa88619551d | 161 | sendlast(); |
nikitateggi | 24:d992ee8369f4 | 162 | blue.printf("\n"); |
nikitateggi | 27:907f8ce0025e | 163 | // sd_close(); |
nikitateggi | 19:1650bbc923cc | 164 | } |
nikitateggi | 19:1650bbc923cc | 165 | else |
nikitateggi | 19:1650bbc923cc | 166 | { |
nikitateggi | 19:1650bbc923cc | 167 | state_rx=5; |
nikitateggi | 27:907f8ce0025e | 168 | total_file_read=file_size1(); |
nikitateggi | 19:1650bbc923cc | 169 | } |
nikitateggi | 19:1650bbc923cc | 170 | |
nikitateggi | 19:1650bbc923cc | 171 | |
nikitateggi | 27:907f8ce0025e | 172 | |
nikitateggi | 19:1650bbc923cc | 173 | |
nikitateggi | 19:1650bbc923cc | 174 | } |
nikitateggi | 27:907f8ce0025e | 175 | |
nikitateggi | 19:1650bbc923cc | 176 | return state_rx; |
nikitateggi | 19:1650bbc923cc | 177 | |
nikitateggi | 19:1650bbc923cc | 178 | } |
nikitateggi | 19:1650bbc923cc | 179 | |
nikitateggi | 19:1650bbc923cc | 180 | |
nikitateggi | 19:1650bbc923cc | 181 | |
nikitateggi | 19:1650bbc923cc | 182 | |
nikitateggi | 19:1650bbc923cc | 183 | uint8_t bt_receive (uint8_t state_rx) |
nikitateggi | 19:1650bbc923cc | 184 | { |
nikitateggi | 19:1650bbc923cc | 185 | |
nikitateggi | 27:907f8ce0025e | 186 | unsigned char state_tx =1; //state for transmitting |
nikitateggi | 19:1650bbc923cc | 187 | |
nikitateggi | 19:1650bbc923cc | 188 | Timer t; // timer |
nikitateggi | 19:1650bbc923cc | 189 | uint8_t ack_rx; // varibale to receive ack from the bluetooth |
nikitateggi | 27:907f8ce0025e | 190 | //Point b; // structure copy |
nikitateggi | 27:907f8ce0025e | 191 | //myBleMsg=&b; |
nikitateggi | 19:1650bbc923cc | 192 | t.start(); // timer start |
nikitateggi | 27:907f8ce0025e | 193 | uint8_t sos_rx=0; // sos received from app |
nikitateggi | 27:907f8ce0025e | 194 | uint8_t eos_rx=0; // eos received from app |
nikitateggi | 27:907f8ce0025e | 195 | uint8_t chksum_rx=0; // check sum received from app |
nikitateggi | 27:907f8ce0025e | 196 | |
nikitateggi | 19:1650bbc923cc | 197 | |
nikitateggi | 19:1650bbc923cc | 198 | switch(state_rx) |
nikitateggi | 19:1650bbc923cc | 199 | { |
nikitateggi | 19:1650bbc923cc | 200 | |
nikitateggi | 19:1650bbc923cc | 201 | case 1: // wait for the ack |
nikitateggi | 22:ffa88619551d | 202 | state_rx=0; |
nikitateggi | 19:1650bbc923cc | 203 | myBleMsg->proto=ACK; |
nikitateggi | 27:907f8ce0025e | 204 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 27:907f8ce0025e | 205 | |
nikitateggi | 22:ffa88619551d | 206 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 19:1650bbc923cc | 207 | { |
nikitateggi | 19:1650bbc923cc | 208 | |
nikitateggi | 19:1650bbc923cc | 209 | state_tx=2; |
nikitateggi | 19:1650bbc923cc | 210 | } |
nikitateggi | 19:1650bbc923cc | 211 | |
nikitateggi | 22:ffa88619551d | 212 | else |
nikitateggi | 19:1650bbc923cc | 213 | |
nikitateggi | 19:1650bbc923cc | 214 | { |
nikitateggi | 19:1650bbc923cc | 215 | |
nikitateggi | 19:1650bbc923cc | 216 | state_tx=1; |
nikitateggi | 19:1650bbc923cc | 217 | sd_close(); |
nikitateggi | 19:1650bbc923cc | 218 | } |
nikitateggi | 19:1650bbc923cc | 219 | break; |
nikitateggi | 19:1650bbc923cc | 220 | |
nikitateggi | 19:1650bbc923cc | 221 | case 2: state_rx =0; //wait for the ack |
nikitateggi | 19:1650bbc923cc | 222 | myBleMsg->proto=ACK; |
nikitateggi | 19:1650bbc923cc | 223 | |
nikitateggi | 27:907f8ce0025e | 224 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 19:1650bbc923cc | 225 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 19:1650bbc923cc | 226 | { |
nikitateggi | 19:1650bbc923cc | 227 | |
nikitateggi | 19:1650bbc923cc | 228 | state_tx=3; |
nikitateggi | 19:1650bbc923cc | 229 | file_pointer_position=total_file_read; |
nikitateggi | 19:1650bbc923cc | 230 | } |
nikitateggi | 19:1650bbc923cc | 231 | |
nikitateggi | 19:1650bbc923cc | 232 | else |
nikitateggi | 19:1650bbc923cc | 233 | |
nikitateggi | 19:1650bbc923cc | 234 | { |
nikitateggi | 19:1650bbc923cc | 235 | |
nikitateggi | 19:1650bbc923cc | 236 | state_tx=2; |
nikitateggi | 22:ffa88619551d | 237 | setpos1(file_pointer_position); |
nikitateggi | 27:907f8ce0025e | 238 | |
nikitateggi | 19:1650bbc923cc | 239 | } |
nikitateggi | 27:907f8ce0025e | 240 | //blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 19:1650bbc923cc | 241 | break; |
nikitateggi | 19:1650bbc923cc | 242 | |
nikitateggi | 19:1650bbc923cc | 243 | |
nikitateggi | 19:1650bbc923cc | 244 | case 3: |
nikitateggi | 19:1650bbc923cc | 245 | state_rx =0; |
nikitateggi | 19:1650bbc923cc | 246 | myBleMsg->proto=ACK; |
nikitateggi | 27:907f8ce0025e | 247 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 19:1650bbc923cc | 248 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 19:1650bbc923cc | 249 | { |
nikitateggi | 19:1650bbc923cc | 250 | |
nikitateggi | 19:1650bbc923cc | 251 | state_tx=3; |
nikitateggi | 27:907f8ce0025e | 252 | count_send=count_send+1; |
nikitateggi | 19:1650bbc923cc | 253 | file_pointer_position=total_file_read; |
nikitateggi | 19:1650bbc923cc | 254 | } |
nikitateggi | 19:1650bbc923cc | 255 | |
nikitateggi | 19:1650bbc923cc | 256 | else |
nikitateggi | 19:1650bbc923cc | 257 | |
nikitateggi | 19:1650bbc923cc | 258 | { |
nikitateggi | 19:1650bbc923cc | 259 | |
nikitateggi | 19:1650bbc923cc | 260 | state_tx=3; |
nikitateggi | 27:907f8ce0025e | 261 | file_start=file_start- no_of_samples; |
nikitateggi | 19:1650bbc923cc | 262 | setpos1(file_pointer_position); |
nikitateggi | 19:1650bbc923cc | 263 | } |
nikitateggi | 19:1650bbc923cc | 264 | |
nikitateggi | 19:1650bbc923cc | 265 | break; |
nikitateggi | 19:1650bbc923cc | 266 | |
nikitateggi | 19:1650bbc923cc | 267 | case 4: |
nikitateggi | 19:1650bbc923cc | 268 | state_rx =0; |
nikitateggi | 19:1650bbc923cc | 269 | myBleMsg->proto=ACK; |
nikitateggi | 27:907f8ce0025e | 270 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 19:1650bbc923cc | 271 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 19:1650bbc923cc | 272 | { |
nikitateggi | 19:1650bbc923cc | 273 | state_tx=4; |
nikitateggi | 27:907f8ce0025e | 274 | count_send=count_send+1; |
nikitateggi | 19:1650bbc923cc | 275 | file_pointer_position=total_file_read; |
nikitateggi | 19:1650bbc923cc | 276 | } |
nikitateggi | 19:1650bbc923cc | 277 | |
nikitateggi | 19:1650bbc923cc | 278 | else |
nikitateggi | 19:1650bbc923cc | 279 | |
nikitateggi | 19:1650bbc923cc | 280 | { |
nikitateggi | 27:907f8ce0025e | 281 | |
nikitateggi | 19:1650bbc923cc | 282 | state_tx=3; |
nikitateggi | 27:907f8ce0025e | 283 | file_start=file_start- no_of_samples; |
nikitateggi | 19:1650bbc923cc | 284 | setpos1(file_pointer_position); |
nikitateggi | 19:1650bbc923cc | 285 | } |
nikitateggi | 19:1650bbc923cc | 286 | break; |
nikitateggi | 19:1650bbc923cc | 287 | |
nikitateggi | 19:1650bbc923cc | 288 | case 5: state_tx=2; |
nikitateggi | 27:907f8ce0025e | 289 | break; |
nikitateggi | 22:ffa88619551d | 290 | |
nikitateggi | 27:907f8ce0025e | 291 | case 6: state_rx =0; |
nikitateggi | 31:0f67acfc6236 | 292 | bt_file_tosend=bt_file_tosend+1; |
nikitateggi | 31:0f67acfc6236 | 293 | eprom_write(6,bt_file_tosend); |
nikitateggi | 31:0f67acfc6236 | 294 | mc.printf("next file"); |
nikitateggi | 27:907f8ce0025e | 295 | /*myBleMsg->proto=ACK; |
nikitateggi | 27:907f8ce0025e | 296 | blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); |
nikitateggi | 27:907f8ce0025e | 297 | if (ack_rx==myBleMsg->proto) |
nikitateggi | 27:907f8ce0025e | 298 | {*/ |
nikitateggi | 31:0f67acfc6236 | 299 | if (bt_file_tosend<=current_file) |
nikitateggi | 33:a80eed071fdc | 300 | { |
nikitateggi | 33:a80eed071fdc | 301 | if (file==1) |
nikitateggi | 33:a80eed071fdc | 302 | { |
nikitateggi | 33:a80eed071fdc | 303 | sd_close(); |
nikitateggi | 33:a80eed071fdc | 304 | } |
nikitateggi | 33:a80eed071fdc | 305 | |
nikitateggi | 33:a80eed071fdc | 306 | |
nikitateggi | 27:907f8ce0025e | 307 | state_tx=1; |
nikitateggi | 27:907f8ce0025e | 308 | |
nikitateggi | 27:907f8ce0025e | 309 | mc.printf("next file"); |
nikitateggi | 27:907f8ce0025e | 310 | } |
nikitateggi | 27:907f8ce0025e | 311 | |
nikitateggi | 27:907f8ce0025e | 312 | else |
nikitateggi | 27:907f8ce0025e | 313 | { |
nikitateggi | 27:907f8ce0025e | 314 | state_tx=0; |
nikitateggi | 27:907f8ce0025e | 315 | mc.printf("out"); |
nikitateggi | 27:907f8ce0025e | 316 | } |
nikitateggi | 27:907f8ce0025e | 317 | |
nikitateggi | 27:907f8ce0025e | 318 | // } |
nikitateggi | 27:907f8ce0025e | 319 | |
nikitateggi | 27:907f8ce0025e | 320 | /* else |
nikitateggi | 27:907f8ce0025e | 321 | |
nikitateggi | 27:907f8ce0025e | 322 | { |
nikitateggi | 27:907f8ce0025e | 323 | |
nikitateggi | 27:907f8ce0025e | 324 | state_tx=4; |
nikitateggi | 27:907f8ce0025e | 325 | |
nikitateggi | 27:907f8ce0025e | 326 | } */ |
nikitateggi | 27:907f8ce0025e | 327 | |
nikitateggi | 19:1650bbc923cc | 328 | break; |
nikitateggi | 19:1650bbc923cc | 329 | |
nikitateggi | 19:1650bbc923cc | 330 | } |
nikitateggi | 27:907f8ce0025e | 331 | |
nikitateggi | 19:1650bbc923cc | 332 | return state_tx; |
nikitateggi | 19:1650bbc923cc | 333 | } |
nikitateggi | 19:1650bbc923cc | 334 | |
nikitateggi | 19:1650bbc923cc | 335 | |
nikitateggi | 19:1650bbc923cc | 336 | |
nikitateggi | 19:1650bbc923cc | 337 | |
nikitateggi | 19:1650bbc923cc | 338 | |
nikitateggi | 19:1650bbc923cc | 339 | |
nikitateggi | 19:1650bbc923cc | 340 | |
nikitateggi | 27:907f8ce0025e | 341 | void send() // function to send the structure to bluetooth |
nikitateggi | 19:1650bbc923cc | 342 | { |
nikitateggi | 22:ffa88619551d | 343 | myBleMsg->start_of_string=sos; |
nikitateggi | 22:ffa88619551d | 344 | myBleMsg->length_file=26; |
nikitateggi | 22:ffa88619551d | 345 | myBleMsg->proto=data_trfr; // data transfer mode |
nikitateggi | 24:d992ee8369f4 | 346 | blue.printf("%02x",myBleMsg->start_of_string); |
nikitateggi | 24:d992ee8369f4 | 347 | blue.printf("%02x",myBleMsg->proto); |
nikitateggi | 24:d992ee8369f4 | 348 | blue.printf("%08x",myBleMsg->length_file); //changed the sequence |
nikitateggi | 24:d992ee8369f4 | 349 | blue.printf("%08x",myBleMsg->bt_msg.length); |
nikitateggi | 24:d992ee8369f4 | 350 | blue.printf("%02x",myBleMsg->bt_msg.device_id); |
nikitateggi | 24:d992ee8369f4 | 351 | blue.printf("%08x",myBleMsg->bt_msg.patient_id); |
nikitateggi | 24:d992ee8369f4 | 352 | blue.printf("%02x",myBleMsg->bt_msg.date_time.date); |
nikitateggi | 24:d992ee8369f4 | 353 | blue.printf("%02x",myBleMsg->bt_msg.date_time.month); |
nikitateggi | 24:d992ee8369f4 | 354 | blue.printf("%02x",myBleMsg->bt_msg.date_time.year); |
nikitateggi | 24:d992ee8369f4 | 355 | blue.printf("%02x",myBleMsg->bt_msg.date_time.hour); |
nikitateggi | 24:d992ee8369f4 | 356 | blue.printf("%02x",myBleMsg->bt_msg.date_time.mins); |
nikitateggi | 24:d992ee8369f4 | 357 | blue.printf("%02x",myBleMsg->bt_msg.date_time.sec); |
nikitateggi | 24:d992ee8369f4 | 358 | blue.printf("%02x",myBleMsg->bt_msg.test_type); |
nikitateggi | 24:d992ee8369f4 | 359 | blue.printf("%04x",myBleMsg->bt_msg.sampling_freq); |
nikitateggi | 24:d992ee8369f4 | 360 | blue.printf("%04x",myBleMsg->bt_msg.num_samples. num_sample_ppg_dummy); |
nikitateggi | 24:d992ee8369f4 | 361 | blue.printf("%04x",myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp); |
nikitateggi | 24:d992ee8369f4 | 362 | blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_sbp_dummy); |
nikitateggi | 24:d992ee8369f4 | 363 | blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_dbp_OTtyp); |
nikitateggi | 22:ffa88619551d | 364 | myBleMsg->end_of_string=eos; |
nikitateggi | 31:0f67acfc6236 | 365 | myBleMsg->chk_sum = checksum_struct((uint8_t *)myBleMsg, sizeof(Point)); |
nikitateggi | 24:d992ee8369f4 | 366 | blue.printf("%02x",myBleMsg->end_of_string); |
nikitateggi | 24:d992ee8369f4 | 367 | blue.printf("%02x",myBleMsg->chk_sum); |
nikitateggi | 19:1650bbc923cc | 368 | |
nikitateggi | 19:1650bbc923cc | 369 | } |
nikitateggi | 19:1650bbc923cc | 370 | |
nikitateggi | 27:907f8ce0025e | 371 | void sendinit() // function to send the initial string at the start f communication to bluetooth |
nikitateggi | 22:ffa88619551d | 372 | { |
nikitateggi | 22:ffa88619551d | 373 | |
nikitateggi | 22:ffa88619551d | 374 | uint8_t sum_init=0 ; |
nikitateggi | 22:ffa88619551d | 375 | myBleMsg->start_of_string=sos; |
nikitateggi | 22:ffa88619551d | 376 | myBleMsg->length_file=0; |
nikitateggi | 19:1650bbc923cc | 377 | myBleMsg->proto=start_of_file; |
nikitateggi | 19:1650bbc923cc | 378 | // myBleMsg->bt_msg=NULL; |
nikitateggi | 22:ffa88619551d | 379 | sum_init=checksum_init(); |
nikitateggi | 22:ffa88619551d | 380 | myBleMsg->chk_sum=sum_init; |
nikitateggi | 24:d992ee8369f4 | 381 | blue.printf("%02x",myBleMsg->start_of_string); |
nikitateggi | 24:d992ee8369f4 | 382 | blue.printf("%02x",myBleMsg->proto); |
nikitateggi | 24:d992ee8369f4 | 383 | blue.printf("%08x",myBleMsg->length_file); // chnged |
nikitateggi | 22:ffa88619551d | 384 | myBleMsg->end_of_string=eos; |
nikitateggi | 24:d992ee8369f4 | 385 | blue.printf("%02x",myBleMsg->end_of_string); |
nikitateggi | 24:d992ee8369f4 | 386 | blue.printf("%02x",myBleMsg->chk_sum); |
nikitateggi | 19:1650bbc923cc | 387 | |
nikitateggi | 19:1650bbc923cc | 388 | } |
nikitateggi | 22:ffa88619551d | 389 | |
nikitateggi | 22:ffa88619551d | 390 | |
nikitateggi | 27:907f8ce0025e | 391 | uint8_t checksum_init() // function to calculate the checksum for the initial string |
nikitateggi | 22:ffa88619551d | 392 | { |
nikitateggi | 22:ffa88619551d | 393 | |
nikitateggi | 22:ffa88619551d | 394 | uint32_t sum=0; |
nikitateggi | 22:ffa88619551d | 395 | uint8_t chksum_init=0; |
nikitateggi | 22:ffa88619551d | 396 | sum=sos+eos+start_of_file; |
nikitateggi | 22:ffa88619551d | 397 | chksum_init=sum & 0x000000FF; |
nikitateggi | 22:ffa88619551d | 398 | return chksum_init; |
nikitateggi | 22:ffa88619551d | 399 | } |
nikitateggi | 22:ffa88619551d | 400 | |
nikitateggi | 27:907f8ce0025e | 401 | uint8_t checksum_last() // function to calculate the checksum for the last string |
nikitateggi | 22:ffa88619551d | 402 | { |
nikitateggi | 22:ffa88619551d | 403 | |
nikitateggi | 22:ffa88619551d | 404 | uint32_t sum=0; |
nikitateggi | 22:ffa88619551d | 405 | uint8_t chksum_last=0; |
nikitateggi | 22:ffa88619551d | 406 | sum=sos+eos+end_of_file; // changed //16/06 #define all the values removing structure |
nikitateggi | 22:ffa88619551d | 407 | chksum_last=sum & 0x000000FF; |
nikitateggi | 22:ffa88619551d | 408 | return chksum_last; |
nikitateggi | 22:ffa88619551d | 409 | } |
nikitateggi | 22:ffa88619551d | 410 | |
nikitateggi | 27:907f8ce0025e | 411 | void sendlast() // function to send the last string to the bluetooth // which determines the end of file |
nikitateggi | 22:ffa88619551d | 412 | { |
nikitateggi | 22:ffa88619551d | 413 | uint8_t sum_last=0; |
nikitateggi | 22:ffa88619551d | 414 | myBleMsg->start_of_string=sos; |
nikitateggi | 22:ffa88619551d | 415 | myBleMsg->length_file=0; |
nikitateggi | 22:ffa88619551d | 416 | myBleMsg->proto=end_of_file; |
nikitateggi | 22:ffa88619551d | 417 | // myBleMsg->bt_msg=NULL; |
nikitateggi | 22:ffa88619551d | 418 | sum_last=checksum_last(); |
nikitateggi | 22:ffa88619551d | 419 | myBleMsg->chk_sum=sum_last; |
nikitateggi | 24:d992ee8369f4 | 420 | blue.printf("%02x",myBleMsg->start_of_string); |
nikitateggi | 24:d992ee8369f4 | 421 | blue.printf("%02x",myBleMsg->proto); |
nikitateggi | 24:d992ee8369f4 | 422 | blue.printf("%08x",myBleMsg->length_file); // chnged |
nikitateggi | 22:ffa88619551d | 423 | myBleMsg->end_of_string=eos; |
nikitateggi | 24:d992ee8369f4 | 424 | blue.printf("%02x",myBleMsg->end_of_string); |
nikitateggi | 24:d992ee8369f4 | 425 | blue.printf("%02x",myBleMsg->chk_sum); |
nikitateggi | 22:ffa88619551d | 426 | |
nikitateggi | 22:ffa88619551d | 427 | } |
nikitateggi | 22:ffa88619551d | 428 | |
nikitateggi | 27:907f8ce0025e | 429 | void send_data_str1() // function to send a part of the structure // after this raw data is sent// |
nikitateggi | 22:ffa88619551d | 430 | { |
nikitateggi | 22:ffa88619551d | 431 | myBleMsg->start_of_string=sos; |
nikitateggi | 22:ffa88619551d | 432 | myBleMsg->length_file=(counter*4); |
nikitateggi | 22:ffa88619551d | 433 | myBleMsg->proto=data_trfr; |
nikitateggi | 24:d992ee8369f4 | 434 | blue.printf("%02x",myBleMsg->start_of_string); |
nikitateggi | 24:d992ee8369f4 | 435 | blue.printf("%02x",myBleMsg->proto); // chnaged |
nikitateggi | 24:d992ee8369f4 | 436 | blue.printf("%08x",myBleMsg->length_file); |
nikitateggi | 22:ffa88619551d | 437 | |
nikitateggi | 22:ffa88619551d | 438 | } |
nikitateggi | 19:1650bbc923cc | 439 | |
nikitateggi | 19:1650bbc923cc | 440 | |
nikitateggi | 19:1650bbc923cc | 441 | |
nikitateggi | 27:907f8ce0025e | 442 | void send_data_str2(uint8_t check_sum) // after raw data// this last part of structure is sent |
nikitateggi | 19:1650bbc923cc | 443 | { |
nikitateggi | 22:ffa88619551d | 444 | myBleMsg->chk_sum=check_sum; |
nikitateggi | 22:ffa88619551d | 445 | myBleMsg->end_of_string=eos; |
nikitateggi | 24:d992ee8369f4 | 446 | blue.printf("%02x",myBleMsg->end_of_string); |
nikitateggi | 24:d992ee8369f4 | 447 | blue.printf("%02x",myBleMsg->chk_sum); |
nikitateggi | 19:1650bbc923cc | 448 | } |
nikitateggi | 19:1650bbc923cc | 449 | |
nikitateggi | 31:0f67acfc6236 | 450 | /*uint8_t checksum(uint32_t *v1) // this function to calculate the checksum for the raw data |
nikitateggi | 22:ffa88619551d | 451 | { |
nikitateggi | 22:ffa88619551d | 452 | |
nikitateggi | 22:ffa88619551d | 453 | uint32_t sum=0; |
nikitateggi | 22:ffa88619551d | 454 | uint8_t chksum_datatrfr=0; |
nikitateggi | 22:ffa88619551d | 455 | |
nikitateggi | 27:907f8ce0025e | 456 | for (int i=0;i< no_of_samples;i++) |
nikitateggi | 22:ffa88619551d | 457 | { |
nikitateggi | 22:ffa88619551d | 458 | sum=sum+v1[i]; |
nikitateggi | 22:ffa88619551d | 459 | } |
nikitateggi | 22:ffa88619551d | 460 | |
nikitateggi | 22:ffa88619551d | 461 | sum=sos+eos+sum+counter+data_trfr; |
nikitateggi | 22:ffa88619551d | 462 | chksum_datatrfr=sum & 0x000000FF; |
nikitateggi | 22:ffa88619551d | 463 | return chksum_datatrfr; |
nikitateggi | 22:ffa88619551d | 464 | } |
nikitateggi | 19:1650bbc923cc | 465 | |
nikitateggi | 19:1650bbc923cc | 466 | |
nikitateggi | 19:1650bbc923cc | 467 | |
nikitateggi | 22:ffa88619551d | 468 | |
nikitateggi | 22:ffa88619551d | 469 | |
nikitateggi | 27:907f8ce0025e | 470 | uint8_t checksum_struct() // calculating checksum for sending the file structure |
nikitateggi | 22:ffa88619551d | 471 | { |
nikitateggi | 22:ffa88619551d | 472 | |
nikitateggi | 22:ffa88619551d | 473 | uint32_t sum=0; |
nikitateggi | 22:ffa88619551d | 474 | uint8_t chksum_struct=0; |
nikitateggi | 22:ffa88619551d | 475 | |
nikitateggi | 22:ffa88619551d | 476 | 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 | 477 | chksum_struct=sum & 0x000000FF; |
nikitateggi | 22:ffa88619551d | 478 | return chksum_struct; |
nikitateggi | 31:0f67acfc6236 | 479 | }*/ |
nikitateggi | 31:0f67acfc6236 | 480 | |
nikitateggi | 31:0f67acfc6236 | 481 | uint8_t checksum_struct(const uint8_t data[], uint16_t numBytes) // calculating checksum for |
nikitateggi | 31:0f67acfc6236 | 482 | { |
nikitateggi | 31:0f67acfc6236 | 483 | uint32_t chksum_struct = 0; |
nikitateggi | 31:0f67acfc6236 | 484 | uint16_t index = 0; |
nikitateggi | 31:0f67acfc6236 | 485 | |
nikitateggi | 31:0f67acfc6236 | 486 | for (index=0U; index < (numBytes-1); index++) |
nikitateggi | 31:0f67acfc6236 | 487 | { |
nikitateggi | 31:0f67acfc6236 | 488 | chksum_struct += data[index]; |
nikitateggi | 31:0f67acfc6236 | 489 | //blue.printf("data=%02x\n",data[index]); |
nikitateggi | 31:0f67acfc6236 | 490 | |
nikitateggi | 31:0f67acfc6236 | 491 | } |
nikitateggi | 31:0f67acfc6236 | 492 | // blue.printf("%08x\n",chksum_struct); |
nikitateggi | 31:0f67acfc6236 | 493 | return chksum_struct; |
nikitateggi | 22:ffa88619551d | 494 | } |
nikitateggi | 31:0f67acfc6236 | 495 | |
nikitateggi | 31:0f67acfc6236 | 496 | |
nikitateggi | 31:0f67acfc6236 | 497 | uint8_t checksum(const uint8_t data[], uint32_t numBytes) // this function to calculate the checksum for the raw data |
nikitateggi | 31:0f67acfc6236 | 498 | { |
nikitateggi | 31:0f67acfc6236 | 499 | |
nikitateggi | 31:0f67acfc6236 | 500 | uint32_t sum=0; |
nikitateggi | 31:0f67acfc6236 | 501 | uint8_t chksum_datatrfr=0; |
nikitateggi | 31:0f67acfc6236 | 502 | uint8_t i = 0; |
nikitateggi | 31:0f67acfc6236 | 503 | uint32_t index = 0; |
nikitateggi | 31:0f67acfc6236 | 504 | uint32_t index1 = 0; |
nikitateggi | 31:0f67acfc6236 | 505 | sum += sos; |
nikitateggi | 31:0f67acfc6236 | 506 | sum += data_trfr; |
nikitateggi | 31:0f67acfc6236 | 507 | index1=(numBytes*4); |
nikitateggi | 31:0f67acfc6236 | 508 | sum +=(index1>>(8*0))&0xFF; |
nikitateggi | 31:0f67acfc6236 | 509 | sum +=(index1>>(8*1))&0xFF; |
nikitateggi | 31:0f67acfc6236 | 510 | |
nikitateggi | 31:0f67acfc6236 | 511 | for (index=0U; index<(numBytes*4); index++) |
nikitateggi | 31:0f67acfc6236 | 512 | { |
nikitateggi | 31:0f67acfc6236 | 513 | sum += data[index]; |
nikitateggi | 31:0f67acfc6236 | 514 | |
nikitateggi | 31:0f67acfc6236 | 515 | } |
nikitateggi | 31:0f67acfc6236 | 516 | |
nikitateggi | 31:0f67acfc6236 | 517 | sum+=eos; |
nikitateggi | 31:0f67acfc6236 | 518 | |
nikitateggi | 31:0f67acfc6236 | 519 | chksum_datatrfr = sum & 0x000000FF; |
nikitateggi | 31:0f67acfc6236 | 520 | mc.printf("chksum_datatrfr=%02x\n",chksum_datatrfr); |
nikitateggi | 31:0f67acfc6236 | 521 | return chksum_datatrfr; |
avp2417 | 36:00d96aa14658 | 522 | } |