Message ID | 20211015082457.6804-4-roland.gaudig-oss@weidmueller.com |
---|---|
State | Changes Requested |
Headers | show |
Series | suricatta: ipc: add request to get hawkBit server status | expand |
Hi Roland, On 15.10.21 10:24, Roland Gaudig wrote: > From: Roland Gaudig <roland.gaudig@weidmueller.com> > > Add example on how to retrieve the hawkBit sserver status from > Surricatta with the CMD_GET_STATUS IPC protocol. > > Signed-off-by: Roland Gaudig <roland.gaudig@weidmueller.com> > --- > CI fails when JSON is not activated, see: https://source.denx.de/swupdate/swupdate/-/jobs/340677 I will suggest that swupdate-gethawkbitstatus won't be compiled if JSON was not turned on, something like in tools/MAkefile: lib-$(CONFIG_JSON) += swupdate-gethawkbitstatus.o Best regartds, Stefano Babic > tools/Makefile | 1 + > tools/swupdate-gethawkbitstatus.c | 56 +++++++++++++++++++++++++++++++ > 2 files changed, 57 insertions(+) > create mode 100644 tools/swupdate-gethawkbitstatus.c > > diff --git a/tools/Makefile b/tools/Makefile > index 013022b..8c495c9 100644 > --- a/tools/Makefile > +++ b/tools/Makefile > @@ -10,6 +10,7 @@ > > lib-y += \ > swupdate-client.o \ > + swupdate-gethawkbitstatus.o \ > swupdate-progress.o \ > swupdate-hawkbitcfg.o \ > swupdate-sendtohawkbit.o \ > diff --git a/tools/swupdate-gethawkbitstatus.c b/tools/swupdate-gethawkbitstatus.c > new file mode 100644 > index 0000000..fb02b92 > --- /dev/null > +++ b/tools/swupdate-gethawkbitstatus.c > @@ -0,0 +1,56 @@ > +/* > + * Copyright (C) 2021 Weidmueller Interface GmbH & Co. KG > + * Roland Gaudig <roland.gaudig@weidmueller.com> > + * > + * SPDX-License-Identifier: GPL-2.0-only > + */ > + > +/* > + * This is a small example how to retrieve the hawkBit server status > + * from surricata. > + */ > + > +#include <stdio.h> > +#include <json-c/json.h> > + > +#include <network_ipc.h> > + > +int main(int __attribute__ ((__unused__)) argc, > + char __attribute__ ((__unused__)) *argv[]) > +{ > + ipc_message msg; > + struct json_object *parsed_json; > + struct json_object *server; > + struct json_object *status; > + struct json_object *time; > + > + msg.type = SWUPDATE_SUBPROCESS; > + msg.data.procmsg.source = SOURCE_SURICATTA; > + msg.data.procmsg.cmd = CMD_GET_STATUS; > + > + msg.data.procmsg.buf[0] = '\0'; > + msg.data.procmsg.len = 0; > + msg.data.procmsg.timeout = 10; /* Wait 10 s for Suricatta response */ > + > + int rc = ipc_send_cmd(&msg); > + > + if (rc) { > + fprintf(stderr, "Error: ipc_send_cmd failed\n"); > + exit(1); > + } > + > + if (msg.type == ACK) { > + parsed_json = json_tokener_parse(msg.data.procmsg.buf); > + json_object_object_get_ex(parsed_json, "server", &server); > + json_object_object_get_ex(server, "status", &status); > + json_object_object_get_ex(server, "time", &time); > + > + printf("status: %d, time: %s\n", > + json_object_get_int(status), > + json_object_get_string(time)); > + exit(0); > + } else { > + printf("Error: suricatta did respond with NACK.\n"); > + exit(1); > + } > +} >
diff --git a/tools/Makefile b/tools/Makefile index 013022b..8c495c9 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -10,6 +10,7 @@ lib-y += \ swupdate-client.o \ + swupdate-gethawkbitstatus.o \ swupdate-progress.o \ swupdate-hawkbitcfg.o \ swupdate-sendtohawkbit.o \ diff --git a/tools/swupdate-gethawkbitstatus.c b/tools/swupdate-gethawkbitstatus.c new file mode 100644 index 0000000..fb02b92 --- /dev/null +++ b/tools/swupdate-gethawkbitstatus.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2021 Weidmueller Interface GmbH & Co. KG + * Roland Gaudig <roland.gaudig@weidmueller.com> + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +/* + * This is a small example how to retrieve the hawkBit server status + * from surricata. + */ + +#include <stdio.h> +#include <json-c/json.h> + +#include <network_ipc.h> + +int main(int __attribute__ ((__unused__)) argc, + char __attribute__ ((__unused__)) *argv[]) +{ + ipc_message msg; + struct json_object *parsed_json; + struct json_object *server; + struct json_object *status; + struct json_object *time; + + msg.type = SWUPDATE_SUBPROCESS; + msg.data.procmsg.source = SOURCE_SURICATTA; + msg.data.procmsg.cmd = CMD_GET_STATUS; + + msg.data.procmsg.buf[0] = '\0'; + msg.data.procmsg.len = 0; + msg.data.procmsg.timeout = 10; /* Wait 10 s for Suricatta response */ + + int rc = ipc_send_cmd(&msg); + + if (rc) { + fprintf(stderr, "Error: ipc_send_cmd failed\n"); + exit(1); + } + + if (msg.type == ACK) { + parsed_json = json_tokener_parse(msg.data.procmsg.buf); + json_object_object_get_ex(parsed_json, "server", &server); + json_object_object_get_ex(server, "status", &status); + json_object_object_get_ex(server, "time", &time); + + printf("status: %d, time: %s\n", + json_object_get_int(status), + json_object_get_string(time)); + exit(0); + } else { + printf("Error: suricatta did respond with NACK.\n"); + exit(1); + } +}