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

Files at this revision

API Documentation at this revision

Comitter:
nikitateggi
Date:
Sat Jun 24 10:24:32 2017 +0000
Parent:
23:e3b533aef4b4
Child:
25:64f75845073f
Commit message:
poc with battery monitoring(commented),; updated pid and bufferless heart rate

Changed in this revision

bt.cpp Show annotated file Show diff for this revision Revisions of this file
ec_bp.h Show annotated file Show diff for this revision Revisions of this file
ecgg.cpp Show annotated file Show diff for this revision Revisions of this file
eeprom_pgm.cpp Show annotated file Show diff for this revision Revisions of this file
eeprom_pgm.h Show annotated file Show diff for this revision Revisions of this file
glc.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
sdcard.cpp Show annotated file Show diff for this revision Revisions of this file
touch_modules.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/bt.cpp	Fri Jun 23 07:26:55 2017 +0000
+++ b/bt.cpp	Sat Jun 24 10:24:32 2017 +0000
@@ -44,7 +44,7 @@
 uint8_t bt_send(uint8_t state_tx)
 {
   uint32_t v1[1500];    
-  mc.baud(115200);                  // baud rate of bluetooth
+  blue.baud(115200);                  // baud rate of bluetooth
   bt_file=&bt_file1;                      
   myBleMsg=&b; 
   int8_t check_sum=0;
@@ -56,8 +56,8 @@
           {
  
        case 1:   sendinit();  
-                  mc.printf("\n");
-                 sd_open_read(66029);                       // open the file for read
+                  blue.printf("\n");
+                 sd_open_read(36);                       // open the file for read
                  total_file_size=file_size() ;             // determined the file size  
               //   mc.printf("filesize=%d",total_file_size);                // TO SEND INITIAL STRING
                  state_rx =1;
@@ -69,7 +69,7 @@
                  sd_read1(bt_file1);               // read the sd card file
                  myBleMsg->bt_msg=bt_file1;         //copy the contents to the structure
                  send();                                // send the initial string
-                 mc.printf("\n");                       
+                 blue.printf("\n");                       
                  total_samples= myBleMsg->bt_msg.num_samples. num_sample_ppg_dummy+myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp;
                  
                  state_tx =0;
@@ -95,7 +95,7 @@
                       for(file_start=j;file_start<(j+1500);file_start++)
                          {     
                        
-                             mc.printf("%08x", v1[file_start]);
+                             blue.printf("%08x", v1[file_start]);
                            // counter++;
                          }
                          
@@ -121,7 +121,7 @@
                            sd_read(v1,(total_samples-(1500*k)));
                         for(file_start=j;file_start<(total_samples-(1500*k));file_start++)
                           {     
-                             mc.printf("%08x", v1[file_start]);
+                             blue.printf("%08x", v1[file_start]);
                              //counter++;
                            }
                            
@@ -132,7 +132,7 @@
                     }   
                      
                        total_file_read=file_size1();
-                        mc.printf("\n"); 
+                        blue.printf("\n"); 
                    //   mc.printf("fileread=%d",total_file_read );
                       //  mc.printf("pointer=%d\n",file_pointer_position);
                 break;        
@@ -145,7 +145,7 @@
                     
                         state_rx=6;
                         sendlast();
-                        mc.printf("\n"); 
+                        blue.printf("\n"); 
                         sd_close();
                       //  mc.printf("exit");
                      }
@@ -191,7 +191,7 @@
           case 1:                                       // wait for the ack
                       state_rx=0;
                       myBleMsg->proto=ACK;
-                    mc.scanf("%02x%02x%08x%02x",&x2,&ack_rx,&x3,&x4);
+                    blue.scanf("%02x%02x%08x%02x",&x2,&ack_rx,&x3,&x4);
                 //  mc.printf("%02x%02x",ack_rx, x2); 
                    if (ack_rx==myBleMsg->proto)
                      {
@@ -211,7 +211,7 @@
          case 2:      state_rx =0;                        //wait for the ack
                       myBleMsg->proto=ACK;
                 
-                       mc.scanf("%02x%02x%08x%02x",&x2,&ack_rx,&x3,&x4);
+                       blue.scanf("%02x%02x%08x%02x",&x2,&ack_rx,&x3,&x4);
                      if (ack_rx==myBleMsg->proto)
                         {
                 
@@ -234,7 +234,7 @@
      case 3:       
                    state_rx =0;
                    myBleMsg->proto=ACK;
-                  mc.scanf("%02x%02x%08x%02x",&x2,&ack_rx,&x3,&x4);
+                  blue.scanf("%02x%02x%08x%02x",&x2,&ack_rx,&x3,&x4);
                  if (ack_rx==myBleMsg->proto)
                       {
                      
@@ -261,7 +261,7 @@
      case 4:       
                    state_rx =0;
                    myBleMsg->proto=ACK;
-                    mc.scanf("%02x%02x%08x%02x",&x2,&ack_rx,&x3,&x4);
+                    blue.scanf("%02x%02x%08x%02x",&x2,&ack_rx,&x3,&x4);
                    if (ack_rx==myBleMsg->proto)
                       {
                        // bt_r.printf("sent");
@@ -311,28 +311,28 @@
                 myBleMsg->start_of_string=sos;
                 myBleMsg->length_file=26;
                 myBleMsg->proto=data_trfr;                      // data transfer mode
-                mc.printf("%02x",myBleMsg->start_of_string); 
-                mc.printf("%02x",myBleMsg->proto);
-                mc.printf("%08x",myBleMsg->length_file);      //changed the sequence 
-                mc.printf("%08x",myBleMsg->bt_msg.length); 
-                mc.printf("%02x",myBleMsg->bt_msg.device_id); 
-                mc.printf("%08x",myBleMsg->bt_msg.patient_id);    
-                mc.printf("%02x",myBleMsg->bt_msg.date_time.date);     
-                mc.printf("%02x",myBleMsg->bt_msg.date_time.month);  
-                mc.printf("%02x",myBleMsg->bt_msg.date_time.year);  
-                mc.printf("%02x",myBleMsg->bt_msg.date_time.hour);      
-                mc.printf("%02x",myBleMsg->bt_msg.date_time.mins);  
-                mc.printf("%02x",myBleMsg->bt_msg.date_time.sec);  
-                mc.printf("%02x",myBleMsg->bt_msg.test_type);   
-                mc.printf("%04x",myBleMsg->bt_msg.sampling_freq); 
-                mc.printf("%04x",myBleMsg->bt_msg.num_samples. num_sample_ppg_dummy); 
-                mc.printf("%04x",myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp); 
-                mc.printf("%04x",myBleMsg->bt_msg.cal_data.cal_sbp_dummy);   
-                mc.printf("%04x",myBleMsg->bt_msg.cal_data.cal_dbp_OTtyp);   
+                blue.printf("%02x",myBleMsg->start_of_string); 
+                blue.printf("%02x",myBleMsg->proto);
+                blue.printf("%08x",myBleMsg->length_file);      //changed the sequence 
+                blue.printf("%08x",myBleMsg->bt_msg.length); 
+                blue.printf("%02x",myBleMsg->bt_msg.device_id); 
+                blue.printf("%08x",myBleMsg->bt_msg.patient_id);    
+                blue.printf("%02x",myBleMsg->bt_msg.date_time.date);     
+                blue.printf("%02x",myBleMsg->bt_msg.date_time.month);  
+                blue.printf("%02x",myBleMsg->bt_msg.date_time.year);  
+                blue.printf("%02x",myBleMsg->bt_msg.date_time.hour);      
+                blue.printf("%02x",myBleMsg->bt_msg.date_time.mins);  
+                blue.printf("%02x",myBleMsg->bt_msg.date_time.sec);  
+                blue.printf("%02x",myBleMsg->bt_msg.test_type);   
+                blue.printf("%04x",myBleMsg->bt_msg.sampling_freq); 
+                blue.printf("%04x",myBleMsg->bt_msg.num_samples. num_sample_ppg_dummy); 
+                blue.printf("%04x",myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp); 
+                blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_sbp_dummy);   
+                blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_dbp_OTtyp);   
                 myBleMsg->end_of_string=eos;  
                 myBleMsg->chk_sum=checksum_struct();
-                mc.printf("%02x",myBleMsg->end_of_string);
-                mc.printf("%02x",myBleMsg->chk_sum);
+                blue.printf("%02x",myBleMsg->end_of_string);
+                blue.printf("%02x",myBleMsg->chk_sum);
     
     }
     
@@ -346,12 +346,12 @@
                //  myBleMsg->bt_msg=NULL;
                 sum_init=checksum_init();
                 myBleMsg->chk_sum=sum_init;
-                mc.printf("%02x",myBleMsg->start_of_string);
-                mc.printf("%02x",myBleMsg->proto); 
-                mc.printf("%08x",myBleMsg->length_file);     // chnged
+                blue.printf("%02x",myBleMsg->start_of_string);
+                blue.printf("%02x",myBleMsg->proto); 
+                blue.printf("%08x",myBleMsg->length_file);     // chnged
                 myBleMsg->end_of_string=eos;  
-                mc.printf("%02x",myBleMsg->end_of_string);
-                mc.printf("%02x",myBleMsg->chk_sum);
+                blue.printf("%02x",myBleMsg->end_of_string);
+                blue.printf("%02x",myBleMsg->chk_sum);
     
     }
   
@@ -385,12 +385,12 @@
                //  myBleMsg->bt_msg=NULL;
                 sum_last=checksum_last();
                 myBleMsg->chk_sum=sum_last;
-                mc.printf("%02x",myBleMsg->start_of_string);
-                mc.printf("%02x",myBleMsg->proto); 
-                mc.printf("%08x",myBleMsg->length_file);     // chnged
+                blue.printf("%02x",myBleMsg->start_of_string);
+                blue.printf("%02x",myBleMsg->proto); 
+                blue.printf("%08x",myBleMsg->length_file);     // chnged
                 myBleMsg->end_of_string=eos;  
-                mc.printf("%02x",myBleMsg->end_of_string);
-                mc.printf("%02x",myBleMsg->chk_sum);
+                blue.printf("%02x",myBleMsg->end_of_string);
+                blue.printf("%02x",myBleMsg->chk_sum);
     
     }
        
@@ -399,9 +399,9 @@
                  myBleMsg->start_of_string=sos;
                  myBleMsg->length_file=(counter*4);
                  myBleMsg->proto=data_trfr;
-                 mc.printf("%02x",myBleMsg->start_of_string); 
-                 mc.printf("%02x",myBleMsg->proto);                   // chnaged
-                 mc.printf("%08x",myBleMsg->length_file);
+                 blue.printf("%02x",myBleMsg->start_of_string); 
+                 blue.printf("%02x",myBleMsg->proto);                   // chnaged
+                 blue.printf("%08x",myBleMsg->length_file);
                
     }
     
@@ -411,8 +411,8 @@
     {          
                 myBleMsg->chk_sum=check_sum;
                 myBleMsg->end_of_string=eos;  
-                mc.printf("%02x",myBleMsg->end_of_string);
-                mc.printf("%02x",myBleMsg->chk_sum);
+                blue.printf("%02x",myBleMsg->end_of_string);
+                blue.printf("%02x",myBleMsg->chk_sum);
     }
     
 uint8_t checksum(uint32_t  *v1)
--- a/ec_bp.h	Fri Jun 23 07:26:55 2017 +0000
+++ b/ec_bp.h	Sat Jun 24 10:24:32 2017 +0000
@@ -79,7 +79,7 @@
 #define LSHIFT_16 16  ////left shift the obtained 8bit data by 16 values
 #define N_ERR 100
 #define N_TEST 500
-#define N_ECG 600
+#define N_ECG 1000
 
 
 //SPI SETTINGS
--- a/ecgg.cpp	Fri Jun 23 07:26:55 2017 +0000
+++ b/ecgg.cpp	Sat Jun 24 10:24:32 2017 +0000
@@ -97,8 +97,6 @@
     
     //----------------------------------------END Structure for Bluetooth - Added Nidhin 1/6/2017-------
 
-
-
     int32_t concatenate_value2 = 0;      // ORG. "int concatenate_value2 = 0;" Nidhin 1/6/17
     int32_t *ecg_ptr;                   // Added 1/6/2017 Nidhin
     ecg_ptr = &concatenate_value2; // Pointer to pass for ECG write into SD card Nidhin 1/6/2017
--- a/eeprom_pgm.cpp	Fri Jun 23 07:26:55 2017 +0000
+++ b/eeprom_pgm.cpp	Sat Jun 24 10:24:32 2017 +0000
@@ -15,13 +15,39 @@
  
 }
 
+void eprom_write_8(uint32_t address, int8_t data) 
+{
+    rom.write(address ,data);           // write data into the address
+ 
+}
+
+void eprom_write_16(uint32_t address, int16_t data) 
+{
+    rom.write(address ,data);           // write data into the address
+ 
+}
 
 
-
-int eprom_read(uint32_t address)       // readng the data from the specified address
+int32_t eprom_read(uint32_t address)       // readng the data from the specified address
 {
     int32_t rdata;                     // changed to int32_t
     rom.read(address, rdata);        
-    ec.printf("Read back value=%d\n", rdata);  
+   // ec.printf("Read back value=%d\n", rdata);  
+    return rdata;
+}
+
+int8_t eprom_read_8(uint32_t address)       // readng the data from the specified address
+{
+    int8_t rdata;                     // changed to int32_t
+    rom.read(address, rdata);        
+    //ec.printf("Read back value=%d\n", rdata);  
+    return rdata;
+}
+
+int16_t eprom_read_16(uint32_t address)       // readng the data from the specified address
+{
+    int16_t rdata;                     // changed to int32_t
+    rom.read(address, rdata);        
+    //ec.printf("Read back value=%d\n", rdata);  
     return rdata;
 }
\ No newline at end of file
--- a/eeprom_pgm.h	Fri Jun 23 07:26:55 2017 +0000
+++ b/eeprom_pgm.h	Sat Jun 24 10:24:32 2017 +0000
@@ -3,6 +3,9 @@
 
 
 void eprom_write(uint32_t address, int32_t data);
-int eprom_read(uint32_t address);
-
+int32_t eprom_read(uint32_t address);
+int8_t eprom_read_8(uint32_t address);
+int16_t eprom_read_16(uint32_t address);
+void eprom_write_8(uint32_t address, int8_t data);
+void eprom_write_16(uint32_t address, int16_t data); 
 #endif
--- a/glc.cpp	Fri Jun 23 07:26:55 2017 +0000
+++ b/glc.cpp	Sat Jun 24 10:24:32 2017 +0000
@@ -417,7 +417,7 @@
    {     
         gtc.printf("DATA1 is - %d\n", data1n); 
         gtc.printf("DATA2 is - %d\n", data2n);  
-        gtc.printf("mgdl is - %d\n", mgdll);   
+        gtc.printf("mgdl is - %d\n", mgdl);   
         
         glcraw[0] = (uint32_t)data1n;
         glcraw[1] = (uint32_t)data2n;
@@ -425,9 +425,9 @@
        sd_glcwrite(glcraw, pid);  //Writes the raw data into GLC file 
  
         //Results Stored to Bluetooth structure
-        glc_testtype = eprom_read(2);  // Reads the test type (before meal = 0 / after meal = 1 OR Random = 2 from location 2 of the EEPROM) Nidhin 12/6/17
+        glc_testtype = eprom_read_16(20);  // Reads the test type (before meal = 0 / after meal = 1 OR Random = 2 from location 2 of the EEPROM) Nidhin 12/6/17
         BLEMsg_info_glc.cal_data.cal_sbp_dummy = (uint16_t) glc_testtype;  // Data stored into structure
-        BLEMsg_info_glc.cal_data.cal_dbp_OTtyp = (uint16_t) mgdll;  //To be checked for reliable results           
+        BLEMsg_info_glc.cal_data.cal_dbp_OTtyp = (uint16_t) mgdl;  //To be checked for reliable results           
             
         structure_file(ptr_BLEMsg_info_glc, pid);           // Copy the structure into the GLC file 
         glcfile_mainfile(pid); 
--- a/main.cpp	Fri Jun 23 07:26:55 2017 +0000
+++ b/main.cpp	Sat Jun 24 10:24:32 2017 +0000
@@ -12,11 +12,12 @@
 #include "eeprom_pgm.h"
 #include "struct.h"
 #include "battery.h" 
+
 Serial gc(USBTX, USBRX);
 DigitalIn q1(PTB11);
 DigitalIn q(PTB8);
 DigitalIn BT(PTA5);                     //bluetooth status pin
-
+  
 uint8_t touch(uint8_t state);           // touch state
 uint8_t display(uint8_t state1);       //  display state
 int32_t pid=0;                // patient ID
@@ -324,7 +325,7 @@
                 state1=0;
                 screen_glc_2();
                  state=6;
-                 eprom_write(3,0);
+                 eprom_write_8(30,0);
               //  gc.printf("%d", state);
               nstate=state;         //////////////
                EnableTouch();
@@ -347,7 +348,7 @@
                          ecg_flag=1;
                          }   
                 state=6;
-                eprom_write(3,1);
+                eprom_write_8(30,1);
                 nstate=state;
                 screen_ecg_bp();
                 EnableTouch();
@@ -371,7 +372,7 @@
                 state1=0;
                // wait(1);
                 state=6;
-                eprom_write(3,2);
+                eprom_write_8(30,2);
                 nstate=state;
                 EnableTouch();
                  break;
--- a/sdcard.cpp	Fri Jun 23 07:26:55 2017 +0000
+++ b/sdcard.cpp	Sat Jun 24 10:24:32 2017 +0000
@@ -10,9 +10,9 @@
   #include "struct.h"
   
   Serial snd(USBTX,USBRX);
-  
+  SDFileSystem sd(PTE1, PTE3, PTE2, PTE4, "sd");
 
-  SDFileSystem sd(PTE1, PTE3, PTE2, PTE4, "sd");
+
   
   FILE *fpecg;  // PPG and ECG File pointers for BP
   FILE *fpppg;  //""          ""
--- a/touch_modules.cpp	Fri Jun 23 07:26:55 2017 +0000
+++ b/touch_modules.cpp	Sat Jun 24 10:24:32 2017 +0000
@@ -167,7 +167,7 @@
       
       unsigned char state;
       int8_t type=0;
-       type=eprom_read(3);
+       type=eprom_read_8(30);
                  
                   if ( ((xt >= 35) && (xt<=100)) && ( (yt>= 65) && (yt<= 118) ) ) // RET   //CHANGED 12/06/17// 
                       {
@@ -232,20 +232,20 @@
                        {
                           
                           state=7;
-                          eprom_write(2,0);  
+                          eprom_write_16(20,0);  
                         }
     
                  else if ( ((xt >=130) && (xt<=195)) && ( (yt>= 135) && (yt<= 185) ) ) // pp
                       {
                            state=7;
-                           eprom_write(2,1);    
+                           eprom_write_16(20,1);    
                         
                           
                        }
                  else if ( ((xt >= 35) && (xt<=100)) && ( (yt>= 65) && (yt<= 118) ) ) // random
                       {
                            state=7;
-                           eprom_write(2,2); 
+                           eprom_write_16(20,2); 
                          
                        }
                  else if ( ((xt >= 130) && (xt<=195)) && ( (yt>= 65) && (yt<= 118) ) ) // return