Browse Source

2020-09-15 / Eason Yang
Action
1. Rename version
2. Fixed DNS problem
3. Added switch case for Disable module and Enable module
4. Fixed log print
5. Fixed connection logic

File
1.Module_4g.c
Action 1
Action 2
Action 3
Action 4
Action 5

Version : V0.05

8009 4 years ago
parent
commit
7e675105cc
1 changed files with 268 additions and 257 deletions
  1. 268 257
      EVSE/Modularization/Module_4g.c

+ 268 - 257
EVSE/Modularization/Module_4g.c

@@ -2,9 +2,9 @@
  *  Module_4g.c
  *
  *  Created on: 2019-11-29
- *  Update on: 2020-08-18
+ *  Update on: 2020-09-15
  *  Author: Eason Yang
- *  Version: V0.04
+ *  Version: V0.05
  */
 
 #include    <sys/types.h>
@@ -57,6 +57,10 @@
 #define CheckInternetInterval		30	// Seconds
 #define DisconnInterval				60 	// Seconds
 
+// Define Telecom mode
+#define DISABLE_4G_MODULE	0
+#define ENABLE_4G			1
+
 int Check4GModem(void);
 int isPppUp(void);
 int isReadInfo(void);
@@ -74,8 +78,10 @@ int set_blocking (int fd, int should_block);
 void trim_s(char *s, unsigned char len);
 void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
 
-char *portName[3] 			= {"/dev/ttyUSB2", "/dev/ttyUSB2", "/dev/ttyACM2"};
-char *valid_Internet[2] 	= {"8.8.8.8", "180.76.76.76"};
+char *LATEST_FIRMWARE_VERSION 	= "V0.05";
+char *LATEST_UPGRAGE_DATE		= "2020-09-15";
+char *portName[3] 				= {"/dev/ttyUSB2", "/dev/ttyUSB2", "/dev/ttyACM2"};
+char *valid_Internet[2] 		= {"8.8.8.8", "180.76.76.76"};
 pid_t	pid;
 
 struct dongle_info
@@ -266,7 +272,7 @@ int isPppUp(void)
 	char buf[512];
 	char tmp[512];
 
-	strcpy(cmd, "ifconfig");;
+	strcpy(cmd, "ifconfig ppp0");;
 	fp = popen(cmd, "r");
 	if(fp != NULL)
 	{
@@ -280,7 +286,7 @@ int isPppUp(void)
 			if(strstr(buf, "addr:") > 0)
 			{
 				sscanf(buf, "%*s%s", tmp);
-				substr((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
+				substr((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress, tmp, strspn(tmp, "addr:"), (strlen(tmp) - strspn(tmp, "addr:")));
 			}
 		}
 	}
@@ -317,7 +323,6 @@ int isReadInfo(void)
 				// Read Manufacturer
 				//==============================
 				Lenght = at_command(uart, "at+gmi\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -333,7 +338,6 @@ int isReadInfo(void)
 				// Read Model
 				//==============================
 				Lenght = at_command(uart, "at+gmm\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -349,7 +353,6 @@ int isReadInfo(void)
 				// Read Revision
 				//==============================
 				Lenght = at_command(uart, "at+gmr\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -365,7 +368,6 @@ int isReadInfo(void)
 				// Read IMEI
 				//==============================
 				Lenght = at_command(uart, "at+gsn\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -381,7 +383,6 @@ int isReadInfo(void)
 				// Read CSQ
 				//==============================
 				Lenght = at_command(uart, "at+csq\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -396,7 +397,6 @@ int isReadInfo(void)
 				// Read Mode
 				//==============================
 				Lenght = at_command(uart, "at+qcfg= \"nwscanmode\"\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -437,7 +437,6 @@ int isReadInfo(void)
 				// Read Manufacturer
 				//==============================
 				Lenght = at_command(uart, "at+cgmi\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -452,7 +451,6 @@ int isReadInfo(void)
 				// Read Model
 				//==============================
 				Lenght = at_command(uart, "at+cgmm\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -467,7 +465,6 @@ int isReadInfo(void)
 				// Read Revision
 				//==============================
 				Lenght = at_command(uart, "at+cgmr\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -482,7 +479,6 @@ int isReadInfo(void)
 				// Read IMEI
 				//==============================
 				Lenght = at_command(uart, "at+cgsn\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -498,7 +494,6 @@ int isReadInfo(void)
 				// Read CSQ
 				//==============================
 				Lenght = at_command(uart, "at+csq\r", rx);
-
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
@@ -555,7 +550,6 @@ int isReadSimInfo(void)
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
-
 					if (strstr(rx, "ERROR"))
 					{
 						memset(Dongle.IMSI, 0, sizeof Dongle.IMSI);
@@ -579,7 +573,6 @@ int isReadSimInfo(void)
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
-
 					if (strstr(rx, "ERROR"))
 					{
 						memset(Dongle.ICCID, 0, sizeof Dongle.ICCID);
@@ -600,7 +593,7 @@ int isReadSimInfo(void)
 				//==============================
 				// Set don't echo command
 				//==============================
-				if (at_command(uart, "ate0\r", rx) <= 0)
+				if(at_command(uart, "ate0\r", rx) <= 0)
 					result = FAIL;
 
 				//==============================
@@ -610,7 +603,6 @@ int isReadSimInfo(void)
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
-
 					if(strstr(rx, "ERROR"))
 					{
 						memset(Dongle.IMSI, 0, sizeof Dongle.IMSI);
@@ -634,8 +626,7 @@ int isReadSimInfo(void)
 				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
-
-					if (strstr(rx, "ERROR"))
+					if(strstr(rx, "ERROR"))
 					{
 						memset(Dongle.ICCID, 0, sizeof Dongle.ICCID);
 						result = FAIL;
@@ -685,15 +676,14 @@ int CheckSignalRssi(void)
 				//==============================
 				// Set don't echo command
 				//==============================
-				if (at_command(uart, "ate0\r", rx) <= 0)
+				if(at_command(uart, "ate0\r", rx) <= 0)
 					result = FAIL;
 
 				//==============================
 				// Read CSQ
 				//==============================
 				Lenght = at_command(uart, "at+csq\r", rx);
-
-				if (Lenght > 0)
+				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
 					memcpy(tmp, rx, strcspn(rx, ","));
@@ -710,15 +700,14 @@ int CheckSignalRssi(void)
 				//==============================
 				// Set don't echo command
 				//==============================
-				if (at_command(uart, "ate0\r", rx) <= 0)
+				if(at_command(uart, "ate0\r", rx) <= 0)
 					result = FAIL;
 
 				//==============================
 				// Read CSQ
 				//==============================
 				Lenght = at_command(uart, "at+csq\r", rx);
-
-				if (Lenght > 0)
+				if(Lenght > 0)
 				{
 					memset(tmp, 0, sizeof tmp);
 					memcpy(tmp, rx, strcspn(rx, ","));
@@ -921,6 +910,8 @@ int rstModule(void)
 				{
 					result = FAIL;
 				}
+				
+				DEBUG_INFO("Dongle hardware reset...\n");
 
 				break;
 			case DONGLE_UBLOX:
@@ -928,6 +919,8 @@ int rstModule(void)
 				{
 					result = FAIL;
 				}
+				
+				DEBUG_INFO("Dongle hardware reset...\n");
 
 				break;
 		}
@@ -1087,279 +1080,297 @@ int main(void)
 
 		return 0;
 	}
+	
+	DEBUG_INFO("4G Module latest Firmware Version : %s\n",LATEST_FIRMWARE_VERSION);
+	DEBUG_INFO("Date for last upgrade : %s\n",LATEST_UPGRAGE_DATE);
 
 	for(;;)
 	{
-		if(((Dongle.Model = Check4GModem()) != FAIL))
+		TOP:
+		
+		switch(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled)
 		{
-			ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken = 0;
-
-			Dongle.cnt_SearchModuleFail = 0;
-			if(isReadInfo() == PASS)
-			{
-				memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName, Dongle.MODELNAME, sizeof Dongle.MODELNAME);
-				memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer, Dongle.REVISION, sizeof Dongle.REVISION);
-				memcpy(ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, Dongle.REVISION, sizeof Dongle.REVISION);
-				memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei, Dongle.IMEI, sizeof Dongle.IMEI);
-				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi = Dongle.CSQ;
-				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = Dongle.MODE;
-
-				#ifdef SystemLogMessage
-				DEBUG_INFO("========================================\n");
-				DEBUG_INFO("Status: Device info readable...\n");
-				DEBUG_INFO("Device MANUFACTURER: %s\n", Dongle.MANUFACTURER);
-				DEBUG_INFO("Device MODEL: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
-				DEBUG_INFO("Device REVISION: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
-				DEBUG_INFO("Device IMEI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
-				DEBUG_INFO("Device RSSI: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
-				DEBUG_INFO("Device MODE: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode);
-				DEBUG_INFO("========================================\n");
-				#endif
-
-				Dongle.cnt_ReadInfoFail = 0;
-				if(isReadSimInfo() == PASS)
+			case ENABLE_4G:
+				DEBUG_INFO("Enable 4G module.\n");
+				if(((Dongle.Model = Check4GModem()) != FAIL))
 				{
-					ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus = 1;
-					memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid, Dongle.ICCID, sizeof Dongle.ICCID);
-					memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi, Dongle.IMSI, sizeof Dongle.IMSI);
-
-					#ifdef SystemLogMessage
-					DEBUG_INFO("========================================\n");
-					DEBUG_INFO("Status: SIM card info readable...\n");
-					DEBUG_INFO("Device IMSI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
-					DEBUG_INFO("Device ICCID: %.20s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
-					DEBUG_INFO("TelcomSimStatus: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus);
-					DEBUG_INFO("========================================\n");
-					#endif
-
-					Dongle.cnt_ReadSimInfoFail = 0;
-					if(isPppUp() == PASS)
-					{
-						#ifdef SystemLogMessage
-						DEBUG_INFO("PPP IP: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
-						#endif
+					ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken = 0;
 
-						Dongle.cnt_pppFail = 0;
-						do
+					Dongle.cnt_SearchModuleFail = 0;
+					if(isReadInfo() == PASS)
+					{
+						memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName, Dongle.MODELNAME, sizeof Dongle.MODELNAME);
+						memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer, Dongle.REVISION, sizeof Dongle.REVISION);
+						memcpy(ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, Dongle.REVISION, sizeof Dongle.REVISION);
+						memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei, Dongle.IMEI, sizeof Dongle.IMEI);
+						ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi = Dongle.CSQ;
+						ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = Dongle.MODE;
+
+						DEBUG_INFO("========================================\n");
+						DEBUG_INFO("Status: Device info readable...\n");
+						DEBUG_INFO("========================================\n");
+						DEBUG_INFO("Device MANUFACTURER: %s\n", Dongle.MANUFACTURER);
+						DEBUG_INFO("Device MODEL: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
+						DEBUG_INFO("Device REVISION: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
+						DEBUG_INFO("Device IMEI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
+						DEBUG_INFO("Device RSSI: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
+						DEBUG_INFO("Device MODE: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode);
+						DEBUG_INFO("========================================\n");
+						
+						Dongle.cnt_ReadInfoFail = 0;
+						if(isReadSimInfo() == PASS)
 						{
-							if(isReachableInternet() == PASS)
+							ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus = 1;
+							memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid, Dongle.ICCID, sizeof Dongle.ICCID);
+							memcpy(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi, Dongle.IMSI, sizeof Dongle.IMSI);
+
+							DEBUG_INFO("========================================\n");
+							DEBUG_INFO("Status: SIM card info readable...\n");
+							DEBUG_INFO("========================================\n");
+							DEBUG_INFO("Device IMSI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
+							DEBUG_INFO("Device ICCID: %.20s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
+							DEBUG_INFO("TelcomSimStatus: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus);
+							DEBUG_INFO("========================================\n");
+						
+							Dongle.cnt_ReadSimInfoFail = 0;
+							if(isPppUp() == PASS)
 							{
-								ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 1;
-								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.Telecom4GModuleCommFail = 0;
-								ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = 0;
-								ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi = 0;
-
-								if(CheckSignalRssi() != PASS)
+								DEBUG_INFO("========================================\n");
+								DEBUG_INFO("Status: PPP interface found...\n");
+								DEBUG_INFO("========================================\n");
+								DEBUG_INFO("PPP IP: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
+								DEBUG_INFO("========================================\n");
+
+								Dongle.cnt_pppFail = 0;
+								if(isReachableInternet() == PASS)
 								{
-									#ifdef SystemLogMessage
-									DEBUG_INFO("No RSSI\n");
-									#endif
+									ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 1;
+									ShmStatusCodeData->AlarmCode.AlarmEvents.bits.Telecom4GModuleCommFail = 0;
+									ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = 0;
+									ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi = 0;
+									Dongle.cnt_InternetFail = 0;
+									
+									// Update Rssi Value
+									if(CheckSignalRssi() != PASS)
+										DEBUG_INFO("No RSSI\n");
+									else
+										ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi = Dongle.CSQ;
+
+									DEBUG_INFO("========================================\n");
+									DEBUG_INFO("Status: 4G Device connecting...\n");
+									DEBUG_INFO("========================================\n");
+									DEBUG_INFO("Network connection: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn);
+									DEBUG_INFO("Dongle internet valid result: Pass\n");
+									DEBUG_INFO("========================================\n");
+								
+									// Escape to the top
+									if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == DISABLE_4G_MODULE)
+									{
+										goto TOP;
+									}
+
+									sleep(CheckInternetInterval);
 								}
 								else
 								{
-									ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi = Dongle.CSQ;
+									DEBUG_INFO("Dongle internet valid result: Fail %d time\n", Dongle.cnt_InternetFail);
+
+									ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 0;
+									ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = 1;
+									ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi = 1;
+
+									Dongle.cnt_InternetFail++;
+									if(Dongle.cnt_InternetFail > 3)
+									{
+										system("killall 4GDetection");
+										system("killall pppd");
+										sleep(2);
+										
+										Dongle.cnt_InternetFail = 0;
+										rstModule();
+									}
+									
+									sleep(DisconnInterval);
 								}
-
-								#ifdef SystemLogMessage
-								DEBUG_INFO("================================\n");
-								DEBUG_INFO("Status: 4G Device connecting.\n");
-								DEBUG_INFO("================================\n");
-								DEBUG_INFO("Device MANUFACTURER: %s\n", Dongle.MANUFACTURER);
-								DEBUG_INFO("Device MODEL: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
-								DEBUG_INFO("Device REVISION: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
-								DEBUG_INFO("Device IMEI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
-								DEBUG_INFO("Device IMSI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
-								DEBUG_INFO("Device RSSI: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
-								DEBUG_INFO("Device ICCID: %.20s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
-								DEBUG_INFO("Device MODE: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode);
-								DEBUG_INFO("Network connection: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn);
-								DEBUG_INFO("================================\n");
-								#endif
-
-								#ifdef SystemLogMessage
-								DEBUG_INFO("Dongle internet valid result: Pass\n");
-								#endif
-
-								Dongle.cnt_InternetFail = 0;
-								sleep(CheckInternetInterval);
 							}
 							else
 							{
-								#ifdef SystemLogMessage
-								DEBUG_INFO("Dongle internet valid result: Fail %d time\n", Dongle.cnt_InternetFail);
-								#endif
-
-								Dongle.cnt_InternetFail++;
-								sleep(DisconnInterval);
-							}
-						}while(Dongle.cnt_InternetFail < 3);
+								if(Load4gConfiguration() == FAIL)
+								{
+									DEBUG_ERROR("4G configuration value NG.\n");
+									if(ShmStatusCodeData!=NULL)
+									{
+										ShmStatusCodeData->AlarmCode.AlarmEvents.bits.Telecom4GModuleCommFail=1;
+									}
+								}
+								else
+								{
+									DEBUG_WARN("PPP interface not found.\n");
+
+									memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress, 0 , sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
+
+									Dongle.cnt_pppFail++;
+									if(Dongle.cnt_pppFail > 3)
+									{
+										system("killall 4GDetection");
+										system("killall pppd");
+										sleep(2);
+										
+										Dongle.cnt_pppFail = 0;
+										rstModule();
+									}
+
+									system("killall 4GDetection");
+									system("killall pppd");
+									sleep(2);
+
+									if(Dongle.Model == DONGLE_QUECTEL)
+									{
+										system("/root/ppp/4GDetection /dev/ttyUSB3 &");
+										printf("4GDetection for primary device.\n");
+									}
+									else if(Dongle.Model == DONGLE_UBLOX)
+									{
+										system("/root/ppp/4GDetection /dev/ttyACM0 &");
+										printf("4GDetection for second device.\n");
+									}
+									else
+									{}
+								}
 
-						ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 0;
-						ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = 1;
-						ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi = 1;
-					}
-					else
-					{
-						if(Load4gConfiguration() == FAIL)
-						{
-							DEBUG_ERROR("4G configuration value NG.\n");
-							if(ShmStatusCodeData!=NULL)
-							{
-								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.Telecom4GModuleCommFail=1;
+								sleep(CheckConnectionInterval);
 							}
 						}
 						else
 						{
-							#ifdef SystemLogMessage
-							DEBUG_WARN("PPP interface not found.\n");
-							#endif
+							DEBUG_ERROR("SIM card info read error fail: %d\n", Dongle.cnt_ReadSimInfoFail);
 
+							ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus = 0;
+							memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
+							memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
 							memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress, 0 , sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
 
-							Dongle.cnt_pppFail++;
-							if(Dongle.cnt_pppFail > 5)
-							{
-								#ifdef SystemLogMessage
-								DEBUG_INFO("Dongle hardware reset...\n");
-								#endif
+							DEBUG_INFO("========================================\n");
+							DEBUG_INFO("Status: Read Sim card info fail...\n");
+							DEBUG_INFO("Device ICCID: %.20s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
+							DEBUG_INFO("Device IMSI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
+							DEBUG_INFO("========================================\n");
 
+							Dongle.cnt_ReadSimInfoFail ++;
+							if(Dongle.cnt_ReadSimInfoFail > 3)
+							{
+								system("killall 4GDetection");
+								system("killall pppd");
+								sleep(2);
+								
+								Dongle.cnt_ReadSimInfoFail = 0;
 								rstModule();
 							}
 
+							sleep(CheckSimInterval);
+						}
+					}
+					else
+					{
+						DEBUG_ERROR("Device info read error fail: %d\n", Dongle.cnt_ReadInfoFail);
+						
+						Dongle.MODE = NO_SERVICE;
+						memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
+						memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
+						memset(ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, 0, sizeof ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev);
+						memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
+						ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi = 0;
+						ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = 0;
+						
+						DEBUG_INFO("========================================\n");
+						DEBUG_INFO("Status: Read device info fail...\n");
+						DEBUG_INFO("Device MANUFACTURER: %s\n", Dongle.MANUFACTURER);
+						DEBUG_INFO("Device MODEL: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
+						DEBUG_INFO("Device REVISION: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
+						DEBUG_INFO("Device IMEI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
+						DEBUG_INFO("Device RSSI: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
+						DEBUG_INFO("Device MODE: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode);
+						DEBUG_INFO("========================================\n");
+
+						Dongle.cnt_ReadInfoFail++;
+						if(Dongle.cnt_ReadInfoFail > 3)
+						{
 							system("killall 4GDetection");
+							system("killall pppd");
 							sleep(2);
-
-							if(Dongle.Model == DONGLE_QUECTEL)
-							{
-								system("/root/ppp/4GDetection /dev/ttyUSB3 &");
-								printf("4GDetection for primary device.\n");
-							}
-							else if(Dongle.Model == DONGLE_UBLOX)
-							{
-								system("/root/ppp/4GDetection /dev/ttyACM0 &");
-								printf("4GDetection for second device.\n");
-							}
-							else
-							{}
+							
+							Dongle.cnt_ReadInfoFail = 0;
+							rstModule();
 						}
-
-						sleep(CheckConnectionInterval);
+						
+						sleep(CheckModemInfoInterval);
 					}
 				}
 				else
 				{
-					#ifdef SystemLogMessage
-					DEBUG_ERROR("SIM card info read error fail: %d\n", Dongle.cnt_ReadSimInfoFail);
-					#endif
-
+					DEBUG_ERROR("Device search error fail: %d\n", Dongle.cnt_SearchModuleFail);
+					
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = 1;
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi = 1;
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.Telecom4GModuleCommFail = 0;
+					ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 0;
+					ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi = 0;
 					ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus = 0;
+					ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = 0;
+					memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
 					memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
+					memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
 					memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
-					memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress, 0 , sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
-
-					#ifdef SystemLogMessage
-					DEBUG_INFO("========================================\n");
-					DEBUG_INFO("Status: Read Sim card info fail...\n");
-					DEBUG_INFO("Device ICCID: %.20s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
-					DEBUG_INFO("Device IMSI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
-					DEBUG_INFO("========================================\n");
-					#endif
-
-					Dongle.cnt_ReadSimInfoFail ++;
-					if(Dongle.cnt_ReadSimInfoFail > 3)
+					memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
+					memset(ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, 0, sizeof ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev);
+					memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
+					
+					Dongle.cnt_SearchModuleFail++;
+					if(Dongle.cnt_SearchModuleFail > 3)
 					{
-						#ifdef SystemLogMessage
-						DEBUG_INFO("Dongle hardware reset...\n");
-						#endif
+						DEBUG_ERROR("4G Module was broken.\n");
+						
+						if(isModuleUnbind() == PASS)
+						{
+							isModuleBind();
+						}
 
-						Dongle.cnt_ReadSimInfoFail = 0;
-						rstModule();
+						ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken = 1;
+						Dongle.cnt_SearchModuleFail = 0;
 					}
 
-					sleep(CheckSimInterval);
+					sleep(CheckModemInterval);
 				}
-			}
-			else
-			{
-				#ifdef SystemLogMessage
-				DEBUG_ERROR("Device info read error fail: %d\n", Dongle.cnt_ReadInfoFail);
-				#endif
-
-				Dongle.MODE = NO_SERVICE;
-				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
-				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
-				memset(ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, 0, sizeof ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev);
-				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
+				break;
+				
+			case DISABLE_4G_MODULE:
+			default:
+				DEBUG_INFO("Disable 4G module.\n");
+				
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = 0;
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi= 0;
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.Telecom4GModuleCommFail = 0;
+				ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken = 0;
+				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 0;
 				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi = 0;
+				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus = 0;
 				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = 0;
-
-				#ifdef SystemLogMessage
-				DEBUG_INFO("========================================\n");
-				DEBUG_INFO("Status: Read device info fail...\n");
-				DEBUG_INFO("Device MANUFACTURER: %s\n", Dongle.MANUFACTURER);
-				DEBUG_INFO("Device MODEL: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
-				DEBUG_INFO("Device REVISION: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
-				DEBUG_INFO("Device IMEI: %s\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
-				DEBUG_INFO("Device RSSI: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
-				DEBUG_INFO("Device MODE: %d\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode);
-				DEBUG_INFO("========================================\n");
-				#endif
-
-				Dongle.cnt_ReadInfoFail++;
-				if(Dongle.cnt_ReadInfoFail > 3)
-				{
-					#ifdef SystemLogMessage
-					DEBUG_INFO("Device hardware reset...\n");
-					#endif
-
-					Dongle.cnt_ReadInfoFail = 0;
-					rstModule();
-				}
-				sleep(CheckModemInfoInterval);
-			}
-		}
-		else
-		{
-			//==========================================
-			// Module valid fail process
-			//==========================================
-			#ifdef SystemLogMessage
-			DEBUG_ERROR("Device search error fail: %d\n", Dongle.cnt_SearchModuleFail);
-			#endif
-
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = 1;
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi = 1;
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.Telecom4GModuleCommFail = 0;
-			ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn = 0;
-			ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi = 0;
-			ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus = 0;
-			ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode = 0;
-			memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
-			memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
-			memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
-			memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
-			memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
-			memset(ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, 0, sizeof ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev);
-			memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
-
-			Dongle.cnt_SearchModuleFail++;
-			if(Dongle.cnt_SearchModuleFail > 3)
-			{
-				#ifdef SystemLogMessage
-				DEBUG_ERROR("4G Module was broken.\n");
-				#endif
-
-				if(isModuleUnbind() == PASS)
-				{
-					isModuleBind();
-				}
-
-				ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken = 1;
-
-				Dongle.cnt_SearchModuleFail = 0;
-			}
-
-			sleep(CheckModemInterval);
+				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei);
+				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
+				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
+				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
+				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer);
+				memset(ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, 0, sizeof ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev);
+				memset(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName, 0, sizeof ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModelName);
+				
+				system("killall 4GDetection");
+				system("killall pppd");
+				system("ifconfig ppp0 down");
+				
+				sleep(SystemInterval);
+				
+				break;
+			
 		}
 		//sleep(SystemInterval);
 	}