From 9cdebc991e8901c82a96f536dbf5aae4998f9917 Mon Sep 17 00:00:00 2001 From: BlueCrescent Date: Mon, 19 Feb 2024 18:35:03 +0900 Subject: [PATCH] =?UTF-8?q?=E5=8F=97=E4=BF=A1=E9=83=A8=E5=88=86=E3=81=AE?= =?UTF-8?q?=E6=9C=80=E9=81=A9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JJYReceiver.cpp | 35 +++++++++++++---------------------- src/JJYReceiver.h | 21 ++++++++------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/JJYReceiver.cpp b/src/JJYReceiver.cpp index 9d59107..544cd37 100644 --- a/src/JJYReceiver.cpp +++ b/src/JJYReceiver.cpp @@ -100,8 +100,8 @@ bool JJYReceiver::timeCheck(){ for (int i = 0; i < 6; i++) { min[0] = ((jjydata[compare[i][0]].bits.min >> 5) & 0x7) * 10 + (jjydata[compare[i][0]].bits.min & 0x0f) + 1; min[1] = ((jjydata[compare[i][1]].bits.min >> 5) & 0x7) * 10 + (jjydata[compare[i][1]].bits.min & 0x0f) + 2; - hour00[0] = min[0] ? 1 : 0; - hour00[1] = min[1] ? 1 : 0; + hour00[0] = ( min[0] == 0 ) ? 1 : 0; + hour00[1] = ( min[1] == 0 ) ? 1 : 0; if (jjydata[compare[i][0]].bits.year == jjydata[compare[i][1]].bits.year && jjydata[compare[i][0]].bits.doyh == jjydata[compare[i][1]].bits.doyh && jjydata[compare[i][0]].bits.doyl == jjydata[compare[i][1]].bits.doyl && @@ -133,12 +133,8 @@ time_t JJYReceiver::getTime() { if(timeavailable == -1) return -1; temp_time = updateTimeInfo(jjydata,timeavailable,1); timeavailable = -1; - switch(mode){ - case HASTY: - if(operation == BOOT){ - temp_time = updateTimeInfo(jjydata,rcvcnt,1); - globaltime = temp_time; - } + switch(reliability){ + case 1: return temp_time; break; } @@ -147,6 +143,9 @@ time_t JJYReceiver::getTime() { globaltime = updateTimeInfo(last_jjydata,0,1); state = TIMETICK; received_time = globaltime; + break; + default: + return received_time; } return received_time; } @@ -161,10 +160,10 @@ void JJYReceiver::delta_tick(){ data = digitalRead(datapin)==HIGH ? 1 : 0; shift_in(data, sampling, N); sampleindex++; - if(sampleindex == 100){ + if(95 < sampleindex){ sampleindex = 0; clear(sampling, N); - }else if(sampleindex == 90){ // クロックが揺らぐので100sampleしっかりないため少し間引く + }else if(sampleindex == 94){ #ifdef DEBUG_BUILD debug2(); #endif @@ -225,22 +224,16 @@ void JJYReceiver::delta_tick(){ } void JJYReceiver::jjy_receive(){ - unsigned long time = millis(); - unsigned long window; if(state == TIMEVALID) return; bool data = digitalRead(datapin); // ピンの状態を読み取る if (data == LOW) { if(monitorpin != -1) digitalWrite(monitorpin,LOW); - window = time - fallingtime[0]; - if(990 < window){ + if(sampleindex < 20){ sampleindex = 0; clear(sampling,N); } - fallingtime[1] = fallingtime[0]; - fallingtime[0] = time; }else{ if(monitorpin != -1) digitalWrite(monitorpin,HIGH); - } } uint8_t JJYReceiver::freq(uint8_t freq){ @@ -289,12 +282,8 @@ void JJYReceiver::monitor(int pin){ monitorpin = pin; } -void JJYReceiver::begin(uint8_t updatemode){ - mode = static_cast(updatemode); - init(); -} void JJYReceiver::begin(){ - begin(NORMAL); + init(); } void JJYReceiver::stop(){ @@ -362,6 +351,8 @@ void JJYReceiver::debug(){ case TIMEVALID: DEBUG_PRINT("TIMEVALID"); break; + default: + break; } DEBUG_PRINT(" "); DEBUG_PRINT((int)jjypayloadlen[jjystate]); diff --git a/src/JJYReceiver.h b/src/JJYReceiver.h index 7906699..c240764 100644 --- a/src/JJYReceiver.h +++ b/src/JJYReceiver.h @@ -29,8 +29,8 @@ #include #include -//#define DEBUG_BUILD -//#define DEBUG_ESP32 +#define DEBUG_BUILD +#define DEBUG_ESP32 #ifdef DEBUG_BUILD # define DEBUG_PRINT(...) Serial.print(__VA_ARGS__); @@ -78,9 +78,7 @@ typedef union { } JJYData; class JJYReceiver { - enum OPERATION {BOOT,OPERATION}; - enum MODE {HASTY=1,NORMAL=0,CONSERVATIVE=2}; - enum STATE {INIT,RECEIVE,TIMEVALID,TIMETICK}; + enum STATE {INIT,RECEIVE,TIMEVALID,TIMETICK}; enum JJYSTATE {JJY_INIT=-1,JJY_MIN=0,JJY_HOUR=1,JJY_DOYH=2,JJY_DOYL=3,JJY_YEAR=4,JJY_WEEK=5}; public: @@ -89,15 +87,13 @@ class JJYReceiver { JJYData last_jjydata[1]; volatile enum STATE state = INIT; volatile enum JJYSTATE jjystate = JJY_INIT; - volatile enum OPERATION operation = BOOT; - //volatile enum MODE mode = NORMAL; - volatile enum MODE mode = HASTY; - volatile uint8_t rcvcnt = 0; + volatile uint8_t rcvcnt = 0; volatile unsigned long fallingtime[2]; volatile const int8_t datapin,selpin,ponpin; volatile int8_t monitorpin = -1; volatile uint8_t frequency = 0; volatile uint8_t markercount = 0; + volatile uint8_t reliability = 0; volatile uint8_t quality = 0; volatile uint8_t tick = 0; @@ -107,9 +103,9 @@ class JJYReceiver { volatile uint8_t sampleindex = 0; volatile uint8_t sampling [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}; + volatile const uint8_t CONST_PM [N] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00}; + volatile const uint8_t CONST_H [N] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00}; + volatile const uint8_t CONST_L [N] = {0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; volatile time_t globaltime = 0; volatile time_t received_time = -1; @@ -126,7 +122,6 @@ class JJYReceiver { void shift_in(uint8_t data,volatile uint8_t* sampling, int length); void clear(volatile uint8_t* sampling, int length); void begin(); - void begin(uint8_t mode); void stop(); bool power(bool powerstate); bool power();