Files
fluxengine/main.c
David Given 607bb141b3 Radically rework decoding: there's now a simple statistical clock guesser, and
then we read the pulsetrain into nice tidy bits with a proper clock, which
makes the decoder's job way easier. We can actually get rid of the entire MFM
decoder state machine. Also, after sorting out the magic bit patterns at the
beginning of records, we can now reliably pull them out of the bitstream
without needing to know anything about the records themselves.
2018-10-18 00:27:48 +02:00

91 lines
1.8 KiB
C

#include "globals.h"
#include <stdarg.h>
#include <sys/time.h>
#include <unistd.h>
#include <libusb.h>
void error(const char* message, ...)
{
va_list ap;
va_start(ap, message);
fprintf(stderr, "fluxengine: ");
vfprintf(stderr, message, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(1);
}
double gettime(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + tv.tv_usec/1000000.0;
}
int countargs(char* const* argv)
{
int count = 0;
while (*argv++)
count++;
return count;
}
void syntax_error(void)
{
error("syntax error (try -h for help)");
}
static char* const* parse_global_options(char* const* argv)
{
for (;;)
{
switch (getopt(countargs(argv), argv, "+ht:"))
{
case -1:
return argv + optind;
case 'h':
error("sorry, no help yet");
default:
syntax_error();
}
}
}
int main(int argc, char* const* argv)
{
argv = parse_global_options(argv);
usb_init();
/* Just check that a FluxEngine is plugged in. */
(void) usb_get_version();
if (!argv[0])
syntax_error();
if (strcmp(argv[0], "rpm") == 0)
cmd_rpm(argv);
else if (strcmp(argv[0], "usbbench") == 0)
cmd_usbbench(argv);
else if (strcmp(argv[0], "read") == 0)
cmd_read(argv);
else if (strcmp(argv[0], "write") == 0)
cmd_write(argv);
else if (strcmp(argv[0], "mfmdecode") == 0)
cmd_mfmdecode(argv);
else if (strcmp(argv[0], "testpattern") == 0)
cmd_testpattern(argv);
else if (strcmp(argv[0], "fluxdump") == 0)
cmd_fluxdump(argv);
else if (strcmp(argv[0], "calibrate") == 0)
cmd_calibrate(argv);
else if (strcmp(argv[0], "getclock") == 0)
cmd_getclock(argv);
else
syntax_error();
return 0;
}