Browse Source

解析SC文件

shishenghui 6 days ago
parent
commit
265b6bb99f

+ 59 - 0
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/SC.cpp

@@ -61,5 +61,64 @@ const char* CSC::getBaseName(const char* s,const char split)
     }
     return s;
 }
+const int CSC::parseScData(const char* scData)
+{
+    static char line[MAX_CONTEXT_LEN];
+    static char scName[MAX_NAME_LEN];
+    static char scValue[MAX_NAME_LEN];
+    int offset = 0;
+    int lineIndex = 0;
+    int count = 0;
+    while (TRUE) {
+        if (scData[offset] == 0x0a || scData[offset] == 0x0d || scData[offset] == 0x00) {
+            if (scData[offset] == 0x0d || scData[offset] == 0x0a) {
+                if (scData[offset + 1] == 0x0d || scData[offset + 1] == 0x0a) {
+                    offset++;
+                }
+            }
+            line[lineIndex] = 0x00;
+            const char* ptrName = strstr(line, "name=");
+            if (ptrName != NULL) {
+                const char* ptrValue = strstr(ptrName, "value=");
+                if (ptrValue != NULL) {
+                    int index = 6;
+                    while (ptrName[index] != 0x00 && ptrName[index] != '"') {
+                        scName[index - 6] = ptrName[index];
+                        index++;
+                    }
+                    scName[index] = 0x00;
+                    index = 7;
+                    while (ptrValue[index] != 0x00 && ptrValue[index] != '"') {
+                        scValue[index - 7] = ptrValue[index];
+                        index++;
+                    }
+                    scValue[index] = 0x00;
+                    if (strcmp_ignoreAa(scValue, "true") == 0) {
+                        boolConfig.set(scName, TRUE);
+                        count++;
+                    }
+                    else if (strcmp_ignoreAa(scValue, "false") == 0) {
+                        boolConfig.set(scName, FALSE);
+                        count++;
+                    }
+                    else {
+                        stringConfig.set(scName, scValue);
+                        count++;
+                    }
 
+                }
+            }
+            ////
+            if (scData[offset] == 0x00) {
+                break;
+            }
+            lineIndex = 0;
+            offset++;
+        }
+        else {
+            line[lineIndex++] = scData[offset++];
+        }
+    }
+    return count;
+}
 CSC *SC;

+ 3 - 3
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/SC.h

@@ -5,8 +5,8 @@
 
 class CSC{
     private:
-        Dictionary<char[MAX_NAME_LEN],MAX_SC_COUNT> stringConfig;
-        Dictionary<PMCBOOL,MAX_SC_COUNT>boolConfig;
+        Dictionary<char[MAX_NAME_LEN],MAX_SC_STRING_COUNT> stringConfig;
+        Dictionary<PMCBOOL,MAX_SC_BOOL_COUNT>boolConfig;
     public:
         const char * getStringValue(const char* name,const char * defaultValue=NULL);
         PMCBOOL getBoolValue(const char* name,PMCBOOL defaultValue=FALSE);
@@ -14,7 +14,7 @@ class CSC{
         void setBoolValue(const char* name,PMCBOOL value);
         PMCBOOL isVP(const char* s);
         const char* getBaseName(const char* s,const char split);
-
+        const int parseScData(const char* scData);
 };
 extern CSC* SC;
 #endif

+ 2 - 1
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/pmc_types.h

@@ -18,7 +18,8 @@
 #define MAX_PARAM_COUNT 512	//OP参数的最大个数
 #define MAX_SUB_OP_COUNT 32	//最大sub op个数
 #define TOTAL_SUB_OP_COUNT 256	//所有sub op加起来的累计个数
-#define MAX_SC_COUNT 512	//最大配置项目(string和bool分别)个数
+#define MAX_SC_STRING_COUNT 2048	//最大配置项目(string和bool分别)个数
+#define MAX_SC_BOOL_COUNT 512	//最大配置项目(string和bool分别)个数
 #define MAX_HOLD_DO_COUNT 64	//最大保持/脉冲点位个数
 #define MAX_WAIT_DI_COUNT 64	//最大等待点位个数