Skip to content

Commit

Permalink
Optimizing receive ability. Improove noise resistance
Browse files Browse the repository at this point in the history
  • Loading branch information
Blue-Crescent committed Feb 19, 2024
1 parent 768fb8f commit 38482cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
20 changes: 8 additions & 12 deletions src/JJYReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ time_t JJYReceiver::getTime() {
received_time = globaltime;
break;
default:
return -1;
return received_time;
}
return received_time;
}
Expand All @@ -160,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 == 95){
#ifdef DEBUG_BUILD
debug2();
#endif
Expand Down Expand Up @@ -224,22 +224,16 @@ void JJYReceiver::delta_tick(){
}

void JJYReceiver::jjy_receive(){
unsigned long time = millis();
unsigned long window;
if(state == TIMEVALID) return;
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{
}else{
if(monitorpin != -1) digitalWrite(monitorpin,HIGH);

}
}
uint8_t JJYReceiver::freq(uint8_t freq){
Expand Down Expand Up @@ -357,6 +351,8 @@ void JJYReceiver::debug(){
case TIMEVALID:
DEBUG_PRINT("TIMEVALID");
break;
default:
break;
}
DEBUG_PRINT(" ");
DEBUG_PRINT((int)jjypayloadlen[jjystate]);
Expand Down
10 changes: 4 additions & 6 deletions src/JJYReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,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;
Expand Down Expand Up @@ -162,9 +162,7 @@ class JJYReceiver {
}
time_t updateTimeInfo(JJYData* jjydata, int8_t index, int8_t offset) {
int year, yday;
// For JJY
year = (((jjydata[index].bits.year & 0xf0) >> 4) * 10 + (jjydata[index].bits.year & 0x0f)) + 2000;

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);
Expand Down

0 comments on commit 38482cd

Please sign in to comment.