OSDN Git Service

jsonrpcparserにBSTR型を追加
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Sun, 29 Jun 2014 12:56:38 +0000 (12:56 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Sun, 29 Jun 2014 12:56:38 +0000 (12:56 +0000)
jsonrpc::memoryを追加
NyLPC_cFormatWriterにBSTRを追加。length計算の最適化

git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@379 47198e57-cb75-475f-84c4-a814cd6f29e0

lib/src/NyLPC_cMiMicEnv.c
lib/src/http/json/NyLPC_cJsonRpcParser.c
lib/src/http/json/NyLPC_cJsonRpcParser.h
lib/src/include/NyLPC_config.h
lib/src/include/NyLPC_jsonrpc.h [new file with mode: 0644]
lib/src/jsonrpc/NyLPC_cJsonRpcFunction.h [new file with mode: 0644]
lib/src/jsonrpc/NyLPC_cJsonRpcFunction_Memory.c [new file with mode: 0644]
lib/src/utils/NyLPC_cFormatWriter.c
lib/src/utils/NyLPC_cFormatWriter.h

index ff5e22c..907f1a9 100644 (file)
@@ -1,7 +1,7 @@
 #include "NyLPC_cMiMicEnv.h"\r
 #include "../uip/NyLPC_cUipService_protected.h"\r
 \r
-const static char* VERSION="MiMic/1.5.8";\r
+const static char* VERSION="MiMic/1.5.10";\r
 \r
 #if NyLPC_MCU==NyLPC_MCU_LPC4088\r
 const static char* MCU="LPC4088";\r
index fb5ef54..eb471ed 100644 (file)
@@ -1,5 +1,5 @@
 #include "NyLPC_cJsonRpcParser.h"\r
-\r
+#include <ctype.h>\r
 //\r
 //     NyLPC_TJsonRpcParserResult\r
 //\r
@@ -27,7 +27,7 @@ NyLPC_TBool NyLPC_TJsonRpcParserResult_getInt32(const union NyLPC_TJsonRpcParser
        *o_val = *((NyLPC_TInt32*)(i_struct->method.param_buf + i_struct->method.param_index[i_idx]));\r
        return NyLPC_TBool_TRUE;\r
 }\r
-NyLPC_TBool NyLPC_TJsonRpcParserResult_getStr(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, const NyLPC_TChar** o_val)\r
+NyLPC_TBool NyLPC_TJsonRpcParserResult_getStr(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, const NyLPC_TChar** o_val, NyLPC_TUInt8* o_len)\r
 {\r
        if(i_struct->method.param_index[i_idx]==0xff){\r
                return NyLPC_TBool_FALSE;\r
@@ -35,9 +35,27 @@ NyLPC_TBool NyLPC_TJsonRpcParserResult_getStr(const union NyLPC_TJsonRpcParserRe
        if (i_struct->method.class_def->functions[i_struct->method.func_number].param_patt[i_idx] != NyLPC_cJsonRpcParser_TYPE_STRING){\r
                return NyLPC_TBool_FALSE;\r
        }\r
-       *o_val = ((NyLPC_TChar*)(i_struct->method.param_buf + i_struct->method.param_index[i_idx]));\r
+       *o_val = ((NyLPC_TChar*)(i_struct->method.param_buf + i_struct->method.param_index[i_idx]+1));\r
+       if (o_len){\r
+               *o_len = *((NyLPC_TUInt8*)(*o_val-1));\r
+       }\r
+       return NyLPC_TBool_TRUE;\r
+}\r
+NyLPC_TBool NyLPC_TJsonRpcParserResult_getByteArray(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, const NyLPC_TUInt8** o_val, NyLPC_TUInt8* o_len)\r
+{\r
+       if (i_struct->method.param_index[i_idx] == 0xff){\r
+               return NyLPC_TBool_FALSE;\r
+       }\r
+       if (i_struct->method.class_def->functions[i_struct->method.func_number].param_patt[i_idx] != NyLPC_cJsonRpcParser_TYPE_BSTRING){\r
+               return NyLPC_TBool_FALSE;\r
+       }\r
+       *o_val = ((NyLPC_TUInt8*)(i_struct->method.param_buf + i_struct->method.param_index[i_idx] + 1));\r
+       if (o_len){\r
+               *o_len = *((NyLPC_TUInt8*)(*o_val - 1));\r
+       }\r
        return NyLPC_TBool_TRUE;\r
 }\r
+\r
 NyLPC_TBool NyLPC_TJsonRpcParserResult_getByte(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, NyLPC_TUInt8* o_val)\r
 {\r
        if(i_struct->method.param_index[i_idx]==0xff){\r
@@ -140,17 +158,53 @@ static const struct NyLPC_TJsonRpcClassDef* findFunction(const struct NyLPC_TJso
        }\r
        return NULL;\r
 }\r
-#define PARAM_ST_START 1\r
-#define PARAM_ST_VAL   2\r
-#define PARAM_ST_INT   3\r
-#define PARAM_ST_UINT  4\r
-#define PARAM_ST_STR   5\r
-#define PARAM_ST_NEXT  6\r
-#define PARAM_ST_BYTE  7\r
+/**\r
+ * putchar_paramのステータス値\r
+ */\r
+#define PARAM_ST_START                  1\r
+#define PARAM_ST_VAL                    2\r
+#define PARAM_ST_INT                    3\r
+#define PARAM_ST_UINT                   4\r
+#define PARAM_ST_STR                    5\r
+#define PARAM_ST_STR_ESCAPE_HEX         6\r
+#define PARAM_ST_STR_ESCAPE             7\r
+#define PARAM_ST_BYTE                   8\r
+#define PARAM_ST_BSTR                   9\r
+#define PARAM_ST_NEXT                  11\r
 \r
-static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)\r
+\r
+/**\r
+ * シングルエスケープ文字列をエスケープされた文字列へ変換します。\r
+ */\r
+static NyLPC_TBool convertSingleCharEscape(const char i_s, char* o_out)\r
+{\r
+       switch (i_s){\r
+       case '0':       *o_out = '\0'; break;\r
+       case 'r':       *o_out = '\r'; break;\r
+       case 'n':       *o_out = '\n'; break;\r
+       case 't':       *o_out = '\t'; break;\r
+       case '\'':      *o_out = '\''; break;\r
+       case '\"':      *o_out = '\"'; break;\r
+       case '\\':      *o_out = '\\'; break;\r
+       default:\r
+               return NyLPC_TBool_FALSE;\r
+       }\r
+       return NyLPC_TBool_TRUE;\r
+}\r
+/**\r
+ * 符号付整数値を構成する文字セットであるかを返します。\r
+ */\r
+static NyLPC_TBool isSignedCharSet(const char i_c)\r
 {\r
+       return (strchr("-0123456789", i_c) != NULL);\r
+}\r
+/**\r
+ * 整数を構成する文字セットであるかを返します。\r
+ */\r
+#define isUnSignedCharSet(i_c) isdigit(i_c)\r
 \r
+static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)\r
+{\r
        switch (i_inst->_pst){\r
        case PARAM_ST_START:\r
                if (i_c == '['){\r
@@ -180,7 +234,7 @@ static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)
                }\r
                switch (i_inst->_result->method.class_def->functions[i_inst->_result->method.func_number].param_patt[i_inst->_pcounter]){\r
                case NyLPC_cJsonRpcParser_TYPE_INT32:\r
-                       if (strchr("-0123456789", i_c) == NULL){\r
+                       if(!isSignedCharSet(i_c)){\r
                                goto ERROR;\r
                        }\r
                        i_inst->_pst = PARAM_ST_INT;\r
@@ -189,7 +243,7 @@ static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)
                        i_inst->_work.str.n = ((i_inst->_work.str.n + 3) / 4) * 4;\r
                        break;\r
                case NyLPC_cJsonRpcParser_TYPE_UINT32:\r
-                       if (strchr("0123456789", i_c) == NULL){\r
+                       if (!isUnSignedCharSet(i_c)){\r
                                goto ERROR;\r
                        }\r
                        i_inst->_pst = PARAM_ST_UINT;\r
@@ -198,7 +252,7 @@ static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)
                        i_inst->_work.str.n = ((i_inst->_work.str.n + 3) / 4) * 4;\r
                        break;\r
                case NyLPC_cJsonRpcParser_TYPE_BYTE:\r
-                       if (strchr("0123456789", i_c) == NULL){\r
+                       if (!isUnSignedCharSet(i_c)){\r
                                goto ERROR;\r
                        }\r
                        i_inst->_pst = PARAM_ST_BYTE;\r
@@ -208,14 +262,67 @@ static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)
                        if (i_c != '"'){\r
                                goto ERROR;\r
                        }\r
+                       i_inst->_result->method.param_index[i_inst->_pcounter] = i_inst->_work.str.n;\r
+                       i_inst->_pcounter++;\r
+                       if (i_inst->_work.str.n >= NyLPC_TJsonRpcParserResult_PARAM_BUF){\r
+                               goto ERROR;\r
+                       }\r
+                       i_inst->_work.str.n++;//文字数の記憶領域\r
                        i_inst->_pst = PARAM_ST_STR;\r
-                       break;\r
+                       return;//開始時に1バイト予約するから手順が違う\r
+               case NyLPC_cJsonRpcParser_TYPE_BSTRING:\r
+                       if (i_c != '"'){\r
+                               goto ERROR;\r
+                       }\r
+                       i_inst->_result->method.param_index[i_inst->_pcounter] = i_inst->_work.str.n;\r
+                       i_inst->_pcounter++;\r
+                       if (i_inst->_work.str.n >= NyLPC_TJsonRpcParserResult_PARAM_BUF){\r
+                               goto ERROR;\r
+                       }\r
+                       i_inst->_work.str.n++;//文字数の記憶領域\r
+                       i_inst->_pst = PARAM_ST_BSTR;\r
+                       i_inst->_work.str.st = 0;\r
+                       return;//開始時に1バイト予約するから手順が違う\r
                default:\r
                        goto ERROR;\r
                }\r
                i_inst->_result->method.param_index[i_inst->_pcounter] = i_inst->_work.str.n;\r
                i_inst->_pcounter++;\r
                return;\r
+       case PARAM_ST_STR_ESCAPE_HEX:\r
+               //16進数構成文字のみ\r
+               if (!isxdigit((int)i_c)){\r
+                       goto ERROR;\r
+               }\r
+               i_inst->_work.str.vt = (i_inst->_work.str.vt << 4) | NyLPC_ctox(i_c);\r
+               i_inst->_work.str.st++;\r
+               //2文字目で値を確定\r
+               if (i_inst->_work.str.st>=2){\r
+                       if (i_inst->_work.str.n >= NyLPC_TJsonRpcParserResult_PARAM_BUF){\r
+                               goto ERROR;\r
+                       }\r
+                       i_inst->_result->method.param_buf[i_inst->_work.str.n] = i_inst->_work.str.vt;\r
+                       i_inst->_work.str.n++;\r
+                       i_inst->_pst = PARAM_ST_STR;\r
+               }\r
+               return;\r
+       case PARAM_ST_STR_ESCAPE:\r
+               if(i_c=='x'){\r
+                       i_inst->_pst = PARAM_ST_STR_ESCAPE_HEX;\r
+                       i_inst->_work.str.st = 0;\r
+                       i_inst->_work.str.vt = 0;\r
+               }\r
+               else{\r
+                       if (i_inst->_work.str.n >= NyLPC_TJsonRpcParserResult_PARAM_BUF){\r
+                               goto ERROR;\r
+                       }\r
+                       if (!convertSingleCharEscape(i_c,&i_inst->_result->method.param_buf[i_inst->_work.str.n])){\r
+                               goto ERROR;\r
+                       }\r
+                       i_inst->_work.str.n++;\r
+                       i_inst->_pst = PARAM_ST_STR;\r
+               }\r
+               return;\r
        case PARAM_ST_STR:\r
                if (i_c == '"'){\r
                        //完了\r
@@ -224,9 +331,14 @@ static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)
                        }\r
                        i_inst->_result->method.param_buf[i_inst->_work.str.n] = '\0';\r
                        i_inst->_work.str.n++;\r
+                       //文字数を更新\r
+                       *((NyLPC_TUInt8*)(i_inst->_result->method.param_buf+i_inst->_result->method.param_index[i_inst->_pcounter - 1])) = i_inst->_work.str.n - i_inst->_result->method.param_index[i_inst->_pcounter - 1]-2;\r
                        i_inst->_pst = PARAM_ST_NEXT;\r
                        return;\r
                }\r
+               else if (i_c=='\\'){\r
+                       i_inst->_pst = PARAM_ST_STR_ESCAPE;\r
+               }\r
                else{\r
                        if (i_inst->_work.str.n >= NyLPC_TJsonRpcParserResult_PARAM_BUF){\r
                                goto ERROR;\r
@@ -235,8 +347,40 @@ static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)
                        i_inst->_work.str.n++;\r
                }\r
                return;\r
+       case PARAM_ST_BSTR:\r
+               if (i_c == '"'){\r
+                       if (i_inst->_work.str.st != 0){\r
+                               goto ERROR;\r
+                       }\r
+                       //文字数を更新\r
+                       *((NyLPC_TUInt8*)(i_inst->_result->method.param_buf + i_inst->_result->method.param_index[i_inst->_pcounter - 1])) = i_inst->_work.str.n - i_inst->_result->method.param_index[i_inst->_pcounter - 1] - 1;\r
+                       i_inst->_pst = PARAM_ST_NEXT;\r
+                       return;\r
+               }\r
+               else{\r
+                       //16進数構成文字のみ\r
+                       if (!isxdigit((int)i_c)){\r
+                               goto ERROR;\r
+                       }\r
+                       switch(i_inst->_work.str.st){\r
+                       case 0:\r
+                               i_inst->_work.str.vt = NyLPC_ctox(i_c);\r
+                               i_inst->_work.str.st++;\r
+                               break;\r
+                       case 1:\r
+                               i_inst->_work.str.vt = (i_inst->_work.str.vt << 4) | NyLPC_ctox(i_c);\r
+                               if (i_inst->_work.str.n >= NyLPC_TJsonRpcParserResult_PARAM_BUF){\r
+                                       goto ERROR;\r
+                               }\r
+                               i_inst->_result->method.param_buf[i_inst->_work.str.n] = i_inst->_work.str.vt;\r
+                               i_inst->_work.str.n++;\r
+                               i_inst->_work.str.st = 0;\r
+                               break;\r
+                       }\r
+               }\r
+               return;\r
        case PARAM_ST_INT:\r
-               if (strchr("0123456789", i_c) != NULL){\r
+               if (isUnSignedCharSet(i_c)){\r
                        i_inst->_work.int32.v = i_inst->_work.int32.v * 10 + (i_c - '0');\r
                        return;\r
                }\r
@@ -258,7 +402,7 @@ static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)
                *((NyLPC_TInt32*)&(i_inst->_result->method.param_buf[i_inst->_work.str.n - 4])) = i_inst->_work.int32.v*i_inst->_work.int32.s;\r
                return;\r
        case PARAM_ST_UINT:\r
-               if (strchr("0123456789", i_c) != NULL){\r
+               if (isUnSignedCharSet(i_c)){\r
                        i_inst->_work.uint32 = i_inst->_work.uint32 * 10 + (i_c - '0');\r
                        return;\r
                }\r
@@ -279,7 +423,7 @@ static void putchar_params(NyLPC_TcJsonRpcParser_t* i_inst, char i_c)
                *((NyLPC_TUInt32*)&(i_inst->_result->method.param_buf[i_inst->_work.str.n - 4])) = i_inst->_work.uint32;\r
                return;\r
        case PARAM_ST_BYTE:\r
-               if (strchr("0123456789", i_c) != NULL){\r
+               if (isUnSignedCharSet(i_c)){\r
                        i_inst->_work.uint32 = i_inst->_work.uint32 * 10 + (i_c - '0');\r
                        return;\r
                }\r
@@ -426,16 +570,16 @@ void NyLPC_cJsonRpcParser_putChar(NyLPC_TcJsonRpcParser_t* i_inst,char i_c)
                        //無視\r
                        return;\r
                }\r
-               if(strchr("0123456789",i_c)!=NULL){\r
-                       i_inst->_work.uint32=(i_c-'0');\r
+               if (isUnSignedCharSet(i_c)){\r
+                       i_inst->_work.uint32 = (i_c - '0');\r
                        i_inst->_st=NyLPC_TcJsonRpcParser_ST_VAL_UINT;\r
                        return;\r
                }\r
                //エラー\r
                goto ERROR;\r
        case NyLPC_TcJsonRpcParser_ST_VAL_UINT:\r
-               if(strchr("0123456789",i_c)!=NULL){\r
-                       i_inst->_work.uint32=i_inst->_work.uint32*10+(i_c-'0');\r
+               if (isUnSignedCharSet(i_c)){\r
+                       i_inst->_work.uint32 = i_inst->_work.uint32 * 10 + (i_c - '0');\r
                        return;\r
                }\r
                if(strchr(" ,}",i_c)!=NULL){\r
@@ -526,6 +670,8 @@ const struct NyLPC_TJsonRpcMethodDef test_method[]=
        { "func9", "ss" },\r
        { "f10", "suu" },\r
        { "f11", "bbbb" },\r
+       { "f12", "usu" },\r
+       { "f13", "uBu" },\r
        { NULL, "" }\r
 };\r
 \r
@@ -550,7 +696,7 @@ void NyLPC_cJsonRpcParser_putText(NyLPC_TcJsonRpcParser_t* i_inst, const NyLPC_T
        NyLPC_TUInt32 u32;\r
        NyLPC_TInt32 i32;\r
        NyLPC_TChar* c;\r
-       NyLPC_TUInt8 u8;\r
+       NyLPC_TUInt8 u8,l8;\r
 \r
 \r
        for (i = 0; i < i_size; i++){\r
@@ -571,7 +717,8 @@ void NyLPC_cJsonRpcParser_putText(NyLPC_TcJsonRpcParser_t* i_inst, const NyLPC_T
                        switch (i_inst->_result->method.class_def->functions[i_inst->_result->method.func_number].param_patt[i]){\r
                        case 'u':NyLPC_TJsonRpcParserResult_getUInt32(i_inst->_result,i, &u32); printf("%u,", u32); break;\r
                        case 'd':NyLPC_TJsonRpcParserResult_getInt32(i_inst->_result, i, &i32); printf("%d,", i32); break;\r
-                       case 's':NyLPC_TJsonRpcParserResult_getStr(i_inst->_result, i, &c); printf("%s,", c); break;\r
+                       case 's':NyLPC_TJsonRpcParserResult_getStr(i_inst->_result, i, &c, &l8); printf("%s:%d,", c, l8); break;\r
+                       case 'B':NyLPC_TJsonRpcParserResult_getByteArray(i_inst->_result, i, &c, &l8); printf("--:%d,", l8); break;\r
                        case 'b':NyLPC_TJsonRpcParserResult_getByte(i_inst->_result, i, &u8); printf("%u,", u8); break;\r
                        }\r
                }\r
@@ -615,7 +762,7 @@ void main(void)
        };\r
 #else\r
        const char* t[] = {\r
-               "{\"version\":\"2.0\",\"method\":\"ns:class:func\",\"params\":[]}",//YES\r
+/*             "{\"version\":\"2.0\",\"method\":\"ns:class:func\",\"params\":[]}",//YES\r
                "{\"version\":\"2.0\",\"method\":\"ns:class:func\",\"params\": [] }",//YES\r
                "{\"version\":\"2.0\",\"method\":\"ns:class:func1\",\"params\": [-123] }",//YES\r
                "{\"version\":\"2.0\",\"method\":\"ns:class:func1\",\"params\": [\"123\"] }",//NG\r
@@ -639,6 +786,9 @@ void main(void)
                "{\"version\":\"2.0\",\"method\":\"ns:class:f10\",\"params\": [\"01234567890123\",22,33] }",//OK\r
                "{\"version\":\"2.0\",\"method\":\"ns:class:f11\",\"params\": [ 0 , 1 ,2,3] }",//OK\r
                "{\"version\":\"2.0\",\"method\":\"ns:class:f11\",\"params\": [ 15 , 1 ,2,3a] }",//NG\r
+*/\r
+               "{\"version\":\"2.0\",\"method\":\"ns:class:f13\",\"params\": [2,\"0011223344ff\",1] }",//NG\r
+//             "{\"version\":\"2.0\",\"method\":\"ns:class:f12\",\"params\": [2,\"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\",1] }",//NG\r
                NULL\r
        };\r
 #endif\r
@@ -648,6 +798,7 @@ void main(void)
                NyLPC_cJsonRpcParser_initialize(&inst, test_def_array);\r
                NyLPC_cJsonRpcParser_initParser(&inst, &ret);\r
                NyLPC_cJsonRpcParser_putText(&inst, t[i], strlen(t[i]));\r
+               continue;\r
        }\r
        printf("end\n");\r
        return;\r
index c67b028..3035c97 100644 (file)
@@ -40,7 +40,9 @@ struct NyLPC_TJsonRpcMethodDef
         * <ul>\r
         * <li>s - 文字列</li>\r
         * <li>i - signed int32</li>\r
-        * <li>s - unsigned int32</li>\r
+        * <li>u - unsigned int32</li>\r
+        * <li>b - unsigned int8</li>\r
+        * <li>B - BSTR (string ByteArray)</li>\r
         * </ul>\r
         */\r
        const char* param_patt;\r
@@ -70,7 +72,7 @@ struct NyLPC_TJsonRpcClassDef
 #define NyLPC_TJsonRpcParserResult_TYPE_RESULT 1\r
 #define NyLPC_TJsonRpcParserResult_TYPE_METHOD 2\r
 \r
-/** NyLPC_TJsonRpcParserResultが格納できる引数の最大数。パラメータの最大数に等しくなります。*/\r
+/** NyLPC_TJsonRpcParserResultが格納できる引数の最大数。パラメータの最大数に等しくなります。 */\r
 #define NyLPC_TJsonRpcParserResult_NUMBER_OF_PARAM_INDEX 32\r
 /**\r
  * NyLPC_TJsonRpcParserResultが格納できるパラメータの総バイト数。\r
@@ -86,7 +88,7 @@ struct NyLPC_TJsonRpcClassDef
 union NyLPC_TJsonRpcParserResult\r
 {\r
        NyLPC_TUInt8    type;                           //タイプ\r
-       /** この構造体は type==NyLPC_TJsonRpcParserResult_TYPE_METHODのときに有効です。*/\r
+       /** この構造体は type==NyLPC_TJsonRpcParserResult_TYPE_METHODのときに有効です。 */\r
        struct{\r
                NyLPC_TUInt8    _type;                  //タイプ\r
                NyLPC_TUInt8    func_number;    //確定した関数番号。\r
@@ -94,7 +96,7 @@ union NyLPC_TJsonRpcParserResult
                NyLPC_TInt32    id;                             //idパラメータの値\r
                NyLPC_TChar             param_buf[NyLPC_TJsonRpcParserResult_PARAM_BUF];\r
                NyLPC_TUInt8    param_index[NyLPC_TJsonRpcParserResult_NUMBER_OF_PARAM_INDEX];\r
-               /** 関数の含まれるクラスへのポインタ。*/\r
+               /** 関数の含まれるクラスへのポインタ。 */\r
                const struct NyLPC_TJsonRpcClassDef* class_def;\r
        }method;\r
        struct{\r
@@ -138,7 +140,12 @@ NyLPC_TBool NyLPC_TJsonRpcParserResult_getInt32(const union NyLPC_TJsonRpcParser
 /**\r
  * i_idx番目のパラメータをchar[]としてo_valへ取り出します。\r
  */\r
-NyLPC_TBool NyLPC_TJsonRpcParserResult_getStr(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, const NyLPC_TChar** o_val);\r
+NyLPC_TBool NyLPC_TJsonRpcParserResult_getStr(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, const NyLPC_TChar** o_val, NyLPC_TUInt8* o_len);\r
+/**\r
+* i_idx番目のパラメータをuchar[]としてo_valへ取り出します。\r
+*/\r
+NyLPC_TBool NyLPC_TJsonRpcParserResult_getByteArray(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, const NyLPC_TUInt8** o_val, NyLPC_TUInt8* o_len);\r
+\r
 /**\r
  * i_idx番目のパラメータをuint8としてo_valへ取り出します。\r
  */\r
@@ -156,6 +163,7 @@ NyLPC_TBool NyLPC_TJsonRpcParserResult_getByte(const union NyLPC_TJsonRpcParserR
 #define NyLPC_cJsonRpcParser_TYPE_UINT32       'u'\r
 #define NyLPC_cJsonRpcParser_TYPE_STRING       's'\r
 #define NyLPC_cJsonRpcParser_TYPE_BYTE         'b'\r
+#define NyLPC_cJsonRpcParser_TYPE_BSTRING      'B'\r
 \r
 /**\r
 * JsonRPCメッセージをパースします。パース出来るメッセージは以下の通りです。\r
@@ -194,8 +202,8 @@ typedef NyLPC_TUInt8 NyLPC_TcJsonRpcParser_TStatus;
 \r
 \r
 \r
-/** NyLPC_TcJsonRpcParserの定数値です。 字句解析ワークメモリの長さ。256未満8*n-1の数を指定してください。 */\r
-#define NyLPC_TcJsonRpcParser_WORK_MAX 47\r
+/** NyLPC_TcJsonRpcParserの定数値です。 字句解析ワークメモリの長さ。256未満8*n-4の数を指定してください。 */\r
+#define NyLPC_TcJsonRpcParser_WORK_MAX (48-4)\r
 \r
 /**\r
  * クラス構造体です。\r
@@ -207,6 +215,9 @@ struct NyLPC_TcJsonRpcParser
                struct{\r
                        NyLPC_TChar     buf[NyLPC_TcJsonRpcParser_WORK_MAX];    //文字解析メモリ\r
                        NyLPC_TUInt8    n;                                                                              //字句解析の文字数\r
+                       NyLPC_TUInt8    st;                                                                             //字句解析のサブステータス\r
+                       NyLPC_TUInt8    vt;                                                                             //数字エスケープ解釈のテンポラリ\r
+                       NyLPC_TUInt8    _padding;                                                               //\r
                }str;\r
                struct{\r
                        NyLPC_TInt32 v;\r
index abca024..386e2e1 100644 (file)
@@ -99,8 +99,8 @@ extern "C" {
        //PACKED STRUCTの無効化\r
        #define PACK_STRUCT_END\r
        //OSタイプによりMCUを修正\r
-       #undef NyLPC_ARCH\r
-       #define NyLPC_MCU NyLPC_MCU_UNKNOWN\r
+#      undef NyLPC_MCU\r
+#      define NyLPC_MCU NyLPC_MCU_UNKNOWN\r
 #endif\r
 \r
 \r
diff --git a/lib/src/include/NyLPC_jsonrpc.h b/lib/src/include/NyLPC_jsonrpc.h
new file mode 100644 (file)
index 0000000..a0ffb66
--- /dev/null
@@ -0,0 +1,42 @@
+/*********************************************************************************\r
+ * PROJECT: MiMic\r
+ * --------------------------------------------------------------------------------\r
+ *\r
+ * This file is part of MiMic\r
+ * Copyright (C)2011 Ryo Iizuka\r
+ *\r
+ * MiMic is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published\r
+ * by the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ * For further information please contact.\r
+ *     http://nyatla.jp/\r
+ *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ *\r
+ *********************************************************************************/\r
+/**\r
+ * @file\r
+ * このファイルは、jsonRPCディレクトリ以下に宣言されるヘッダファイルを集積します。\r
+ */\r
+#ifndef NYLPC_JSONRPC_H_\r
+#define NYLPC_JSONRPC_H_\r
+#include "../jsonrpc/NyLPC_cJsonRpcFunction.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif /* __cplusplus */\r
+\r
+#endif\r
diff --git a/lib/src/jsonrpc/NyLPC_cJsonRpcFunction.h b/lib/src/jsonrpc/NyLPC_cJsonRpcFunction.h
new file mode 100644 (file)
index 0000000..f6feed4
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+ * NyLPC_cJsonRpcFunction.h\r
+ *\r
+ *  Created on: 2014/06/28\r
+ *      Author: nyatla\r
+ */\r
+\r
+#ifndef NYLPC_CJSONRPCFUNCTION_H_\r
+#define NYLPC_CJSONRPCFUNCTION_H_\r
+#include "NyLPC_net.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+\r
+/**\r
+ * メモリ操作API\r
+ * paramにはNyLPC_modJsonRPCのポインタが必要です。\r
+ */\r
+extern const struct NyLPC_TJsonRpcClassDef NyLPC_cJsonRpcFunction_Memory;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif /* __cplusplus */\r
+\r
+#endif /* NYLPC_CJSONRPCFUNCTION_H_ */\r
diff --git a/lib/src/jsonrpc/NyLPC_cJsonRpcFunction_Memory.c b/lib/src/jsonrpc/NyLPC_cJsonRpcFunction_Memory.c
new file mode 100644 (file)
index 0000000..d573d60
--- /dev/null
@@ -0,0 +1,133 @@
+#include "NyLPC_net.h"\r
+\r
+///**\r
+// * 1バイトをメモリに書き込む\r
+// */\r
+//static NyLPC_TBool write(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param)\r
+//{\r
+//     //ubb\r
+//     NyLPC_TcModJsonRpc_t* mod=(NyLPC_TcModJsonRpc_t*)i_param;\r
+//     NyLPC_TUInt8* addr;\r
+//     NyLPC_TUInt8 v,mask;\r
+//     if(NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,0,((NyLPC_TUInt32*)&addr))){\r
+//             if(NyLPC_TJsonRpcParserResult_getByte(i_rpc,1,((NyLPC_TUInt8*)&v))){\r
+//                     if(NyLPC_TJsonRpcParserResult_getByte(i_rpc,2,((NyLPC_TUInt8*)&mask))){\r
+//                             *addr=((*addr)&(~mask))|((*addr)|mask);\r
+//                             return NyLPC_cModJsonRpc_putResult(mod,i_rpc->method.id,"");\r
+//                     }\r
+//             }\r
+//     }\r
+//     NyLPC_cModJsonRpc_putError(mod,i_rpc->method.id,NyLPC_TJsonRpcErrorCode_INVALID_PARAMS);\r
+//     return NyLPC_TBool_FALSE;\r
+//}\r
+///**\r
+// * 1バイトをメモリから読み込む\r
+// */\r
+//static NyLPC_TBool read(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param)\r
+//{\r
+//     //u\r
+//     NyLPC_TcModJsonRpc_t* mod=(NyLPC_TcModJsonRpc_t*)i_param;\r
+//     NyLPC_TUInt8* addr;\r
+//     if(NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,0,((NyLPC_TUInt32*)&addr))){\r
+//             return NyLPC_cModJsonRpc_putResult(mod,i_rpc->method.id,"%u",(int)(*addr));\r
+//     }\r
+//     NyLPC_cModJsonRpc_putError(mod,i_rpc->method.id,NyLPC_TJsonRpcErrorCode_INVALID_PARAMS);\r
+//     return NyLPC_TBool_FALSE;\r
+//}\r
+//\r
+///**\r
+// * write32\r
+// */\r
+//static NyLPC_TBool write32(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param)\r
+//{\r
+//     //uuu\r
+//     NyLPC_TcModJsonRpc_t* mod=(NyLPC_TcModJsonRpc_t*)i_param;\r
+//     NyLPC_TUInt32* addr;\r
+//     NyLPC_TUInt32 v,mask;\r
+//     if(NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,0,((NyLPC_TUInt32*)&addr))){\r
+//             if(NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,1,((NyLPC_TUInt32*)&v))){\r
+//                     if(NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,2,((NyLPC_TUInt32*)&mask))){\r
+//                             *addr=((*addr)&(~mask))|((*addr)|mask);\r
+//                             return NyLPC_cModJsonRpc_putResult(mod,i_rpc->method.id,"");\r
+//                     }\r
+//             }\r
+//     }\r
+//     NyLPC_cModJsonRpc_putError(mod,i_rpc->method.id,NyLPC_TJsonRpcErrorCode_INVALID_PARAMS);\r
+//     return NyLPC_TBool_FALSE;\r
+//}\r
+///**\r
+// * read32\r
+// */\r
+//static NyLPC_TBool read32(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param)\r
+//{\r
+//     //u\r
+//     NyLPC_TcModJsonRpc_t* mod=(NyLPC_TcModJsonRpc_t*)i_param;\r
+//     NyLPC_TUInt32* addr;\r
+//     NyLPC_TUInt32 v;\r
+//     if(NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,0,((NyLPC_TUInt32*)&addr))){\r
+//             v=(*addr);\r
+//             return NyLPC_cModJsonRpc_putResult(mod,i_rpc->method.id,"%u",v);\r
+//     }\r
+//     NyLPC_cModJsonRpc_putError(mod,i_rpc->method.id,NyLPC_TJsonRpcErrorCode_INVALID_PARAMS);\r
+//     return NyLPC_TBool_FALSE;\r
+//}\r
+/**\r
+ * 準備(特にやることない)\r
+ */\r
+static NyLPC_TBool init(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param)\r
+{\r
+       //uB\r
+       NyLPC_TcModJsonRpc_t* mod=(NyLPC_TcModJsonRpc_t*)i_param;\r
+       return NyLPC_cModJsonRpc_putResult(mod,i_rpc->method.id,"");\r
+}\r
+\r
+/**\r
+ * メモリブロックを書き込む\r
+ */\r
+static NyLPC_TBool write(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param)\r
+{\r
+       //uB\r
+       NyLPC_TcModJsonRpc_t* mod=(NyLPC_TcModJsonRpc_t*)i_param;\r
+       NyLPC_TUInt8* addr;\r
+       const NyLPC_TUInt8* v;\r
+       NyLPC_TUInt8 l;\r
+       if(NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,0,((NyLPC_TUInt32*)&addr))){\r
+               if(NyLPC_TJsonRpcParserResult_getByteArray(i_rpc,1,&v,&l)){\r
+                       memcpy(addr,v,l);\r
+                       return NyLPC_cModJsonRpc_putResult(mod,i_rpc->method.id,"");\r
+               }\r
+       }\r
+       NyLPC_cModJsonRpc_putError(mod,i_rpc->method.id,NyLPC_TJsonRpcErrorCode_INVALID_PARAMS);\r
+       return NyLPC_TBool_FALSE;\r
+}\r
+/**\r
+ * メモリブロックを読み込む\r
+ */\r
+static NyLPC_TBool read(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param)\r
+{\r
+       //uu\r
+       NyLPC_TcModJsonRpc_t* mod=(NyLPC_TcModJsonRpc_t*)i_param;\r
+       NyLPC_TUInt8* addr;\r
+       NyLPC_TUInt32 l;\r
+       if(NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,0,((NyLPC_TUInt32*)&addr))){\r
+               if(NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,1,((NyLPC_TUInt32*)&l))){\r
+                       return NyLPC_cModJsonRpc_putResult(mod,i_rpc->method.id,"\"%.*B\"",(int)l,addr);\r
+               }\r
+       }\r
+       NyLPC_cModJsonRpc_putError(mod,i_rpc->method.id,NyLPC_TJsonRpcErrorCode_INVALID_PARAMS);\r
+       return NyLPC_TBool_FALSE;\r
+}\r
+\r
+\r
+\r
+const static struct NyLPC_TJsonRpcMethodDef func_table[]=\r
+{\r
+       { "init"        ,""             ,init},\r
+       { "write"       ,"uB"   ,write},\r
+       { "read"        ,"uu"   ,read},\r
+       { NULL      ,NULL   ,NULL}\r
+};\r
+\r
+const struct NyLPC_TJsonRpcClassDef NyLPC_cJsonRpcFunction_Memory={\r
+       "MiMic","Memory",func_table\r
+};\r
index 39e49e4..26af5fc 100644 (file)
@@ -73,20 +73,16 @@ NyLPC_TBool NyLPC_cFormatWriter_print(NyLPC_cFormatWriter_printHandler i_handler
                                continue;\r
                        case 'u':\r
                                //ワークを空にする。\r
-                               if(ol>0){\r
-                                       i_handler(i_inst,wk,ol);\r
+                               if (ol>0){\r
+                                       i_handler(i_inst, wk, ol);\r
+                                       ol = 0;\r
                                }\r
-                               ut=va_arg(args,NyLPC_TUInt32);\r
-                               ol=15;\r
-                               wk[ol--]='\0';\r
-                               do{\r
-                                       wk[ol--]='0'+(ut%10);\r
-                                       ut/=10;\r
-                               }while(ut>0);\r
-                               i_handler(i_inst,(wk+ol+1),14-ol);\r
-                               ol=0;\r
+                               NyLPC_uitoa((va_arg(args, NyLPC_TUInt32)), wk, 10);\r
+                               //強制コミット\r
+                               i_handler(i_inst, wk, strlen(wk));\r
                                rp++;\r
                                continue;\r
+                       //16進数\r
                        case 'x':\r
                                //ワークを空にする。\r
                                if(ol>0){\r
@@ -98,7 +94,30 @@ NyLPC_TBool NyLPC_cFormatWriter_print(NyLPC_cFormatWriter_printHandler i_handler
                                i_handler(i_inst,wk,strlen(wk));\r
                                rp++;\r
                                continue;\r
-//                     case 'X':\r
+                       //BYTE値のHEXエンコード文字列(XX形式のテキスト。%.*Bのみ)\r
+                       case 'B':\r
+                               switch(ftype){\r
+                               case FTYPE_LENGTH:\r
+                                       //%.*Bの場合\r
+                                       ut=va_arg(args,NyLPC_TUInt32);\r
+                                       break;\r
+                               default:\r
+                                       ut=0;\r
+                               }\r
+                               sp=va_arg(args,const char*);\r
+                               while(ut>0){\r
+                                       //2文字以上の空きがないなら書き込み\r
+                                       if (ol >= (NUM_OF_WORK - 2)){\r
+                                               i_handler(i_inst, wk, ol);\r
+                                               ol = 0;\r
+                                       }\r
+                                       NyLPC_uitoa2((int)(*sp), wk + ol, 16, 2);\r
+                                       ol += 2;\r
+                                       sp++;\r
+                                       ut--;\r
+                               }\r
+                               rp++;\r
+                               continue;\r
                        case '%':\r
                                wk[ol]='%';\r
                                ol++;\r
@@ -141,7 +160,6 @@ NyLPC_TInt16 NyLPC_cFormatWriter_length(const NyLPC_TChar* i_fmt,va_list args)
        NyLPC_TUInt32 ut;\r
        NyLPC_TUInt8 ftype;\r
        NyLPC_TInt16 len=0;\r
-       NyLPC_TInt16 ol=0;\r
        while(*rp!='\0'){\r
                if(*rp=='%'){\r
                        ftype=FTYPE_NOTHING;\r
@@ -157,8 +175,7 @@ NyLPC_TInt16 NyLPC_cFormatWriter_length(const NyLPC_TChar* i_fmt,va_list args)
                                        goto FMT_NEXT;\r
                                }\r
                                //その他\r
-                               wk[ol]=*rp;\r
-                               ol++;\r
+                               len++;\r
                                rp++;\r
                                break;\r
                        case 's':\r
@@ -172,29 +189,18 @@ NyLPC_TInt16 NyLPC_cFormatWriter_length(const NyLPC_TChar* i_fmt,va_list args)
                                }\r
                                sp=va_arg(args,const char*);\r
                                while(*sp!=0 && ut>0){\r
-                                       wk[ol]=*sp;\r
-                                       ol++;\r
+                                       len++;\r
                                        sp++;\r
-                                       //バッファフルなら書込み。\r
-                                       if(ol>=NUM_OF_WORK){\r
-                                               len+=NUM_OF_WORK;\r
-                                               ol=0;\r
-                                       }\r
                                        ut--;\r
                                }\r
                                rp++;\r
                                continue;\r
                        case 'c':\r
-                               wk[ol]=(char)va_arg(args,int);\r
+                               va_arg(args,int);\r
+                               len++;\r
                                rp++;\r
-                               ol++;\r
                                break;\r
                        case 'd':\r
-                               //ワークを空にする。\r
-                               if(ol>0){\r
-                                       len+=ol;\r
-                                       ol=0;\r
-                               }\r
                                NyLPC_itoa((va_arg(args,int)),wk,10);\r
                                //強制コミット\r
                                len+=(NyLPC_TInt16)strlen(wk);\r
@@ -202,62 +208,49 @@ NyLPC_TInt16 NyLPC_cFormatWriter_length(const NyLPC_TChar* i_fmt,va_list args)
                                continue;\r
                        case 'u':\r
                                //ワークを空にする。\r
-                               if(ol>0){\r
-                                       len+=ol;\r
-                               }\r
-                               ut=va_arg(args,NyLPC_TUInt32);\r
-                               ol=15;\r
-                               wk[ol--]='\0';\r
-                               do{\r
-                                       wk[ol--]='0'+(ut%10);\r
-                                       ut/=10;\r
-                               }while(ut>0);\r
-                               len+=14-ol;\r
-                               ol=0;\r
+                               NyLPC_uitoa((va_arg(args, NyLPC_TUInt32)), wk, 10);\r
+                               //強制コミット\r
+                               len += (NyLPC_TInt16)strlen(wk);\r
                                rp++;\r
                                continue;\r
                        case 'x':\r
-                               //ワークを空にする。\r
-                               if(ol>0){\r
-                                       len+=ol;\r
-                                       ol=0;\r
-                               }\r
                                NyLPC_uitoa((va_arg(args,unsigned int)),wk,16);\r
                                //強制コミット\r
                                len+=(NyLPC_TInt16)strlen(wk);\r
                                rp++;\r
                                continue;\r
-//                     case 'X':\r
+                       //BYTE値のHEXエンコード文字列(XX形式のテキスト。%.*Bのみ)\r
+                       case 'B':\r
+                               switch(ftype){\r
+                               case FTYPE_LENGTH:\r
+                                       //%.*Bの場合\r
+                                       ut=va_arg(args,NyLPC_TUInt32);\r
+                                       break;\r
+                               default:\r
+                                       ut=0;\r
+                               }\r
+                               sp=va_arg(args,const char*);\r
+                               len += (NyLPC_TInt16)ut * 2;\r
+                               rp++;\r
+                               continue;\r
                        case '%':\r
-                               wk[ol]='%';\r
-                               ol++;\r
+                               len++;\r
                                rp++;\r
                                break;\r
                        case '\0':\r
                                //オワタ(ループ抜けるためにrpはそのまま。)\r
                                break;\r
                        default:\r
-                               wk[ol]=*rp;\r
-                               ol++;\r
-                       }\r
-                       //バッファフルなら書込み。\r
-                       if(ol>=NUM_OF_WORK){\r
-                               len+=NUM_OF_WORK;\r
-                               ol=0;\r
+                               len++;\r
                        }\r
                }else if(*rp==0){\r
                        //オワタ\r
                        break;\r
                }else{\r
-                       wk[ol]=*rp;\r
-                       ol++;\r
+                       len++;\r
                        rp++;\r
-                       if(ol>=NUM_OF_WORK){\r
-                               len+=NUM_OF_WORK;\r
-                               ol=0;\r
-                       }\r
                }\r
        }\r
        //どこかでエラーが起こってればFALSE返す。\r
-       return len+ol;\r
+       return len;\r
 }\r
index 7ada3d7..524dd0c 100644 (file)
@@ -12,11 +12,13 @@ typedef NyLPC_TBool(*NyLPC_cFormatWriter_printHandler)(void* i_inst,const void*
  * printfライクな書式出力関数です。i_handlerへi_fmtに示される書式文字列を出力します。\r
  * @param i_fmt\r
  * フォーマット文字列。以下の形式をサポートします。\r
- * %d\r
- * %u\r
- * %c\r
- * %%\r
- * %s,%.*s\r
+ * %d          int値\r
+ * %u          uint値\r
+ * %c          char値\r
+ * %%          '%'\r
+ * %s,%.*s     文字列\r
+ * 独自拡張\r
+ * %.*B                BYTE配列をXX形式で並べた文字列\r
  *\r
  */\r
 NyLPC_TBool NyLPC_cFormatWriter_print(NyLPC_cFormatWriter_printHandler i_handler,void* i_inst,const NyLPC_TChar* i_fmt,va_list args);\r