Internal RTC Nucleo F767ZI

Dependents:   Internal_RTC

Files at this revision

API Documentation at this revision

Comitter:
shivanandgowdakr
Date:
Wed Jun 06 06:54:18 2018 +0000
Child:
1:12b099f1e8da
Commit message:
Internal RTC Nucleo F767ZI

Changed in this revision

RTC.cpp Show annotated file Show diff for this revision Revisions of this file
RTC.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC.cpp	Wed Jun 06 06:54:18 2018 +0000
@@ -0,0 +1,129 @@
+#include "mbed.h"
+#include "RTC.h"
+#include <string>
+
+
+
+int Date_Time_Setting(struct tm curt,char *str)
+{
+    int len=0;
+    len= strlen(str);
+    printf("len = %d",len);
+    if(len < 14)
+        return 0;
+
+    curt.tm_mday = ( str[0]-0x30)*10+(str[1]-0x30);
+    curt.tm_mon  = ( str[2]-0x30)*10+(str[3]-0x30) -1;
+    curt.tm_year = (( str[4]-0x30)*1000 + (str[5]-0x30)*100 + (str[6]-0x30)*10 + (str[7]-0x30)) -1900 ;
+
+    curt.tm_hour=(str[8]-0x30)*10+(str[9]-0x30);
+    curt.tm_min=(str[10]-0x30)*10+(str[11]-0x30);
+    curt.tm_sec=(str[12]-0x30)*10+(str[13]-0x30);
+
+    time_t epoch = mktime(&curt);
+    if (epoch == (time_t) -1) {
+        error("Error in clock setting\n");
+        // Stop here
+    }
+    set_time(epoch);
+    return 1;
+}
+
+
+int iSetTerminalTime(char *tstring)
+{
+    int ret=0;
+    struct tm curt;
+
+    ret = Date_Time_Setting(curt,tstring);
+
+    if(ret == 1) {
+         wait(1);
+         
+       // printf("     DATE-TIME    SET SUCCESS   ");
+       printf("Date Time Set succesfully\r\n");
+
+    } else {
+      
+        printf("Date Time Set Failure \r\n");
+
+    }
+    wait(2);
+ //  Clear_LCD();
+
+    return ret;
+}
+
+
+int chk_time (char *str)
+{
+    int HH,MM,SS;
+    HH=(str[0]-0x30)*10+(str[1]-0x30);
+    MM=(str[2]-0x30)*10+(str[3]-0x30);
+    SS=(str[4]-0x30)*10+(str[5]-0x30);
+
+    if ( HH < 0 || HH > 23 || MM < 0 || MM > 59 || SS < 0 || SS > 59 )
+        return -1;
+
+    return 1;
+}
+
+int chk_date (char *str)
+{
+    int epos_date=0,epos_month=0,epos_year=0;
+
+    epos_date  = ( str[0]-0x30)*10+(str[1]-0x30);
+    epos_month = ( str[2]-0x30)*10+(str[3]-0x30);
+    epos_year  = ( str[4]-0x30)*1000+ (str[5]-0x30)*100 + (str[6]-0x30)*10 + (str[7]-0x30);
+
+
+    if ( epos_month < 1 || epos_date < 1 || epos_date > 31 || epos_month > 12  ||  epos_year < 2008 ) return ERROR ;
+
+    else if(epos_month == 1 || epos_month == 3 || epos_month == 5 || epos_month == 7 ||                                                                     epos_month == 8 || epos_month ==10 ||epos_month == 12) {
+
+        if (epos_date > 31)
+            return -1;
+    }
+
+    else  if (epos_month == 4 || epos_month == 6 || epos_month == 9 || epos_month == 11) {
+
+        if (epos_date > 30)
+            return -1;
+    }
+
+    else if  (epos_month == 2 )
+
+    {
+        if ( !(epos_year%400) || (epos_year%100 != 0 && epos_year%4==0 ) ) {
+            if (epos_date > 29 ) return -1;
+        }
+
+        else  if( epos_date > 28 ) return -1;
+    }
+
+
+    return 1;
+}
+
+void  Get_Date_Time(char *date_string,char *time_string, char *DTSTRING)
+{
+
+    time_t curr_time;
+    tm * curr_tm;
+    time(&curr_time);
+    curr_tm = localtime(&curr_time);
+    strftime(date_string,10,"%Y%m%d",curr_tm);
+}
+
+
+void  Get_Date_Time( char *DTSTRING)
+{
+
+    time_t curr_time;
+    tm * curr_tm;
+    time(&curr_time);
+    curr_tm = localtime(&curr_time);  
+    strftime(DTSTRING,20,"%Y%m%d%H%M%S",curr_tm);
+   // printf("Time is : %s",DTSTRING);
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC.h	Wed Jun 06 06:54:18 2018 +0000
@@ -0,0 +1,43 @@
+
+/**
+ ******************************************************************************
+ * @file    APSEPM207LV.h
+ * @author  Shivanand Gowda 
+ * @version V1.0.0
+ * @date    06 June 2018
+ * @brief   This file contains the class of a APSEPM207LV thermal control component
+ ******************************************************************************
+ * @attention
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#ifndef MBED_RTC_H
+#define MBED_RTC_H
+
+
+int Date_Time_Setting(struct tm curt,char *str);
+int iSetTerminalTime(char *tstring);
+int chk_time (char *str);
+int chk_date (char *str);
+void  Get_Date_Time(char *date_string,char *time_string, char *DTSTRING);
+void  Get_Date_Time( char *DTSTRING);
+
+#endif
\ No newline at end of file