[Feature][ZXW-292]merge P56U06 version
Only Configure: No
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No
Change-Id: I922cf7b03b256d7dd5b0a6b73c3eac813f9512eb
diff --git a/ap/app/zte_amt/amt.c b/ap/app/zte_amt/amt.c
index 8cd888c..438c6c1 100755
--- a/ap/app/zte_amt/amt.c
+++ b/ap/app/zte_amt/amt.c
@@ -92,8 +92,11 @@
#ifdef USE_CAP_SUPPORT
static int g_amt_fd_cap = -1;
#endif
-
-
+static unsigned int rat = 0;
+static unsigned int ant_num = 0;
+static void send_ok(int fd);
+static void send_error(int fd);
+static void send_query_result(int fd,char* cmd, char* param);
/**
@@ -308,6 +311,160 @@
}
#endif
+/**
+ * @brief ½âÎöAMTÏûϢת»¯ÎªAT×Ö·û´®·¢Ë͸øPC
+ * @param[in] fd ÎļþÃèÊö·û
+ * @param[in] buf ½ÓÊÕÊý¾Ýbuffer
+ * @param[in] buf_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
+ * @return ·µ»Ø·¢Ë͵ÄÊý¾Ý³¤¶È
+ * @note
+ * @see
+ */
+static int At_SendData(int fd, unsigned char* buf, unsigned int buf_len)
+{
+ unsigned char *pSTX = NULL;
+ unsigned char *pETX = NULL;
+ unsigned char *pTID = NULL;
+ unsigned char *pFID = NULL;
+ unsigned char *pCheck = NULL;
+ unsigned char *pData = NULL;
+ unsigned char CheckSum = 0;
+ unsigned int msg_id;
+ unsigned int i = 0;
+ unsigned int phy_msg_id;
+ unsigned int phy_ret;
+ pTID = pTID;
+ pCheck = pCheck;
+ pData = pData;
+
+ pSTX = &buf[0];
+ pETX = &buf[buf_len - 1];
+ pTID = &buf[1];
+ pFID = &buf[1 + 1];
+ pCheck = &buf[buf_len - 2];
+ pData = &buf[1 + 1 + 1];
+
+ if (!((0x02 == *pSTX) && (0x02 == *pETX)))
+ {
+ return -1;
+ }
+
+ CheckSum = 0;
+
+ for (i = 0; i < (buf_len - 2); i++)
+ CheckSum ^= buf[1 + i];
+
+ if (CheckSum != 0)
+ {
+ return -1;
+ }
+
+ // TIDÓëFID×éºÏʹÓÃÒÑÀ©Õ¹¹¦ÄܺÅ
+ msg_id = (*pTID << 8) | *pFID;
+
+ AmtPrintf(AMT_INFO "%s: msg_id = %#04x, buf_len = %d.\n", __FUNCTION__, msg_id, buf_len);
+
+ switch(msg_id)
+ {
+ //LTEÎïÀí²ãAMTÏûÏ¢
+ case FID_LTEA_PHY_MSG:
+ {
+ memcpy(&phy_msg_id, pData, 4);
+ memcpy(&phy_ret, pData + 4, 4);
+ AmtPrintf(AMT_INFO "%s: lte_phy_msg_id = %#04x, lte_phy_ret = %d.\n", __FUNCTION__, phy_msg_id,phy_ret);
+ switch(phy_msg_id)
+ {
+ case 0x505://ZAMT_LTEA_GET_NST_RSRP
+ {
+ typedef struct
+ {
+ UINT32 dwMsgId; //x0505
+ UINT32 dwRet; //=0,±êʶ³É¹¦; ÆäËûÖµ±êʶʧ°Ü
+ UINT16 wAntRsrp[4]; // ×î¶à4¸öÌìÏß½ÓÊÕRSRPÖµ
+ UINT16 wAntRssi[2]; // Ö÷¸¨ÌìÏß½ÓÊÕRSSIÖµµÄÕûÊý²¿·Ö
+ UINT16 wAntRssiDec[2]; // Ö÷¸¨ÌìÏß½ÓÊÕRSSIÖµµÄСÊý²¿·Ö
+ }T_zAMT_LTEA_GetRsrp_Rsp;
+
+ T_zAMT_LTEA_GetRsrp_Rsp stGetRsrp_Rsp = {0};
+
+ if(phy_ret == 0)
+ {
+ memcpy(&stGetRsrp_Rsp, pData,sizeof(stGetRsrp_Rsp));
+ AmtPrintf(AMT_INFO "%s: RSRP[0] = %d, RSRP[1] = %d,RSSI[0] = %d, RSSI[1] = %d,RSSIDec[0] = %d, RSSIDec[1] = %d\n", \
+ __FUNCTION__, stGetRsrp_Rsp.wAntRsrp[0],stGetRsrp_Rsp.wAntRsrp[1],\
+ stGetRsrp_Rsp.wAntRssi[0],stGetRsrp_Rsp.wAntRssi[1],\
+ stGetRsrp_Rsp.wAntRssiDec[0],stGetRsrp_Rsp.wAntRssiDec[1]);\
+ char strRSSI[100] = {0};
+ UINT16 wAnt0RSSI = stGetRsrp_Rsp.wAntRssi[0];
+ UINT16 wAnt0RSSIDec = stGetRsrp_Rsp.wAntRssiDec[0];
+ double dAnt0RSSI = (double)(wAnt0RSSI + (wAnt0RSSIDec/128.0) - 65535);
+ UINT16 wAnt1RSSI = stGetRsrp_Rsp.wAntRssi[1];
+ UINT16 wAnt1RSSIDec = stGetRsrp_Rsp.wAntRssiDec[1];
+ double dAnt1RSSI = (double)(wAnt1RSSI + (wAnt1RSSIDec/128.0) - 65535);
+
+ switch(ant_num)
+ {
+ //»ñÈ¡Ö÷·rssi
+ case 10:
+ {
+ sprintf(strRSSI,"%.2f",dAnt0RSSI);
+ send_query_result(fd, "RSSI",strRSSI);
+ break;
+ }
+ //»ñÈ¡¸¨Â·rssi
+ case 11:
+ {
+ sprintf(strRSSI,"%.2f",dAnt1RSSI);
+ send_query_result(fd, "RSSI",strRSSI);
+ break;
+ }
+ //»ñÈ¡Ö÷¸¨Â·rssi
+ default:
+ {
+ sprintf(strRSSI,"%.2f,%.2f",dAnt0RSSI,dAnt1RSSI);
+ send_query_result(fd, "RSSI",strRSSI);
+ break;
+ }
+ }
+ }
+ else
+ {
+ send_error(fd);
+ }
+
+ break;
+ }
+ case 0x500://ZAMT_LTEA_SET_NST_INIT
+ {
+ if(phy_ret == 0)
+ {
+ send_ok(fd);
+ }
+ else
+ {
+ send_error(fd);
+ }
+ break;
+ }
+ default:
+ {
+ AmtPrintf(AMT_INFO "%s: lte_phy_msg_id = %#04x\n", __FUNCTION__, phy_msg_id);
+ break;
+ }
+ }
+
+ break;
+ }
+ default:
+ {
+ AmtPrintf(AMT_INFO "%s: unknown msg_id = %#04x\n", __FUNCTION__, msg_id);
+ break;
+ }
+ }
+
+ return 1;
+
+}
/**
* @brief ¶ÁÈ¡cp²àµÄ·´À¡ÏûÏ¢Ï̺߳¯Êý
@@ -345,17 +502,23 @@
{
Amt_SendData(*g_amt_fd_current, (unsigned char *)receive_buffer, read_len);
}
+ else
+ {
+
+ At_SendData(*g_amt_fd_current, (unsigned char *)receive_buffer, read_len);
+ }
}
else
{
AmtPrintf(AMT_ERROR "%s: Current fd is wrong.\n", __FUNCTION__);
}
-
+#if 0
unsigned int status = cpnv_FsGcWait(FS_NVROFS);
if(status != CPNV_OK)
AmtPrintf(AMT_INFO "%s: cpnv_FsGcWait fail, err = %d.\n", __FUNCTION__, status);
- }
+#endif
+ }
}
free(receive_buffer);
@@ -1696,6 +1859,166 @@
}
+static double lte_channel_to_freq(unsigned int band,unsigned int channel,unsigned int link)
+{
+ double freq = 0;
+ typedef struct
+ {
+ int band;
+ double dl_f_low;
+ int dl_n_offset;
+ double ul_f_low;
+ int ul_n_offset;
+ }stLteChannelArrangement;
+
+ stLteChannelArrangement info[64] = {
+
+ { 1, 2110, 0, 1920, 18000 },
+ { 2, 1930, 600, 1850, 18600 },
+ { 3, 1805, 1200, 1710, 19200 },
+ { 4, 2110, 1950, 1710, 19950 },
+ { 5, 869, 2400, 824, 20400 },
+ { 6, 875, 2650, 830, 20650 },
+ { 7, 2620, 2750, 2500, 20750 },
+ { 8, 925, 3450, 880, 21450 },
+ { 9, 1844.9, 3800, 1749.9, 21800 },
+ { 10, 2110, 4150, 1710, 22150 },
+ { 11, 1475.9, 4750, 1427.9, 22750 },
+ { 12, 729, 5010, 699, 23010 },
+ { 13, 746, 5180, 777, 23180 },
+ { 14, 758, 5280, 788, 23280 },
+ { 15, 0, 0, 0, 0 },
+ { 16, 0, 0, 0, 0 },
+ { 17, 734, 5730, 704, 23730 },
+ { 18, 860, 5850, 815, 23850 },
+ { 19, 875, 6000, 830, 24000 },
+ { 20, 791, 6150, 832, 24150 },
+ { 21, 1495.9, 6450, 1447.9, 24450 },
+ { 22, 3510, 6600, 3410, 24600 },
+ { 23, 2180, 7500, 2000, 25500 },
+ { 24, 1525, 7700, 1626.5, 25700 },
+ { 25, 1930, 8040, 1850, 26040 },
+ { 26, 859, 8690, 814, 26690 },
+ { 27, 852, 9040, 807, 27040 },
+ { 28, 758, 9210, 703, 27210 },
+ { 29, 0, 0, 0, 0 },
+ { 30, 2350, 9770, 2305, 27660 },
+ { 31, 462.5, 9870, 452.5, 27760 },
+ { 32, 0, 0, 0, 0 },
+ { 33, 1900, 36000, 1900, 36000 },
+ { 34, 2010, 36200, 2010, 36200 },
+ { 35, 1850, 36350, 1850, 36350 },
+ { 36, 1930, 36950, 1930, 36950 },
+ { 37, 1910, 37550, 1910, 37550 },
+ { 38, 2570, 37750, 2570, 37750 },
+ { 39, 1880, 38250, 1880, 38250 },
+ { 40, 2300, 38650, 2300, 38650 },
+ { 41, 2496, 39650, 2496, 39650 },
+ { 42, 3400, 41590, 3400, 41590 },
+ { 43, 3600, 43590, 3600, 43590 },
+ { 44, 703, 45590, 703, 45590 },
+ { 45, 0, 0, 0, 0 },
+ { 46, 0, 0, 0, 0 },
+ { 47, 0, 0, 0, 0 },
+ { 48, 0, 0, 0, 0 },
+ { 49, 0, 0, 0, 0 },
+ { 50, 0, 0, 0, 0 },
+ { 51, 0, 0, 0, 0 },
+ { 52, 0, 0, 0, 0 },
+ { 53, 0, 0, 0, 0 },
+ { 54, 0, 0, 0, 0 },
+ { 55, 0, 0, 0, 0 },
+ { 56, 0, 0, 0, 0 },
+ { 57, 0, 0, 0, 0 },
+ { 58, 0, 0, 0, 0 },
+ { 59, 0, 0, 0, 0 },
+ { 60, 0, 0, 0, 0 },
+ { 61, 0, 0, 0, 0 },
+ { 62, 0, 0, 0, 0 },
+ { 63, 0, 0, 0, 0 },
+ { 64, 0, 0, 0, 0 },
+
+ };
+
+ AmtPrintf(AMT_INFO "%s: beore transform band=%d,channel=%d,link=%d,freq=%f\n", __FUNCTION__, band,channel,link,freq);
+
+ if (band > 0 && band <= 64)
+ {
+ freq = info[band - 1].ul_f_low + 0.1 * (channel - info[band - 1].ul_n_offset);
+ if(link)
+ {
+ freq = info[band -1].dl_f_low + 0.1 * (channel - info[band - 1].dl_n_offset);
+ }
+ }
+ AmtPrintf(AMT_INFO "%s: after transform freq=%f\n", __FUNCTION__, freq);
+ return freq;
+}
+
+static void send_lte_nst_init_packet(unsigned int band,unsigned int channel,unsigned int band_width)
+{
+ typedef struct
+ {
+ u32 MsgId;
+ unsigned short wBandNum[2]; // Ƶ¶Î
+ unsigned short wFreq[2]; // ÖÐÐÄÆµµã£¬100kHzΪµ¥Î»
+ unsigned short wBandWidth[2]; // ´ø¿í
+ unsigned short wAntennaPort[2]; // ÌìÏß¶Ë¿Ú
+ unsigned short wModulation[2]; // µ÷ÖÆ·½Ê½£¬0£ºQPSK£¬1£º16QAM£¬2£º64QAM
+ unsigned short wRbNum[2]; // rb num
+ unsigned short wRbStartPostion[2]; // rb start
+ unsigned short wSingleCarrier[2]; //0:·¢µ÷ÖÆÐźŠ1:·¢µ¥Ôز¨
+ }T_zAMT_LTEA_NST_INIT;
+
+ unsigned short freq = 0;
+ freq = (unsigned short)(lte_channel_to_freq(band,channel,1)*10);
+
+
+ T_zAMT_LTEA_NST_INIT stNSTInitReq = {0};
+ stNSTInitReq.MsgId = 0x0500;
+ stNSTInitReq.wBandNum[0] = band;
+ stNSTInitReq.wFreq[0] = freq;
+ stNSTInitReq.wBandWidth[0] = band_width;
+ stNSTInitReq.wAntennaPort[0] = 1;
+ stNSTInitReq.wModulation[0] = 0;
+ stNSTInitReq.wRbNum[0] = 50;
+ stNSTInitReq.wRbStartPostion[0] = 0;
+ stNSTInitReq.wSingleCarrier[0] = 0;
+
+ AmtPrintf(AMT_INFO "%s: stNSTInitReq:MsgId=%d,wBandNum[0]=%d,wFreq[0]=%d,wBandWidth[0]=%d\n",\
+ __FUNCTION__, stNSTInitReq.MsgId,stNSTInitReq.wBandNum[0],stNSTInitReq.wFreq[0],stNSTInitReq.wBandWidth[0]);
+
+ AmtPrintf(AMT_INFO "%s: stNSTInitReq:wAntennaPort[0]=%d,wModulation[0]=%d,wRbNum[0]=%d\n",\
+ __FUNCTION__, stNSTInitReq.wAntennaPort[0],stNSTInitReq.wModulation[0],stNSTInitReq.wRbNum[0]);
+
+ AmtPrintf(AMT_INFO "%s: wRbStartPostion[0]=%d,wSingleCarrier[0]=%d\n",\
+ __FUNCTION__, stNSTInitReq.wRbStartPostion[0],stNSTInitReq.wSingleCarrier[0]);
+
+ unsigned char lte_nst_init_packet[sizeof(stNSTInitReq)+5] = {0};
+ unsigned short fid = 0x005f;
+ CreateSendPacket(fid,(unsigned char*)&stNSTInitReq,sizeof(stNSTInitReq),lte_nst_init_packet);
+ Amt_ComposeAndProcess(lte_nst_init_packet, sizeof(lte_nst_init_packet));
+
+}
+
+static void send_lte_get_rssi_packet()
+{
+ u32 lte_get_rssi_req[1] = {0};
+ lte_get_rssi_req[0] = 0x0505;
+ unsigned char lte_get_rssi_packet[1*4+5] = {0};
+ unsigned short fid = 0x005f;
+ CreateSendPacket(fid,(unsigned char*)lte_get_rssi_req,sizeof(lte_get_rssi_req),lte_get_rssi_packet);
+ Amt_ComposeAndProcess(lte_get_rssi_packet, sizeof(lte_get_rssi_packet));
+}
+
+static void send_lte_rx_close_packet()
+{
+ u32 lte_rx_close_req[1] = {0};
+ lte_rx_close_req[0] = 0x0301;
+ unsigned char lte_rx_close_packet[1*4+5] = {0};
+ unsigned short fid = 0x005f;
+ CreateSendPacket(fid,(unsigned char*)lte_rx_close_req,sizeof(lte_rx_close_req),lte_rx_close_packet);
+ Amt_ComposeAndProcess(lte_rx_close_packet, sizeof(lte_rx_close_packet));
+}
static void send_switch_to_user_mode_packet()
{
unsigned char bootmode[] = {0x54, 0x00};
@@ -1711,6 +2034,37 @@
PortSend(fd, (unsigned char*)rep_ok, strlen(rep_ok), WAIT_ALL);
}
+static void send_error(int fd)
+{
+ char rep_ok[] = "ERROR\r\n";
+ PortSend(fd, (unsigned char*)rep_ok, strlen(rep_ok), WAIT_ALL);
+}
+
+static void send_query_result(int fd,char* cmd, char* param)
+{
+ char * at_str = NULL;
+ int len = 0;
+
+ if(param)
+ {
+ len = 32 + strlen(cmd) + strlen(param);
+ at_str = malloc(len);
+ }
+ else
+ {
+ len = 32 + strlen(cmd);
+ at_str = malloc(len);
+ }
+ assert(at_str);
+ memset(at_str, 0, len);
+ if(!param)
+ sprintf(at_str,"\r\n+%s\r\n\r\nOK\r\n",cmd);
+ else
+ sprintf(at_str,"\r\n+%s: %s\r\n\r\nOK\r\n",cmd,param);
+
+ PortSend(fd, (unsigned char*)at_str, strlen(at_str), WAIT_ALL);
+ free(at_str);
+}
/**
* @brief ATÃüÁî½ÓÊÕ
* @param[in] fd ÎļþÃèÊö·û
@@ -1790,6 +2144,149 @@
send_switch_to_user_mode_packet();
send_ok(fd);
}
+ else if(strstr(buf,"at+rxstart") != NULL)
+ {
+ //½âÎöATÃüÁîat+rxstart=rat,band,channel,bandwidth,antnum,expect_level
+ AmtPrintf(AMT_INFO "%s: receive at+rxstart\n", __FUNCTION__);
+ int data[6] = {0};
+ //unsigned int rat = 0;
+ unsigned int band = 0;
+ unsigned int channel = 0;
+ unsigned int band_width = 0;
+ //unsigned int ant_num = 0;
+ int expect_level = 0;
+ int ret = 0;
+
+ //»ñÈ¡²ÎÊý
+ buf = buf + strlen("at+rxstart=");
+ if(buf != NULL)
+ {
+ ret = sscanf(buf, "%d,%d,%d,%d,%d,%d", &data[0], &data[1], &data[2], &data[3],&data[4],&data[5]);
+ if(ret == 6)
+ {
+ rat = data[0];
+ band = data[1];
+ channel = data[2];
+ band_width = data[3];
+ ant_num = data[4];
+ expect_level = data[5];
+ AmtPrintf(AMT_INFO "%s: rat=%d,band=%d,channel=%d,band_width=%d,ant_num=%d,expect_level=%d\n", __FUNCTION__, rat,band,channel,band_width,ant_num,expect_level);
+ //rat(ÖÆÊ½)ȡֵ·¶Î§[0,2] 0:GSM 1:WCDMA 2:LTE
+ if((rat < 0) || (rat > 2))
+ {
+ AmtPrintf(AMT_ERROR "%s: invalid rat=%d[0,2]!\n", __FUNCTION__,rat);
+ return read_len;
+ }
+ if(band == 0)
+ {
+ AmtPrintf(AMT_ERROR "%s: invalid band!\n", __FUNCTION__);
+ return read_len;
+
+ }
+ if(channel == 0 )
+ {
+ AmtPrintf(AMT_ERROR "%s: invalid channel!\n", __FUNCTION__);
+ return read_len;
+ }
+ //ant_num·¶Î§[0,1000]
+ if((ant_num < 0) || (ant_num > 1000))
+ {
+ AmtPrintf(AMT_ERROR "%s: invalid ant_num=%d[0,1000]!\n", __FUNCTION__,ant_num);
+ return read_len;
+ }
+
+ switch(rat)
+ {
+ //LTE
+ case 2:
+ {
+ //LTE´ø¿í·¶Î§
+ /*
+ typedef enum TDDLTE_bandW
+ {
+ RX1point75M = 0,
+ RX2point25M,
+ RX3point5M,
+ RX5M,
+ RX5point5M,
+ RX6M,
+ RX7M,
+ RX8M,
+ RX9M,
+ RX10M,
+ RX12M,
+ RX14M,
+ RX15M,
+ RX20M,
+ RX24M,
+ RX28M
+ RX1point4M
+ } TDDLTE_BandWidth;*/
+ if((band_width < 0) || (band_width > 16))
+ {
+ AmtPrintf(AMT_ERROR "%s: invalid LTE band_width=%d[0,16]!\n", __FUNCTION__,band_width);
+ return read_len;
+ }
+ //ת»¯Îª½øÈëamtģʽºÍnstinitÁ½ÌõAMTÖ¸Áî
+ send_enter_amt_mode_packet();
+ sleep(1);
+ send_lte_nst_init_packet(band,channel,band_width);
+ break;
+ }
+ case 0:
+ case 1:
+ default:
+ {
+ AmtPrintf(AMT_ERROR "%s: rat=%d not support\n", __FUNCTION__,rat);
+ send_error(fd);
+ break;
+ }
+ }
+
+ }
+ else
+ {
+ AmtPrintf(AMT_INFO "%s: at+rxstart param parse error!\n", __FUNCTION__);
+ return read_len;
+ }
+ }
+ else
+ {
+ AmtPrintf(AMT_INFO "%s: at+rxstart param str is empty!\n", __FUNCTION__);
+ return read_len;
+ }
+ }
+ else if(strstr(buf,"at+rssi") != NULL)
+ {
+ //½âÎöATÃüÁîat+rssi
+ AmtPrintf(AMT_INFO "%s: receive at+rssi\n", __FUNCTION__);
+ switch(rat)
+ {
+ //LTE
+ case 2:
+ {
+ //ת»¯Îª»ñÈ¡RSSIµÄAMTÖ¸Áî
+ send_lte_get_rssi_packet();
+ break;
+ }
+ case 0:
+ case 1:
+ default:
+ {
+ AmtPrintf(AMT_ERROR "%s: rat=%d not support\n", __FUNCTION__,rat);
+ send_error(fd);
+ break;
+ }
+ }
+ }
+ else if(strstr(buf,"at+rxstop") != NULL)
+ {
+ //ת»¯Îª¹Ø±Õ½ÓÊÕ»úºÍÍ˳öamtģʽÁ½ÌõAMTÖ¸Áî
+ send_lte_rx_close_packet();
+ sleep(1);
+ send_exit_amt_mode_packet();
+ send_ok(fd);
+ }
else
{
AmtPrintf(AMT_ERROR "%s: unknown at %s.\n", __FUNCTION__, buf);