Ver código fonte

2021.1.04 / Yuanda Tsai

action:
1. Judge Timeout program (previously could not be judged correctly)

file:
1. Module_Dcmeter.c
2. curlapi.c
3.meterComm.c
Yuanda_Tsai 3 anos atrás
pai
commit
8341d003ad

+ 23 - 23
EVSE/Modularization/DcMeter/Module_DcMeter.c

@@ -105,7 +105,7 @@ int main(void)
 	meterInitialize(METER_MODEL_LEM_L18005A);
 	
 	
-	DEBUG_INFO("modelnameInfo.GetGunCount %d \n", modelnameInfo.GetGunCount);
+	DEBUG_INFO("modelnameInfo.GetGunCount : %d \n", modelnameInfo.GetGunCount);
 
 	// Main loop
 	for(;;)
@@ -125,7 +125,7 @@ int main(void)
 					switch(pollingIndex)
 					{
 						case 0:
-							if(readCurrent(&meter_info[meterIndex]))
+							if(readCurrent(&meter_info[meterIndex]) != FAIL)
 							{
 								#ifndef DEBUG_STANDALONG
 								/*
@@ -134,7 +134,7 @@ int main(void)
 								 */
 								 
 								 ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].presentCurrent = meter_info[meterIndex].presentCurrent;
-								 #ifdef DEBUG_STANDALONG
+								 #ifdef DEBUG_SHAREMEM_LOG
 								 DEBUG_INFO("shm Output current %d : %.3f A\n", meterIndex, ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].presentCurrent);
 								 #endif
 								 
@@ -151,7 +151,7 @@ int main(void)
 							}
 							break;
 						case 1:
-							if(readVoltage(&meter_info[meterIndex]))
+							if(readVoltage(&meter_info[meterIndex]) != FAIL)
 							{
 								#ifndef DEBUG_STANDALONG
 								/*
@@ -160,7 +160,7 @@ int main(void)
 								 */
 								 
 								ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].presetVoltage = meter_info[meterIndex].presetVoltage;
-								#ifdef DEBUG_STANDALONG
+								#ifdef DEBUG_SHAREMEM_LOG
 								DEBUG_INFO("shm Output voltage %d : %.3f V\n", meterIndex, ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].presetVoltage);
 								#endif
 								#else
@@ -176,7 +176,7 @@ int main(void)
 							}
 							break;
 						case 2:
-							if(readPower(&meter_info[meterIndex]))
+							if(readPower(&meter_info[meterIndex]) != FAIL)
 							{
 								#ifndef DEBUG_STANDALONG
 								/*
@@ -185,7 +185,7 @@ int main(void)
 								 */
 								 
 								ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].presentPower = meter_info[meterIndex].presentPower;
-								#ifdef DEBUG_STANDALONG
+								#ifdef DEBUG_SHAREMEM_LOG
 								DEBUG_INFO("shm Output power %d : %.3f kw\n", meterIndex, ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].presentPower);
 								#endif
 								#else
@@ -201,7 +201,7 @@ int main(void)
 							}
 							break;
 						case 3:
-							if(readEnergy(&meter_info[meterIndex]))
+							if(readEnergy(&meter_info[meterIndex]) != FAIL)
 							{
 								#ifndef DEBUG_STANDALONG
 								/*
@@ -210,15 +210,15 @@ int main(void)
 								 */
 								 
 								ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].totlizeImportEnergy = meter_info[meterIndex].totlizeImportEnergy;
-								#ifdef DEBUG_STANDALONG
+								#ifdef DEBUG_SHAREMEM_LOG
 								DEBUG_INFO("shm Totalize import energy %d : %.3f kwh\n", meterIndex, ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].totlizeImportEnergy);
 								#endif
 								ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].totlizeExportEnergy = meter_info[meterIndex].totlizeExportEnergy;
-								#ifdef DEBUG_STANDALONG
+								#ifdef DEBUG_SHAREMEM_LOG
 								DEBUG_INFO("shm Totalize export energy %d : %.3f kwh\n", meterIndex, ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].totlizeExportEnergy);
 								#endif
 								#else
-								DEBUG_INFO("Totalize import energy %d : %.3f kwh\n", meterIndex, meter_info[meterIndex].totlizeImportEnergy);
+								DEBUG_INFO("Totalize import energy %d : %.3f kwh\n", meterIndex, meter_info[meterIndex].totlizeImportEnergy);   
 								DEBUG_INFO("Totalize export energy %d : %.3f kwh\n", meterIndex, meter_info[meterIndex].totlizeExportEnergy);
 								#endif//DEBUG_STANDALONG
 								//pollingIndex++;
@@ -239,26 +239,26 @@ int main(void)
 				//meterIndex++;
 			}
 
-			if(failCount[meterIndex] >= 10)
+			
+			if(failCount[meterIndex] >= 8)
 			{
-				#ifndef DEBUG_STANDALONG
-				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout)
-				{
+				//if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout)
+				//{
 					DEBUG_ERROR("Meter communication timeout");
 					ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].LinkStatus = 2;
-					//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = ON;
-				}
-				#endif//DEBUG_STANDALONG
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = ON;
+				//}
 			}
 			else
 			{
-				#ifndef DEBUG_STANDALONG
-				ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].LinkStatus = 1;
-				//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = OFF;
-				#endif//DEBUG_STANDALONG
+				ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].LinkStatus = 1; 
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = OFF;
 			}
-			usleep(200000); 
+			
+			DEBUG_INFO("Meter %d - LinkStatus %d :  failCount: %d \n", meterIndex, ShmSysConfigAndInfo->SysInfo.DcMeterInfo[meterIndex].LinkStatus,failCount[meterIndex]);
+			usleep(200000);
 		}
+				
 	}
 
 

+ 6 - 3
EVSE/Modularization/DcMeter/curlApi.c

@@ -92,6 +92,7 @@ int httpGet(uint8_t *url, uint8_t *responseData)
 		 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
 		 //curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
 		 //curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
+		 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 2500L);
 
 		 res = curl_easy_perform(curl);
 
@@ -142,6 +143,7 @@ int httpPost(uint8_t *url, uint8_t *postData, uint8_t *responseData)
 		 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
 		 //curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
 		 //curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
+		 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 2500L);
 
 		 res = curl_easy_perform(curl);
 
@@ -192,6 +194,7 @@ int httpPut(uint8_t *url, uint8_t *postData)
 		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
 		//curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
 		//curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
+		curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 2500L);
 
 		res = curl_easy_perform(curl);
 
@@ -243,7 +246,7 @@ int curlDownload(uint8_t *url, uint8_t *filename)
 
 	if(curl)
 	{
-		curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30L);
+		curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 30000L);
 		curl_easy_setopt(curl, CURLOPT_URL, (char*)url);
 		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
 		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
@@ -296,7 +299,7 @@ int httpUpload(uint8_t *url, uint8_t *filename)
 			curl = curl_easy_init();
 			if(curl)
 			{
-				curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30L);
+				curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 30000L);
 				curl_easy_setopt(curl, CURLOPT_URL, (char*)url);
 				curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
 				curl_easy_setopt(curl, CURLOPT_READDATA, upFile);
@@ -378,7 +381,7 @@ int ftpUpload(uint8_t *url, uint8_t *filename)
 			curl = curl_easy_init();
 			if(curl)
 			{
-				curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30L);
+				curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 30000L);
 				curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
 				curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
 				curl_easy_setopt(curl, CURLOPT_URL, url);

+ 4 - 4
EVSE/Modularization/DcMeter/meterComm.c

@@ -61,7 +61,7 @@ int readVoltage(Meter_Info *meter_info)
 
 		case METER_MODEL_LEM_L18005A:
 		default:
-			if(httpGet((uint8_t*)meterApiAddress, data))
+			if(httpGet((uint8_t*)meterApiAddress, data) != FAIL)
 			{
 				//printf("data: %s\n", data);
 				//printf("meterApiAddress: %s\n", meterApiAddress);
@@ -109,7 +109,7 @@ int readCurrent(Meter_Info *meter_info)
 	{
 		case METER_MODEL_LEM_L18005A:
 		default:
-			if(httpGet((uint8_t*)meterApiAddress, data))
+			if(httpGet((uint8_t*)meterApiAddress, data) != FAIL)
 			{
 				json_object *livemeasure;
 				livemeasure = json_tokener_parse((char*)data);
@@ -154,7 +154,7 @@ int readPower(Meter_Info *meter_info)
 	{
 		case METER_MODEL_LEM_L18005A:
 		default:
-			if(httpGet((uint8_t*)meterApiAddress, data))
+			if(httpGet((uint8_t*)meterApiAddress, data) != FAIL)
 			{
 				json_object *livemeasure;
 				livemeasure = json_tokener_parse((char*)data);
@@ -199,7 +199,7 @@ int readEnergy(Meter_Info *meter_info)
 	{
 		case METER_MODEL_LEM_L18005A:
 		default:
-			if(httpGet((uint8_t*)meterApiAddress, data))
+			if(httpGet((uint8_t*)meterApiAddress, data) != FAIL)
 			{
 				json_object *livemeasure;
 				livemeasure = json_tokener_parse((char*)data);