STM32F103C8T6_Internal_RTC

Dependencies:   mbed-STM32F103C8T6 mbed

Fork of STM32F103C8T6_GPRS_TCP by Shivanand Gowda

Files at this revision

API Documentation at this revision

Comitter:
shivanandgowdakr
Date:
Fri Jul 13 08:22:41 2018 +0000
Parent:
12:91de57777095
Commit message:
STM32F103C8T6 BLUE PILL Internal RTC ;

Changed in this revision

GPRS.lib Show diff for this revision Revisions of this file
Time.cpp Show annotated file Show diff for this revision Revisions of this file
Time.h 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
--- a/GPRS.lib	Fri Jul 13 07:36:58 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/shivanandgowdakr/code/GPRS/#35feba458a38
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Time.cpp	Fri Jul 13 08:22:41 2018 +0000
@@ -0,0 +1,158 @@
+#include "mbed.h"
+#include "Time.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 succesfully\r\n");
+
+    } else {
+      
+             printf("Date Time Set Failure \r\n");
+
+    }
+    wait(2);
+  
+
+    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);
+    strftime(time_string,10,"%H%M%S",curr_tm);
+    strftime(DTSTRING,20,"%Y%m%d%H%M%S",curr_tm);
+}
+
+void  Get_Date_Time(char *date_string,char *time_string)
+{
+    time_t curr_time;
+    tm * curr_tm;
+    time(&curr_time);
+    curr_tm = localtime(&curr_time);
+    strftime(date_string,10,"%Y/%m/%d",curr_tm);
+    strftime(time_string,10,"%H:%M:%S",curr_tm);
+
+  
+}
+
+void  Get_Date_Time()
+{
+    time_t curr_time;
+    tm * curr_tm;
+    time(&curr_time);
+    char date_string[12]={'\0'};
+    char time_string[12]={'\0'};
+    curr_tm = localtime(&curr_time);
+    strftime(date_string,10,"%Y/%m/%d",curr_tm);
+    strftime(time_string,10,"%H:%M:%S",curr_tm);
+    printf("Date : %s\r\n",date_string);
+    printf("Time : %s\r\n",time_string);
+  
+}
+
+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);
+    
+}
+
+void  Get_Date_Time_Trns( char *DTSTRING)
+{
+    time_t curr_time;
+    tm * curr_tm;
+    time(&curr_time);
+    curr_tm = localtime(&curr_time);  
+    strftime(DTSTRING,20,"%d%m%Y%H%M%S",curr_tm);
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Time.h	Fri Jul 13 08:22:41 2018 +0000
@@ -0,0 +1,16 @@
+
+#ifndef MBED_TIME_H
+#define MBED_TIME_H
+#include "mbed.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);
+void  Get_Date_Time_Trns( char *DTSTRING);
+void  Get_Date_Time(char *date_string,char *time_string);
+
+#endif
\ No newline at end of file
--- a/main.cpp	Fri Jul 13 07:36:58 2018 +0000
+++ b/main.cpp	Fri Jul 13 08:22:41 2018 +0000
@@ -1,101 +1,37 @@
 #include "stm32f103c8t6.h"
 #include "mbed.h"
-#include "gprs.h"
+#include "Time.h"
+
 
-    char Server[20]="119.81.0.11" ;              //write your Server IP here shoud be a static IP
-    char Port[5]="8080";                         // write your port Number 
-    char Phone_No[11]="1234567890";
-    char Service_Provider[40]="airtelgprs.com";
-    char Data[100]="Hellow World to Server";
-    
-    Serial      pc(PA_2, PA_3);
-    DigitalOut  myled(LED1);
-    GPRS   gprs(PB_6,PB_7,9600,Phone_No);
-    char Reply[100]={'\0'};
+Serial  pc(PA_2, PA_3);
+DigitalOut  myled(LED1);
+  
+
 int main()
  {
-    confSysClock();     
+    confSysClock();        
         myled = 0;      // turn the LED on
         wait_ms(200);   // 200 millisecond
         myled = 1;      // turn the LED off
         wait_ms(1000);  // 1000 millisecond
         pc.printf("Blink\r\n");
-        
-          
-    pc.printf("Am here.... GOOD\r\n"); 
-    gprs.init();
-    if(gprs.checkSIMStatus()==0)
-    { 
-        pc.printf("SIM Status is GOOD\r\n"); 
-        }
-    else
-    {
-        pc.printf("SIM NOT Preset \r\n"); 
-        }
-    
-     if(gprs.checkSignalStrength ()>=3)
-     {
-         pc.printf("Signal strength Good \r\n");  
-           
-        }  
-        else
-        {
-        pc.printf("Signal strength Weak\r\n");  
-        }
-        
-        if(gprs.checkSIMStatus()==0)
-        {
-             pc.printf("SIM Status is GOOD\r\n"); 
-        }  
-            
-        else
-        {
-             pc.printf("SIM NOT Present \r\n"); 
-        }  
+        char DATE[12]={'\0'};
+        char TIME[10]={'\0'};
+             
+        int success=iSetTerminalTime("14072018101113");
         
-//        gprs.networkInit( "202.56.231.117:8080");
-         int success= gprs.networkInit(Service_Provider);   //write your apn here
-         if(success==0)
-         pc.printf("Network Initialised \r\n");
-         else
-         pc.printf("Unable Initialise Network  \r\n");
-          
-          
-          success=gprs.connectTCP(Server,Port);
-          
-         if(success==0)
-         pc.printf("Connected to Server  \r\n");
-         else
-         pc.printf("Unable connect to Server   \r\n");
-         
-         success= gprs.sendTCPData(Data);
-         
-         if(success==0)
-         pc.printf("Data Sent  \r\n");
-         else
-         pc.printf("Unable connect to Server   \r\n");
-         
-         success=gprs.waitforReply(Reply);
-         
-         if(success==0)
-         pc.printf("Data Received form Server  \r\n");
-         else
-         pc.printf("No Reply from Server \r\n");
-
-         success=gprs.closeTCP();
-         
-         if(success==0)
-         pc.printf("Close TCP Connection  \r\n");
-         else
-         pc.printf("Unable to detach from Server \r\n");
-         
-         success=gprs.shutTCP();
-         
-         if(success==0)
-         pc.printf("Shut TCP Connection  \r\n");
-         else
-         pc.printf("Unable to Shut TCP Connection \r\n");
+        if(success==0)
+        pc.printf(" Time Set Successfull\r\n");
+        else
+        pc.printf(" Unable to set terminal time \r\n");
         
+        while(success==0)
+        {
+         Get_Date_Time(DATE,TIME);
+          pc.printf("Date : %s\r\n",DATE);
+          pc.printf("Time : %s\r\n",TIME);
+        }
+             
     }