|
|
@ -41,6 +41,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CFG_DEV_TYPE_LAND_PD
|
|
|
|
#ifdef CFG_DEV_TYPE_LAND_PD
|
|
|
|
/* 标准C库头文件. */
|
|
|
|
/* 标准C库头文件. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* 用户代码头文件. */
|
|
|
|
/* 用户代码头文件. */
|
|
|
@ -61,6 +66,38 @@
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
/* Internal functions --------------------------------------------------------*/
|
|
|
|
/* Internal functions --------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* description: 发包线程锁
|
|
|
|
|
|
|
|
param: slot -- slot id
|
|
|
|
|
|
|
|
sec -- 等待的秒
|
|
|
|
|
|
|
|
nsec -- 等待的纳秒
|
|
|
|
|
|
|
|
return: */
|
|
|
|
|
|
|
|
int32_t _hf_lock_timeout(uint8_t slot, uint32_t sec, uint32_t nsec)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
struct timespec time_out;
|
|
|
|
|
|
|
|
dau_t *dau = &daus[slot];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_REALTIME, &time_out);
|
|
|
|
|
|
|
|
time_out.tv_sec += sec;
|
|
|
|
|
|
|
|
time_out.tv_nsec += nsec;
|
|
|
|
|
|
|
|
if (time_out.tv_nsec >= 1000000000)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
time_out.tv_nsec -= 1000000000;
|
|
|
|
|
|
|
|
time_out.tv_sec++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sem_timedwait(&dau->sem_send, &time_out);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* description: 发包线程解锁
|
|
|
|
|
|
|
|
param: unit -- DAU id
|
|
|
|
|
|
|
|
return: */
|
|
|
|
|
|
|
|
void _hf_unlock(uint8_t slot)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dau_t *dau = &daus[slot];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sem_post(&dau->sem_send);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 重启发送 */
|
|
|
|
/* 重启发送 */
|
|
|
|
void _hf_send_reset(uint8_t slot, void *data)
|
|
|
|
void _hf_send_reset(uint8_t slot, void *data)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -79,6 +116,106 @@ void _hf_send_reset(uint8_t slot, void *data)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 发送升级文件 */
|
|
|
|
|
|
|
|
void _hf_send_update(uint8_t slot, void *data)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
struct stat file_stat;
|
|
|
|
|
|
|
|
dau_head_init_t head_data;
|
|
|
|
|
|
|
|
hf_upate_msg_t *msg = (hf_upate_msg_t*)data;
|
|
|
|
|
|
|
|
dau_t *dau = &daus[slot];
|
|
|
|
|
|
|
|
hf_upate_t *head = (hf_upate_t*)(dau->buf_send + sizeof(dau_pkt_head_t));
|
|
|
|
|
|
|
|
char *data_update = dau->buf_send + sizeof(dau_pkt_head_t) + sizeof(hf_upate_t);
|
|
|
|
|
|
|
|
uint8_t err_cnt = 0;
|
|
|
|
|
|
|
|
uint16_t index = 0;
|
|
|
|
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
int fd1 = -1;
|
|
|
|
|
|
|
|
int32_t len = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fd1 = open("test", O_RDWR | O_CREAT | O_TRUNC, 0777);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 打开文件 */
|
|
|
|
|
|
|
|
fd = open(msg->name, O_RDONLY, 0777);
|
|
|
|
|
|
|
|
if (-1 == fd)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DBG(DBG_M_PD_HF_ERR, "Can't open %s\r\n", msg->name);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 获取文件大小, 计算报文总数 */
|
|
|
|
|
|
|
|
if (stat(msg->name, &file_stat) < 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DBG(DBG_M_PD_HF_ERR, "Can't open %s\r\n", msg->name);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
close(fd1);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
head->type = msg->type;
|
|
|
|
|
|
|
|
head->sum = file_stat.st_size / HF_DATA_LEN;
|
|
|
|
|
|
|
|
if (file_stat.st_size % HF_DATA_LEN)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
head->sum++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printh("#1 type %d sum %d\r\n", head->type, head->sum);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 初始化报文头 */
|
|
|
|
|
|
|
|
head_data.cmd_type = DAU_REQUEST;
|
|
|
|
|
|
|
|
head_data.cmd = DAU_C_UPDATE;
|
|
|
|
|
|
|
|
head_data.pkt = dau->buf_send;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 发送报文 */
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* 读取文件数据 */
|
|
|
|
|
|
|
|
len = read(fd, data_update, HF_DATA_LEN);
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* 正好读完, 直接退出 */
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 初始化报文头 */
|
|
|
|
|
|
|
|
dau->pkt_index = index;
|
|
|
|
|
|
|
|
head->index = index;
|
|
|
|
|
|
|
|
head->len = len;
|
|
|
|
|
|
|
|
head_data.pkt_id = dau->pkt_id;
|
|
|
|
|
|
|
|
head_data.len = sizeof(dau_pkt_head_t) + sizeof(hf_upate_t) + len;
|
|
|
|
|
|
|
|
printh("#2 index %d len %d\r\n", index, len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 发送报文, 等待数据回复 */
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dau_data_send(dau, &head_data);
|
|
|
|
|
|
|
|
if (_hf_lock_timeout(slot, HF_SEND_TIMEOUT, 0) != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
err_cnt++;
|
|
|
|
|
|
|
|
if (err_cnt >= HF_SEND_ERR_CNT)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DBG(DBG_M_PD_HF_ERR, "Send error cnt %d.\r\n", err_cnt);
|
|
|
|
|
|
|
|
close(fd1);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG(DBG_M_PD_HF_ERR, "Send sem error.\r\n");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
write(fd1, data_update, len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dau->pkt_id++;
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
close(fd1);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 设备信息配置发送 */
|
|
|
|
/* 设备信息配置发送 */
|
|
|
|
void _hf_send_info_set(uint8_t slot, void *data)
|
|
|
|
void _hf_send_info_set(uint8_t slot, void *data)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -247,6 +384,24 @@ void _hf_recv_reset(uint8_t slot, char *pkt, uint16_t len)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 升级报文接收 */
|
|
|
|
|
|
|
|
void _hf_recv_update(uint8_t slot, char *pkt, uint16_t len)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dau_t *dau = &daus[slot];
|
|
|
|
|
|
|
|
hf_upate_ack_t *ack = (hf_upate_ack_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ack->result && ack->index == dau->pkt_index)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_hf_unlock(slot);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DBG(DBG_M_PD_HF_ERR, "Update rv %d index %d err!\r\n", ack->result, ack->index);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 设备信息配置报文接收 */
|
|
|
|
/* 设备信息配置报文接收 */
|
|
|
|
void _hf_recv_info_set(uint8_t slot, char *pkt, uint16_t len)
|
|
|
|
void _hf_recv_info_set(uint8_t slot, char *pkt, uint16_t len)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -739,7 +894,7 @@ static hf_recv_fun_cb _hf_command[] =
|
|
|
|
NULL, // DAU_C_ADD_DAU 2
|
|
|
|
NULL, // DAU_C_ADD_DAU 2
|
|
|
|
_hf_recv_reset, // DAU_C_RESET 3
|
|
|
|
_hf_recv_reset, // DAU_C_RESET 3
|
|
|
|
NULL, // 4
|
|
|
|
NULL, // 4
|
|
|
|
NULL, // DAU_C_UPDATE 5
|
|
|
|
_hf_recv_update, // DAU_C_UPDATE 5
|
|
|
|
_hf_recv_info_set, // DAU_C_DEV_INFO_SET 6
|
|
|
|
_hf_recv_info_set, // DAU_C_DEV_INFO_SET 6
|
|
|
|
_hf_recv_info_get, // DAU_C_DEV_INFO_GET 7
|
|
|
|
_hf_recv_info_get, // DAU_C_DEV_INFO_GET 7
|
|
|
|
NULL, // 8
|
|
|
|
NULL, // 8
|
|
|
@ -771,7 +926,7 @@ static hf_send_fun_cb _hf_send_command[] =
|
|
|
|
NULL, // 0
|
|
|
|
NULL, // 0
|
|
|
|
NULL, // DAU_SEND_ADD 1
|
|
|
|
NULL, // DAU_SEND_ADD 1
|
|
|
|
_hf_send_reset, // DAU_SEND_RESET 2
|
|
|
|
_hf_send_reset, // DAU_SEND_RESET 2
|
|
|
|
NULL, // 3
|
|
|
|
_hf_send_update, // DAU_SEND_UPDATE 3
|
|
|
|
_hf_send_info_set, // DAU_SEND_INFO_SET 4
|
|
|
|
_hf_send_info_set, // DAU_SEND_INFO_SET 4
|
|
|
|
_hf_send_info_get, // DAU_SEND_INFO_GET 5
|
|
|
|
_hf_send_info_get, // DAU_SEND_INFO_GET 5
|
|
|
|
NULL, // 6
|
|
|
|
NULL, // 6
|
|
|
|