1
0
Fork 0
DD2-monitor/ui/t.c

93 linhas
1.8 KiB
C

/*
* essais de gadgets UI
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ncurses.h>
#include "../serial/serial.h"
#include "terminal.h"
int verbosity;
/* ---------------------------------------------------------------- */
int special_dumper(FILE *fp, unsigned char octet)
{
static int idx = 0;
static unsigned char buffer[16];
int foo, c;
#if DEBUG_LEVEL > 1
fprintf(stderr, "%s $%x %c\n", __func__, octet, octet);
#endif
buffer[idx++] = octet;
if (idx==16) {
fprintf(fp, "dmp : ");
for (foo=0; foo<16; foo++) {
fprintf(fp, "%02x ", buffer[foo]);
}
fprintf(fp, " - |");
for (foo=0; foo<16; foo++) {
c = buffer[foo];
fprintf(fp, "%c", isprint(c) ? c : ' ');
}
fprintf(fp, "|\n"); fflush(fp);
idx = 0;
}
return 0;
}
/* ---------------------------------------------------------------- */
void help(int k)
{
puts("options : ");
puts("\t-d\tserial device to read.");
puts("\t-K\tset the K parameter.");
puts("\t-v\tincrease verbosity.");
exit(0);
}
/* ---------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int opt, foo;
int serial_in;
char *device = "/dev/ttyS0";
int K = 0;
// char ligne[100];
while ((opt = getopt(argc, argv, "d:hv")) != -1) {
switch (opt) {
case 'd': device = optarg; break;
case 'h': help(0); break;
case 'K': K = atoi(optarg); break;
case 'v': verbosity++; break;
default: break;
}
}
printf("\n*** compiled %s %s\n", __DATE__, __TIME__);
printf("*** device: %s\n", device);
serial_in = prepare_UART(device, 9600);
if (serial_in < 0) {
fprintf(stderr, "err open %s : %d\n", device, serial_in);
exit(1);
}
sleep(1);
foo = essai_terminal(serial_in, device, K);
fprintf(stderr, "essai terminal -> %d\n", foo);
return 0;
}
/* ---------------------------------------------------------------- */