Modified inputCmd function in cmdLine.c to support 16bit length parameter for command... master
authorHector Ramos <h-ramos@ti.com>
Mon, 11 May 2015 19:40:32 +0000 (12:40 -0700)
committerHector Ramos <h-ramos@ti.com>
Mon, 11 May 2015 19:40:32 +0000 (12:40 -0700)
examples/cmdLine/cmdLine.c

index c4bd0752f09b7147c84c18d9a99545ca500bb7be..9db00fb9fe0342f6365e7b849a38ee82667498d9 100644 (file)
@@ -2191,7 +2191,7 @@ static uint8_t mtZdoMsgCbIncomingCb(MsgCbIncomingFormat_t *msg)
        consolePrint("Status: 0x%02X\n", msg->Status);\r
        consolePrint("ExtAddr: 0x%016llX\n", (long long unsigned int) msg->ExtAddr);\r
        consolePrint("NwkAddr: 0x%04X\n", msg->NwkAddr);\r
-       \r
+\r
        SET_NRM_COLOR();\r
        return 0;\r
 }\r
@@ -3070,51 +3070,65 @@ static void inputCmd(uint16_t index)
                }\r
                else\r
                {\r
-                       uint16_t tempPos = currentPos;\r
-                       uint8_t listLen = input[currentPos - 1];\r
-                       uint8_t listIdx;\r
-                       for (listIdx = 0; listIdx < listLen; listIdx++)\r
-                       {\r
-                               SET_PARAM_COLOR();\r
-                               consolePrint("Enter %s[%d]:\n", commands[index].atts[x].name,\r
-                                       listIdx);\r
-                               SET_NRM_COLOR();\r
-                               consoleGetLine(value, 128);\r
-                               if (attSize == 2)\r
-                               {\r
-                                       sscanf(value, "%x", &tem);\r
-                                       sprintf(value, "%04X", tem);\r
-                                       //strPos = value;\r
-                                       if (tempPos % 2 != 0)\r
-                                       {\r
-                                               tempPos++;\r
-                                               currentPos++;\r
-                                       }\r
-                               }\r
-                               else if (attSize == 1)\r
-                               {\r
-                                       sscanf(value, "%x", &tem);\r
-                                       sprintf(value, "%02X", tem);\r
-                                       //strPos = value;\r
-                               }\r
-                               strPos = value;\r
-                               uint8_t idx;\r
-                               for (idx = 0; idx < attSize; idx++)\r
-                               {\r
-                                       if (strlen(strPos) > 0)\r
-                                       {\r
-                                               sscanf(strPos, "%2hhx",\r
-                                                       &input[tempPos + attSize - 1 - idx]);\r
-                                               strPos += (strPos[2] == ':' ? 3 : 2);\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               input[currentPos + attSize - 1 - idx] = 0;\r
-                                       }\r
-                               }\r
-                               tempPos += attSize;\r
-                       }\r
-                       currentPos += (attSize * commands[index].atts[x].isList);\r
+                       uint16_t tempPos = currentPos;
+                       uint8_t prevAttSize = commands[index].atts[x - 1].size;
+                       uint16_t maxLen = commands[index].atts[x].isList;\r
+                       uint16_t listLen = (prevAttSize == 1) ?
+                                    ((uint16_t)input[currentPos - 1]) :
+                                    BUILD_UINT16(input[currentPos - 2], input[currentPos - 1]);\r
+                       uint16_t listIdx;
+
+                       if(listLen >= maxLen)
+            {
+                consolePrint("\nPlease enter a length less than 0x%02X\n\n", maxLen);
+                x-=2;
+                currentPos -= prevAttSize;
+            }
+                       else
+            {
+                for (listIdx = 0; listIdx < listLen; listIdx++)\r
+                {\r
+                    SET_PARAM_COLOR();\r
+                    consolePrint("Enter %s[%d]:\n", commands[index].atts[x].name,\r
+                            listIdx);\r
+                    SET_NRM_COLOR();\r
+                    consoleGetLine(value, 128);\r
+                    if (attSize == 2)\r
+                    {\r
+                        sscanf(value, "%x", &tem);\r
+                        sprintf(value, "%04X", tem);\r
+                        //strPos = value;\r
+                        if (tempPos % 2 != 0)\r
+                        {\r
+                            tempPos++;\r
+                            currentPos++;\r
+                        }\r
+                    }\r
+                    else if (attSize == 1)\r
+                    {\r
+                        sscanf(value, "%x", &tem);\r
+                        sprintf(value, "%02X", tem);\r
+                        //strPos = value;\r
+                    }\r
+                    strPos = value;\r
+                    uint8_t idx;\r
+                    for (idx = 0; idx < attSize; idx++)\r
+                    {\r
+                        if (strlen(strPos) > 0)\r
+                        {\r
+                            sscanf(strPos, "%2hhx",\r
+                                    &input[tempPos + attSize - 1 - idx]);\r
+                            strPos += (strPos[2] == ':' ? 3 : 2);\r
+                        }\r
+                        else\r
+                        {\r
+                            input[currentPos + attSize - 1 - idx] = 0;\r
+                        }\r
+                    }\r
+                    tempPos += attSize;\r
+                }\r
+                currentPos += (attSize * commands[index].atts[x].isList);
+            }\r
                }\r
        }\r
 \r