Working_SRTC_7232021
Dependencies: MAX30003 max32630fthr DS1307
Diff: main.cpp
- Revision:
- 19:0a602ad15284
- Parent:
- 18:101042d225ef
--- a/main.cpp Fri Jun 11 23:20:20 2021 +0000 +++ b/main.cpp Fri Jul 23 23:22:26 2021 +0000 @@ -6,7 +6,6 @@ //#include <BufferedSerial.h> #include <string> //#include <Serial.h> -#include "ds3231.h" #define TARGET_TX_PIN P3_1 #define TARGET_RX_PIN P3_0 @@ -75,34 +74,6 @@ const int FIFO_FAST_SAMPLE_MASK = 0x1; const int ETAG_BITS_MASK = 0x7; -//-------------------------------------------------------------RTC-------------------------------------------------------------// - //instantiate rtc object -Ds3231 rtc(SDA, SCL); - - uint16_t rtn_val; - - //time = 12:00:00 AM 12hr mode - ds3231_time_t time = {25,20,9,1, 0}; // seconds, min, hours, am_pm, mode - - -rtn_val = rtc.set_time(time); - - - //see datasheet for calendar format - ds3231_calendar_t calendar = {6, 11, 6, 21}; // day date month year - - - rtn_val = rtc.set_calendar(calendar); - - -//see datasheet for calendar format - - ds3231_cntl_stat_t data = {0x1C, 0x08}; - - rtn_val = rtc.set_cntl_stat_reg(data); - //------------------------------------------------------------------------------------------------------------------------------// - - timer_fast.start(); DigitalOut rLed(LED2, LED_ON); // pc.baud(9600); @@ -154,6 +125,7 @@ uint8_t cksm_1 = 0; uint8_t cksm_2 = 0; uint8_t header_device_id[3] = {0,0,210}; + //uint8_t header_device_id[3] = {0,0,1}; //for rahul uint8_t header_packet_type[2] = {0,2}; uint8_t ending[5] = {'@','#','%','!','7'}; @@ -168,17 +140,42 @@ bool timestamp_reader = false; - time_t epoch_time; - - do { - rtc.get_time(&time); - rtc.get_calendar(&calendar); - epoch_time = rtc.get_epoch(); - //printf("seconds since the Epoch: %ld\n", epoch_time); +//---------------------------------software RTC check---------------------------------------------// + do + { + if (pc.readable()) + { + scanf("%s",buf); + //printf("The entered string is %s : \n ",buf);*/ + // buf[20] = 1621297647; + packet_1 = atoi(buf); + set_time(packet_1); - packet_1 = epoch_time; - }while((epoch_time % 60)!=0); // come out at the start of minute - + 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 (timestamp_reader==false); // take the third timestamp + while(1) { @@ -192,11 +189,12 @@ pc.write((uint8_t *)header_packet_type, sizeof(header_packet_type)); // packet type - epoch_time = rtc.get_epoch(); + time_t seconds = time(NULL); + packet_1 = seconds; + //time_t seconds = time(NULL); // if remove it the timestamp will be static - packet_1 = epoch_time; // - //packet_1 ++; - // printf("Time as seconds since January 1, 1970 = %d\n", 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;