forked from xuos/xiuos
support adapter_4G send and receive data function
This commit is contained in:
parent
ab578dfe0e
commit
8aac82b1b4
|
@ -84,16 +84,16 @@ int Adapter4GInit(void)
|
||||||
/******************4G TEST*********************/
|
/******************4G TEST*********************/
|
||||||
int Adapter4GTest(void)
|
int Adapter4GTest(void)
|
||||||
{
|
{
|
||||||
const char *send_msg = "SendHeart";
|
const char *send_msg = "Adapter_4G Test";
|
||||||
char recv_msg[128];
|
char recv_msg[256] = {0};
|
||||||
int baud_rate = BAUD_RATE_115200;
|
int baud_rate = BAUD_RATE_115200;
|
||||||
|
|
||||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_4G_NAME);
|
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_4G_NAME);
|
||||||
|
|
||||||
#ifdef ADAPTER_EC200T
|
#ifdef ADAPTER_EC200T
|
||||||
//Using DSD server to test 4G Socket connection
|
//Using Hang Xiao server to test 4G Socket connection
|
||||||
uint8 server_addr[64] = "115.238.53.61";
|
uint8 server_addr[64] = "101.68.82.219";
|
||||||
uint8 server_port[64] = "33333";
|
uint8 server_port[64] = "9898";
|
||||||
|
|
||||||
adapter->socket.socket_id = 0;
|
adapter->socket.socket_id = 0;
|
||||||
|
|
||||||
|
@ -102,11 +102,12 @@ int Adapter4GTest(void)
|
||||||
|
|
||||||
AdapterDeviceConnect(adapter, CLIENT, server_addr, server_port, IPV4);
|
AdapterDeviceConnect(adapter, CLIENT, server_addr, server_port, IPV4);
|
||||||
|
|
||||||
// while (1) {
|
while (1) {
|
||||||
// AdapterDeviceSend(adapter, send_msg, strlen(send_msg));
|
AdapterDeviceSend(adapter, send_msg, strlen(send_msg));
|
||||||
// AdapterDeviceRecv(adapter, recv_msg, 128);
|
AdapterDeviceRecv(adapter, recv_msg, 256);
|
||||||
// printf("4G recv msg %s\n", recv_msg);
|
printf("4G recv msg %s\n", recv_msg);
|
||||||
// }
|
memset(recv_msg, 0, 256);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -170,7 +170,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch
|
||||||
__out:
|
__out:
|
||||||
agent->reply = NULL;
|
agent->reply = NULL;
|
||||||
PrivMutexAbandon(&agent->lock);
|
PrivMutexAbandon(&agent->lock);
|
||||||
agent->receive_mode = ENTM_MODE;
|
agent->receive_mode = DEFAULT_MODE;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -275,22 +275,26 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
||||||
|
|
||||||
PrivTaskDelay(1000);
|
PrivTaskDelay(1000);
|
||||||
|
|
||||||
memset(agent->entm_recv_buf, 0, ENTM_RECV_MAX);
|
|
||||||
agent->entm_recv_len = 0;
|
|
||||||
|
|
||||||
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) {
|
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) {
|
||||||
return -ERROR;
|
return -ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PrivMutexObtain(&agent->lock);
|
||||||
|
|
||||||
if (buffer_len < agent->entm_recv_len) {
|
if (buffer_len < agent->entm_recv_len) {
|
||||||
return -ERROR;
|
return -ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("EntmRecv once .\n");
|
printf("EntmRecv once len %u.\n", agent->entm_recv_len);
|
||||||
|
|
||||||
agent->entm_recv_buf[agent->entm_recv_len - 2] = '\0';
|
agent->entm_recv_buf[agent->entm_recv_len - 1] = '\0';
|
||||||
memcpy(rev_buffer, agent->entm_recv_buf, agent->entm_recv_len - 2);
|
memcpy(rev_buffer, agent->entm_recv_buf, agent->entm_recv_len - 2);
|
||||||
|
|
||||||
|
memset(agent->entm_recv_buf, 0, ENTM_RECV_MAX);
|
||||||
|
agent->entm_recv_len = 0;
|
||||||
|
|
||||||
|
PrivMutexAbandon(&agent->lock);
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,20 +314,22 @@ static int GetCompleteATReply(ATAgentType agent)
|
||||||
|
|
||||||
if (agent->receive_mode == ENTM_MODE){
|
if (agent->receive_mode == ENTM_MODE){
|
||||||
if (agent->entm_recv_len < ENTM_RECV_MAX) {
|
if (agent->entm_recv_len < ENTM_RECV_MAX) {
|
||||||
|
PrivMutexObtain(&agent->lock);
|
||||||
|
|
||||||
agent->entm_recv_buf[agent->entm_recv_len] = ch;
|
agent->entm_recv_buf[agent->entm_recv_len] = ch;
|
||||||
agent->entm_recv_len++;
|
agent->entm_recv_len++;
|
||||||
|
|
||||||
|
PrivMutexAbandon(&agent->lock);
|
||||||
|
|
||||||
if (last_ch == '!' && ch == '@'){
|
if (last_ch == '!' && ch == '@'){
|
||||||
PrivSemaphoreAbandon(&agent->entm_rx_notice);
|
PrivSemaphoreAbandon(&agent->entm_rx_notice);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_ch = ch;
|
last_ch = ch;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
printf("entm_recv_buf is_full ...\n");
|
printf("entm_recv_buf is_full ...\n");
|
||||||
}
|
}
|
||||||
}
|
} else if (agent->receive_mode == AT_MODE) {
|
||||||
else if (agent->receive_mode == AT_MODE){
|
|
||||||
if (read_len < agent->maintain_max){
|
if (read_len < agent->maintain_max){
|
||||||
agent->maintain_buffer[read_len] = ch;
|
agent->maintain_buffer[read_len] = ch;
|
||||||
read_len++;
|
read_len++;
|
||||||
|
@ -407,8 +413,7 @@ static void *ATAgentReceiveProcess(void *param)
|
||||||
memcpy(reply->reply_buffer, agent->maintain_buffer, agent->maintain_len);
|
memcpy(reply->reply_buffer, agent->maintain_buffer, agent->maintain_len);
|
||||||
|
|
||||||
reply->reply_len = agent->maintain_len;
|
reply->reply_len = agent->maintain_len;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
printf("out of memory (%d)!", reply->reply_max_len);
|
printf("out of memory (%d)!", reply->reply_max_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,8 +503,7 @@ int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
|
||||||
agent->maintain_max = maintain_max;
|
agent->maintain_max = maintain_max;
|
||||||
|
|
||||||
result = ATAgentInit(agent);
|
result = ATAgentInit(agent);
|
||||||
if (result == EOK)
|
if (result == EOK) {
|
||||||
{
|
|
||||||
PrivTaskStartup(&agent->at_handler);
|
PrivTaskStartup(&agent->at_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
enum ReceiveMode
|
enum ReceiveMode
|
||||||
{
|
{
|
||||||
|
DEFAULT_MODE = 0,
|
||||||
ENTM_MODE = 1,
|
ENTM_MODE = 1,
|
||||||
AT_MODE = 2,
|
AT_MODE = 2,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue