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