Channel_ID

Dependencies:   MAX30003 max32630fthr DS1307

Revision:
15:0356e9454a60
Parent:
14:1a643834b33b
Child:
16:8fc65c8fa0e8
--- a/main.cpp	Thu Oct 08 20:53:30 2020 +0000
+++ b/main.cpp	Thu Mar 11 21:22:19 2021 +0000
@@ -19,7 +19,7 @@
 
 void ecg_config(MAX30003 &ecgAFE);
 //BufferedSerial pc(P3_1,P3_0);            // Use USB debug probe for serial link static Unbuffered
-static BufferedSerial pc(TARGET_TX_PIN, TARGET_RX_PIN, 115200);
+static BufferedSerial pc(TARGET_TX_PIN, TARGET_RX_PIN, 230400); // 230400 works well
 
 //Serial uart_1(USBTX, USBRX);            // Use USB debug probe for serial link static Unbuffered
 //
@@ -58,7 +58,7 @@
     const int FIFO_FAST_SAMPLE_MASK =  0x1;
     const int ETAG_BITS_MASK = 0x7;
     timer_fast.start();
-    DigitalOut rLed(LED1, LED_OFF);
+    DigitalOut rLed(LED2, LED_ON);
 //    pc.baud(9600);
     
     //pc.set_baud(115200);                    // Baud rate = 115200
@@ -111,32 +111,53 @@
     
     uint8_t ending[5] = {'@','#','%','!','7'};
     
+    bool flip = true;
+     int sampleps = 0;
+     
     char buf[20];
-    pc.write("Welcome",8*sizeof(char));
-    printf("In the main loop");
+   // pc.write("Welcome",8*sizeof(char));
+   // printf("In the main loop"); //printf("In the main loop");
      bool flag_first = false;
-       int counter_reader = 0;
+       bool timestamp_reader = false;
       do
       {
         if (pc.readable()) 
         {     
         scanf("%s",buf);
-     printf("The entered string is %s : \n ",buf);
+     //printf("The entered string is %s : \n ",buf);
      
      packet_1 = atoi(buf);
      set_time(packet_1);
      
-    counter_reader++;
+     if ((packet_1 % 60) == 0)
+         { 
+           /*  for (int u = 0;u<3;u++)
+             {
+                 if (pc.readable()) 
+                {     
+                    scanf("%s",buf);
+                    printf("Entered the minute string  %s : \n ",buf);
+                 
+                    packet_1 = atoi(buf);
+                    set_time(packet_1);
+                }
+             }*/
+         timestamp_reader = true;
+         }
+         else
+         {
+             //printf("The timestamp is not divisible by 60 \n");
+             }
      //flag_first = true;
     
         }
         
-        }while (counter_reader<=3); // take the third timestamp
+        }while (timestamp_reader==false); // take the third timestamp
          while(1) 
     {
        
     
-    if (timer_fast.read() >= 0.99) 
+    if ((onesec_counter>=125))
     {
      //t.start();
      //ledA = !ledA;   
@@ -148,7 +169,7 @@
       time_t seconds = time(NULL);
       packet_1 = seconds;
       //packet_1 ++;
-      //printf("Time as seconds since January 1, 1970 = %d\n", packet_1);
+     // printf("Time as seconds since January 1, 1970 = %d\n", packet_1);
       p_1 = packet_1 & 0xff;
       p_2 = (packet_1 >> 8) & 0xff;
       p_3 = (packet_1 >> 16) & 0xff;
@@ -171,15 +192,18 @@
       pc.write((uint8_t *)header_ecg_checksum, sizeof(header_ecg_checksum));
       
       pc.write((int16_t *)ecgSample_1sec,onesec_counter * sizeof(int16_t));
+     // printf("Samples per second  %d \n", (onesec_counter));
       onesec_counter = 0;
        // memset(ecgSample_1sec, 0, sizeof(ecgSample_1sec));
               
         pc.write((uint8_t *)ending, sizeof(ending));
         checksum_ = 0;
-       // t.stop();
+        //t.stop();
        // auto us = t.elapsed_time().count();
-       // printf("Timer time: %llu ms \n", us);
-      timer_fast.reset();
+       // float time_taken = us/1000000;
+       // printf("Timer time: %lu ms \n", (time_taken*100));
+      // t.reset();
+    //  timer_fast.reset();
        } 
         // Read back ECG samples from the FIFO 
         else if( (ecgFIFOIntFlag==1))// && (timerflag == 0)) 
@@ -218,7 +242,19 @@
                 //memcpy(ecgSample_1sec , ecgSample, sizeof(ecgSample));
                 
                 //memcpy(ecgSample_1sec + (onesec_counter * sizeof(int16_t)), ecgSample, sizeof(ecgSample));
-                 for( idx = 0; idx < readECGSamples; idx++ ) 
+                
+                if (flip)
+                {
+                 sampleps = 12;
+                 //printf("Flipped 12\r\n");     
+                 }
+                 else
+                 {
+                     sampleps = 13;
+                    // printf("Flipped 13\r\n");     
+                  }
+                
+                 for( idx = 0; idx < sampleps; idx++ ) 
                 {
                     //pc.printf("%6d\r\n", ecgSample[idx]);     
                     ecgSample_1sec[onesec_counter] = ecgSample[idx];
@@ -228,7 +264,8 @@
                     checksum_ += cksm_1 + cksm_2;
                     onesec_counter++;      
                 } 
-                              
+                  flip =!flip; 
+                  rLed = ! rLed;           
             }
            
         }