C# Класс Subaru.SSM2.Ssm2Packet

Subaru SSM2 packet base class. Designed for object reusability which means immutable. Properties can be changed and will only affect those packet bytes. I.e. once header info has been set, one can modify payload data, header bytes won't be rewritten. Also avoids many backing fields since most properties directly read/write packet bytes.
Наследование: ISsm2Packet
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
buffer byte[]
propsSet SetProperties

Открытые методы

Метод Описание
Check ( ) : bool

Validate packet completely including checksum. Checks common and packet type specific characteristics.

Equals ( Ssm2Packet p ) : bool
Equals ( object obj ) : bool
Finish ( ) : void

Finish the packet. (Checksum and inline length byte.) Also checks if all properties have been set.

FromBytes ( byte buffer ) : void

Parses packet by taking packet bytes, does not use a copy! Assumes complete packet, does not validate. May want to call Check () afterwards. (Packet size is being calculated based on packet length byte.)

GetHashCode ( ) : int
NewFromBytes ( byte bytes ) : Ssm2Packet

Returns a specific Ssm2Packet type based on given content. Does not validate the packet, so manually call the Check method afterwards!

Ssm2Packet ( ) : System

Creates a SSM2 packet. Afterwards you have to set all properties and call Finish() to complete the packet. (This constructor allocates maximum possible packet size of 260 bytes.)

Ssm2Packet ( byte buffer ) : System

Takes given (empty) storage buffer and sets first byte. Afterwards you have to set all properties and call Construct() to finish the packet. This constructor is not meant for parsing an existing packet, use static method NewFromBytes instead or instance method FromBytes instead!

Ssm2Packet ( int capacity ) : System

Creates a new packet with specified capacity. Afterwards you have to set all properties and call Construct() to finish the packet.

ToBytesCopy ( ) : byte[]

Returns a copy of the actual packet bytes. May return empty array or less bytes if packet is incomplete. Guaranteed to not return null. Use method Check () before to assure validity.

Защищенные методы

Метод Описание
AssertAddress ( int address ) : void

Throw ArgumentOutOfRangeException if outside valid range: 0 ≤ address ≤ 0xFFFFFF. (SSM2 addresses consist of 3 bytes allowing 16 MiB address space.)

GetAddress ( int index ) : int
SetAddress ( int address, int index ) : void
SetConstBytes ( ) : void

Sets the const bytes except first packet byte. (Must be overriden by derived classes to set command and possible padding bytes.)

Ssm2Packet ( byte buffer, int capacityMin ) : System

Assures minimum capacity of given buffer. Useful when specific minimum or fixed packet size is known. Also sets packet size to given capacity.

TakeBuffer ( byte buffer, int minLength ) : void

Takes the buffer and checks for minimum length.

UpdateFlags ( SetProperties toSet ) : void

Set flag to indicate that this part of the packet has been set. Also unsets checksum flag as it needs recalculation in method Finish().

Приватные методы

Метод Описание
SetFirstByte ( ) : void

Описание методов

AssertAddress() защищенный статический Метод

Throw ArgumentOutOfRangeException if outside valid range: 0 ≤ address ≤ 0xFFFFFF. (SSM2 addresses consist of 3 bytes allowing 16 MiB address space.)
protected static AssertAddress ( int address ) : void
address int /// A ///
Результат void

Check() публичный Метод

Validate packet completely including checksum. Checks common and packet type specific characteristics.
public Check ( ) : bool
Результат bool

Equals() публичный Метод

public Equals ( Ssm2Packet p ) : bool
p Ssm2Packet
Результат bool

Equals() публичный Метод

public Equals ( object obj ) : bool
obj object
Результат bool

Finish() публичный Метод

Finish the packet. (Checksum and inline length byte.) Also checks if all properties have been set.
/// Not all required properties have been set.
public Finish ( ) : void
Результат void

FromBytes() публичный Метод

Parses packet by taking packet bytes, does not use a copy! Assumes complete packet, does not validate. May want to call Check () afterwards. (Packet size is being calculated based on packet length byte.)
/// /// Length ≥ 6 required. ///
public FromBytes ( byte buffer ) : void
buffer byte /// A . Length can be larger than needed. ///
Результат void

GetAddress() защищенный Метод

protected GetAddress ( int index ) : int
index int
Результат int

GetHashCode() публичный Метод

public GetHashCode ( ) : int
Результат int

NewFromBytes() публичный статический Метод

Returns a specific Ssm2Packet type based on given content. Does not validate the packet, so manually call the Check method afterwards!
public static NewFromBytes ( byte bytes ) : Ssm2Packet
bytes byte /// A containing the packet. /// The packet must start at index 0 though the array may be larger than needed. ///
Результат Ssm2Packet

SetAddress() защищенный Метод

protected SetAddress ( int address, int index ) : void
address int
index int
Результат void

SetConstBytes() защищенный Метод

Sets the const bytes except first packet byte. (Must be overriden by derived classes to set command and possible padding bytes.)
protected SetConstBytes ( ) : void
Результат void

Ssm2Packet() публичный Метод

Creates a SSM2 packet. Afterwards you have to set all properties and call Finish() to complete the packet. (This constructor allocates maximum possible packet size of 260 bytes.)
public Ssm2Packet ( ) : System
Результат System

Ssm2Packet() публичный Метод

Takes given (empty) storage buffer and sets first byte. Afterwards you have to set all properties and call Construct() to finish the packet. This constructor is not meant for parsing an existing packet, use static method NewFromBytes instead or instance method FromBytes instead!
/// If buffer.Length < minimum (6). ///
public Ssm2Packet ( byte buffer ) : System
buffer byte /// A . Minimum ///
Результат System

Ssm2Packet() защищенный Метод

Assures minimum capacity of given buffer. Useful when specific minimum or fixed packet size is known. Also sets packet size to given capacity.
protected Ssm2Packet ( byte buffer, int capacityMin ) : System
buffer byte
capacityMin int
Результат System

Ssm2Packet() публичный Метод

Creates a new packet with specified capacity. Afterwards you have to set all properties and call Construct() to finish the packet.
/// Capacity ≥ 6 required. ///
public Ssm2Packet ( int capacity ) : System
capacity int /// Maximum packet size. ///
Результат System

TakeBuffer() защищенный Метод

Takes the buffer and checks for minimum length.
/// Is thrown when an argument passed to a method is invalid because it is . /// /// If buffer.Length < minimum. ///
protected TakeBuffer ( byte buffer, int minLength ) : void
buffer byte /// Buffer. ///
minLength int /// Minimum buffer length. ///
Результат void

ToBytesCopy() публичный Метод

Returns a copy of the actual packet bytes. May return empty array or less bytes if packet is incomplete. Guaranteed to not return null. Use method Check () before to assure validity.
public ToBytesCopy ( ) : byte[]
Результат byte[]

UpdateFlags() защищенный Метод

Set flag to indicate that this part of the packet has been set. Also unsets checksum flag as it needs recalculation in method Finish().
protected UpdateFlags ( SetProperties toSet ) : void
toSet SetProperties /// The flag to set. ///
Результат void

Описание свойств

buffer защищенное свойство

Storage to use, make sure it is big enough. Use constant MaxBytesPacket.
protected byte[] buffer
Результат byte[]

propsSet защищенное свойство

protected SetProperties propsSet
Результат SetProperties