给4G模组发送函数加了互斥锁,防止出错
This commit is contained in:
parent
a7602b3042
commit
230109ef78
|
@ -201,6 +201,8 @@ struct Nt26k_Ops
|
|||
};
|
||||
|
||||
extern struct Nt26k_Ops nt26k_ops;
|
||||
extern rt_mutex_t nt26k_mutex;
|
||||
|
||||
extern rt_sem_t nt26k_recv_sem;
|
||||
extern rt_sem_t nt26k_recv_msg_sem;
|
||||
extern rt_sem_t nt26k_disconnect_sem;
|
||||
|
|
|
@ -52,6 +52,8 @@ struct rt_completion nt26k_init_complate;
|
|||
volatile int socket_id = 0;
|
||||
volatile rt_uint8_t ntp_flag = 0;
|
||||
|
||||
|
||||
|
||||
// 将本地时间转换为对应时区时间
|
||||
void Time_Zone_Conversion(TsRtcDateTime *timeInfo)
|
||||
{
|
||||
|
@ -370,6 +372,7 @@ int at_send_data(struct at_device *device, const char *data, rt_size_t size)
|
|||
at_delete_resp(resp);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
rt_mutex_take(nt26k_mutex, RT_WAITING_FOREVER);
|
||||
if (at_obj_exec_cmd(device->client, resp, TCP_SEND_DATA, socket_id, data) == RT_EOK)
|
||||
{
|
||||
if ((line_buffer = at_resp_get_line(resp, 2)) != RT_NULL)
|
||||
|
@ -377,11 +380,13 @@ int at_send_data(struct at_device *device, const char *data, rt_size_t size)
|
|||
if (rt_strstr(line_buffer, "SEND OK") != RT_NULL)
|
||||
{
|
||||
LOG_D("send data success, socket_id: %d", socket_id);
|
||||
rt_mutex_release(nt26k_mutex);
|
||||
at_delete_resp(resp);
|
||||
return RT_EOK;
|
||||
}
|
||||
}
|
||||
}
|
||||
rt_mutex_release(nt26k_mutex);
|
||||
at_delete_resp(resp);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ struct rt_event at_device_event;
|
|||
rt_sem_t nt26k_recv_sem;
|
||||
rt_sem_t nt26k_recv_msg_sem; // 用于接收信号
|
||||
rt_sem_t nt26k_disconnect_sem;
|
||||
|
||||
rt_mutex_t nt26k_mutex;
|
||||
static rt_timer_t nt26k_timer; // 上报心跳
|
||||
static rt_timer_t nt26k_upload_timer; // 更新本地时间定时器
|
||||
static rt_timer_t nt26k_error_timer; // 上电失败情况下启动定时器
|
||||
|
@ -77,7 +77,7 @@ rt_uint8_t nt26k_disconnect_retry_flag = 0; // 用于判断是否已经启动了
|
|||
Nt26kEventIndex nt26k_event_index;
|
||||
|
||||
rt_uint8_t power_on_send_flag = 0;
|
||||
rt_mutex_t nt26k_mutex;
|
||||
|
||||
int BSP_Nt26k_Init(struct Nt26k_Ops *ops, rt_uint8_t version);
|
||||
int BSP_Nt26k_Update(struct Nt26k_Ops *ops, rt_uint8_t device_type, rt_uint8_t event_type);
|
||||
int Nt26k_Send_Data(struct Nt26k_Ops *ops, rt_uint8_t data_num, rt_uint8_t cmd, rt_uint8_t device_type, rt_uint8_t event_type);
|
||||
|
@ -346,7 +346,7 @@ int Nt26k_Send_Data(struct Nt26k_Ops *ops, rt_uint8_t data_num, rt_uint8_t cmd,
|
|||
return RT_ERROR;
|
||||
}
|
||||
rt_memset(ops->body, 0, sizeof(struct DataBody));
|
||||
rt_mutex_take(nt26k_mutex, RT_WAITING_FOREVER);
|
||||
|
||||
ret = nt26k_ops.update_data(ops, device_type, event_type);
|
||||
if (ret == RT_EOK)
|
||||
{
|
||||
|
@ -361,7 +361,7 @@ int Nt26k_Send_Data(struct Nt26k_Ops *ops, rt_uint8_t data_num, rt_uint8_t cmd,
|
|||
ret = -ret;
|
||||
}
|
||||
}
|
||||
rt_mutex_release(nt26k_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -811,6 +811,7 @@ int Nt26k_Process_Events(Nt26kEvent nt26k_recv_event, struct at_device *device,
|
|||
if (result != RT_EOK)
|
||||
{
|
||||
LOG_E("nt26k send failed\n");
|
||||
nt26k_connect_sever_flag = 1;
|
||||
ret = RT_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
@ -825,7 +826,7 @@ int Nt26k_Process_Events(Nt26kEvent nt26k_recv_event, struct at_device *device,
|
|||
}
|
||||
else
|
||||
{
|
||||
// 收不到说明在平台未注册,此时nt26k_connect_sever_flag 为0,但nt26k_conncet_tcp_flag = 1;此时不发起重连,等待事件触发就行
|
||||
// 收不到说明在平台未注册或者信号不行,此时nt26k_connect_sever_flag 为0,但nt26k_conncet_tcp_flag = 1;此时不发起重连,等待事件触发就行
|
||||
nt26k_connect_sever_flag = 0;
|
||||
ret = RT_ERROR;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue