Skip to content

Commit

Permalink
extract YEAR and MONTH from __DATE__ macro
Browse files Browse the repository at this point in the history
  • Loading branch information
miyazakh committed Sep 20, 2024
1 parent 310f592 commit 93922df
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 6 deletions.
48 changes: 45 additions & 3 deletions IDE/Renesas/e2studio/RX65N/GR-ROSE/common/wolfssl_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,59 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wolfssl/wolfcrypt/wc_port.h>

#define YEAR 2024
#define MON 7
#define DEFAULT_YEAR 2024
#define DEFAULT_MONTH 9

static int YEAR;
static int MON;
static int IsYearMonSet = 0;
static int tick = 0;
static char* month[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec"};

static int char2mon(char* mon)
{
int i;

for (i = 0;i < 12; i++){
if (strcmp(month[i], mon) == 0) {
break;
}
}
return (i+1);
}

static void setTime()
{
/*01234567890*/
char buf[12];/*Mmm dd yyyy*/

sprintf(buf, "%s", __DATE__);
/* convert year to int */
buf[11] = '\0';
YEAR = atoi(&buf[7]);
if (YEAR == 0)
YEAR = DEFAULT_YEAR;

/* convert month to int */
buf[3] = '\0';
MON = char2mon(buf);
if (MON == 13)
MON = DEFAULT_MONTH;

IsYearMonSet = 1;
}

time_t time(time_t *t)
{
(void)t;
if(!IsYearMonSet)
setTime();
return ((YEAR-1970)*365+30*MON)*24*60*60 + tick++;
}

Expand Down
51 changes: 48 additions & 3 deletions IDE/Renesas/e2studio/RX65N/RSK/wolfssl_demo/wolfssl_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "platform/iot_network.h"
#include "platform.h"


#include <wolfssl/wolfcrypt/settings.h>
#include "wolfssl/ssl.h"
#include <wolfssl/wolfio.h>
Expand Down Expand Up @@ -61,19 +60,65 @@

#define TLSSERVER_IP "192.168.10.6"
#define TLSSERVER_PORT 11111
#define YEAR 2024
#define MON 9
#define FREQ 10000 /* Hz */

static long tick;
static int tmTick;

#define DEFAULT_YEAR 2024
#define DEFAULT_MONTH 9

static int YEAR;
static int MON;
static int IsYearMonSet = 0;
static char* month[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec"};

/* char2mon
* convert month to integer
*/
static int char2mon(char* mon)
{
int i;

for (i = 0;i < 12; i++){
if (strcmp(month[i], mon) == 0) {
break;
}
}
return (i+1);
}
/* setTiime
* set year and month from __DATE__
*/
static void setTime()
{
/*01234567890*/
char buf[12];/*Mmm dd yyyy*/

sprintf(buf, "%s", __DATE__);
/* convert year to int */
buf[11] = '\0';
YEAR = atoi(&buf[7]);
if (YEAR == 0)
YEAR = DEFAULT_YEAR;

/* convert month to int */
buf[3] = '\0';
MON = char2mon(buf);
if (MON == 13)
MON = DEFAULT_MONTH;

IsYearMonSet = 1;
}
/* time
* returns seconds from EPOCH
*/
time_t time(time_t *t)
{
(void)t;
if(!IsYearMonSet)
setTime();
return ((YEAR-1970)*365+30*MON)*24*60*60 + tmTick++;
}

Expand Down

0 comments on commit 93922df

Please sign in to comment.