X-Git-Url: https://git.karo-electronics.de/?p=magstrip.git;a=blobdiff_plain;f=lmain.c;fp=lmain.c;h=19ab4a3978b5c193d7581731b119aa11bd24d5f4;hp=a74ea2f8490f4d511aff2b8841e47e6c4413f980;hb=cca86dfa8eed9bb98574bc908a0fdb18dd200222;hpb=15890c0fda5647d737f30bc6c1ce2d3e60f41423 diff --git a/lmain.c b/lmain.c index a74ea2f..19ab4a3 100755 --- a/lmain.c +++ b/lmain.c @@ -64,54 +64,76 @@ unsigned int sbpos = 0; free(sbuf); } +void print_help(void) +{ + fprintf(stderr, "r - initial RESET, required after power-on\n"); + fprintf(stderr, "i - C:2 insert permit request\n"); + fprintf(stderr, "s - C10 C/R status request\n"); + fprintf(stderr, "S - C11 sensor status\n"); + fprintf(stderr, "1 - Reads ISO #1 and sends data\n"); + fprintf(stderr, "2 - Reads ISO #2 and sends data\n"); + fprintf(stderr, "3 - Reads ISO #3 and sends data\n"); + fprintf(stderr, "m - Sends the read data in memory by this command\n"); + fprintf(stderr, "M - Sends multi-tracks data in the memory by this command and parameter\n"); + fprintf(stderr, "q - close serial and quite\n"); + fprintf(stderr, "h - this help\n"); +} + int process_user_cmd(char *rxbuf, int len, int ufd) { int in_cmd = 0; - if (rxbuf[0] == 'i') { - fprintf(stderr, "Init permit request... "); - send_command(ufd, "C:2", 3); - in_cmd = 1; - } - if (rxbuf[0] == 'r') { - fprintf(stderr, "RESET request... "); - send_command(ufd, "C00", 3); - in_cmd = 1; - } - if (rxbuf[0] == 'e') { - fprintf(stderr, "Eject request... "); - send_command(ufd, "C30", 3); - in_cmd = 1; - } - if (rxbuf[0] == 's') { - fprintf(stderr, "Status request... "); - send_command(ufd, "C10", 3); - in_cmd = 1; - } - if (rxbuf[0] == 'S') { - fprintf(stderr, "Status request... "); - send_command(ufd, "C11", 3); - in_cmd = 1; - } - if (rxbuf[0] == '1') { - fprintf(stderr, "Status request... "); - send_command(ufd, "C61", 3); - in_cmd = 1; - } - if (rxbuf[0] == '2') { - fprintf(stderr, "Status request... "); - send_command(ufd, "C62", 3); - in_cmd = 1; - } - if (rxbuf[0] == '3') { - fprintf(stderr, "Status request... "); - send_command(ufd, "C63", 3); - in_cmd = 1; - } - - if (rxbuf[0] == 'q') { - fprintf(stderr, "Exiting...\n"); - in_cmd = -1; + switch (rxbuf[0]) { + case 'i': + fprintf(stderr, "Insert permit request... "); + send_command(ufd, "C:2", 3); + in_cmd = 1; + break; + case 'r': + fprintf(stderr, "RESET request... "); + send_command(ufd, "C00", 3); + in_cmd = 1; + break; + case 'e': + fprintf(stderr, "Eject request... "); + send_command(ufd, "C30", 3); + in_cmd = 1; + break; + case 's': + fprintf(stderr, "Status request... "); + send_command(ufd, "C10", 3); + in_cmd = 1; + break; + case 'S': + fprintf(stderr, "Status request... "); + send_command(ufd, "C11", 3); + in_cmd = 1; + break; + case '1': + fprintf(stderr, "Status request... "); + send_command(ufd, "C61", 3); + in_cmd = 1; + break; + case '2': + fprintf(stderr, "Status request... "); + send_command(ufd, "C62", 3); + in_cmd = 1; + break; + case '3': + fprintf(stderr, "Status request... "); + send_command(ufd, "C63", 3); + in_cmd = 1; + break; + case 'h': + print_help(); + in_cmd = 0; + break; + case 'q': + fprintf(stderr, "Exiting...\n"); + in_cmd = -1; + break; + default: + break; } return in_cmd; @@ -181,23 +203,29 @@ int bpos; int main(int argc, char **argv) { +char *ser_dev; char rxbuf[256]; int ufd, rxlen=0, rxpos=0, ret; int in_cmd = 0; fd_set rfds; struct timeval tval; - if (open_uart("/dev/ttyUSB0", B9600) != 0) + if (argc > 1) + ser_dev = argv[1]; + else + ser_dev = "/dev/ttyS0"; + if (open_uart(ser_dev, B9600) != 0) return -1; ufd = uart_get_fd(); // fprintf(stderr, "UART fd = %d\n", ufd); + FD_ZERO(&rfds); FD_SET(ufd, &rfds); FD_SET(0, &rfds); tval.tv_sec = 0; tval.tv_usec = 5000000; - fprintf(stderr, "OMRON MVFW card reader terminal\nEnter 'h' for help\n"); + fprintf(stderr, "OMRON MVFW card reader terminal\non serial %s\nEnter 'h' for help\n", ser_dev); while (1) { ret = select((ufd+1), &rfds, NULL, NULL, &tval); if (ret == 0) {