66 lines
1.6 KiB
C
66 lines
1.6 KiB
C
/**
|
|
* @file s7tcpmaster.h
|
|
* @brief 西门子S7Comm TCP客户端主站头文件
|
|
*/
|
|
#ifndef S7TCPMASTER_H
|
|
#define S7TCPMASTER_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
// ============================================================================
|
|
// 全局变量
|
|
// ============================================================================
|
|
|
|
extern uint8_t s7_txbuf[1024];
|
|
extern uint8_t s7_rxbuf[1024];
|
|
extern uint16_t s7_idx;
|
|
extern uint16_t s7_addr;
|
|
extern uint16_t s7_size;
|
|
extern uint16_t s7Timegap;
|
|
extern uint16_t client_wait_timeout;
|
|
extern uint16_t comm_count;
|
|
|
|
// ============================================================================
|
|
// 接口函数
|
|
// ============================================================================
|
|
|
|
/**
|
|
* @brief 处理接收到的S7响应
|
|
* @param size: 接收长度
|
|
* @param byte_offset: 数据字节偏移
|
|
* @return true: 处理成功,false: 不是有效的读响应
|
|
*/
|
|
_Bool s7_handle_recv(uint16_t size, uint16_t *byte_offset);
|
|
|
|
/**
|
|
* @brief 构建S7请求帧,返回发送长度
|
|
* @return 发送长度,0表示不发送
|
|
*/
|
|
uint16_t s7_build_send(void);
|
|
|
|
/**
|
|
* @brief 超时计数,由主循环每次调用递增
|
|
*/
|
|
void update_timeout_s7(void);
|
|
|
|
/**
|
|
* @brief S7 TCP客户端主函数,W5500socket主循环处理
|
|
* @param sn: socket编号
|
|
* @param recvbuf: 接收缓冲区
|
|
* @param destip: 目标IP地址
|
|
* @param destport: 目标端口
|
|
* @return 0/正表示正常,负表示错误
|
|
*/
|
|
int32_t loopback_tcpc_s7(uint8_t sn, uint8_t *recvbuf, uint8_t *destip, uint16_t destport);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|