📄 flag.h
字号:
/***************************************************************************
* This code and information is provided "as is" without warranty of any *
* kind, either expressed or implied, including but not limited to the *
* implied warranties of merchantability and/or fitness for a particular *
* purpose. *
* *
* Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved. *
***************************************************************************/
//**************************************************************************
//
// DESCRIPTION: 71M652x POWER METER - FLAG protocol.
//
// AUTHOR: RGV
//
// HISTORY: See end of file
//
//**************************************************************************
//
// File: flag.h
//
//**************************************************************************
// This file is the shared logic of all the flag interfaces on a meter.
// This flag protocol is a simplified subset, with fixed baud rates,
// a fixed password and only a few commands.
// To use this file, include it after including a serial hardware abstraction
// layer. See flag0.c and ser0.h for an example.
#ifndef FLAG_H
#if FLAG
#define FLAG_H 1
// states in the flag protocol
typedef enum
{
STATE_XMIT_EMPTY_READOUT = 0,
STATE_XMIT_BREAK,
STATE_XMIT_ERR,
STATE_RCV_SIGN_ON,
STATE_XMIT_ID,
STATE_RCV_ID_ACK,
STATE_XMIT_PASSWORD_OPERAND,
STATE_XMIT_DATA,
STATE_XMIT_NAK,
STATE_RCV_COMMAND,
STATE_XMIT_ACK,
STATE_INVALID
} FLAG_STATE;
#define STATE_LOWER_LIMIT (STATE_XMIT_EMPTY_READOUT)
#define STATE_UPPER_LIMIT (STATE_XMIT_ACK)
#define STATE_COUNT ((STATE_UPPER_LIMIT - STATE_LOWER_LIMIT) + 1)
// error types reported
enum FlagError
{
NoError = 0, // no error is detected yet.
AuthorizationBad = 'A', // didn't get permission!
CommandBad = 'C', // command is not known!
DataBad = 'D', // the data or address is wrong!
// it should send a NAK for the following
MessageBad = 'M', // The message is malformed.
PasswordBad = 'P', // The message had a bad password.
ParityBad = 'R', // character parity.
ChecksumBad = 'S', // the checksum (BCC) is bad.
CharTimeout = 'T', // IO timed out
SessionTimeout = 'U' // IO timed out
};
// fields in a flag message
enum FlagMsgFld
{
// character fields
SOH = 0x01,
STX = 0x02,
ETX = 0x03,
ACK = 0x06,
LF = 0x0A,
CR = 0x0D,
NAK = 0x15,
// data fields
END = 0x80,
Z,
Y,
C, // command
D, // command subtype
DEVICE_ADDRESS,
DATA_ADDRESS,
DATA_COUNT,
HEX_DATA,
BEGIN_BCC,
BCC,
ERROR,
#if 0
ID, // only used in an HHU
#endif
INVALID
};
#define MSG_FLD_LOWER_LIMIT (END)
#define MSG_FLD_UPPER_LIMIT (ERROR)
#define MSG_FLD_COUNT \
((MSG_FLD_UPPER_LIMIT - MSG_FLD_LOWER_LIMIT) + 1)
// This begins the list of messages
// initial message from HHU to meter
extern uint8r_t msg_sign_on[];
// meter identifies itself to the HHU
// In an HHU, FLAG_ID would become ID
extern uint8r_t msg_id[];
// HHU acknowledges meter's identification
extern uint8r_t msg_ack_id[];
// meter responds to HHU's acknowledge of meter's identification
extern uint8r_t msg_nak_ack_id[];
// ACK
extern uint8r_t msg_ack[];
// NAK
extern uint8r_t msg_nak[];
// meter sends an error message
extern uint8r_t msg_err[];
// meter sends a data message
extern uint8r_t msg_data[];
// basic form of a command
extern uint8r_t msg_cmd[];
// an "EXIT B" command
extern uint8r_t msg_B0[];
// password operand command
extern uint8r_t msg_P0[];
// password receive
extern uint8r_t msg_P1[];
extern uint8r_t msg_R1[];
extern uint8r_t msg_W1[];
// start of TDK's nonstandard command message types
extern uint8r_t msg_U0[];
extern uint8r_t msg_C0[];
extern uint8r_t msg_Z0[];
// end of TDK's nonstandard command message types
// This array is searched backward
// by the command subtype
// to find a valid message template
#define CMD_FLD_INDEX 2
#define CMD_SUBTYPE_FLD_INDEX 3
#define MAX_MSG_INDEX 7
extern const uint8r_t * code msg_ptr_array[MAX_MSG_INDEX + 1];
#define MAX_CHAR_CNT 128 // number of data characters that can be transferred
#define MAX_DATA_INDEX ((MAX_CHAR_CNT/2) - 1) // number of data bytes to be send
#define CHAR_TIMEOUT (milliseconds(1500))
#define SESSION_TIMEOUT (seconds(60))
#endif // FLAG.
#endif // already defined.
/***************************************************************************
* $Log: flag.h,v $
* Revision 1.7 2006/07/22 01:32:19 tvander
* Fopund some lurking xdata arrays that needed to be in code space.
*
* Revision 1.6 2006/03/06 03:29:52 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.5 2005/11/09 02:21:15 tvander
* Added code to display watt hours from brownout mode.
* Added code to clear EEPROM (lapie command "EEE")
*
* Revision 1.4 2005/09/22 23:45:00 tvander
* Clean build all models and unit tests, updated copyright to be fore Teridian
*
* Revision 1.3 2005/06/04 01:24:40 tvander
* Fixed real time failure to read. Added conditional debug code to log state transitions and routine boundaries.
*
* Revision 1.2 2005/06/01 20:56:28 tvander
* Reworked to count characters rather than bytes.
*
* Revision 1.1 2005/05/27 23:27:44 tvander
* Table-driven flag, verified large (64 byte) transfers and calibration command.
*
* Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved. *
* this program is fully protected by the United States copyright *
* laws and is the property of Teridian Semiconductor Corporation. *
***************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -