Browse Source

同步离线代码

shishenghui 4 days ago
parent
commit
87ad782ebe

+ 38 - 1
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/CRemoteLog.cpp

@@ -56,4 +56,41 @@ void CRemoteLog::error(const char* format, ...) {
 }
 
 CRemoteLog m_logger;
-CRemoteLog* logger;
+CRemoteLog* logger;
+
+int strcmp_ignoreAa(const char* s1, const char* s2)
+{
+	int i = 0;
+	if (s1 == NULL && s2 == NULL) {
+		return 0;
+	}
+	if (s1 == NULL) {
+		return -1;
+	}
+	while (s1[i] != '\0') {
+		char ch1 = s1[i];
+		if (s2[i] == '\0') {
+			return 1;
+		}
+		char ch2 = s2[i];
+		if (ch1 >= 'a' && ch1 <= 'z') {
+			ch1 = ch1 - 'a' + 'A';
+		}
+		if (ch2 >= 'a' && ch2 <= 'z') {
+			ch2 = ch2 - 'a' + 'A';
+		}
+		if (ch1 > ch2) {
+			return 1;
+		}
+		else if (ch1 < ch2) {
+			return -1;
+		}
+		i++;
+	}
+	if (s2[i] == '\0') {
+		return 0;
+	}
+	else {
+		return -1;
+	}
+}

+ 3 - 0
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/CRemoteLog.h

@@ -13,4 +13,7 @@ public:
 };
 extern CRemoteLog* logger;
 extern CRemoteLog m_logger;
+//一些全局性的公共函数也放这里吧
+//字符串比较,忽略大小写
+int strcmp_ignoreAa(const char* s1, const char* s2);
 #endif

+ 173 - 0
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/Fields.cpp

@@ -0,0 +1,173 @@
+#include"TcPch.h"
+#pragma hdrstop
+#include"Fields.h"
+#include"debug.h"
+#define MAX_STATIC_FIELDS_SIZE 1024*200
+static char fieldsMemory[MAX_STATIC_FIELDS_SIZE * 6];
+/*
+* 存储结构
+*     [32字节块][32字节块].........共MAX_STATIC_FIELDS_SIZE字节长,6400条
+* *   [64字节块][64字节块].........共MAX_STATIC_FIELDS_SIZE字节长,3200条
+* *   [128字节块][128字节块].......共MAX_STATIC_FIELDS_SIZE字节长,1600条
+* *   [256字节块][256字节块].......共MAX_STATIC_FIELDS_SIZE字节长,800条
+* *   [512字节块][512字节块].......共MAX_STATIC_FIELDS_SIZE字节长,400条
+* *   [1024字节块][1024字节块].....共MAX_STATIC_FIELDS_SIZE字节长,200条
+* 每块结构:
+*     [1个字节占用标志][块长度-2个字节数据][1个字节0]
+*     占用标志:0-空闲 1-占用
+* 请注意Fields经过优化之后,只能用于静态使用场景,即不会自动释放空间,除非调用clear或者parse
+*/
+void initAllFields() {
+	memset(fieldsMemory, '\0', sizeof(fieldsMemory));
+
+}
+
+//得到一个空闲块地址
+static char* allockOneField(int size) {
+	int index = 0;
+	int offset = 0;
+	int blockSize = 0;
+	if (size + 2 > 1024) {
+		return NULL;
+	}else if (size + 2 > 512) {
+		index = 5;
+		blockSize = 1024;
+	}
+	else if (size + 2 > 256) {
+		index = 4;
+		blockSize = 512;
+	}
+	else if (size + 2 > 128) {
+		index = 3;
+		blockSize = 256;
+	}
+	else if (size + 2 > 64) {
+		index = 2;
+		blockSize = 128;
+	}
+	else if (size + 2 > 32) {
+		index = 1;
+		blockSize = 64;
+	}
+	else {
+		index = 0;
+		blockSize = 32;
+	}
+	int blockCount = MAX_STATIC_FIELDS_SIZE / blockSize;
+	for (offset = 0; offset < blockCount; offset++) {
+		if (!fieldsMemory[index * MAX_STATIC_FIELDS_SIZE + offset * blockSize]) {
+			break;
+		}
+	}
+	if (offset < blockCount) {
+		fieldsMemory[index * MAX_STATIC_FIELDS_SIZE + offset * blockSize] = 1;
+		return fieldsMemory + index * MAX_STATIC_FIELDS_SIZE + offset * blockSize+1;
+	}
+	return NULL;
+}
+void freeOneField(char* ptr) {
+	if (ptr == NULL) {
+		return;
+	}
+	*(ptr - 1) = 0;
+}
+short Fields::size() {
+	return length;
+}
+Fields::Fields() {
+	memset(&fields, '\0', sizeof(fields));
+	length = 0;
+}
+void Fields::clear() {
+	for (int i = 0; i < MAX_PARAM_COUNT; i++) {
+		if (fields[i] != NULL) {
+			freeOneField(fields[i]);
+			fields[i] = NULL;
+		}
+		else {
+			break;
+		}
+
+	}
+	length = 0;
+}
+void Fields::parse(const char* src, char split) {
+	int pos1 = 0;
+	int pos2 = 0;
+	length = 0;
+	clear();
+	if (src == NULL) {
+		return;
+	}
+	PMCBOOL breakFlag = FALSE;
+	while (!breakFlag) {
+		if (src[pos2] == 0) {
+			breakFlag = TRUE;
+		}
+		if (src[pos2] == split || src[pos2] == '\0') {
+			if (pos2 - pos1 >= MAX_NAME_LEN) {
+				logger->error("String fields too long:[%.20s]", src);
+				return;
+			}
+			if (length >= MAX_PARAM_COUNT) {
+				logger->error("String fields too more:[%.20s]", src);
+				return;
+			}
+			fields[length] = allockOneField(pos2 - pos1);
+			if (fields[length] != NULL) {
+				memcpy(fields[length], src + pos1, pos2 - pos1);
+				fields[length][pos2 - pos1] = '\0';
+			}
+			else {
+				logger->error("Too more fields,please reset the MAX_STATIC_FIELDS_SIZE");
+				return;
+			}
+
+			pos1 = pos2 + 1;
+
+			//zipSpace(fields[length]);
+			length++;
+
+		}
+		pos2++;
+	}
+}
+char* Fields::get(short index) {
+	if (index < 0 || index >= length) {
+		return NULL;
+	}
+	return fields[index];
+}
+#ifdef _DEBUG
+char* Fields::getValue(const char* key, const char* file , int line) {
+	size_t keyLen = strlen(key);
+	if (keyLen >= MAX_NAME_LEN - 1) {
+		return NULL;
+	}
+	static char keyEqual[MAX_NAME_LEN];
+	strcpy_debug(keyEqual, key, sizeof(keyEqual), file, line);
+	strcat(keyEqual, "=");
+	for (int i = 0; i < length; i++) {
+		if (strncmp(keyEqual, fields[i], keyLen + 1) == 0) {
+			return fields[i] + keyLen + 1;
+		}
+	}
+	return NULL;
+}
+#else
+char* Fields::getValue(const char* key) {
+	size_t keyLen = strlen(key);
+	if (keyLen >= MAX_NAME_LEN - 1) {
+		return NULL;
+	}
+	static char keyEqual[MAX_NAME_LEN];
+	strcpy(keyEqual, key);
+	strcat(keyEqual, "=");
+	for (int i = 0; i < length; i++) {
+		if (strncmp(keyEqual, fields[i], keyLen + 1) == 0) {
+			return fields[i] + keyLen + 1;
+		}
+	}
+	return NULL;
+}
+#endif

+ 12 - 98
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/Fields.h

@@ -2,110 +2,24 @@
 #define __Fields_H__
 #include"pmc_types.h"
 #include"CRemoteLog.h"
-template <short MAX_SIZE>
+#include"string.h"
+
+
+
 class Fields {
 private:
-	char fields[MAX_SIZE][MAX_NAME_LEN];
-	void zipSpace(char* str) {
-		int i = 0;
-		int j = 0;
-		while (str[i] != '\0') {
-			if (str[i] != ' ' && str[i] != '\t') {
-				if (i != j) {
-					str[j] = str[i];
-				}
-				j++;
-			}
-			
-			i++;
-		}
-		str[j] = '\0';
-	}
+	char* fields[MAX_PARAM_COUNT];
 public:
 	short length;
-	short size() {
-		return length;
-	}
-	Fields() {
-		memset(&fields, '\0', sizeof(fields));
-		length = 0;
-	}
-	void clear() {
-		memset(&fields, '\0', sizeof(fields));
-		length = 0;
-	}
-	void parse(const char* src, char split) {
-		int pos1 = 0;
-		int pos2 = 0;
-		length = 0;
-		clear();
-		if (src == NULL) {
-			return;
-		}
-		PMCBOOL breakFlag = FALSE;
-		while (!breakFlag) {
-			if (src[pos2] == 0) {
-				breakFlag = TRUE;
-			}
-			if (src[pos2] == split || src[pos2] == '\0') {
-				if (pos2 - pos1 >= MAX_NAME_LEN) {
-					logger->info("String fields too long:[%s]", src);
-					return;
-				}
-				if (length >= MAX_SIZE) {
-					logger->info("String fields too more:[%s]", src);
-					return;
-				}
-				memcpy(fields[length], src + pos1, pos2 - pos1);
-				fields[length][pos2 - pos1] = '\0';
-				
-				pos1 = pos2+1;
-				
-				//zipSpace(fields[length]);
-				length++;
-				
-			}
-			pos2++;
-		}
-	}
-	char* get(short index) {
-		if (index < 0 || index >= length) {
-			return NULL;
-		}
-		return fields[index];
-	}
+	short size();
+	Fields();
+	void clear();
+	void parse(const char* src, char split);
+	char* get(short index);
 #ifdef _DEBUG
-	char* getValue(const char* key,const char* file=__FILE__,int line=__LINE__) {
-		size_t keyLen = strlen(key);
-		if (keyLen >= MAX_NAME_LEN - 1) {
-			return NULL;
-		}
-		static char keyEqual[MAX_NAME_LEN];
-		strcpy_debug(keyEqual, key,sizeof(keyEqual),file,line);
-		strcat(keyEqual, "=");
-		for (int i = 0; i < length; i++) {
-			if (strncmp(keyEqual, fields[i], keyLen + 1) == 0) {
-				return fields[i] + keyLen + 1;
-			}
-		}
-		return NULL;
-	}
+	char* getValue(const char* key, const char* file = __FILE__, int line = __LINE__);
 #else
-	char* getValue(const char* key) {
-		size_t keyLen = strlen(key);
-		if (keyLen >= MAX_NAME_LEN - 1) {
-			return NULL;
-		}
-		static char keyEqual[MAX_NAME_LEN];
-		strcpy(keyEqual, key);
-		strcat(keyEqual, "=");
-		for (int i = 0; i < length; i++) {
-			if (strncmp(keyEqual, fields[i], keyLen + 1) == 0) {
-				return fields[i] + keyLen + 1;
-			}
-		}
-		return NULL;
-	}
+	char* getValue(const char* key);
 #endif
 };
 #endif

+ 5 - 0
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/FurancePMC.vcxproj

@@ -115,6 +115,7 @@
     <ClCompile Include="DeviceAttribute.cpp" />
     <ClCompile Include="errcode.cpp" />
     <ClCompile Include="EV.cpp" />
+    <ClCompile Include="Fields.cpp" />
     <ClCompile Include="FurnaceSignalTower.cpp" />
     <ClCompile Include="IoAlarmSignal.cpp" />
     <ClCompile Include="IoAPC.cpp" />
@@ -279,6 +280,10 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|TwinCAT UM (x86)'">
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|TwinCAT RT (x86)'">
+    <ClCompile>
+      <AdditionalOptions>/Zm2000 %(AdditionalOptions)</AdditionalOptions>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+    </ClCompile>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|TwinCAT RT (x86)'">
   </ItemDefinitionGroup>

+ 3 - 0
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/FurancePMC.vcxproj.filters

@@ -338,6 +338,9 @@
     <ClCompile Include="IoFFU.cpp">
       <Filter>Device Drivers</Filter>
     </ClCompile>
+    <ClCompile Include="Fields.cpp">
+      <Filter>Device Drivers</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="FurancePMC.rc">

+ 89 - 3
TIN001-PLC/Jet_Furance_PMC/Jet_Furance_PMC/Jet_Furance_PMC/FurancePMC/SC.cpp

@@ -12,10 +12,12 @@
 const char* CSC::getStringValue(const char* name,const char* defaultValue){
     char  *find =  (char *)stringConfig.get(name);
     if (find == NULL) {
+        
+        static char buffer[MAX_NAME_LEN];
         if (defaultValue == NULL) {
-            return NULL;
+            buffer[0] = '\0';
+            return buffer;
         }
-        static char buffer[MAX_NAME_LEN];
         strcpy(buffer, defaultValue);
         stringConfig.set(name, buffer,__FILE__,__LINE__);
         return (char*)stringConfig.get(name);
@@ -36,5 +38,89 @@ void CSC::setStringValue(const char* name, const char* value) {
 }
 void CSC::setBoolValue(const char * name,PMCBOOL value){
     boolConfig.set(name,value,__FILE__,__LINE__);
-} 
+}
+PMCBOOL CSC::isVP(const char* s)
+{
+    if (s != NULL && ((s[0] >= 'a' && s[0] <= 'z') || (s[0] >= 'A' && s[0] <= 'Z'))) {
+        return TRUE;
+    }
+    return FALSE;
+}
+const char* CSC::getBaseName(const char* s,const char split)
+{
+    static char retBuf[MAX_NAME_LEN];
+    retBuf[0] = '\0';
+    int i = 0;
+    while (s[i] != '\0') {
+        if (s[i] ==split) {            
+            memcpy(retBuf, s, i);
+            retBuf[i] = '\0';
+            return retBuf;
+        }
+        i++;
+    }
+    return s;
+}
+
+const int CSC::parseScData(const char* scData)
+{
+    int count = 0;
+    static char line[MAX_CONTEXT_LEN];
+    static char scName[MAX_NAME_LEN];
+    static char scValue[MAX_NAME_LEN];
+    int offset = 0;
+    int lineIndex = 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;

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

@@ -5,14 +5,16 @@
 
 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);
         void setStringValue(const char* name,const char* value);
         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 20	//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 7000	//最大配置项目(string和bool分别)个数
+#define MAX_SC_BOOL_COUNT 1024	//最大配置项目(string和bool分别)个数
 #define MAX_HOLD_DO_COUNT 64	//最大保持/脉冲点位个数
 #define MAX_WAIT_DI_COUNT 64	//最大等待点位个数