Test2

Dependencies:   MAX30003 max32630fthr DS1307

Revision:
18:462e396f9e5a
Parent:
17:4bf0775c1b38
--- a/main.cpp	Thu May 20 01:40:51 2021 +0000
+++ b/main.cpp	Thu May 20 15:54:10 2021 +0000
@@ -17,7 +17,7 @@
 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
 
 void task_fast(void);
-DigitalOut ledA(LED2);
+//DigitalOut ledA(LED2);
 
 void ecg_config(MAX30003 &ecgAFE);
 
@@ -25,13 +25,13 @@
 
 
 //BufferedSerial pc(P3_1,P3_0);            // Use USB debug probe for serial link static Unbuffered
-BufferedSerial pc(P0_1,P0_0);
+//BufferedSerial pc(P0_1,P0_0);
 
-//atic BufferedSerial pc(TARGET_TX_PIN, TARGET_RX_PIN, 230400); // 230400 works well
+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
 //
-//rial pc(P0_1,P0_0);
+//Serial pc(P0_1,P0_0);
 
 volatile bool timerflag = 0;
 
@@ -75,9 +75,8 @@
     const int ETAG_BITS_MASK = 0x7;
     
     timer_fast.start();
-    DigitalOut rLed(LED2, LED_ON);    
+ //   DigitalOut rLed(LED2, LED_ON);    
 //    pc.baud(9600);
-    
     //pc.set_baud(115200);                    // Baud rate = 115200
     //pc.set_format(
     //    /* bits */ 8,   
@@ -104,10 +103,10 @@
     ecgAFE.writeRegister( MAX30003::SYNCH , 0);
     
     uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
-    int16_t ecgSample[32]; int8_t x;
+    int16_t ecgSample[32],x = 0;
 //-----------------------------------------------------------------------------------------------// 
     
-    //bool timerflag = false;
+   //bool timerflag = false;
     int16_t ecgSample_1sec[200];
     //uint8_t ecg_1 = 0;
   //  uint8_t ecg_2 = 0;
@@ -143,7 +142,7 @@
     bool flip = true;
      int sampleps = 0;
      
-    char buf[20];
+    char buf[20] = {"1621525631"};
     
     
     
@@ -151,7 +150,9 @@
    // printf("In the main loop"); //printf("In the main loop");
      bool flag_first = false;
      bool timestamp_reader = false;
-      do
+     
+     /*
+     do
       {
         if (pc.readable())  // For nordic - Readiing time
         {     
@@ -174,7 +175,7 @@
                     set_time(packet_1);
                 }
              }*/
-         timestamp_reader = true;
+         /*timestamp_reader = true;
          }
          else
          {
@@ -184,10 +185,14 @@
     
         }
         
-        }while (timestamp_reader==false); // take the third timestamp
+        }while (timestamp_reader==false); // take the third timestamp */
+           
          
-         
-        
+    packet_1 = atoi(buf);  // converting ascii to integer
+    set_time(packet_1);   // check unit in packet_1 ??  
+              
+            
+                 
     while(1)        
     {
        
@@ -195,23 +200,23 @@
     {
      //t.start();
      //ledA = !ledA;   
-     
-      //pc.write((uint8_t *)header_device_id, sizeof(header_device_id));                                                      // sensor ID
-      
+     //pc.write((uint8_t *)header_device_id, sizeof(header_device_id));                                                      // sensor ID
      // pc.write((uint8_t *)header_packet_type, sizeof(header_packet_type));                                                  // packet type
       
       time_t seconds = time(NULL); // setting zero
       packet_1 = seconds;
-      //packet_1 ++;
+     //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;
       p_4 = (packet_1 >> 24) & 0xff;
+      
      // checksum_  = checksum_ + (packet_1 & 0xffff) + ((packet_1 >> 16) & 0xffff) ;
      checksum_  = checksum_ + p_1 + p_2 + p_3 + p_4 ;
      uint8_t header_packet_id[4] = {p_4,p_3,p_2,p_1};
-      //pc.write((uint8_t *)header_packet_id, sizeof(header_packet_id));                                                      //packet ID
+     //pc.write((uint8_t *)header_packet_id, sizeof(header_packet_id));                                                      //packet ID
       
           
       uint8_t Channel_Num = 0;
@@ -244,8 +249,7 @@
       
     //  pc.write((int16_t *)ecgSample_1sec,onesec_counter * sizeof(int16_t));                                                 // ECG Data
       printf("Samples per second  %d \n", (onesec_counter));
-     
-      
+           
       onesec_counter = 0;
        // memset(ecgSample_1sec, 0, sizeof(ecgSample_1sec));
               
@@ -299,8 +303,7 @@
                  {
                      sampleps = 13;
                     // printf("Flipped 13\r\n");     
-                  }                
-                
+                  }             
                 // Print results 
                 for( idx = 0; idx < readECGSamples; idx++ ) 
                 {