raiden00pl commented on code in PR #1460:
URL: https://github.com/apache/nuttx-apps/pull/1460#discussion_r1051650601


##########
logging/nxscope/nxscope_pser.c:
##########
@@ -0,0 +1,297 @@
+/****************************************************************************
+ * apps/logging/nxscope/nxscope_pser.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional 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 <assert.h>
+#include <debug.h>
+#include <byteswap.h>
+#include <errno.h>
+#include <string.h>
+
+#include <nuttx/crc16.h>
+
+#include <logging/nxscope/nxscope.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define NXSCOPE_HDR_LEN       (sizeof(struct nxscope_hdr_s))
+#define NXSCOPE_DATA_START    (NXSCOPE_HDR_LEN)
+#define NXSCOPE_BASEFRAME_LEN (NXSCOPE_HDR_LEN + NXSCOPE_CRC_LEN)
+#define NXSCOPE_HDR_SOF       (0x55)
+#define NXSCOPE_CRC_LEN       (sizeof(uint16_t))
+
+/****************************************************************************
+ * Private Type Definition
+ ****************************************************************************/
+
+/* Nxscope serial protocol frame:
+ * +--------------------+------------+-------------+
+ * | HDR [4B]           | frame data | footer [2B] |
+ * +-----+---------+----+------------+-------------+
+ * | SOF | len [1] | id | frame data | crc16 [2]   |
+ * +-----+----+----+----+------------+------+------+
+ * | 0   | 1  | 2  | 3  | ...        | n+1  | n+2  |
+ * +-----+----+----+----+------------+------+------+
+ *
+ * [1] - always little-endian
+ * [2] - always big-endian
+ */
+
+/* Nxscope header */
+
+begin_packed_struct struct nxscope_hdr_s
+{
+  uint8_t  sof;                 /* SOF */
+  uint16_t len;                 /* Frame length */
+  uint8_t  id;                  /* Frame ID */
+} end_packed_struct;
+
+/* Nxscope footer */
+
+begin_packed_struct struct nxscope_footer_s
+{
+  uint16_t crc16;               /* check sum (see nxscope_frame_final()) */
+} end_packed_struct;
+
+/****************************************************************************
+ * Private Function Protototypes
+ ****************************************************************************/
+
+static int nxscope_frame_get(FAR struct nxscope_proto_s *p,
+                             FAR uint8_t *buff, size_t len,
+                             FAR struct nxscope_frame_s *frame);
+static int nxscope_frame_final(FAR struct nxscope_proto_s *p,
+                               uint8_t id,
+                               FAR uint8_t *buff, FAR size_t *len);
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+struct nxscope_proto_ops_s g_nxscope_proto_ser_ops =
+{
+  .frame_get     = nxscope_frame_get,
+  .frame_final   = nxscope_frame_final,
+};
+
+struct nxscope_proto_s g_nxscope_proto_ser =
+{
+  .priv          = NULL,
+  .ops           = &g_nxscope_proto_ser_ops,
+  .footlen       = NXSCOPE_CRC_LEN,
+  .hdrlen        = NXSCOPE_HDR_LEN
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxscope_hdr_fill
+ ****************************************************************************/
+
+static void nxscope_hdr_fill(FAR uint8_t *buff, uint8_t id, uint16_t len)
+{
+  FAR struct nxscope_hdr_s *hdr  = NULL;
+
+  hdr = (FAR struct nxscope_hdr_s *) buff;

Review Comment:
   I missed here DEBUGASSERT(buff)



##########
logging/nxscope/nxscope_pser.c:
##########
@@ -0,0 +1,297 @@
+/****************************************************************************
+ * apps/logging/nxscope/nxscope_pser.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional 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 <assert.h>
+#include <debug.h>
+#include <byteswap.h>
+#include <errno.h>
+#include <string.h>
+
+#include <nuttx/crc16.h>
+
+#include <logging/nxscope/nxscope.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define NXSCOPE_HDR_LEN       (sizeof(struct nxscope_hdr_s))
+#define NXSCOPE_DATA_START    (NXSCOPE_HDR_LEN)
+#define NXSCOPE_BASEFRAME_LEN (NXSCOPE_HDR_LEN + NXSCOPE_CRC_LEN)
+#define NXSCOPE_HDR_SOF       (0x55)
+#define NXSCOPE_CRC_LEN       (sizeof(uint16_t))
+
+/****************************************************************************
+ * Private Type Definition
+ ****************************************************************************/
+
+/* Nxscope serial protocol frame:
+ * +--------------------+------------+-------------+
+ * | HDR [4B]           | frame data | footer [2B] |
+ * +-----+---------+----+------------+-------------+
+ * | SOF | len [1] | id | frame data | crc16 [2]   |
+ * +-----+----+----+----+------------+------+------+
+ * | 0   | 1  | 2  | 3  | ...        | n+1  | n+2  |
+ * +-----+----+----+----+------------+------+------+
+ *
+ * [1] - always little-endian
+ * [2] - always big-endian
+ */
+
+/* Nxscope header */
+
+begin_packed_struct struct nxscope_hdr_s
+{
+  uint8_t  sof;                 /* SOF */
+  uint16_t len;                 /* Frame length */
+  uint8_t  id;                  /* Frame ID */
+} end_packed_struct;
+
+/* Nxscope footer */
+
+begin_packed_struct struct nxscope_footer_s
+{
+  uint16_t crc16;               /* check sum (see nxscope_frame_final()) */
+} end_packed_struct;
+
+/****************************************************************************
+ * Private Function Protototypes
+ ****************************************************************************/
+
+static int nxscope_frame_get(FAR struct nxscope_proto_s *p,
+                             FAR uint8_t *buff, size_t len,
+                             FAR struct nxscope_frame_s *frame);
+static int nxscope_frame_final(FAR struct nxscope_proto_s *p,
+                               uint8_t id,
+                               FAR uint8_t *buff, FAR size_t *len);
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+struct nxscope_proto_ops_s g_nxscope_proto_ser_ops =
+{
+  .frame_get     = nxscope_frame_get,
+  .frame_final   = nxscope_frame_final,
+};
+
+struct nxscope_proto_s g_nxscope_proto_ser =
+{
+  .priv          = NULL,
+  .ops           = &g_nxscope_proto_ser_ops,
+  .footlen       = NXSCOPE_CRC_LEN,
+  .hdrlen        = NXSCOPE_HDR_LEN
+};

Review Comment:
   done



-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to