Skip to content

Commit

Permalink
added test mode for testing accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
aschulm committed May 17, 2015
1 parent 0f833f5 commit 3c437f6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
13 changes: 8 additions & 5 deletions sw/battor.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(int argc, char** argv)
int i;
FILE* file;
char opt;
char usb = 0, format = 0, down = 0, reset = 0;
char usb = 0, format = 0, down = 0, reset = 0, test = 0;

uint16_t down_file;
uint16_t timer_ovf, timer_div;
Expand All @@ -45,7 +45,7 @@ int main(int argc, char** argv)

// process the options
opterr = 0;
while ((opt = getopt(argc, argv, "sfd:b:r:g:o:vhu:k")) != -1)
while ((opt = getopt(argc, argv, "sfd:b:r:g:o:vhu:kt")) != -1)
{
switch(opt)
{
Expand Down Expand Up @@ -87,7 +87,10 @@ int main(int argc, char** argv)
break;
case 'k':
reset = 1;
break ;
break;
case 't':
test = 1;
break;
case 'v':
g_verb++;
break;
Expand Down Expand Up @@ -131,7 +134,7 @@ int main(int argc, char** argv)
{
// read configuration
control(CONTROL_TYPE_READ_FILE, down_file, 0, 1);
samples_print_loop(gain, ovs_bits, g_verb, sample_rate);
samples_print_loop(gain, ovs_bits, g_verb, sample_rate, 0);
}

// start configuration recording if enabled
Expand All @@ -156,7 +159,7 @@ int main(int argc, char** argv)
if (usb)
{
control(CONTROL_TYPE_START_SAMPLING_UART, 0, 0, 1);
samples_print_loop(gain, ovs_bits, g_verb, sample_rate);
samples_print_loop(gain, ovs_bits, g_verb, sample_rate, test);
}

return EXIT_SUCCESS;
Expand Down
27 changes: 25 additions & 2 deletions sw/samples.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int16_t samples_read(sample* v_s, sample* i_s, uint32_t* seqnum) //{{{
return hdr->samples_len / sizeof(sample);
} //}}}

void samples_print_loop(double gain, double ovs_bits, char verb, uint32_t sample_rate) //{{{
void samples_print_loop(double gain, double ovs_bits, char verb, uint32_t sample_rate, char test) //{{{
{
int i;
sample v_s[2000], i_s[2000];
Expand All @@ -84,6 +84,7 @@ void samples_print_loop(double gain, double ovs_bits, char verb, uint32_t sample
int16_t samples_len = 0;
double v_cal = 0, i_cal = 0;
sigset_t sigs;
double test_val = 0.0;

// will block and unblock SIGINT
sigemptyset(&sigs);
Expand Down Expand Up @@ -133,7 +134,29 @@ void samples_print_loop(double gain, double ovs_bits, char verb, uint32_t sample
double mv = sample_v(v_s + i, v_cal, 1);
double mi = sample_i(i_s + i, i_cal, gain, 1);

printf("%f %f %f\n", msec, mi, mv);
printf("%f %f %f", msec, mi, mv);

// check for test value on STDIN and print
if (test)
{
struct timeval tv;
fd_set fds;
int ret;

tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
select(STDIN_FILENO+1, &fds, NULL, NULL, &tv);

if (FD_ISSET(STDIN_FILENO, &fds))
{
ret = fscanf(stdin, "%lf", &test_val);
}
printf(" %f", test_val);
}

printf("\n");

sample_num++;
}
Expand Down
2 changes: 1 addition & 1 deletion sw/samples.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ typedef struct samples_hdr_ samples_hdr;
void samples_init(uint16_t ovs_bits);
double sample_v(sample* s, double cal, uint8_t warning);
double sample_i(sample* s, double cal, double gain, uint8_t warning);
void samples_print_loop(double gain, double ovs_bits, char verb, uint32_t sample_rate);
void samples_print_loop(double gain, double ovs_bits, char verb, uint32_t sample_rate, char test);

#endif

0 comments on commit 3c437f6

Please sign in to comment.