平车主控板(运维板)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

141 lines
2.7 KiB

//////////////////////////////////////////////////////////////////////////
/// COPYRIGHT NOTICE
/// Copyright (c) 2018, 传控科技
/// All rights reserved.
///
/// @file tpc_fsk.c
/// @brief transaction protocol control of fsk
///
///(本文件实现的功能的详述)
///
/// @version 1.1 CCsens technology
/// @author CC
/// @date 20150102
///
///
/// @version 1.2 CCsens technology
/// @author CC
/// @date 20180308
/// @info 整理
//
//////////////////////////////////////////////////////////////////////////
#ifndef __TPC_MODBUS_H_
#define __TPC_MODBUS_H_
#include "../clib/Type.h"
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
/**
* 用户协议
*/
enum MODBUS_OPER
{
MODBUS_OPER_READ = 0x03,
MODBUS_OPER_WRITE = 0x06,
MODBUS_OPER_WRITE_M = 0x10,
MODBUS_OPER_ERR = 0x8F,
MODBUS_OPER_AUTH = 0x90,
};
enum MODBUS_ERR_CODE
{
MODBUS_ERR_LEN = 0x01,
MODBUS_ERR_CRC = 0x02,
MODBUS_ERR_OPCODE = 0x03,
};
//协议类型: MODBUS RTU模式
//#define D_s_PH4_modbus_max (32)
#define D_s_PH4_modbus_max (64)
typedef struct ts_ph4_modbus
{
U8 salver; //从机地址
U8 oper; //功能码
U8 buf[D_s_PH4_modbus_max];
U8 crc[2];
U8 num;
}TS_PH4_modbus;
typedef struct s_modbus_03
{
U8 slaverId;
U16 reg;
U16 num;
}Modbus03;
typedef struct s_modbus_03_ack
{
U8 bytes;
U8 buf[D_s_PH4_modbus_max-1];
}Modbus03Ack;
typedef struct s_modbus_06
{
U16 reg;
U16 val;
}Modbus06;
typedef struct s_modbus_06_ack
{
U16 reg;
U16 val;
}Modbus06Ack;
typedef struct s_modbus_10
{
U16 reg;
U16 num;
U8 count;
}Modbus10;
typedef struct s_modbus_10_ack
{
U16 reg;
U16 num;
}Modbus10Ack;
typedef struct s_modbus_err_ack
{
U8 errcode;
}ModbusErrAck;
typedef struct
{
U16 slaver;
U16 oper;
U16 reg;
U16 regnum;
U16 bytes;
U8 *buf;
U16 mask;
}MD_SLAVER_INFO;
typedef struct
{
U8 reg;
U8 max; //接收到的数目的最大值
vU8 head; //接收标志头标志
vU8 ok; //接收协议ok标志
vU8 num;
vU8 error; //错误
vU8 *sp;
U8 buf[D_s_PH4_modbus_max + 8];
vU8 crc[2];
}TS_Handle_PH4;
extern U8 L3_pack_modbus(TS_PH4_modbus *pmodbus, MD_SLAVER_INFO *slaver_info);
extern void L1_s2b_PH4_init(TS_Handle_PH4 *p);
extern void L1_s2b_PH4(TS_Handle_PH4 *p);
#endif /* end __TPC_UART_H_ */
/*****************************************************************************
** End Of File
******************************************************************************/