From patchwork Thu Nov 4 11:41:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Jowsa X-Patchwork-Id: 1550863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=1qVPlepT; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=f1/gO8rg; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HlMNd3157z9s1l for ; Thu, 4 Nov 2021 22:48:48 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=tLeBBgIS68126Bx8P/9EA3TycYxy3katr9MBTdZTNxw=; b=1qVPlepTRM448s +/krob7hijNyK02hi7BtnIxSQxwGLX5oHBwH4m15eF9MS4c/4JfCYL6S7pEN9NGtY0ZF1Ay8bYXEX w3aLCkUnumgNDbPdV5uIq93aBv9r8W/cWoMZK6lrffEYK2k9AW/rWNmDkWQh/XBI24BnCji9dnJk+ usHg0TDXy+dMuuqcYmcxNltBPD7WKyQaSGo+PbktKH1qU1gRNmyZd8XS5dRDvqpmbqlVvXvbZaDPN IMCGONT5kqrxtcYMrn3dgwrU7/JaovoD3TSEBxanQTWYcAMdJJLll4hMOjcrUUx66LVjAw+KXUB1g S1qg5HbrdPjOvI2B/3GQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mib9g-008jv5-Il; Thu, 04 Nov 2021 11:43:40 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mib9d-008jtk-47 for openwrt-devel@lists.openwrt.org; Thu, 04 Nov 2021 11:43:38 +0000 Received: by mail-lj1-x232.google.com with SMTP id v15so1905732ljc.0 for ; Thu, 04 Nov 2021 04:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PKZdoHjowtGFnN7HZOE48oBKe45l91dASHJivRed16g=; b=f1/gO8rg879dQfgDuA7tXINQJuGa5LfZEGOjpiYtZLIZQ0yIifZ1Z7zduEjpJkY9jB bkHwCG5/vPUaNWEeoWiF+MEpI3LJr/wqnzqiycU4Gjb6zoP6TNyuSgcxfW6aIOCj+iaP 5GETbBGPBMj7Qk6EcQBn0SKqMLdlOHlsgL1bf0lveNUl0vY8XWTsNg+1jKD3Q7z5xiVh Ss3h+DqJ5fkBGrLa0CZ/54q6UYl0UukQbn2DO2hgK6ihGcmoZ8XSM05dhgwsE7NxJJ58 Fql7/krPtcwg0v4mg/Ip9emRggvnpq4zdPb16J8dLRmDjUxv+0orNmE7JFpvL8Rjtpun j7lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PKZdoHjowtGFnN7HZOE48oBKe45l91dASHJivRed16g=; b=6nN7hYKfKXINMM3ifE7qVxuvzm+JxW1PVxwgAR+jGP6iRcntI2AE6cW3zW3eLIJMty 41lgrKPsqhJqAVFmBfCpwX5seZxmK7rb3xaEasefyOZMtwhCH3NpStjsghxXke4pgnNJ 7rbzpHQ6xHcWGhGtKjfvoSsTNT7hc/SEIbuL8VoaqY2Eb9Do3LkmZ4vZ1WjGJWkxZNOy PVbbkNiNEN56D1b93tGPzfFmU57/ezSaOWUrUOQo7tVa6GcdQRovMTiw+Zlj5Yf7+jQy H9fZsokIZ+ne/CDYSRl4L6rwl3DwW4Z6ORg10mGbONl2Z24rEcxXy88jtIpASfEPhv6y MPgA== X-Gm-Message-State: AOAM532TyfVsVTjpYrKRb2At+kf+v5WlV+rsZ2Lt9GvhtRDaLjc6kKpQ L3wwz8RxP2gtiAK7aKjxASfY6GePko4= X-Google-Smtp-Source: ABdhPJwvCqhHQtdhprcMN8kdBLs/gzF1JLFCKv51SNdodtl8D0GAZJrt7MrsBCrKE8yd3lSaJg5E3A== X-Received: by 2002:a05:651c:553:: with SMTP id q19mr46217398ljp.53.1636026212445; Thu, 04 Nov 2021 04:43:32 -0700 (PDT) Received: from wjow-XPS-15-9570.lan ([31.179.130.194]) by smtp.gmail.com with ESMTPSA id d10sm441800lfg.157.2021.11.04.04.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 04:43:32 -0700 (PDT) From: Wojciech Jowsa To: openwrt-devel@lists.openwrt.org Cc: Wojciech Jowsa Subject: [PATCH] ubus: add option for enabling ubus notification Date: Thu, 4 Nov 2021 12:41:43 +0100 Message-Id: <20211104114143.34397-1-wojciech.jowsa@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211104_044337_188339_7BE59E68 X-CRM114-Status: GOOD ( 15.70 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: ubus notifications have to be enabled to support publish / subscribe pattern. This pattern is an alternative to polling, and can be used e.g. for streaming gps data directly to other application or a [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:232 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wojciech.jowsa[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org ubus notifications have to be enabled to support publish / subscribe pattern. This pattern is an alternative to polling, and can be used e.g. for streaming gps data directly to other application or a browser. Signed-off-by: Wojciech Jowsa --- main.c | 41 +++++++++++++++++++++++++++++++++++------ nmea.c | 5 ++++- nmea.h | 1 + 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 2ab0f8c..1626c01 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * Copyright (C) 2014 John Crispin + * Copyright (C) 2014 John Crispin */ #include @@ -34,6 +34,7 @@ static struct blob_buf b; static char *ubus_socket; struct timespec stamp = { 0 }; unsigned int adjust_clock = 0; +bool notify = false; void gps_timestamp(void) @@ -41,10 +42,8 @@ gps_timestamp(void) clock_gettime(CLOCK_MONOTONIC, &stamp); } -static int -gps_info(struct ubus_context *ctx, struct ubus_object *obj, - struct ubus_request_data *req, const char *method, - struct blob_attr *msg) +static void +prepare_data() { struct timespec now; @@ -67,6 +66,15 @@ gps_info(struct ubus_context *ctx, struct ubus_object *obj, if (gps_fields & GPS_FIELD_SPD) blobmsg_add_string(&b, "speed", speed); } +} + +static int +gps_info(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + prepare_data(); + ubus_send_reply(ctx, req, b.head); return UBUS_STATUS_OK; @@ -105,10 +113,28 @@ usage(const char *prog) " -s Path to ubus socket\n" " -d Enable debug messages\n" " -S Print messages to stdout\n" + " -n Enable ubus notfication\n" "\n", prog); return -1; } +void +notify_ubus() +{ + int err; + + if (!notify) { + return; + } + + prepare_data(); + + err = ubus_notify(&(conn.ctx), &gps_object, "update", b.head, -1); + if (err) { + ERROR("Ubus notify failed: %s\n", ubus_strerror(err)); + } +} + int main(int argc, char ** argv) { @@ -124,7 +150,7 @@ main(int argc, char ** argv) unsetenv("DBGLVL"); } - while ((ch = getopt(argc, argv, "ad:s:S")) != -1) { + while ((ch = getopt(argc, argv, "and:s:S")) != -1) { switch (ch) { case 'a': adjust_clock = -1; @@ -138,6 +164,9 @@ main(int argc, char ** argv) case 'S': ulog_channels = ULOG_STDIO; break; + case 'n': + notify = true; + break; default: return usage(argv[0]); } diff --git a/nmea.c b/nmea.c index e86f68f..44a739a 100644 --- a/nmea.c +++ b/nmea.c @@ -52,7 +52,7 @@ struct nmea_param { } nmea_params[MAX_NMEA_PARAM]; static int nmea_bad_time; -char longitude[33] = { 0 }, latitude[33] = { 0 }, course[17] = { 0 }, speed[17] = { 0 }, elevation[17] = { 0 }; +char longitude[33] = { 0 }, latitude[33] = { 0 }, course[17] = { 0 }, speed[17] = { 0 }, elevation[17] = { 0 }; int gps_valid = 0; char gps_fields = 0; @@ -123,6 +123,7 @@ parse_gps_coords(char *latstr, char *vhem, char *lonstr, char *hhem) gps_fields |= GPS_FIELD_LAT | GPS_FIELD_LON; gps_timestamp(); + notify_ubus(); } static void @@ -224,6 +225,7 @@ nmea_gga_cb(void) return; strncpy(elevation, nmea_params[9].str, sizeof(elevation)); gps_fields |= GPS_FIELD_ALT; + notify_ubus(); DEBUG(4, "height: %s\n", elevation); } @@ -235,6 +237,7 @@ nmea_vtg_cb(void) strncpy(course, nmea_params[1].str, sizeof(course)); strncpy(speed, nmea_params[7].str, sizeof(speed)); gps_fields |= GPS_FIELD_COG | GPS_FIELD_SPD; + notify_ubus(); DEBUG(4, "course: %s\n", course); DEBUG(4, "speed: %s\n", speed); } diff --git a/nmea.h b/nmea.h index 2de06dc..4bd07d8 100644 --- a/nmea.h +++ b/nmea.h @@ -27,6 +27,7 @@ extern char longitude[33], latitude[33], course[17], speed[17], elevation[17]; extern int nmea_open(char *dev, struct ustream_fd *s, speed_t speed); extern void gps_timestamp(void); extern unsigned int adjust_clock; +extern void notify_ubus(void); extern char gps_fields; #define GPS_FIELD_LAT (1<<0) #define GPS_FIELD_LON (1<<1)