alandeassis commented on code in PR #11589:
URL: https://github.com/apache/nuttx/pull/11589#discussion_r1464003100


##########
drivers/modem/alt1250/altcom_lwm2m_hdlr.c:
##########
@@ -352,23 +352,89 @@ static int32_t fwup_srvop_handle(FAR uint8_t *pktbuf, 
size_t pktsz,
 }
 
 /****************************************************************************
- * name: fwupdate_notice_hndl
+ * name: parse_inst_number
  ****************************************************************************/
 
-static int32_t fwupdate_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
-                          FAR void **cb_args, size_t arglen)
+static int parse_inst_number(FAR uint8_t **buf, FAR size_t *bufsz)
 {
-  return fwup_srvop_handle(pktbuf, pktsz, cb_args, arglen);
+  int ret = 0;
+
+  if (!isdigit(**buf))
+    {
+      return -1;
+    }
+
+  while (*bufsz)
+    {
+      if (!isdigit(**buf))
+        {
+          break;
+        }
+
+      ret = ret * 10 + ((**buf) - '0');
+      (*bufsz)--;
+      (*buf)++;
+    }
+
+  return ret;
 }
 
 /****************************************************************************
  * name: server_op_notice_hndl
  ****************************************************************************/
 
 static int32_t server_op_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
-                          FAR void **cb_args, size_t arglen)
+                                     FAR void **cb_args, size_t arglen)
 {
-  return fwup_srvop_handle(pktbuf, pktsz, cb_args, arglen);
+  int i;
+  FAR int *event = (FAR int *)&cb_args[0];
+  FAR int *srvid = (FAR int *)&cb_args[1];
+  FAR int *inst  = (FAR int *)cb_args[2];
+
+  /* The valiable of "inst" is a type of struct lwm2mstub_instance_s in fact.
+   * But actually it is the same as int[4].
+   * To make simpler logic, inst is defined as int[4] (int pointer).
+   */
+
+  /* Set invalid value as initialize */
+
+  *srvid = -1;
+  inst[0] = -1;
+  inst[1] = -1;
+  inst[2] = -1;
+  inst[3] = -1;
+
+  /* Expected unsolicited event
+   *    %LWM2MOPEV: <event>[,[<serverShortId>],[<ObjectID>],
+   *                         [<ObjectInstanceID>],[<ResourceID>],
+   *                         [<ResourceInstanceID>],[<val>][,<MsgId>]]
+   */
+
+  *event = parse_inst_number(&pktbuf, &pktsz);
+  if (*event < 0)
+    {
+      return -1;
+    }
+
+  if (pktsz > 0 && pktbuf[0] == ',')
+    {
+      pktsz--;
+      pktbuf++;
+
+      *srvid = parse_inst_number(&pktbuf, &pktsz);
+
+      for (i = 0; i < 4 && pktsz > 0 && pktbuf[0] == ','; i++)
+        {
+          /* Skip comma */
+
+          pktbuf++;
+          pktsz--;
+
+          inst[i] = parse_inst_number(&pktbuf, &pktsz);
+        }
+    }
+
+  return 1;

Review Comment:
   > > return TRUE; Maybe you will need to include sys/types.h to find the 
definition
   > 
   > Is it preferred to return 'OK' instead of 'TRUE'?
   
   OK mean 0 in POSIX. Also there is not Description for the functions on this 
drive, so we don't know exactly what it is expecting.



-- 
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