acassis commented on code in PR #3341:
URL: https://github.com/apache/nuttx-apps/pull/3341#discussion_r2701555414


##########
sensors/netsensor/netsensor_main.c:
##########
@@ -0,0 +1,246 @@
+/****************************************************************************
+ * apps/sensors/netsensor/netsensor_main.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for asyslogditional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <fcntl.h>
+#include <poll.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <syslog.h>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+#include <getopt.h>
+
+#include <uORB/uORB.h>
+
+#include "helptext.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEFAULT_PORT (5555)
+#define DEFAULT_QLEN (5)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void print_usage(FILE *sink) { fprintf(sink, HELP_TEXT); }
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv)
+{
+  int err;
+  int netfd;
+  int sock;
+  ssize_t brecvd;
+  const struct orb_metadata *meta;
+  struct sockaddr_in addr; /* TODO: IPv6 support */
+  socklen_t addrlen = sizeof(addr);
+  int sockoptval;
+  void *dbuf = NULL;
+
+  const char *topic = NULL;
+  uint16_t port = DEFAULT_PORT;
+  uint16_t queue_len = DEFAULT_QLEN;
+  int devno = 0;
+  bool usedevno = false;
+  bool restamp = false;
+
+  /* Get parameters for operation from the command line. */
+
+  int c;
+  while ((c = getopt(argc, argv, ":p:q:d:th")) != -1)
+    {
+      switch (c)
+        {
+        case 'h':
+          print_usage(stdout);
+          return EXIT_SUCCESS;
+          break;
+        case 'p':
+          port = strtoul(optarg, NULL, 10);
+          break;
+        case 'd':
+          usedevno = true;
+          devno = atoi(optarg);
+          break;
+        case 'q':
+          queue_len = strtoul(optarg, NULL, 10);
+          break;
+        case 't':
+          restamp = true;
+          break;
+        case '?':
+          fprintf(stderr, "Unknown option -%c\n", optopt);
+          return EXIT_FAILURE;
+          break;
+        }
+    }
+
+  /* Get topic name */
+
+  if (optind >= argc)
+    {
+      fprintf(stderr, "Missing topic.\n");
+      print_usage(stderr);
+      return EXIT_FAILURE;
+    }
+
+  topic = argv[optind];
+
+  /* Get topic metadata */
+
+  meta = orb_get_meta(topic);
+  if (meta == NULL)
+    {
+      fprintf(stderr, "Could not get metadata for topic '%s'\n", topic);
+      return EXIT_FAILURE;
+    }
+
+  /* Set up topic advertisement */
+
+  if (usedevno)

Review Comment:
   ```suggestion
     if (usedevno > 0)



##########
sensors/netsensor/netsensor_main.c:
##########
@@ -0,0 +1,246 @@
+/****************************************************************************
+ * apps/sensors/netsensor/netsensor_main.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for asyslogditional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <fcntl.h>
+#include <poll.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <syslog.h>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+#include <getopt.h>
+
+#include <uORB/uORB.h>
+
+#include "helptext.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEFAULT_PORT (5555)
+#define DEFAULT_QLEN (5)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void print_usage(FILE *sink) { fprintf(sink, HELP_TEXT); }
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv)
+{
+  int err;
+  int netfd;
+  int sock;
+  ssize_t brecvd;
+  const struct orb_metadata *meta;
+  struct sockaddr_in addr; /* TODO: IPv6 support */

Review Comment:
   @linguini1 not an issue, but normally structs and complex type are defined 
early inside a function, I think this is just a convention that Greg created, 
but in some cases it avoid misalignment, i.e. it you have an uint8_t followed 
by a struct definition. Maybe others here have a better explanation why this 
convention is used, since the C compiler don't care much about the variables 
position



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to