49 lines
1.4 KiB
C
49 lines
1.4 KiB
C
#ifndef _JT808_PKG_TRANSMIT_H_
|
||
#define _JT808_PKG_TRANSMIT_H_
|
||
#include "jt808_msg_pkg.h"
|
||
#include "jt808_msg_parse.h"
|
||
#include "jt808_config.h"
|
||
#include "tcp_client.h"
|
||
|
||
// #pragma pack(1)
|
||
typedef struct{
|
||
uint16_t msg_id;
|
||
uint32_t timeout; //超时时间,单位ms
|
||
}pkg_msg_t;
|
||
// #pragma pack()
|
||
|
||
// 原型 :int tcp_client_send(const char *buf, int len);
|
||
#ifdef __TCP_CLIENT_H__
|
||
#define PKG_SEND(__buf, __len) tcp_client_send(__buf, __len)
|
||
#else
|
||
#define PKG_SEND(__buf, __len) 0
|
||
#endif
|
||
|
||
#define MAX_PENDING_REQUESTS 5 // 最大并发等待请求数
|
||
|
||
extern PrsResult_t PrsResult;
|
||
|
||
// 等待请求结构体
|
||
typedef struct {
|
||
uint16_t msg_id; // 发送的消息ID
|
||
uint16_t flow_num; // 消息流水号
|
||
uint32_t timeout; // 等待超时时间(毫秒)
|
||
uint32_t start_tick; // 开始等待的时间戳
|
||
uint8_t is_waiting; // 是否在等待中(1=是,0=否)
|
||
uint8_t response_received; // 是否已收到应答(1=是,0=否)
|
||
} PendingRequest_t;
|
||
|
||
|
||
// 全局变量
|
||
static PendingRequest_t pending_requests[MAX_PENDING_REQUESTS]; // 等待请求数组
|
||
|
||
// 触发消息发送
|
||
int jt808_pkg_send(MessageID_t Msg_ID, uint32_t timeout);
|
||
|
||
// 接收处理 (放入TCP接收回调中)
|
||
void jt808_pkg_handle(uint8_t *receive_buf, uint16_t receive_len);
|
||
|
||
// jt808协议初始化
|
||
int jt808_init(void);
|
||
|
||
#endif // _JT808_PKG_TRANSMIT_H_
|