# HG changeset patch # User Mychaela Falconia # Date 1513472262 0 # Node ID 182c3ae209f6ee4760f64ae96fa9878468a6c36f # Parent b8479251ad0a1d6763df0cbd0cf5df75e558833f compile-fc-batt tool written, compiles diff -r b8479251ad0a -r 182c3ae209f6 .hgignore --- a/.hgignore Wed Nov 22 19:15:29 2017 +0000 +++ b/.hgignore Sun Dec 17 00:57:42 2017 +0000 @@ -8,6 +8,7 @@ ^ffstools/cal2text/fc-cal2text$ ^ffstools/caltools/c1xx-calextr$ ^ffstools/caltools/fc-cal2bin$ +^ffstools/newcomp/compile-fc-batt$ ^ffstools/tiaud/compile$ ^ffstools/tiaud/decomp$ ^ffstools/tiaud/mkvol$ diff -r b8479251ad0a -r 182c3ae209f6 ffstools/newcomp/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ffstools/newcomp/Makefile Sun Dec 17 00:57:42 2017 +0000 @@ -0,0 +1,16 @@ +CC= gcc +CFLAGS= -O2 +PROGS= compile-fc-batt +INSTBIN=/opt/freecalypso/bin + +all: ${PROGS} + +compile-fc-batt: compile-fc-batt.c + ${CC} ${CFLAGS} -o $@ $@.c + +install: ${PROGS} + mkdir -p ${INSTBIN} + install -c ${PROGS} ${INSTBIN} + +clean: + rm -f ${PROGS} diff -r b8479251ad0a -r 182c3ae209f6 ffstools/newcomp/compile-fc-batt.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ffstools/newcomp/compile-fc-batt.c Sun Dec 17 00:57:42 2017 +0000 @@ -0,0 +1,110 @@ +/* + * This utility compiles a table of battery thresholds for the new FreeCalypso + * battery management code from ASCII source into the binary form suitable + * for uploading into /etc/batterytab on a FreeCalypso device. + */ + +#include +#include +#include +#include +#include +#include "../../rvinterf/include/exitcodes.h" + +char *infname; +FILE *inf, *outf; +char linebuf[256]; +int lineno, record_count; +unsigned last_mv, last_percent; + +process_line() +{ + char *cp; + unsigned mv, percent; + + for (cp = linebuf; isspace(*cp); cp++) + ; + if (*cp == '\0' || *cp == '#') + return(0); + if (!isdigit(*cp)) { +inv: fprintf(stderr, "%s line %d: invalid syntax\n", infname, + lineno); + exit(ERROR_USAGE); + } + mv = strtoul(cp, 0, 10); + while (isdigit(*cp)) + cp++; + if (!isspace(*cp)) + goto inv; + while (isspace(*cp)) + cp++; + if (!isdigit(*cp)) + goto inv; + percent = strtoul(cp, 0, 10); + while (isdigit(*cp)) + cp++; + while (isspace(*cp)) + cp++; + if (*cp != '\0' && *cp != '#') + goto inv; + if (mv > 0xFFFF) { + fprintf(stderr, "%s line %d: the millivolt value is invalid\n", + infname, lineno); + exit(ERROR_USAGE); + } + if (percent > 100) { + fprintf(stderr, "%s line %d: the percent value is invalid\n", + infname, lineno); + exit(ERROR_USAGE); + } + if (record_count) { + if (mv >= last_mv) { + fprintf(stderr, + "%s line %d: millivolt numbers must be decreasing\n", + infname, lineno); + exit(ERROR_USAGE); + } + if (percent >= last_percent) { + fprintf(stderr, + "%s line %d: percent numbers must be decreasing\n", + infname, lineno); + exit(ERROR_USAGE); + } + } + putc(mv, outf); + putc(mv >> 8, outf); + putc(percent, outf); + putc(0, outf); + last_mv = mv; + last_percent = percent; + record_count++; + return(1); +} + +main(argc, argv) + char **argv; +{ + if (argc != 3) { + fprintf(stderr, "usage: %s srcfile output-binfile\n", argv[0]); + exit(ERROR_USAGE); + } + infname = argv[1]; + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(ERROR_UNIX); + } + outf = fopen(argv[2], "w"); + if (!outf) { + perror(argv[2]); + exit(ERROR_UNIX); + } + for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) + process_line(); + fclose(inf); + fclose(outf); + if (record_count) + exit(0); + fprintf(stderr, "error: %s is empty\n", infname); + exit(ERROR_USAGE); +}