summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/daemon/genversion.sh9
-rw-r--r--src/daemon/main.c45
-rw-r--r--src/daemon/meson.build20
-rw-r--r--src/daemon/settings.c35
-rw-r--r--src/daemon/usurpation.conf2
-rw-r--r--src/device/main.ino62
-rw-r--r--src/device/meson.build17
-rw-r--r--src/meson.build5
8 files changed, 195 insertions, 0 deletions
diff --git a/src/daemon/genversion.sh b/src/daemon/genversion.sh
new file mode 100755
index 0000000..d182db6
--- /dev/null
+++ b/src/daemon/genversion.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+versionstring=$(git describe 2>/dev/null)
+
+if [[ -z $versionstring ]]; then
+ versionstring=$(cat $1)
+fi
+
+echo "const char * const version = \"$versionstring\";" > $2
diff --git a/src/daemon/main.c b/src/daemon/main.c
new file mode 100644
index 0000000..9ecdd4d
--- /dev/null
+++ b/src/daemon/main.c
@@ -0,0 +1,45 @@
+/*
+ * Usurpation – server daemon main logic
+ *
+ * Copyright (C) 2019 Gediminas Jakutis
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <unistd.h>
+#include <time.h>
+#include <stdio.h>
+#include "settings.h"
+
+/* the logic is a placeholder right now */
+int main(int argc, char **argv)
+{
+ extern const char * const version;
+ struct timespec t = {3600, 0}; /* one hour */
+
+ printf("Usurpation daemon version %s starting\n", version);
+
+ /* by default and if running by as a system service, the init system
+ * needs to keep control of the process and thus only detach if
+ * requested when ran manually by a user.
+ */
+ if (setting_detach()) {
+ daemon(0, 0);
+ }
+
+ while(!(nanosleep(&t, NULL))) {
+ /* noop */
+ }
+}
diff --git a/src/daemon/meson.build b/src/daemon/meson.build
new file mode 100644
index 0000000..48190c8
--- /dev/null
+++ b/src/daemon/meson.build
@@ -0,0 +1,20 @@
+d_filenames = [
+ 'main.c',
+ 'settings.c',
+]
+
+d_conf_filenames = [
+ 'usurpation.conf'
+]
+
+d_version_filename = 'version.c'
+
+version_script = files('genversion.sh')
+
+version = custom_target('version',
+ input : version_fallback,
+ output : d_version_filename,
+ command : [version_script, '@INPUT@', '@OUTPUT@'])
+
+d_sources = files(d_filenames)
+d_conf = files(d_conf_filenames)
diff --git a/src/daemon/settings.c b/src/daemon/settings.c
new file mode 100644
index 0000000..6796ac1
--- /dev/null
+++ b/src/daemon/settings.c
@@ -0,0 +1,35 @@
+/*
+ * Usurpation – server daemon settings handling
+ *
+ * Copyright (C) 2019 Gediminas Jakutis
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "settings.h"
+
+static struct settings {
+ int daemonize;
+} settings;
+
+int setting_detach(void)
+{
+ /* should be, in this order: looking at options provided via command
+ * line arguments, looking at at /etc/conf.d/usurpation.conf or
+ * using default.
+ * Right now just uses default.
+ */
+ return settings.daemonize;
+}
diff --git a/src/daemon/usurpation.conf b/src/daemon/usurpation.conf
new file mode 100644
index 0000000..3407ef1
--- /dev/null
+++ b/src/daemon/usurpation.conf
@@ -0,0 +1,2 @@
+# currently the configuration file is unused
+deamonize 0
diff --git a/src/device/main.ino b/src/device/main.ino
new file mode 100644
index 0000000..b028d17
--- /dev/null
+++ b/src/device/main.ino
@@ -0,0 +1,62 @@
+/*
+ * Usurpation – wearable device main logic
+ *
+ * Copyright (C) 2019 Gediminas Jakutis
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+
+static const unsigned int internal_led = 2;
+
+unsigned int toggleled(void);
+
+void setup(void)
+{
+ pinMode(internal_led, OUTPUT);
+
+ /* don't set pin mode here, it will get toggled at the very start of
+ * the logic loop, either way.
+ */
+}
+
+/* the logic is a placeholder right now */
+void loop(void)
+{
+ /* sleep length to use */
+ static unsigned int delta = 100;
+
+ /* progresivelly grow the time delta while changing state*/
+ delta += delta >> (6 + toggleled());
+
+ /* sleep */
+ delay(delta);
+}
+
+/* toggle the bult-in led and return current state */
+unsigned int toggleled(void)
+{
+ static unsigned int state = 0;
+
+ state = !state;
+ /* as the cathode of the builtin diode is connected to the MCU's pin,
+ * while the anode is connected to Vcc, to turn it off, we need to set
+ * the pin to HIGH.
+ */
+ digitalWrite(internal_led, state ? LOW : HIGH);
+
+ return state;
+}
diff --git a/src/device/meson.build b/src/device/meson.build
new file mode 100644
index 0000000..9bb9b69
--- /dev/null
+++ b/src/device/meson.build
@@ -0,0 +1,17 @@
+fw_image = 'fw.bin'
+if get_option('fwbuild')
+ espmake = find_program('espmake')
+
+ sourcedir = meson.current_source_dir()
+ fw_filenames = ['main.ino']
+ fw_sources = files(fw_filenames)
+ fw = custom_target('fw',
+ output : fw_image,
+ input : fw_sources,
+ command : [espmake, '-C', sourcedir, '&&', 'cp', '/tmp/mkESP/main_d1_mini/main.bin', '@OUTDIR@/' + fw_image], install : true, install_dir : resource_dir)
+
+ if get_option('fwflash')
+ esptool = find_program('esptool.py')
+ run_target('flash_fw', depends : fw, command : [esptool, 'write_flash', '0x0', fw])
+ endif
+endif
diff --git a/src/meson.build b/src/meson.build
new file mode 100644
index 0000000..be166e6
--- /dev/null
+++ b/src/meson.build
@@ -0,0 +1,5 @@
+subdir('daemon')
+subdir('device')
+
+sources = [d_sources]
+conf = [d_conf]