12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using Edge.Core.Parser.BinaryParser.Attributes;
- using Edge.Core.Parser.BinaryParser.MessageEntity;
- using System;
- namespace PetroChinaOnlineWatchPlugin.MessageEntity
- {
- public enum MessageCode
- {
- IFSF_MESSAGE_CODE_APPLICATION = 0,
- IFSF_MESSAGE_CODE_HEARTBEAT = 1,
- IFSF_MESSAGE_CODE_COMMUNICATION = 2
- }
- public enum MessageType
- {
- IFSF_MESSAGE_TYPE_READ = 0x00,
- IFSF_MESSAGE_TYPE_ANSWER = 0x20,
- IFSF_MESSAGE_TYPE_WRITE = 0x40,
- /// <summary>
- /// message type is an event, and need Ack.
- /// </summary>
- IFSF_MESSAGE_TYPE_UNSOLICITED_ACK = 0x60,
- IFSF_MESSAGE_TYPE_UNSOLICITED_WITHOUT_ACK = 0x80,
- IFSF_MESSAGE_TYPE_ACK = 0xE0
- }
- public abstract class MessageBase : MessageTemplateBase
- {
- [Format(1, EncodingType.BIN, -9990)]
- [Range(0, 255, "Recipient subnet must range in 1 to 255")]
- public byte RecipientSubnet { get; set; }
- [Format(1, EncodingType.BIN, -9980)]
- [Range(0, 127, "Recipient node must range in 1 to 127, but now is {0}")]
- public byte RecipientNode { get; set; }
- [Format(1, EncodingType.BIN, -9970)]
- [Range(0, 255, "Originator subnet must range in 1 to 255")]
- public byte OriginatorSubnet { get; set; }
- [Format(1, EncodingType.BIN, -9960)]
- [Range(0, 127, "Originator node must range in 1 to 127, but now is {0}")]
- public byte OriginatorNode { get; set; }
- [Format(1, EncodingType.BIN, -9950)]
- public MessageCode MessageCode { get; set; }
- /// <summary>
- /// 000xxxxx (bit map)
- /// 000 indicates the message type is READ
- /// xxxxx is the token created by the originator of the message
- /// 010xxxxx
- /// 010 indicates message type is WRITE
- /// xxxxx is the token
- /// 111xxxxx
- /// 111 indicates type ACKNOWLEDGE
- /// xxxxx is the token
- /// </summary>
- [Format(1, EncodingType.BIN, -9940)]
- public byte RawMessageStatusAndToken { get; protected set; }
- public MessageType MessageType
- {
- get { return (MessageType)(this.RawMessageStatusAndToken & 0xE0); }
- set
- {
- //1F = 0001 1111
- this.RawMessageStatusAndToken = (byte)((this.RawMessageStatusAndToken & 0x1F) + ((byte)value));
- }
- }
- public byte MessageToken
- {
- get { return (byte)(this.RawMessageStatusAndToken & 0x1F); }
- set
- {
- if (value > 0x1F) throw new ArgumentOutOfRangeException("Message Token max value is 0x1F");
- //E0 = 1110 0000
- this.RawMessageStatusAndToken = (byte)((this.RawMessageStatusAndToken & 0xE0) + value);
- }
- }
- public abstract override string ToString();
- }
- }
|