changeset 321:0cb766828d7a

fc-fsio: implemented write-battery-table and write-charging-config commands
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 17 Dec 2017 03:31:54 +0000
parents 7572c35a768a
children ee6443191465
files rvinterf/etmsync/Makefile rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/fsnew.c
diffstat 3 files changed, 76 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/Makefile	Sun Dec 17 02:25:05 2017 +0000
+++ b/rvinterf/etmsync/Makefile	Sun Dec 17 03:31:54 2017 +0000
@@ -10,10 +10,10 @@
 		simplemain.o
 
 FSIO_OBJS=	cl_des.o connect.o dispatch.o fdcmd.o fileio.o fsbasics.o \
-		fscmdtab.o fserr.o fsiomain.o fsmisc.o fspath.o fsread.o \
-		fsupload.o fsuploadrf.o fswrite.o help.o hostmkdir.o interf.o \
-		launchrvif.o memcmd.o memops.o pirimei.o pirmagnetite.o rfcap.o\
-		stddirs.o symlink.o ${LIBRFTAB}
+		fscmdtab.o fserr.o fsiomain.o fsmisc.o fsnew.o fspath.o \
+		fsread.o fsupload.o fsuploadrf.o fswrite.o help.o hostmkdir.o \
+		interf.o launchrvif.o memcmd.o memops.o pirimei.o \
+		pirmagnetite.o rfcap.o stddirs.o symlink.o ${LIBRFTAB}
 
 MEMDUMP_OBJS=	connect.o interf.o launchrvif.o memdump.o memops.o
 
--- a/rvinterf/etmsync/fscmdtab.c	Sun Dec 17 02:25:05 2017 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Sun Dec 17 03:31:54 2017 +0000
@@ -32,6 +32,8 @@
 extern int cmd_upload_file();
 extern int cmd_upload_rf_table();
 extern int cmd_upload_subtree();
+extern int cmd_write_battery_table();
+extern int cmd_write_charging_config();
 
 extern int create_std_dirs();
 extern int get_pirelli_imei();
@@ -70,5 +72,7 @@
 	{"upload-fs", 1, 1, cmd_uploadfs},
 	{"upload-rf-table", 1, 2, cmd_upload_rf_table},
 	{"upload-subtree", 2, 2, cmd_upload_subtree},
+	{"write-battery-table", 1, 1, cmd_write_battery_table},
+	{"write-charging-config", 1, 1, cmd_write_charging_config},
 	{0, 0, 0, 0}
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/fsnew.c	Sun Dec 17 03:31:54 2017 +0000
@@ -0,0 +1,68 @@
+/*
+ * In this module we are going to implement the commands that upload
+ * new FreeCalypso-invented stuff into the FFS of our FC devices.
+ */
+
+#include <sys/wait.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "exitcodes.h"
+
+char batterytab_compile_tool[] = "/opt/freecalypso/bin/compile-fc-batt";
+char charging_compile_tool[]   = "/opt/freecalypso/bin/compile-fc-chg";
+
+upload_fc_table_from_ascii(asciisrc, compiletool, ffs_pathname)
+	char *asciisrc, *compiletool, *ffs_pathname;
+{
+	char tmpfile[] = "/tmp/fc-fsioXXXXXX";
+	int tmpfd;
+	pid_t child, waitres;
+	int status, rc;
+
+	tmpfd = mkstemp(tmpfile);
+	if (tmpfd < 0) {
+		fprintf(stderr, "unable to get temp file via mkstemp()\n");
+		return(ERROR_UNIX);
+	}
+	close(tmpfd);
+	child = vfork();
+	if (child < 0) {
+		fprintf(stderr, "unable to vfork to run compiler tool\n");
+		unlink(tmpfile);
+		return(ERROR_UNIX);
+	}
+	if (!child) {
+		execl(compiletool, compiletool, asciisrc, tmpfile, 0);
+		perror(compiletool);
+		_exit(ERROR_UNIX);
+	}
+	waitres = waitpid(child, &status, 0);
+	if (waitres != child || !WIFEXITED(status)) {
+		fprintf(stderr, "unexpected wait result after compiler run\n");
+		unlink(tmpfile);
+		return(ERROR_UNIX);
+	}
+	rc = WEXITSTATUS(status);
+	if (rc) {
+		unlink(tmpfile);
+		return rc;
+	}
+	rc = fwrite_from_file(ffs_pathname, tmpfile);
+	unlink(tmpfile);
+	return rc;
+}
+
+cmd_write_battery_table(argc, argv)
+	char **argv;
+{
+	return upload_fc_table_from_ascii(argv[1], batterytab_compile_tool,
+					  "/etc/batterytab");
+}
+
+cmd_write_charging_config(argc, argv)
+	char **argv;
+{
+	return upload_fc_table_from_ascii(argv[1], charging_compile_tool,
+					  "/etc/charging");
+}