From patchwork Sun Jan 16 20:19:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Jowsa X-Patchwork-Id: 1580534 X-Patchwork-Delegate: ynezz@true.cz 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=x1ekt7lt; 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=MiCebCNa; 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 4JcRKy1lgjz9ssD for ; Mon, 17 Jan 2022 07:22:43 +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:References:In-Reply-To: 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: List-Owner; bh=T2wZ9V2M9avQi3QBaduDRUa9Qebyxkgsea2JCZfw7z4=; b=x1ekt7lt8zOhOn wtDCB/SUymeoIVekExV0FPxjIuMUpLiM7i0EHW7ljR9RLK75OQXDf4U57dCKJ9gwn5/B0NeoZ8qyG r2dXGxBQBO8LEcD0CqMZWusYVGUECaik7I9ur+2UyajF6EpxetWj3yuXTaIX8sLtmgyB0e+qtJHxF cLHB6vRGs8c/8n1fe2ysHILqC6YR3ylkg15p86R7Mn08pOEnoOJkLBJ7KTdFkFhppRevxTgVI9Yf8 +qhsp97zXtxO5mkiVPv2pjKBq0b+mhyIb5ruTh4Mycnyum2jFsI3RHTru+UurwwCmu5OZGZUpqGfx svSiF5wc2Zn/eyrvncuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9C0Z-00Cvhn-6t; Sun, 16 Jan 2022 20:20:11 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9C0W-00Cvgx-3x for openwrt-devel@lists.openwrt.org; Sun, 16 Jan 2022 20:20:09 +0000 Received: by mail-lf1-x130.google.com with SMTP id d3so49866109lfv.13 for ; Sun, 16 Jan 2022 12:20:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=stQ3E4L9oedubunCgRjIOZgh3IWPLR3GQZjYeFMDYKE=; b=MiCebCNabEYFn/1/IZXlA7C4BT+p66P7fl77lf8fu3CnnfulpEhW/UYyFmmsrzoPVJ 1iTrAWOOzXqjVw4nbhdnitB6yOPdRD89qW0wqzIiOK+Ovodiwc848wLrozwR78CRXygW as2G5Hkc/2WX0YU4/AA/CzxG8WIssr9LUafhOiEaNqreurXkhlEYa9oOrRy1lRjLXmmY YdYdcsWpmpbt0S2TD7XdTMxejSI6AWYhfI+TSxqJYmUZyBho1HHYWCu1BWCoXorNoR59 Y1fykxxQnWt+zzzf34VUEGjiESYqjzUK/PgJ5JFaBWlnKK+PkqxpAzUCIwljiozFCtw8 W1Lw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=stQ3E4L9oedubunCgRjIOZgh3IWPLR3GQZjYeFMDYKE=; b=HL9qF9tQL0Y4Sg/wyFnBUVdu1yC5rGicSY6hxxCDYrnieANqdgtXOdkaC6UMXq1fbt 4qroxr/9tpZfS3Q6hAUnuDNHciHvtiQbh1XX1+Yvz+kq6TqOKzdocA1P4Vk0RaO9yxrz MjQcH4jDWJv3QlFkV2LSEQ+k6LFp2Xv1P3CbUgv3GormdNQ/ZhQaK4OjtV61pfreswZ3 yxI/LuKdP+58oJ7rgFlJStG2fQYu8KCkQdXyYuaIp9MqgFUha2oNcq1WHozChgDKFSfY woEVWrEps/UpWiTKaIRADan2+p7SZDBhhMomD/LzpDGeOOR7yvGP+fpwZnS4jcrq9jUX xSxA== X-Gm-Message-State: AOAM530h/HLTZeGnbgQ/mIIqnMwfQMYVR1Z6FufW8VylcwQCmAIh1YPe 9+EcjOfxNx3/uwJR4ZNrBW+XhBkw5gE= X-Google-Smtp-Source: ABdhPJyFn6nU+DhWn/3mgeu/KCYmc1dtjkQVRRTBfw6w4yDEZQRpssJeCisAcBHqIFyJr6k0JaaMRQ== X-Received: by 2002:a19:c209:: with SMTP id l9mr8765818lfc.679.1642364406192; Sun, 16 Jan 2022 12:20:06 -0800 (PST) Received: from wjow-XPS-15-9570.lan (host-188-122-2-56.finemedia.com.pl. [188.122.2.56]) by smtp.gmail.com with ESMTPSA id 4sm684911ljq.65.2022.01.16.12.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jan 2022 12:20:05 -0800 (PST) From: Wojciech Jowsa To: openwrt-devel@lists.openwrt.org Cc: Wojciech Jowsa Subject: [PATCH] ugps: add baud rate command line option Date: Sun, 16 Jan 2022 21:19:15 +0100 Message-Id: <20220116201915.253654-1-wojciech.jowsa@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <042c0b00-40d3-7cf6-806a-a8dba78e52a6@phrozen.org> References: <042c0b00-40d3-7cf6-806a-a8dba78e52a6@phrozen.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220116_122008_169797_EAE5439F X-CRM114-Status: GOOD ( 11.27 ) 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: currently, gps device baud rate is hardcoded so ugps might not work with devices that baud rate is configured to be different than 4800. Signed-off-by: Wojciech Jowsa --- main.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) 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:130 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 currently, gps device baud rate is hardcoded so ugps might not work with devices that baud rate is configured to be different than 4800. Signed-off-by: Wojciech Jowsa --- main.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 2ab0f8c..bb1592b 100644 --- a/main.c +++ b/main.c @@ -105,10 +105,31 @@ usage(const char *prog) " -s Path to ubus socket\n" " -d Enable debug messages\n" " -S Print messages to stdout\n" + " -b Set gps device baud rate\n" "\n", prog); return -1; } +static speed_t get_baudrate(int baudrate) +{ + switch (baudrate) { + case 4800: + return B4800; + case 9600: + return B9600; + case 19200: + return B19200; + case 38400: + return B38400; + case 57600: + return B57600; + case 115200: + return B115200; + default: + return B0; + } +} + int main(int argc, char ** argv) { @@ -116,6 +137,7 @@ main(int argc, char ** argv) char *device = NULL; char *dbglvl = getenv("DBGLVL"); int ulog_channels = ULOG_KMSG; + speed_t baudrate = B4800; signal(SIGPIPE, SIG_IGN); @@ -124,7 +146,7 @@ main(int argc, char ** argv) unsetenv("DBGLVL"); } - while ((ch = getopt(argc, argv, "ad:s:S")) != -1) { + while ((ch = getopt(argc, argv, "ad:s:S:b:")) != -1) { switch (ch) { case 'a': adjust_clock = -1; @@ -138,11 +160,19 @@ main(int argc, char ** argv) case 'S': ulog_channels = ULOG_STDIO; break; + case 'b': + baudrate = get_baudrate(atoi(optarg)); + break; default: return usage(argv[0]); } } + if (!baudrate) { + fprintf(stderr, "ERROR: incorrect baud rate \n"); + return usage(argv[0]); + } + if (argc - optind < 1) { fprintf(stderr, "ERROR: missing device parameter\n"); return usage(argv[0]); @@ -156,7 +186,7 @@ main(int argc, char ** argv) conn.cb = ubus_connect_handler; ubus_auto_connect(&conn); - if (nmea_open(device, &stream, B4800) < 0) + if (nmea_open(device, &stream, baudrate) < 0) return -1; uloop_run();