Skip to content

Commit

Permalink
信頼度導入
Browse files Browse the repository at this point in the history
  • Loading branch information
Blue-Crescent committed Feb 14, 2024
1 parent 9bd229d commit c1d4fe2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
23 changes: 17 additions & 6 deletions src/JJYReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ time_t JJYReceiver::getTime() {
if(timeavailable == -1) return -1;
timeavailable = -1;
switch(reliability){
case 1:
case LENGTHOK:
return updateTimeInfo(jjydata,timeavailable,1);
break;
break;
case PARITYOK:
return updateTimeInfo(jjydata,timeavailable,1);
break;
}
return -1;
case TIMEVALID:
Expand Down Expand Up @@ -135,10 +138,18 @@ void JJYReceiver::delta_tick(){
markercount++;
if(markercount==2){
rcvcnt = (rcvcnt + 1) % VERIFYLOOP;
if(settime(rcvcnt)){
datetimeCheck();
timeCheck(rcvcnt);
timeavailable = rcvcnt;
if(lencheck(jjypayloadlen)){ // Payload Length check
settime(rcvcnt);
if(timeCheck(rcvcnt)){ // Parity check
datetimeCheck();
timeavailable = rcvcnt;
reliability = static_cast<RELIABILITY>((reliability < LENGTHOK) ? LENGTHOK : reliability);
}
}else{
if(timeCheck(rcvcnt)){ // Payload bad, but Parity check passed. Time could be used.
timeavailable = rcvcnt;
reliability = static_cast<RELIABILITY>((reliability < PARITYOK) ? PARITYOK : reliability);
}
}
#ifdef DEBUG_BUILD
debug3();
Expand Down
9 changes: 3 additions & 6 deletions src/JJYReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef union {

class JJYReceiver {
enum STATE {INIT,RECEIVE,TIMEVALID,TIMETICK};
enum RELIABILITY {UNKNOWN=-1,PARITYOK=0,LENGTHOK=1};
enum JJYSTATE {JJY_INIT=-1,JJY_MIN=0,JJY_HOUR=1,JJY_DOYH=2,JJY_DOYL=3,JJY_YEAR=4,JJY_WEEK=5};

public:
Expand All @@ -93,7 +94,7 @@ class JJYReceiver {
volatile int8_t monitorpin = -1;
volatile uint8_t frequency = 0;
volatile uint8_t markercount = 0;
volatile uint8_t reliability = 0;
volatile enum RELIABILITY reliability = UNKNOWN;
volatile uint8_t quality = 0;

volatile uint8_t tick = 0;
Expand Down Expand Up @@ -142,10 +143,7 @@ class JJYReceiver {
#endif

private:
bool settime(uint8_t index){
if(lencheck(jjypayloadlen) == false){
return false;
}
void settime(uint8_t index){
jjydata[index].bits.year =(uint8_t) 0x00FF & jjypayload[JJY_YEAR];
jjydata[index].bits.doyh =(uint16_t) 0x007F & jjypayload[JJY_DOYH];
jjydata[index].bits.doyl =(uint8_t) ((0x01E0 & jjypayload[JJY_DOYL]) >> 5);
Expand All @@ -154,7 +152,6 @@ class JJYReceiver {
jjydata[index].bits.PA1_h =(uint8_t) ((0x0004 & jjypayload[JJY_DOYL]) >> 2);
jjydata[index].bits.PA2_m =(uint8_t) ((0x0002 & jjypayload[JJY_DOYL]) >> 1);
timeinfo.tm_sec = 1; //
return true;
}
time_t updateTimeInfo(JJYData* jjydata, int8_t index, int8_t offset) {
int year, yday;
Expand Down

0 comments on commit c1d4fe2

Please sign in to comment.