#include <stdio.h>
#include <signal.h>
#include <getopt.h>
typedef enum p_mode_t{
P_MODE_NONE,
P_MODE_RAW,
P_MODE_NORM
} p_mode_t;
static int running = 0;
static p_mode_t print_mode;
static void __print_usage(void)
{
printf("\n");
printf("-r print raw channel values in microseconds\n");
printf("-n print normalized channel values/s\n");
printf("-h print this help message\n");
printf("\n");
}
static void __signal_handler(__attribute__ ((unused)) int dummy)
{
running=0;
return;
}
static void __new_dsm_data_callback(void)
{
int i;
printf("\r");
printf("%d-ch ", channels);
if(print_mode==P_MODE_NORM){
for(i=0;i<channels;i++){
}
}
else{
for(i=0;i<channels;i++){
}
}
fflush(stdout);
}
int main(int argc, char *argv[])
{
int c;
print_mode = P_MODE_NONE;
opterr = 0;
while ((c = getopt(argc, argv, "rnh")) != -1){
switch (c){
case 'r':
if(print_mode!=P_MODE_NONE){
printf("\ntoo many arguments given\n");
__print_usage();
return -1;
}
print_mode = P_MODE_RAW;
break;
case 'n':
if(print_mode!=P_MODE_NONE){
printf("\ntoo many arguments given\n");
__print_usage();
return -1;
}
print_mode = P_MODE_NORM;
break;
break;
case 'h':
__print_usage();
return 0;
default:
fprintf(stderr,"Invalid Argument\n");
__print_usage();
return -1;
}
}
if(print_mode==P_MODE_NONE){
fprintf(stderr, "Please select raw or normalized mode\n");
__print_usage();
return -1;
}
printf("\n");
printf("Make sure transmitter and receiver are bound and on.\n");
printf("If data is received, the normalized values will be printed\n");
printf("here along with the bit resolution and the number of channels\n");
printf("\n");
printf("If connection is lost the number of seconds since last packet\n");
printf("will be displayed\n");
printf("\n");
signal(SIGINT, __signal_handler);
running =1;
printf("Waiting for first packet");
fflush(stdout);
if(running==0){
return 0;
}
}
while(running){
printf("\rSeconds since last DSM packet: ");
printf(" ");
fflush(stdout);
}
}
printf("\n");
return 0;
}