-
-
Save wa5znu/e3480cdb7cdc0ffa13bb to your computer and use it in GitHub Desktop.
arduino version of byte test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
// wall_ticks counts seconds and goes from 0-180 because there is a 3-minute beacon schedule. | |
volatile unsigned char wall_ticks = 0; | |
volatile unsigned char next_tx_click = 255; | |
struct station { | |
char *call; | |
char *location; | |
char *op; | |
unsigned char start_time; | |
}; | |
struct station station; | |
void txon() { | |
} | |
void print(unsigned int x, unsigned char y) { | |
Serial.print(x, DEC); | |
Serial.print(" "); | |
Serial.println(y, DEC); | |
} | |
// tick interrupt | |
// keep track of wall_ticks; use GPS PPS to discipline millis_per_second when it's safe to do so (no interrupts masked). | |
void tick() { | |
wall_ticks = (wall_ticks+1) % (3*60); | |
if ((wall_ticks - station.start_time) == next_tx_click) { | |
txon(); | |
} | |
print(wall_ticks, wall_ticks); | |
} | |
int gps_discipline_clock_byte(unsigned char minutes, unsigned char seconds) { | |
wall_ticks = ((minutes * 60) + seconds) % (3*60); | |
return wall_ticks; | |
} | |
int gps_discipline_clock_int(int minutes, int seconds) { | |
int foo = ((minutes * 60) + seconds) % (3*60); | |
wall_ticks = foo; | |
return wall_ticks; | |
} | |
void test_tick() { | |
Serial.println("testing tick"); | |
for (int i = 0; i < 1000; i++) { | |
Serial.print(i); | |
Serial.print(":"); | |
tick(); | |
} | |
Serial.println("done testing tick"); | |
} | |
void test_gps_discipline_clock() { | |
Serial.println("testing gps_discipline_clock"); | |
for (int minutes = 0; minutes < 60; minutes++) { | |
Serial.print("Testing Minutes: "); | |
Serial.println(minutes, DEC); | |
for (int seconds = 0; seconds < 60; seconds++) { | |
if (gps_discipline_clock_byte(minutes, seconds) != gps_discipline_clock_int(minutes, seconds)) { | |
Serial.print("fail "); | |
print(minutes, seconds); | |
return; | |
} else { | |
// Serial.print("OK"); | |
// print(minutes, seconds); | |
} | |
} | |
} | |
Serial.println("done gps_discipline_clock"); | |
} | |
void setup() { | |
Serial.begin(115200); | |
test_tick(); | |
test_gps_discipline_clock(); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment