⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 meter.h

📁 电力行业的DL645采集程序,嵌入式Linux环境
💻 H
字号:

/*****************************************************************************************
版权所有:   银骏科技
版本号:     2.00
文件名:     METER.H
生成日期:   2005.8.27
功能说明:   读写电能表程序头文件
其它说明:   
*****************************************************************************************/


#ifndef __METER_H
	#define __METER_H

#ifdef   ARM_METER_GLOBALS 
#define	ARM_METER_EXT
#else
#define	ARM_METER_EXT    extern
#endif 
#define 	MAX_TRY_RECV											3		
#define  METER_FRAME_SIZE              270
#define  METER_FRAME_DATA_SIZE   256

#define  METER_FRAME_START_CH  	0x68
#define  METER_FRAME_END_CH      	0x16

#define  METER_ADDR_LEN               		6
#define  METER_PASSWORD_LEN      	4

#define  METER_FRAME_EXT_LEN         12

#define  METER_CTRL_READ_DATA              1
#define  METER_CTRL_RE_READ                  3
#define  METER_CTRL_WRITE_DATA            4
#define  METER_CTRL_CALIBRATE_CLOCK   8
#define  METER_CTRL_ALARM                      7
#define  METER_CTRL_SET_ADDR               10
#define  METER_CTRL_DEMAND_RESET       16

//电表帧类型
#define  METER_FRAME_TYPE_NORMAL      0
#define  METER_FRAME_TYPE_AA               1
#define  METER_FRAME_TYPE_KEY             2
#define  METER_FRAME_TYPE_IRDA           3


typedef  struct tagMeterCtrlCodeType
{
	INT8U function:5;
	INT8U append:1;
	INT8U err:1;
	INT8U direct:1;
}_PACKED_   MeterCtrlCodeType;

#define METER_MASK_ADDR_CH            0xaa
#define METER_MASK_LEN                     4

typedef  struct tapMeterAddrType
{
	INT16U m_ma;
	INT8U m_mask[METER_MASK_LEN];
}_PACKED_   MeterAddrType;

typedef struct lzgdataType
{
	INT16U length;
	INT8U lstat;
}_PACKED_ backdatatype;

typedef  struct tagMeterFrameType
{
	INT8U header1;
	MeterAddrType addr;
	INT8U header2;
	_PACKED_  union
	{
		MeterCtrlCodeType code;
		INT8U value;
	}ctrl_un;	
	INT8U datalen;
	INT8U data[1];
}_PACKED_ MeterFrameType;

//电表操作错误码
#define METER_NO_ERR                  0x00
#define METER_ERR_DATA              0x01
#define METER_ERR_DI                   0x02
#define METER_ERR_PASSWORD     0x04
#define METER_ERR_ZONEOFYEAR  0x10
#define METER_ERR_ZONEOFDAY    0x20
#define METER_ERR_NUMOFRATE    0x40


//读数据包状态
#define  METER_RX_NULL           0x00
#define  METER_RX_HEADER       0x01
#define  METER_RX_DATALEN     0x02
#define  METER_RX_DATA           0x03
#define  METER_RX_END             0x04

#define  METER_FRAME_MODE_METER     0x00 
#define  METER_FRAME_MODE_LC           0x01 
typedef  struct tagMeterRxStateType
{
	INT8U state;
	INT8U mode;
	INT16U offset;
	INT16U size;
}_PACKED_ MeterRxStateType;


typedef  struct tagMeterRetDataType
{
	INT8U *retbuf;
	INT16U size;
	INT8U   retvalue;
}_PACKED_ MeterRetDataType;

typedef  struct tagMeterRWSendInfoType
{
	INT16U packsn;
	INT16U mp;
	INT16U dataId;
}_PACKED_ MeterRWSendInfoType;

typedef  struct tagMeterRelaySendInfoType
{
	INT16U packsn;
	INT16U mp;
	INT16U dataId;
}_PACKED_ MeterRelaySendInfoType;

typedef  struct tagMeterSampleSendInfoType
{
	INT16U packsn;
	INT16U mp;
	INT16U dataId;
	INT16U offset;
	INT16U idsize;	
	INT8U *buf;
}_PACKED_ MeterSampleSendInfoType;


#define METER_REPEAT_COUNT                          3
#define METER_RW_TIMEOUT                             5

//交采表FSM  状态
#define METER_STATE_INITIAL				 0
#define METER_STATE_READY  	                     1
#define METER_STATE_STARTID    	                     2
#define METER_STATE_REPEAT  	                     3
#define METER_STATE_SEND			               4
#define METER_STATE_WAIT       	    		        5
#define METER_STATE_ENDID       	    		        6
#define METER_STATE_RET       	    		        7

//交采表模式
#define METER_MODE_READ                               0
#define METER_MODE_WRITE                             1
#define METER_MODE_SAMPLE                            2
#define METER_MODE_RELAY                              3
#define METER_MODE_SEND                                4


typedef struct tagMeterFsmType
{
	INT8U   state;
	INT8U   mode;
	INT8U   repeatcount;
	INT8U   idcount;
	INT32U abortsecond;
	INT32U framesize;
	INT8U  *pFrame;
	MeterRetDataType retdata;
	_PACKED_  union {
		MeterRWSendInfoType rw;
		MeterRelaySendInfoType relay;
		MeterSampleSendInfoType sample;
	}sendInfo;
}_PACKED_ MeterFsmType;

#define METER_FSM_LEVEL_NOR          0
#define METER_FSM_LEVEL_LOW          1


#define METER_FSM_LEVEL_NUM          2

//交流采样表串口定义
#define METER_PORT 	   UART3
#define METER_BAUD  	   BAUD_9600
#define METER_STOPBITS    1
#define METER_PARITY 	   EVEN_PARITY
#define METER_BYTESIZE    8

BOOL MeterFilterFrame(INT8U *pbuf);

#endif /*METER_H_*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -