From a7e337c459b2b7284757127b64235579b061561c Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 25 Mar 2013 21:33:29 +0100 Subject: cethcan: skeleton --- cethcan/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 cethcan/main.c (limited to 'cethcan/main.c') diff --git a/cethcan/main.c b/cethcan/main.c new file mode 100644 index 0000000..938721e --- /dev/null +++ b/cethcan/main.c @@ -0,0 +1,45 @@ +#include "cethcan.h" + +struct event_base *ev_base; +json_t *config; + +int main(int argc, char **argv) +{ + int optch = 0; + const char *cfgfile = "cethcan.json"; + json_error_t je; + + do { + optch = getopt(argc, argv, "c:"); + switch (optch) { + case 'c': + cfgfile = optarg; + break; + case -1: + break; + } + } while (optch != -1); + + if (optind < argc) { + fprintf(stderr, "leftover arguments\n"); + return 1; + } + + config = json_load_file(cfgfile, JSON_REJECT_DUPLICATES, &je); + if (!config) { + fprintf(stderr, "failed to load config:\n%s:%d:%d %s\n", + je.source, je.line, je.column, je.text); + return 1; + } + if (!json_is_object(config)) { + fprintf(stderr, "config must be object/dictionary\n"); + return 1; + } + + ev_base = event_base_new(); + + can_init(); + + event_base_loop(ev_base, 0); + return 0; +} -- cgit v1.2.1 From f5c47e42e40e980c51fa561ca8bb0beb421ae0c0 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 25 Mar 2013 22:08:41 +0100 Subject: cethcan: more code --- cethcan/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'cethcan/main.c') diff --git a/cethcan/main.c b/cethcan/main.c index 938721e..6d79a9f 100644 --- a/cethcan/main.c +++ b/cethcan/main.c @@ -1,13 +1,13 @@ #include "cethcan.h" struct event_base *ev_base; -json_t *config; int main(int argc, char **argv) { int optch = 0; const char *cfgfile = "cethcan.json"; json_error_t je; + json_t *config, *ethercfg; do { optch = getopt(argc, argv, "c:"); @@ -40,6 +40,13 @@ int main(int argc, char **argv) can_init(); + ethercfg = json_object_get(config, "ethernet"); + for (size_t i = 0; i < json_array_size(ethercfg); i++) { + json_t *c = json_array_get(ethercfg, i); + if (ether_init(c)) + return 1; + } + event_base_loop(ev_base, 0); return 0; } -- cgit v1.2.1 From 1b5e4f4ba195ad4ed02cfac6129c386c4aeaf7cd Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 25 Mar 2013 23:01:50 +0100 Subject: cethcan: more code --- cethcan/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'cethcan/main.c') diff --git a/cethcan/main.c b/cethcan/main.c index 6d79a9f..0794254 100644 --- a/cethcan/main.c +++ b/cethcan/main.c @@ -7,7 +7,7 @@ int main(int argc, char **argv) int optch = 0; const char *cfgfile = "cethcan.json"; json_error_t je; - json_t *config, *ethercfg; + json_t *config, *ethercfg, *lightcfg; do { optch = getopt(argc, argv, "c:"); @@ -47,6 +47,13 @@ int main(int argc, char **argv) return 1; } + lightcfg = json_object_get(config, "lights"); + for (size_t i = 0; i < json_array_size(lightcfg); i++) { + json_t *c = json_array_get(lightcfg, i); + if (light_init_conf(c)) + return 1; + } + event_base_loop(ev_base, 0); return 0; } -- cgit v1.2.1 From a69a211a4a95e5c4ac0055a8f2de8ec1c56a7d1a Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 25 Mar 2013 23:19:42 +0100 Subject: cethcan: more code --- cethcan/main.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cethcan/main.c') diff --git a/cethcan/main.c b/cethcan/main.c index 0794254..d6c5bbf 100644 --- a/cethcan/main.c +++ b/cethcan/main.c @@ -54,6 +54,8 @@ int main(int argc, char **argv) return 1; } + http_init(); + event_base_loop(ev_base, 0); return 0; } -- cgit v1.2.1 From cd4484ab068678edfa9335a1c6d7c91b93793970 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sat, 1 Jun 2013 00:00:46 +0200 Subject: socketcan v0 --- cethcan/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'cethcan/main.c') diff --git a/cethcan/main.c b/cethcan/main.c index d6c5bbf..5bdca0a 100644 --- a/cethcan/main.c +++ b/cethcan/main.c @@ -7,7 +7,7 @@ int main(int argc, char **argv) int optch = 0; const char *cfgfile = "cethcan.json"; json_error_t je; - json_t *config, *ethercfg, *lightcfg; + json_t *config, *ethercfg, *lightcfg, *socancfg; do { optch = getopt(argc, argv, "c:"); @@ -54,6 +54,13 @@ int main(int argc, char **argv) return 1; } + socancfg = json_object_get(config, "socketcan"); + for (size_t i = 0; i < json_array_size(socancfg); i++) { + json_t *c = json_array_get(socancfg, i); + if (socan_init(c)) + return 1; + } + http_init(); event_base_loop(ev_base, 0); -- cgit v1.2.1