From 9caff88910d68e00a800c4dae0dd72d6539dae67 Mon Sep 17 00:00:00 2001 From: BlueCrescent Date: Mon, 12 Feb 2024 19:58:45 +0900 Subject: [PATCH] =?UTF-8?q?=E9=96=A2=E6=95=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JJYReceiver.cpp | 55 ++++++++++++++++++++++++--------------------- src/JJYReceiver.h | 14 +++++++++++- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/JJYReceiver.cpp b/src/JJYReceiver.cpp index 0fc9a19..d36f472 100644 --- a/src/JJYReceiver.cpp +++ b/src/JJYReceiver.cpp @@ -85,9 +85,9 @@ bool JJYReceiver::timeCheck(){ min1 == min2) { if(min1 > min2){ - last_jjydata = jjydata[compare[i][0]]; + last_jjydata[0] = jjydata[compare[i][0]]; }else{ - last_jjydata = jjydata[compare[i][1]]; + last_jjydata[0] = jjydata[compare[i][1]]; } state = TIMEVALID; stop(); @@ -100,17 +100,18 @@ bool JJYReceiver::timeCheck(){ time_t JJYReceiver::get_time() { return globaltime; } + time_t JJYReceiver::get_time(uint8_t index) { uint16_t year,yday; - time_t temptime; - year = (((jjydata[index].bits.year & 0xf0) >> 4) * 10 + (jjydata[index].bits.year & 0x0f)) + 2000; - timeinfo.tm_year = year - 1900; // 年 - yday = ((((jjydata[index].bits.doyh >> 5) & 0x0002)) * 100) + (((jjydata[index].bits.doyh & 0x000f)) * 10) + jjydata[index].bits.doyl; - calculateDate(year, yday ,(uint8_t*) &timeinfo.tm_mon,(uint8_t*) &timeinfo.tm_mday); - timeinfo.tm_hour = ((jjydata[index].bits.hour >> 5) & 0x3) * 10 + (jjydata[index].bits.hour & 0x0f) ; // 時 - timeinfo.tm_min = ((jjydata[index].bits.min >> 5) & 0x7) * 10 + (jjydata[index].bits.min & 0x0f) + 1; // 分 - temptime = mktime(&timeinfo); - return temptime; + return updateTimeInfo(jjydata,index,1); +// year = (((jjydata[index].bits.year & 0xf0) >> 4) * 10 + (jjydata[index].bits.year & 0x0f)) + 2000; +// timeinfo.tm_year = year - 1900; // 年 +// yday = ((((jjydata[index].bits.doyh >> 5) & 0x0002)) * 100) + (((jjydata[index].bits.doyh & 0x000f)) * 10) + jjydata[index].bits.doyl; +// calculateDate(year, yday ,(uint8_t*) &timeinfo.tm_mon,(uint8_t*) &timeinfo.tm_mday); +// timeinfo.tm_hour = ((jjydata[index].bits.hour >> 5) & 0x3) * 10 + (jjydata[index].bits.hour & 0x0f) ; // 時 +// timeinfo.tm_min = ((jjydata[index].bits.min >> 5) & 0x7) * 10 + (jjydata[index].bits.min & 0x0f) + 1; // 分 +// temptime = mktime(&timeinfo); +// return temptime; } time_t JJYReceiver::getTime() { uint16_t year,yday; @@ -119,24 +120,26 @@ time_t JJYReceiver::getTime() { return -1; case RECEIVE: // Intermediate update (1st receive update) if(timeavailable == -1) return -1; - year = (((jjydata[timeavailable].bits.year & 0xf0) >> 4) * 10 + (jjydata[timeavailable].bits.year & 0x0f)) + 2000; - timeinfo.tm_year = year - 1900; // 年 - yday = ((((jjydata[timeavailable].bits.doyh >> 5) & 0x0002)) * 100) + (((jjydata[timeavailable].bits.doyh & 0x000f)) * 10) + jjydata[timeavailable].bits.doyl; - calculateDate(year, yday ,(uint8_t*) &timeinfo.tm_mon,(uint8_t*) &timeinfo.tm_mday); - timeinfo.tm_hour = ((jjydata[timeavailable].bits.hour >> 5) & 0x3) * 10 + (jjydata[timeavailable].bits.hour & 0x0f) ; // 時 - timeinfo.tm_min = ((jjydata[timeavailable].bits.min >> 5) & 0x7) * 10 + (jjydata[timeavailable].bits.min & 0x0f) + 2; // 分 - globaltime = mktime(&timeinfo); + globaltime = updateTimeInfo(jjydata,timeavailable,1); + //year = (((jjydata[timeavailable].bits.year & 0xf0) >> 4) * 10 + (jjydata[timeavailable].bits.year & 0x0f)) + 2000; + //timeinfo.tm_year = year - 1900; // 年 + //yday = ((((jjydata[timeavailable].bits.doyh >> 5) & 0x0002)) * 100) + (((jjydata[timeavailable].bits.doyh & 0x000f)) * 10) + jjydata[timeavailable].bits.doyl; + //calculateDate(year, yday ,(uint8_t*) &timeinfo.tm_mon,(uint8_t*) &timeinfo.tm_mday); + //timeinfo.tm_hour = ((jjydata[timeavailable].bits.hour >> 5) & 0x3) * 10 + (jjydata[timeavailable].bits.hour & 0x0f) ; // 時 + //timeinfo.tm_min = ((jjydata[timeavailable].bits.min >> 5) & 0x7) * 10 + (jjydata[timeavailable].bits.min & 0x0f) + 1; // 分 + //globaltime = mktime(&timeinfo); timeavailable = -1; return -1; case TIMEVALID: - year = (((last_jjydata.bits.year & 0xf0) >> 4) * 10 + (last_jjydata.bits.year & 0x0f)) + 2000; - timeinfo.tm_year = year - 1900; // 年 - //timeinfo.tm_yday = // Day of the year is not implmented in Arduino time.h - yday = ((((last_jjydata.bits.doyh >> 5) & 0x0002)) * 100) + (((last_jjydata.bits.doyh & 0x000f)) * 10) + last_jjydata.bits.doyl; - calculateDate(year, yday ,(uint8_t*) &timeinfo.tm_mon,(uint8_t*) &timeinfo.tm_mday); - timeinfo.tm_hour = ((last_jjydata.bits.hour >> 5) & 0x3) * 10 + (last_jjydata.bits.hour & 0x0f) ; // 時 - timeinfo.tm_min = ((last_jjydata.bits.min >> 5) & 0x7) * 10 + (last_jjydata.bits.min & 0x0f) + 2; // 分 - globaltime = mktime(&timeinfo); + globaltime = updateTimeInfo(last_jjydata,0,2); + //year = (((last_jjydata.bits.year & 0xf0) >> 4) * 10 + (last_jjydata.bits.year & 0x0f)) + 2000; + //timeinfo.tm_year = year - 1900; // 年 + ////timeinfo.tm_yday = // Day of the year is not implmented in Arduino time.h + //yday = ((((last_jjydata.bits.doyh >> 5) & 0x0002)) * 100) + (((last_jjydata.bits.doyh & 0x000f)) * 10) + last_jjydata.bits.doyl; + //calculateDate(year, yday ,(uint8_t*) &timeinfo.tm_mon,(uint8_t*) &timeinfo.tm_mday); + //timeinfo.tm_hour = ((last_jjydata.bits.hour >> 5) & 0x3) * 10 + (last_jjydata.bits.hour & 0x0f) ; // 時 + //timeinfo.tm_min = ((last_jjydata.bits.min >> 5) & 0x7) * 10 + (last_jjydata.bits.min & 0x0f) + 2; // 分 + //globaltime = mktime(&timeinfo); state = TIMETICK; received_time = globaltime; } diff --git a/src/JJYReceiver.h b/src/JJYReceiver.h index 8b9a0ec..3381771 100644 --- a/src/JJYReceiver.h +++ b/src/JJYReceiver.h @@ -63,7 +63,7 @@ class JJYReceiver { public: volatile uint8_t jjypayloadlen[6] = {0,0,0,0,0,0}; JJYData jjydata[VERIFYLOOP]; - JJYData last_jjydata; + JJYData last_jjydata[1]; volatile enum STATE state = INIT; volatile enum JJYSTATE jjystate = JJY_INIT; volatile uint8_t rcvcnt = 0; @@ -111,6 +111,7 @@ class JJYReceiver { int max_of_three(uint8_t a, uint8_t b, uint8_t c); bool calculateParity(uint8_t value, uint8_t bitLength, uint8_t expectedParity); bool timeCheck(); + //time_t updateTimeInfo(JJYData jjydata*, int8_t index, int8_t offset); time_t getTime(); time_t get_time(); time_t get_time(uint8_t index); @@ -134,6 +135,17 @@ class JJYReceiver { timeinfo.tm_sec = 1; // 秒 return true; } + time_t updateTimeInfo(JJYData* jjydata, int8_t index, int8_t offset) { + int year, yday; + year = (((jjydata[index].bits.year & 0xf0) >> 4) * 10 + (jjydata[index].bits.year & 0x0f)) + 2000; + timeinfo.tm_year = year - 1900; // 年 + yday = ((((jjydata[index].bits.doyh >> 5) & 0x0002)) * 100) + (((jjydata[index].bits.doyh & 0x000f)) * 10) + jjydata[index].bits.doyl; + calculateDate(year, yday ,(uint8_t*) &timeinfo.tm_mon,(uint8_t*) &timeinfo.tm_mday); + timeinfo.tm_hour = ((jjydata[index].bits.hour >> 5) & 0x3) * 10 + (jjydata[index].bits.hour & 0x0f) ; // 時 + timeinfo.tm_min = ((jjydata[index].bits.min >> 5) & 0x7) * 10 + (jjydata[index].bits.min & 0x0f) + offset; // 分 + time_t temp = mktime(&timeinfo); + return temp; + } void init(){ state = RECEIVE; clear(sampling,N);