Skip to content

Commit

Permalink
受信中間データ時刻反映
Browse files Browse the repository at this point in the history
  • Loading branch information
Blue-Crescent committed Feb 12, 2024
1 parent f371621 commit 14f3b99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/JJYReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ bool JJYReceiver::timeCheck(){
}else{
last_jjydata = jjydata[compare[i][1]];
}
timeavailable[compare[i][1]] = 1;
state = TIMEVALID;
stop();
return true;
Expand All @@ -106,7 +105,6 @@ time_t JJYReceiver::get_time(uint8_t index) {
time_t temptime;
year = (((jjydata[index].bits.year & 0xf0) >> 4) * 10 + (jjydata[index].bits.year & 0x0f)) + 2000;
timeinfo.tm_year = year - 1900; //
//timeinfo.tm_yday = // Day of the year is not implmented in Arduino time.h
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) ; //
Expand All @@ -119,7 +117,16 @@ time_t JJYReceiver::getTime() {
switch(state){
case INIT:
return -1;
case RECEIVE:
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);
timeavailable = -1;
return -1;
case TIMEVALID:
year = (((last_jjydata.bits.year & 0xf0) >> 4) * 10 + (last_jjydata.bits.year & 0x0f)) + 2000;
Expand All @@ -128,7 +135,7 @@ time_t JJYReceiver::getTime() {
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) + 1; //
timeinfo.tm_min = ((last_jjydata.bits.min >> 5) & 0x7) * 10 + (last_jjydata.bits.min & 0x0f) + 2; //
globaltime = mktime(&timeinfo);
state = TIMETICK;
received_time = globaltime;
Expand Down Expand Up @@ -179,6 +186,7 @@ void JJYReceiver::delta_tick(){
rcvcnt = (rcvcnt + 1) % VERIFYLOOP;
if(settime(rcvcnt)){
timeCheck();
timeavailable = rcvcnt;
}
#ifdef DEBUG_BUILD
debug3();
Expand Down
3 changes: 1 addition & 2 deletions src/JJYReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class JJYReceiver {

volatile uint8_t sampleindex = 0;
volatile uint8_t sampling [N];
volatile uint8_t timeavailable [N];
volatile int8_t timeavailable = -1;
volatile const uint8_t CONST_PM [N] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00};
volatile const uint8_t CONST_H [N] = {0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
volatile const uint8_t CONST_L [N] = {0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
Expand Down Expand Up @@ -137,7 +137,6 @@ class JJYReceiver {
void init(){
state = RECEIVE;
clear(sampling,N);
clear(timeavailable,3);
jjydata[0].bits.hour = 25;
jjydata[1].bits.hour = 26;
jjydata[2].bits.hour = 27;
Expand Down

0 comments on commit 14f3b99

Please sign in to comment.