Эх сурвалжийг харах

[Add][Modularization][Module_4g]

2021.08.23 / Folus Wen

Actions:
1. Thales module at command implement.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 3 жил өмнө
parent
commit
6ac31a7d70

+ 129 - 43
EVSE/Modularization/Module_4g.c

@@ -36,8 +36,13 @@
 #define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS	1
 #define FAIL	-1
-#define DONGLE_QUECTEL	1
-#define DONGLE_UBLOX	2
+
+enum DONGLE_MODEL
+{
+	DONGLE_QUECTEL=0,
+	DONGLE_THALES,
+	DONGLE_UBLOX
+};
 
 // Define Module network mode
 #define NET_MODE_NO_SERVICE		0
@@ -80,7 +85,7 @@ 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 *portName[3] 				= {"/dev/ttyUSB2", "/dev/ttyACM2", "/dev/ttyACM2"};
 char *valid_Internet[2] 		= {"8.8.8.8", "180.76.76.76"};
 char *Version_And_Date[2]		= {"V0.11","2021-07-06"};
 pid_t	pid;
@@ -91,7 +96,7 @@ struct dongle_info
 	char ICCID[20];
 	char IMSI[16];
 	char IMEI[16];
-	char MANUFACTURER[8];
+	char MANUFACTURER[16];
 	char MODELNAME[10];
 	char REVISION[18];
 	unsigned char MODE;
@@ -224,22 +229,29 @@ int Check4GModem(void)
         	(access("/dev/ttyACM2", F_OK) != -1) &&
 			(access("/dev/ttyACM3", F_OK) != -1))
     {
-    	result = DONGLE_UBLOX;
+    	if(access("/dev/ttyACM4", F_OK) != -1)
+    		result = DONGLE_UBLOX;
+    	else
+    		result = DONGLE_THALES;
     }
     else
     {}
 
-    if(result == DONGLE_QUECTEL)
-    {
-    	DEBUG_INFO("Quectel 4G modem be found\n");
-    }
-    else if(result == DONGLE_UBLOX)
-    {
-    	DEBUG_INFO("Ublox 4G modem be found\n");
-    }
-    else
+
+    switch(result)
     {
-    	DEBUG_WARN("No 4G modem be found\n");
+    	case DONGLE_QUECTEL:
+    		DEBUG_INFO("Quectel 4G modem be found\n");
+    		break;
+    	case DONGLE_THALES:
+			DEBUG_INFO("Thelas 4G modem be found\n");
+			break;
+    	case DONGLE_UBLOX:
+    		DEBUG_INFO("Ublox 4G modem be found\n");
+    		break;
+    	default:
+    		DEBUG_WARN("No 4G modem be found\n");
+    		break;
     }
 
     return result;
@@ -300,6 +312,7 @@ int isReadInfo(void)
 				//==============================
 				// Set don't echo command
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "ate0\r", rx);
 				if(Length > 0)
 				{
@@ -316,12 +329,13 @@ int isReadInfo(void)
 				//==============================
 				// Read Manufacturer
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "at+gmi\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
 					memcpy(tmp, rx, strcspn(rx,"OK"));
-					memset(rx, 0, sizeof rx);
+					memset(rx, 0, ARRAY_SIZE(rx));
 					trim_s(tmp,Length);
 
 					if(strstr(tmp, "atgmi") != NULL)
@@ -337,12 +351,13 @@ int isReadInfo(void)
 				//==============================
 				// Read Model
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "at+gmm\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
 					memcpy(tmp, rx, strcspn(rx,"OK"));
-					memset(rx, 0, sizeof rx);
+					memset(rx, 0, ARRAY_SIZE(rx));
 					trim_s(tmp,Length);
 
 					if(strstr(tmp, "atgmm") != NULL)
@@ -358,12 +373,13 @@ int isReadInfo(void)
 				//==============================
 				// Read Revision
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "at+gmr\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
 					memcpy(tmp, rx, strcspn(rx, "OK"));
-					memset(rx, 0, sizeof rx);
+					memset(rx, 0, ARRAY_SIZE(rx));
 					trim_s(tmp,Length);
 
 					if(strstr(tmp, "atgmr") != NULL)
@@ -379,12 +395,13 @@ int isReadInfo(void)
 				//==============================
 				// Read IMEI
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "at+gsn\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
 					memcpy(tmp, rx, strcspn(rx, "OK"));
-					memset(rx, 0, sizeof rx);
+					memset(rx, 0, ARRAY_SIZE(rx));
 					trim_s(tmp,Length);
 
 					if(strstr(tmp, "atgsn") != NULL)
@@ -400,10 +417,11 @@ int isReadInfo(void)
 				//==============================
 				// Read CSQ
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "at+csq\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
 					memcpy(tmp, rx, strcspn(rx,","));
 					strncpy(rx, tmp + strcspn(tmp,":")+1, 10);
 					Dongle.CSQ = atoi(rx);
@@ -414,6 +432,7 @@ int isReadInfo(void)
 				//==============================
 				// Read Mode
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "at+qnwinfo\r", rx);
 				if(Length > 0)
 				{
@@ -447,10 +466,11 @@ int isReadInfo(void)
 					result = FAIL;
 
 				break;
-			case DONGLE_UBLOX:
+			case DONGLE_THALES:
 				//==============================
 				// Set don't echo command
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "ate0\r", rx);
 				if(Length > 0)
 				{
@@ -467,14 +487,15 @@ int isReadInfo(void)
 				//==============================
 				// Read Manufacturer
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "at+cgmi\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
 					memcpy(tmp, rx, strcspn(rx,"OK"));
-					memset(rx, 0, sizeof rx);
+					memset(rx, 0, ARRAY_SIZE(rx));
 					memset(Dongle.MANUFACTURER, 0x00, ARRAY_SIZE(Dongle.MANUFACTURER));
-					strncpy(Dongle.MANUFACTURER, tmp+2, 6);
+					strncpy(Dongle.MANUFACTURER, tmp+2, 9);
 				}
 				else
 					result = FAIL;
@@ -482,14 +503,15 @@ int isReadInfo(void)
 				//==============================
 				// Read Model
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "at+cgmm\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
-					memcpy(tmp, rx, strcspn(rx,"OK"));
-					memset(rx, 0, sizeof rx);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
+					memcpy(tmp, &rx[strcspn(rx,"PLS")], strcspn(rx,"OK"));
+					memset(rx, 0, ARRAY_SIZE(rx));
 					memset(Dongle.MODELNAME, 0x00, ARRAY_SIZE(Dongle.MODELNAME));
-					strncpy(Dongle.MODELNAME , tmp+2, 9);
+					strncpy(Dongle.MODELNAME , tmp, 8);
 				}
 				else
 					result = FAIL;
@@ -497,14 +519,15 @@ int isReadInfo(void)
 				//==============================
 				// Read Revision
 				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
 				Length = at_command(uart, "at+cgmr\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
-					memcpy(tmp, rx, strcspn(rx, "OK"));
-					memset(rx, 0, sizeof rx);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
+					memcpy(tmp, &rx[strcspn(rx, "REVISION")+9], strcspn(rx, "OK"));
+					memset(rx, 0, ARRAY_SIZE(rx));
 					memset(Dongle.REVISION, 0x00, ARRAY_SIZE(Dongle.REVISION));
-					strncpy(Dongle.REVISION, tmp+2, 5);
+					strncpy(Dongle.REVISION, tmp, 6);
 				}
 				else
 					result = FAIL;
@@ -515,9 +538,9 @@ int isReadInfo(void)
 				Length = at_command(uart, "at+cgsn\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
 					memcpy(tmp, rx, strcspn(rx, "OK"));
-					memset(rx, 0, sizeof rx);
+					memset(rx, 0, ARRAY_SIZE(rx));
 					trim_s(tmp,Length);
 					memset(Dongle.IMEI, 0x00, ARRAY_SIZE(Dongle.IMEI));
 					strncpy(Dongle.IMEI, tmp, strlen(tmp));
@@ -531,7 +554,7 @@ int isReadInfo(void)
 				Length = at_command(uart, "at+csq\r", rx);
 				if(Length > 0)
 				{
-					memset(tmp, 0, sizeof tmp);
+					memset(tmp, 0, ARRAY_SIZE(tmp));
 					memcpy(tmp, rx, strcspn(rx,","));
 					strncpy(rx, tmp + strcspn(tmp,":")+1, 10);
 					Dongle.CSQ = atoi(rx);
@@ -539,6 +562,69 @@ int isReadInfo(void)
 				else
 					result = FAIL;
 
+				//==============================
+				// Read Mode
+				//==============================
+				memset(rx, 0x00, ARRAY_SIZE(rx));
+				Length = at_command(uart, "AT^SMONI\r", rx);
+				if(Length > 0)
+				{
+					memset(tmp, 0, sizeof tmp);
+					if(strstr(rx, "2G,") != NULL)
+					{
+						DEBUG_INFO("2G network\n");
+
+						if(sscanf(rx, "%*[^:]:%*[^,],%d,%*[^,],%*[^,],%[^,],%*[^,],%*[^,],%*[^,],%*[^,],%*[^,],%*[^,],%[^,],", &Dongle.channel, Dongle.operator, Dongle.act) == 2)
+						{
+							if(strstr(Dongle.act, "G") != NULL)
+								Dongle.MODE = NET_MODE_GMS_GPRS;
+							else if(strstr(Dongle.act, "E") != NULL)
+								Dongle.MODE = NET_MODE_GMS_GPRS;
+							else
+								Dongle.MODE = NET_MODE_CDMA;
+						}
+						else
+						{
+							DEBUG_WARN("AT^SMONI response can not parse.\n");
+						}
+					}
+					else if(strstr(rx, "3G,") != NULL)
+					{
+						if(sscanf(rx, "%*[^:]:%*[^,],%d,%*[^,],%*[^,],%*[^,],%*[^,],%[^,]", &Dongle.channel, Dongle.operator) == 2)
+						{
+							Dongle.MODE = NET_MODE_GSM_WCDMA;
+							memset(Dongle.band, 0x00, ARRAY_SIZE(Dongle.band));
+							memset(Dongle.act, 0x00, ARRAY_SIZE(Dongle.act));
+						}
+						else
+						{
+							DEBUG_WARN("AT^SMONI response can not parse.\n");
+						}
+					}
+					else if(strstr(rx, "4G,") != NULL)
+					{
+						if(sscanf(rx, "%*[^:]:%*[^,],%d,%[^,],%*[^,],%*[^,],%[^,],%*[^,],%[^,],", &Dongle.channel, Dongle.band, Dongle.act, Dongle.operator) == 4)
+						{
+							if(strstr(Dongle.act, "FDD") != NULL)
+								Dongle.MODE = NET_MODE_LTE;
+							else if(strstr(Dongle.act, "TDD") != NULL)
+								Dongle.MODE = NET_MODE_TD_SCDMA;
+							else
+								Dongle.MODE = NET_MODE_UNKNOWN;
+						}
+						else
+						{
+							DEBUG_WARN("AT^SMONI response can not parse.\n");
+						}
+					}
+					else
+					{
+						DEBUG_WARN("AT^SMONI response can not parse.\n");
+					}
+				}
+				else
+					result = FAIL;
+
 				break;
 		}
 	}
@@ -641,7 +727,7 @@ int isReadSimInfo(void)
 					result = FAIL;
 
 				break;
-			case DONGLE_UBLOX:
+			case DONGLE_THALES:
 				//==============================
 				// Set don't echo command
 				//==============================
@@ -739,7 +825,7 @@ int CheckSignalRssi(void)
 	{
 		switch (Dongle.Model)
 		{
-			case DONGLE_UBLOX:
+			case DONGLE_THALES:
 				//==============================
 				// Set don't echo command
 				//==============================
@@ -1034,7 +1120,7 @@ int rstModule(void)
 				DEBUG_INFO("Dongle hardware reset...\n");
 
 				break;
-			case DONGLE_UBLOX:
+			case DONGLE_THALES:
 				if(at_command(uart, "at+cfun=1,1\r", rx) <= 0)
 				{
 					result = FAIL;
@@ -1396,7 +1482,7 @@ TOP:
 										system("/root/ppp/4GDetection /dev/ttyUSB3 &");
 										printf("4GDetection for primary device.\n");
 									}
-									else if(Dongle.Model == DONGLE_UBLOX)
+									else if(Dongle.Model == DONGLE_THALES)
 									{
 										system("/root/ppp/4GDetection /dev/ttyACM0 &");
 										printf("4GDetection for second device.\n");