C12Adapter Opensource C++ Interface
|
Generic ANSI C12 abstract protocol, base for C12.18, C12.21, and C12.22. More...
Public Types | |
enum | ReadFunctionResponseEnum { ReadFunctionResponseWhenPresent = 0, ReadFunctionResponseWhenDesired = 1, ReadFunctionResponseAlways = 2 } |
Logic of when ST8 has to be read during execution of function. More... | |
enum | { READ_SERVICE_OVERHEAD = 4, WRITE_SERVICE_OVERHEAD = 7, PARTIAL_WRITE_SERVICE_OVERHEAD = 9 } |
![]() | |
enum | { MAXIMUM_NUMBER_STRING_SIZE = 64, MAXIMUM_SERVICE_NAME_STRING_SIZE = MAXIMUM_NUMBER_STRING_SIZE + 64, DEFAULT_ESTIMATED_RESPONSE_SIZE = 0x1000, MAXIMUM_POSSIBLE_TABLE_OFFSET = 0xFFFFFF, MAXIMUM_POSSIBLE_TABLE_LENGTH = 0xFFFFFF } |
typedef std::vector< TableRawData > | TableRawDataVector |
Vector of table raw data. | |
Public Member Functions | |
virtual | ~MProtocolC12 () |
Destroy the C12 protocol object. More... | |
virtual void | ApplyChannelParameters () |
Setup the configuration of the channel in a way compatible with ANSI C12 protocol handshake sequence. More... | |
virtual void | Logon () |
Perform ANSI C12 Logon service. More... | |
virtual void | Security () |
Perform ANSI C12 Security service. More... | |
virtual void | FullLogin () |
Perform whatever is required by the protocol to clear security with the meter. More... | |
virtual void | Logoff () |
Perform ANSI C12 Logoff service. More... | |
virtual void | Wait (unsigned seconds) |
Perform ANSI C12 Wait service. More... | |
virtual void | Terminate () |
Perform ANSI C12 Terminate service. More... | |
virtual Muint16 | CalculateCRC16FromBuffer (const char *buffer, unsigned length) const |
Two-byte CRC calculation procedure specific to C12 protocol. More... | |
unsigned | GetMaximumReadTableSize () const |
Return the maximum possible size of a table to read partially or fully in a single application layer packet. More... | |
virtual unsigned | CalculateChecksumFromBuffer (const char *buffer, unsigned length) const |
Protocol dependent one-byte checksum calculation procedure that uses buffer and its size. More... | |
MByteString | ApplicationLayerRequestResponse (char command, const MByteString &request) |
Perform the full application layer request and return a response. More... | |
char | ReceiveServiceCode () |
Read a code of the incoming application layer data packet. More... | |
Muint8 | ReceiveServiceByte () |
Read one byte from the incoming application layer data packet. More... | |
unsigned | ReceiveServiceUInt (unsigned size) |
Read several bytes from the incoming application layer data packet. More... | |
MByteString | ReceiveServiceBytes (unsigned length) |
Read several bytes of the incoming application layer data packet. More... | |
MByteString | ReceiveServiceRemainingBytes () |
Read bytes of the incoming application layer data packet. More... | |
unsigned | GetLinkLayerRetries () const |
void | SetLinkLayerRetries (unsigned retries) |
bool | GetIssueSecurityOnStartSession () const |
virtual void | SetIssueSecurityOnStartSession (bool) |
ReadFunctionResponseEnum | GetAlwaysReadFunctionResponse () const |
void | SetAlwaysReadFunctionResponse (ReadFunctionResponseEnum value) |
bool | GetAlwaysUsePartial () const |
void | SetAlwaysUsePartial (bool yes) |
bool | GetUseReadInKeepSessionAlive () const |
void | SetUseReadInKeepSessionAlive (bool yes) |
unsigned | GetUserId () const |
void | SetUserId (unsigned userId) |
const MByteString & | GetUser () const |
void | SetUser (const MByteString &userName) |
unsigned | GetTurnAroundDelay () const |
void | SetTurnAroundDelay (unsigned delay) |
unsigned | GetApplicationLayerRetries () const |
void | SetApplicationLayerRetries (unsigned retries) |
unsigned | GetApplicationLayerRetryDelay () const |
void | SetApplicationLayerRetryDelay (unsigned milliseconds) |
unsigned | GetApplicationLayerProcedureRetries () const |
void | SetApplicationLayerProcedureRetries (unsigned retries) |
unsigned | GetApplicationLayerProcedureRetryDelay () const |
void | SetApplicationLayerProcedureRetryDelay (unsigned milliseconds) |
unsigned | GetProcedureSequenceNumber () const |
void | SetProcedureSequenceNumber (unsigned number) |
void | SetEndSessionOnApplicationLayerError (bool endSessionOnApplicationLayerError) |
bool | GetEndSessionOnApplicationLayerError () const |
![]() | |
virtual MProtocol * | CreateClone () const |
Virtual copy constructor, creates the protocol which is a clone of current. More... | |
virtual | ~MProtocol ()=0 |
Destroy the protocol object. More... | |
void | Finalize () |
Execute this method as first action in the destructor of any child protocol. More... | |
unsigned | GetCountApplicationLayerServicesSuccessful () const |
The number of Application Layer services that have been successfully processed. More... | |
void | IncrementCountApplicationLayerServicesSuccessful () |
Increment the number of application layer services successfully processed. More... | |
unsigned | GetCountApplicationLayerServicesRetried () const |
The number of Application Layer services that have been retried. More... | |
void | IncrementCountApplicationLayerServicesRetried () |
Increment the number of application layer services retried. More... | |
unsigned | GetCountApplicationLayerServicesFailed () const |
The number of Application Layer services that have failed. More... | |
void | IncrementCountApplicationLayerServicesFailed () |
Increment the number of application layer services failed. More... | |
unsigned | GetCountLinkLayerPacketsSuccessful () const |
The number of Link Layer packets that have been successfully processed. More... | |
void | IncrementCountLinkLayerPacketsSuccessful () |
Increment the number of data link layer packets successfully processed. More... | |
unsigned | GetCountLinkLayerPacketsRetried () const |
The number of Link Layer packets that have been retried. More... | |
void | IncrementCountLinkLayerPacketsRetried () |
Increment the number of data link layer packets retried. More... | |
unsigned | GetCountLinkLayerPacketsFailed () const |
Get number of data link layer packets failed. More... | |
void | IncrementCountLinkLayerPacketsFailed () |
Increment the number of data link layer packets failed. More... | |
unsigned | GetMaximumRoundTripTime () const |
Gets the maximum measured approximate packet round trip time over the link layer. More... | |
unsigned | GetMinimumRoundTripTime () const |
Gets the minimum measured approximate packet round trip time over the link layer. More... | |
unsigned | GetAverageRoundTripTime () const |
Gets the average measured approximate packet round trip time over the link layer. More... | |
void | ClearPasswordList () |
Set the password list for the protocol to none, so the SetPassword property is used. More... | |
void | AddToPasswordList (const MByteString &password) |
Add a password to the password list. More... | |
int | GetPasswordListSuccessfulEntry () const |
Return the entry, which was successfully tried with the meter. More... | |
void | ResetCounts () |
Clear the statistical data for the channel. More... | |
void | Connect () |
Initializes the channel and establishes the connection with the peer. More... | |
void | Disconnect () |
Severs the connection between the computer and the end device. More... | |
bool | IsConnected () const |
Tells whether the protocol is currently connected. More... | |
bool | IsInSession () const |
Whether the protocol is in session. More... | |
MProgressAction * | CreateRootProgressAction () |
Create root of the progress actions hierarchy. More... | |
MProgressAction * | GetLocalProgressAction () |
Read-only access to the currently preset local action in progress monitor. More... | |
bool | QNeedToCommit () const |
Whether or not it is time to call QCommit(true) in order to sync with the background thread. More... | |
bool | QIsBackgroundCommunicationProgressing () const |
True if the background communication is still progressing. More... | |
bool | QIsDone () |
Combines QNeedToCommit with the following QCommit in case all commands in the queue have been sent. More... | |
void | QAbort () |
Clears the commands in the queue, or cancel the ongoing background communication. More... | |
void | QWriteToMonitor (const MStdString &message) |
Add the message to write to the Monitor log file to MProtocol's command queue. More... | |
void | QConnect () |
Places a Connect command in the queue. More... | |
void | QDisconnect () |
Places a Disconnect command in the queue. More... | |
void | QIdentifyMeter () |
Places an IdentifyMeter task in the queue. More... | |
void | QStartSession () |
Adds a start session command to MProtocol's command queue. More... | |
void | QEndSession () |
Adds an end session command to MProtocol's command queue. More... | |
void | QEndSessionNoThrow () |
EndSessionNoThrow request is queued. More... | |
void | QTableRead (MCOMNumberConstRef number, unsigned expectedSize, int id) |
Adds a ReadTable command to MProtocol's command queue. More... | |
void | QTableWrite (MCOMNumberConstRef number, const MByteString &data) |
Adds a table write command to MProtocol's command queue. More... | |
void | QTableReadPartial (MCOMNumberConstRef number, int offset, int size, int id) |
Adds a partial table read command to MProtocol's command queue. More... | |
void | QTableWritePartial (MCOMNumberConstRef number, const MByteString &data, int offset) |
Adds a partial table write command to MProtocol's command queue. More... | |
void | QFunctionExecute (MCOMNumberConstRef number) |
Place a function without data request in MProtocol command queue. More... | |
void | QFunctionExecuteRequest (MCOMNumberConstRef number, const MByteString &request) |
Place a function with request data in MProtocol's command queue. More... | |
void | QFunctionExecuteResponse (MCOMNumberConstRef number, int id, unsigned estimatedResponseSize=DEFAULT_ESTIMATED_RESPONSE_SIZE) |
Place a function with response data in MProtocol's command queue. More... | |
void | QFunctionExecuteRequestResponse (MCOMNumberConstRef number, const MByteString &request, int id, unsigned estimatedResponseSize=DEFAULT_ESTIMATED_RESPONSE_SIZE) |
Place a function with request and response data in MProtocol's command queue. More... | |
virtual void | QCommit (bool asynchronously=false) |
Executes all operations in MProtocol's command queue. More... | |
MByteString | QGetTableData (MCOMNumberConstRef number, int id=-1) |
Fetch the table data after the table read has been successfully performed by QCommit. More... | |
MByteString | QGetFunctionData (MCOMNumberConstRef number, int id=-1) |
Fetch the function response data after the function has been successfully executed in QCommit. More... | |
MStdString | QGetIdentifyMeterData () |
Fetch the identify meter string after the QIdentifyMeter has been successfully performed in QCommit. More... | |
virtual void | WriteToMonitor (const MStdString &message) |
Synchronously write a message to the monitor, if it is connected. More... | |
void | WriteCountsToMonitor () |
Write running values of communication quality counters to monitor. More... | |
void | StartSession () |
Synchronously start the session. More... | |
void | EndSession () |
Synchronously end the session. More... | |
void | EndSessionNoThrow () |
End the session, but do not throw errors. More... | |
Muint8 | ReadStartByte (const MByteString &setOfValidStartBytes, unsigned trafficTimeout) |
Read the start byte of the packet in a proper way, taking into consideration timeouts and ignoring garbage. More... | |
MByteString | TableRead (MCOMNumberConstRef number, unsigned expectedSize=0) |
Synchronously read the whole table with number given as parameter. More... | |
void | TableReadBuffer (MCOMNumberConstRef number, void *buff, unsigned size) |
Same as ReadTable, but instead of returning a byte string, read table into a given buffer. More... | |
template<class T > | |
void | TableReadBuffer (MCOMNumberConstRef number, T &table) |
Same as ReadTable, but instead of returning a byte string, read table into a given template variable. More... | |
MByteString | TableReadNoThrow (MCOMNumberConstRef number, MException **exception, unsigned expectedSize=0) |
Synchronously read the whole table with number given as parameter, do not throw an exception, but rather return it. More... | |
void | TableWrite (MCOMNumberConstRef number, const MByteString &data) |
Synchronously write the whole table with number given as parameter. More... | |
void | TableWriteBuffer (MCOMNumberConstRef number, const void *data, unsigned size) |
Same as TableWrite, but uses buffer, given as data and size parameters. More... | |
template<class T > | |
void | TableWriteBuffer (MCOMNumberConstRef number, const T &table) |
Same as WriteTable, but uses variable of some specific template class or structure. More... | |
MByteString | TableReadPartial (MCOMNumberConstRef number, int offset, int size) |
Synchronously read part of the table with number given as parameter. More... | |
void | TableReadPartialBuffer (MCOMNumberConstRef number, int offset, void *buff, unsigned size) |
Same as TableReadPartial, but instead of returning a byte string, read table into a given buffer. More... | |
template<class T > | |
void | TableReadPartialBuffer (MCOMNumberConstRef number, T &table, int offset) |
Same as TableReadPartial, but instead of returning a byte string, partially read table into a given template variable. More... | |
void | TableWritePartial (MCOMNumberConstRef number, const MByteString &data, int offset) |
Synchronously write part of the table with number given as parameter. More... | |
void | TableWritePartialBuffer (MCOMNumberConstRef number, int offset, const void *buff, unsigned size) |
Same as TableWritePartial, but instead of using a byte string, write table using a given buffer. More... | |
template<class T > | |
void | TableWritePartialBuffer (MCOMNumberConstRef number, const T &table, int offset) |
Same as TableWritePartial, but instead of using a byte string, write table using a given template class contents. More... | |
void | FunctionExecute (MCOMNumberConstRef number) |
Synchronously execute the function with no parameters, the number of the function is given as parameter. More... | |
void | FunctionExecuteRequest (MCOMNumberConstRef number, const MByteString &request) |
Synchronously execute the function with request data, the number of the function is given as parameter. More... | |
MByteString | FunctionExecuteResponse (MCOMNumberConstRef number) |
Synchronously execute the function with response data, the number of the function is given as parameter. More... | |
MByteString | FunctionExecuteRequestResponse (MCOMNumberConstRef number, const MByteString &request) |
Synchronously execute the function with request and response data, the number of the function is given as parameter. More... | |
virtual unsigned | GetNumberOfDataLinkPackets (MCommunicationCommand::CommandType typeOfRequest, unsigned applicationLayerDataSize=0) |
Return the number of data link packets that are required for a given request, provided an optional size of the application data. More... | |
MStdString | IdentifyMeterWithContext (bool sessionIsStarted=false, TableRawDataVector *tablesRead=NULL) |
Identify the meter if the protocol is known (note this is not an ANSI Identify protocol command). More... | |
unsigned | CalculateChecksum (const MByteString &buffer) const |
Protocol dependent one-byte checksum calculation procedure that uses byte string. More... | |
unsigned | CalculateCRC16 (const MByteString &buffer) const |
Protocol dependent two-byte CRC calculation procedure that accepts the byte string. More... | |
void | Sleep (unsigned milliseconds) |
Calls channel's Sleep method if the channel is present. More... | |
bool | GetMeterIsLittleEndian () const |
void | SetMeterIsLittleEndian (bool isLittleEndian) |
MChannel * | GetChannel () const |
void | SetChannel (MChannel *channel) |
bool | IsChannelOwned () const |
void | SetIsChannelOwned (bool yes) |
bool | GetKeepSessionAlive () const |
void | SetKeepSessionAlive (bool alive) |
MByteString | GetPassword () const |
void | SetPassword (const MByteString &password) |
const MByteStringVector & | GetPasswordList () const |
void | SetPasswordList (const MByteStringVector &passwordList) |
MProgressMonitor * | GetProgressMonitor () const |
void | SetProgressMonitor (MProgressMonitor *p) |
MCommunicationQueue & | GetCommandQueue () |
M_NO_PROGRESS_MONITOR. More... | |
const MCommunicationQueue & | GetCommandQueue () const |
M_NO_PROGRESS_MONITOR. More... | |
MStdString | IdentifyMeter (bool sessionIsStarted=false) |
MStdString | DoIdentifyMeter0 () |
![]() | |
virtual | ~MCOMObject () |
Object destructor. | |
virtual MStdStringVector | GetAllPropertyNames () const |
Return the list of publicly available properties in MCOM syntax. More... | |
virtual MStdStringVector | GetAllPersistentPropertyNames () const |
Return the list of publicly available persistent properties in MCOM syntax. More... | |
MStdString | GetPersistentPropertyValues (bool onlyNondefaults=false, bool excludeSecurityRelated=false) const |
Get the string with the list of persistent property names and their values. More... | |
void | SetPersistentPropertyValues (const MStdString &values) |
Set the persistent properties for the object using the string with the following format: More... | |
void | SetPropertyValues (const MDictionary &values) |
Set the properties for the object using the property list object. More... | |
void | WritePropertiesToMonitor () |
Write all non-default values of protocol properties into monitor. More... | |
MStdString | DoGetPersistentPropertyValues0 () const |
Get the string with the whole list of persistent property names and their values. More... | |
MStdString | DoGetPersistentPropertyValues1 (bool onlyNondefaults) const |
Get the string with the list of persistent property names and their values. More... | |
![]() | |
virtual | ~MObject () |
Object destructor. | |
virtual const MClass * | GetClass () const =0 |
Get the final class of the object. More... | |
virtual unsigned | GetEmbeddedSizeof () const |
For embedded object types, return the size of the class. More... | |
bool | IsEmbeddedObject () const |
Tell if the object is of embedded kind. More... | |
SHOW_INTERNAL MVariant | Call (const MStdString &name, const MVariant ¶ms) |
Call the object service with parameters, given as variant. More... | |
MVariant | Call0 (const MStdString &name) |
Call the object service with no parameters. More... | |
MVariant | Call1 (const MStdString &name, const MVariant &p1) |
Call the object service with one parameter. More... | |
MVariant | Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2) |
Call the object service with two parameter. More... | |
MVariant | Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3) |
Call the object service with three parameter. More... | |
MVariant | Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4) |
Call the object service with four parameter. More... | |
MVariant | Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5) |
Call the object service with five parameter. More... | |
MVariant | Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6) |
Call the object service with six parameter. More... | |
virtual MVariant | CallV (const MStdString &name, const MVariant::VariantVector ¶ms) |
Call the object service with parameters, given as variant vector. More... | |
virtual bool | IsPropertyPresent (const MStdString &name) const |
Tell if the property with the given name exists. | |
virtual bool | IsServicePresent (const MStdString &name) const |
Tell if the service with the given name exists. | |
virtual MVariant | GetProperty (const MStdString &name) const |
Get the property value using name of the property. More... | |
virtual void | SetProperty (const MStdString &name, const MVariant &value) |
Set the property using name of the property, and value. More... | |
virtual void | SetPersistentPropertiesToDefault () |
Set the persistent properties of the object to their default values. More... | |
virtual MVariant | GetPersistentPropertyDefaultValue (const MStdString &name) const |
Get the default value of persistent property with the name given. More... | |
virtual void | SetPersistentPropertyToDefault (const MStdString &name) |
Set the persistent property with the name given to default value. More... | |
virtual const char * | GetType () const |
Get the name of the type for the object (could be the same as class name). | |
virtual void | SetType (const MStdString &) |
Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More... | |
virtual void | Validate () |
Validate internal structures of the object. More... | |
Static Public Member Functions | |
static unsigned | StaticCalculateChecksum (const MByteString &buff) |
Compute checksum of the byte string given as parameters. More... | |
static unsigned | StaticCalculateChecksumFromBuffer (const char *data, unsigned size) |
Compute checksum of the buffer and length given as parameters. More... | |
static Muint16 | StaticCalculateCRC16FromBuffer (const char *buffer, unsigned length) |
Two-byte CRC calculation static procedure specific to C12 protocol. More... | |
static unsigned | CRC16 (const MByteString &buffer) |
Same as above, but taking byte string, reflected. More... | |
![]() | |
static unsigned | StaticCalculateChecksumFromBuffer (const char *buff, unsigned size) |
Most popular one-byte checksum calculation procedure, a sum of all bytes. More... | |
static unsigned | StaticCalculateChecksum (const MByteString &buffer) |
Compute checksum of the byte string given as parameters. More... | |
![]() | |
static const MClass * | GetStaticClass () |
Get the declared class of this particular object. More... | |
static bool | IsClassPresent (const MStdString &name) |
Tells if the given class name is available. More... | |
Protected Member Functions | |
MProtocolC12 (MChannel *channel, bool channelIsOwned=true) | |
Create a new abstract ANSI C12 protocol with the channel given. More... | |
![]() | |
MProtocol (MChannel *channel, bool channelIsOwned=true) | |
Create a new abstract protocol with the channel given. More... | |
virtual void | DoStartSession () |
Synchronously start the session, don't do service count. More... | |
virtual void | DoEndSession () |
Synchronously end the session, don't do service count. More... | |
virtual void | DoTableRead (MCOMNumberConstRef number, MByteString &data, unsigned expectedSize=0) |
Synchronously read the whole table with number given as parameter, don't do service count. More... | |
virtual void | DoTableWrite (MCOMNumberConstRef number, const MByteString &data) |
Synchronously write the whole table with number given as parameter, don't do service count. More... | |
virtual void | DoTableReadPartial (MCOMNumberConstRef number, MByteString &data, int offset, int size) |
Synchronously read part of the table with number given as parameter, don't do service count. More... | |
virtual void | DoTableWritePartial (MCOMNumberConstRef number, const MByteString &data, int offset) |
Synchronously write part of the table with number given as parameter, don't do service count. More... | |
virtual void | DoFunctionExecute (MCOMNumberConstRef number) |
Synchronously execute the function with no parameters, the number of the function is given as parameter, don't do service count. More... | |
virtual void | DoFunctionExecuteRequest (MCOMNumberConstRef number, const MByteString &request) |
Synchronously execute the function with request data, the number of the function is given as parameter, don't do service count. More... | |
virtual void | DoFunctionExecuteResponse (MCOMNumberConstRef number, MByteString &response) |
Synchronously execute the function with response data, the number of the function is given as parameter, don't do service count. More... | |
virtual void | DoFunctionExecuteRequestResponse (MCOMNumberConstRef number, const MByteString &request, MByteString &response) |
Synchronously execute the function with request and response data, the number of the function is given as parameter, don't do service count. More... | |
virtual MStdString | DoIdentifyMeter (bool sessionIsStarted, TableRawDataVector *tablesRead) |
Identify the meter if the protocol is known (note this is not an ANSI Identify protocol command). More... | |
void | DoTryPasswordOrPasswordList () |
Try password or passwords for the protocol according to the PASSWORD and PasswordList settings. More... | |
virtual void | DoTryPasswordEntry (const MByteString &entry) |
Try one password, throw if error. More... | |
virtual void | DoBuildComplexServiceName (MChars fullServiceName, MConstChars serviceName, MCOMNumberConstRef number, int par1=-1, int par2=-1) |
Build service name with a number and given parameters. More... | |
void | DoBuildPossiblyNumericComplexServiceName (MChars fullServiceName, MConstChars serviceName, MCOMNumberConstRef number, bool isHex, int par1=-1, int par2=-1) |
Helper service name builder that can interpret numeric values either as hex or as decimal. More... | |
![]() | |
MCOMObject () | |
Object constructor, protected as the class is abstract. | |
![]() | |
MObject () | |
Object constructor, protected as the class is abstract. | |
void | DoSetPersistentPropertiesToDefault (const MClass *staticClass) |
Set the persistent properties to their default values for one object provided the class for that object. More... | |
Additional Inherited Members | |
![]() | |
static const MClass | s_class |
Class of MObject. | |
Generic ANSI C12 abstract protocol, base for C12.18, C12.21, and C12.22.
anonymous enum |
Logic of when ST8 has to be read during execution of function.
Enumerator | |
---|---|
ReadFunctionResponseWhenPresent |
Read function response only when response is present. |
ReadFunctionResponseWhenDesired |
Avoid reading function response in special cases. The behavior of this legacy flag is the same as ReadFunctionResponseAlways. |
ReadFunctionResponseAlways |
Fully compliant ANSI behavior, always read function response. |
|
protected |
Create a new abstract ANSI C12 protocol with the channel given.
The service is protected because the class is abstract.
channel | Channel object of the protocol. It will be a rare case when a protocol can be created without a channel, in which case this parameter can be NULL. |
channelIsOwned | Whether the channel has to be owned by the protocol, deleted in protocol destructor or at channel reassignment. By default the protocol owns its channel. |
|
virtual |
Destroy the C12 protocol object.
If the channel is owned, MProtocol::IsChannelOwned is true, the channel is also destroyed.
MByteString MProtocolC12::ApplicationLayerRequestResponse | ( | char | command, |
const MByteString & | request | ||
) |
Perform the full application layer request and return a response.
The command will be the first byte in the packet, while the request parameter, if present, will form the rest of the packet. The returned response will not have the status byte, which will be thrown as MEC12NokResponse if it was not zero.
command | C12 command of the application layer. |
request | Request buffer of the command. |
|
virtual |
Setup the configuration of the channel in a way compatible with ANSI C12 protocol handshake sequence.
The action depends on the channel and particular ANSI C12 protocol. Implementations ensure that the service behaves gracefully whether the channel is connected or not.
Reimplemented from MProtocol.
Reimplemented in MProtocolC1222, MProtocolC1218, and MProtocolC1221.
|
virtual |
Protocol dependent one-byte checksum calculation procedure that uses buffer and its size.
This particular implementation of the checksum calculation fits the majority of the protocols, override if needed. There is also CalculateChecksum, that works on byte string and returns a checksum value as unsigned integer.
buffer | Pointer to the beginning of buffer. |
length | Length of the buffer in bytes. |
Reimplemented from MProtocol.
|
virtual |
Two-byte CRC calculation procedure specific to C12 protocol.
The algorithm itself uses a set of shifts and XOR operators for efficiency. When executing on Intel, or other Little Endian architectures, the bytes are swapped after polynom calculation.
Reimplemented from MProtocol.
|
static |
Same as above, but taking byte string, reflected.
|
virtual |
Perform whatever is required by the protocol to clear security with the meter.
This can call ANSI C12 Security request, or in case of C12.21 Authenticate request.
Reimplemented in MProtocolC1221.
|
inline |
Determines whether or not ST-8 will be read if the function does not have a response.
This property should be true for most ANSI meters. However, for some option boards installed on an ANSI meter, this property needs to be set to false.
|
inline |
Whether to use partial reads and writes in place of full reads and writes.
Standard table 7 write and standard table 8 write, the sequence that forms function execution, and are always performed in full, regardless of the value of this property. Also, full reads and full writes have to always be made through partial operations when full table size would not fit into a single application layer request.
|
inline |
Number of application layer retries for functions (ANSI C12 procedures).
Number of times to retry on the application layer procedure request when the request has been successfully transmitted to the meter, but the meter responded that it cannot service the request. The most common meter responses that trigger an application retry are the meter is busy BSY or the data is not ready DNR.
The typical value for ApplicationLayerProcedureRetries is a large number (like 20) as the communications are okay and the meter is sending a meaningful response. Set the value to something small (like 0) to force the operation to fail when the meter is busy or the data is not ready.
ApplicationLayerProcedureRetries is different from ApplicationLayerRetries which specifies the application retries when the request is a table.
|
inline |
Get the number of milliseconds which the application layer should wait after reading procedure status code 1 from table 8.
Number of milliseconds to wait before resubmitting the table 8 read request during procedure handling. This is most useful for handling the meter is busy (BSY) and data is not ready (DNR) response codes.
ApplicationLayerProcedureRetryDelay is different from ApplicationLayerRetryDelay which specifies the application retries when the request is a table.
|
inline |
Get the number of application layer retries for tables. The application layer table request is retried only in the case the meter is busy, or the data are not available.
Number of times to retry on the application layer table request when the request has been successfully transmitted to the meter, but the meter responded that it cannot service the request. The most common meter responses that trigger an application retry are the meter is busy BSY or the data is not ready DNR.
The typical value for ApplicationLayerRetries is a large number (like 20) as the communications are okay and the meter is sending a meaningful response. Set the value to something small (like 0) to force the operation to fail when the meter is busy or the data is not ready.
ApplicationLayerRetries is different from LinkLayerRetries which specifies how many times to attempt sending a link layer packet (the link layer handles the data transfer) and is different from ApplicationLayerProcedureRetries which specifies the application retries when the request is a procedure.
|
inline |
Get the number of milliseconds which the application layer should wait after receiving a busy response from the table.
Number of milliseconds to wait before resubmitting the application layer retry during table handling. This is most useful for handling the meter is busy (BSY) and data is not ready (DNR) response codes.
ApplicationLayerRetryDelay is different from ApplicationLayerProcedureRetryDelay which specifies the application retries when the request is a procedure.
|
inline |
Defines whether to process Terminate service on Application Layer error.
This property enables automatic handling of protocols with sessions. When such protocol encounters an error within the session, and this property is true, it is possible to enable the attempt of closing the session prior to throwing the error to the user.
|
inline |
Whether the start session will include the security service or the authenticate service.
When it is set to False, neither the security nor the authenticate service is sent, allowing data that is not password protected to be accessed without the password.
MeteringSDK has a check prior to sending the authenticate service. When an identify service is sent (always the first service sent in a start session sequence), the device responds with what it supports. If it says that it does not support authentication, then MeteringSDK aborts the start session sequence and throws the error "Meter does not support authentication".
Refer to the ANSI protocol standards for more information on the start session, security, and authenticate services.
|
inline |
Number of link layer retries.
The link layer retry takes place if an error occurs in the data transfer. For protocols that break application layer into link layer packets, such as C12.18, C12.21, and serial C12.22, this is the number of times to re-send a packet after a link layer NAK (negative-acknowledge) or timeout before giving up. The most common causes are incorrect CRC or noise in the line (data lost on the line, extra garbage characters, framing errors, bits tweaked, etc.)
For C12.22 protocol, this property only applies when the channel is of type MChannelSocketUdp, in which case this is the number of resends of the outgoing UDP packet.
|
inline |
Return the maximum possible size of a table to read partially or fully in a single application layer packet.
When the requested table size is bigger than the value of this property, the request is transparently broken into multiple application layer packets, so that each table data transfer fits within the property value.
The property value is calculated using the current protocol properties, capabilities, and overhead. The value can change after properties are negotiated with the device.
For example, when the protocol is C12.18, the maximum read table size will depend on the packet size and the maximum number of packets. After Negotiate is issued, the value can change depending on the negotiated packet size and the negotiated maximum number of packets.
|
inline |
Sequence number byte to use in the next C12 procedure.
Procedure sequence number is a dynamic property, not persistent, and it will always be set to zero at the creation of the protocol object. During the lifespan of the protocol, the property can either be modified by the user (the caller), or by the incoming packet that relates to ANSI C12 procedure as defined in ANSI C12.19 standard paper.
In client protocols the user (the caller) can modify this property at any moment before a desired FUNCTION is executed to change SEQ_NBR field of ST7 write. The following ST8 read will modify this property with the SEQ_NBR value. The compliant protocol implementation will always respond with the same value for SEQ_NBR. Currently MeteringSDK client does not check by itself if sequence numbers in ST7 write and in the following ST8 read match, as this can possibly break some C12 implementations. The behavior can be reconsidered later after the extensive testing.
In the server implementation, ST7 write arrives first, and it changes the value of this property with the incoming SEQ_NBR. The same value is sent back in ST8 unless the user modifies the property to a different value in the function handler, in which case a noncompliant value of SEQ_NBR is sent back. This can be helpful for testing purposes.
|
inline |
The number of milliseconds to wait before the computer sends data to the meter on the link layer.
The data may be an ACK or NAK to a packet received from the meter or it may be the next request to send to the meter. The delay is required so that the UART and firmware in the meter has time to switch from transmit to receive and to process the last transmission it received. If the data is sent to too soon, the meter may not receive it, which results in communication failures and retry attempts. The actual amount of delay will depend on the computer and the number of tasks running (for example, the Sleep method causes a task switch). Faster machines will approach the specified time more closely.
|
inline |
Get the user name that will be used during logon service of the protocol.
Value used in the "user" parameter of the ANSI C12 logon service. The logon service is part of QStartSession. The User as defined by the ANSI C12 standard is a utility supplied name of the operator requesting the access to the device.
The User property can have a maximum of 10 characters. If the User property is specified with less than 10 characters, then during communications the remaining characters are filled with blank spaces. For example, if User is specified as "METER1", then "METER1 " is used in the user field of the logon service, but the property User reports "METER1".
|
inline |
Whether to use table read for session keeping instead of C12 Wait. This property has no effect if KEEP_SESSION_ALIVE is False.
|
inline |
User identity number reported to device.
User ID is used in logon services of all variants of ANSI C12, and in sessionless mode Security service of ANSI C12.22. The User ID as defined by the ANSI C12 standard is a code indicating a utility supplied identity of the operator requesting the creation of the session. If the metering device supports Events and History logs, it has the option of storing the User ID as defined in the "Utility Industry End Device Data Tables" document.
|
virtual |
Perform ANSI C12 Logoff service.
This standard service is part of MProtocol::StartSession(), but it can also be called directly by the user for any purpose such as testing, or custom implementation of Start Session sequence.
|
virtual |
Perform ANSI C12 Logon service.
This standard service is part of MProtocol::StartSession(), but it can also be called directly by the user for any purpose such as testing, or custom implementation of Start Session sequence.
Reimplemented in MProtocolC1222.
Muint8 MProtocolC12::ReceiveServiceByte | ( | ) |
Read one byte from the incoming application layer data packet.
The service works like a stream, one can issue ReceiveByte many times in small chunks, and it will be returning subsequent bytes.
MByteString MProtocolC12::ReceiveServiceBytes | ( | unsigned | length | ) |
Read several bytes of the incoming application layer data packet.
The length of the returned buffer is expected. The service works like a stream, one can issue ReceiveServiceUInt many times in small chunks, and it will be returning subsequent bytes.
char MProtocolC12::ReceiveServiceCode | ( | ) |
Read a code of the incoming application layer data packet.
MByteString MProtocolC12::ReceiveServiceRemainingBytes | ( | ) |
Read bytes of the incoming application layer data packet.
Returned buffer has a remaining size.
unsigned MProtocolC12::ReceiveServiceUInt | ( | unsigned | size | ) |
Read several bytes from the incoming application layer data packet.
No more than 4 bytes are allowed to be read. To read more than 4 bytes use ReceiveServiceBytes. The service works like a stream, one can issue ReceiveServiceUInt many times in small chunks, and it will be returning subsequent bytes.
|
virtual |
Perform ANSI C12 Security service.
This standard service is part of MProtocol::StartSession(), but it can also be called directly by the user for any purpose such as testing, or custom implementation of Start Session sequence.
void MProtocolC12::SetAlwaysReadFunctionResponse | ( | ReadFunctionResponseEnum | value | ) |
Determines whether or not ST-8 will be read if the function does not have a response.
This property should be true for most ANSI meters. However, for some option boards installed on an ANSI meter, this property needs to be set to false.
|
inline |
Whether to use partial reads and writes in place of full reads and writes.
Standard table 7 write and standard table 8 write, the sequence that forms function execution, and are always performed in full, regardless of the value of this property. Also, full reads and full writes have to always be made through partial operations when full table size would not fit into a single application layer request.
|
inline |
Number of application layer retries for functions (ANSI C12 procedures).
Number of times to retry on the application layer procedure request when the request has been successfully transmitted to the meter, but the meter responded that it cannot service the request. The most common meter responses that trigger an application retry are the meter is busy BSY or the data is not ready DNR.
The typical value for ApplicationLayerProcedureRetries is a large number (like 20) as the communications are okay and the meter is sending a meaningful response. Set the value to something small (like 0) to force the operation to fail when the meter is busy or the data is not ready.
ApplicationLayerProcedureRetries is different from ApplicationLayerRetries which specifies the application retries when the request is a table.
|
inline |
Get the number of milliseconds which the application layer should wait after reading procedure status code 1 from table 8.
Number of milliseconds to wait before resubmitting the table 8 read request during procedure handling. This is most useful for handling the meter is busy (BSY) and data is not ready (DNR) response codes.
ApplicationLayerProcedureRetryDelay is different from ApplicationLayerRetryDelay which specifies the application retries when the request is a table.
|
inline |
Get the number of application layer retries for tables. The application layer table request is retried only in the case the meter is busy, or the data are not available.
Number of times to retry on the application layer table request when the request has been successfully transmitted to the meter, but the meter responded that it cannot service the request. The most common meter responses that trigger an application retry are the meter is busy BSY or the data is not ready DNR.
The typical value for ApplicationLayerRetries is a large number (like 20) as the communications are okay and the meter is sending a meaningful response. Set the value to something small (like 0) to force the operation to fail when the meter is busy or the data is not ready.
ApplicationLayerRetries is different from LinkLayerRetries which specifies how many times to attempt sending a link layer packet (the link layer handles the data transfer) and is different from ApplicationLayerProcedureRetries which specifies the application retries when the request is a procedure.
|
inline |
Get the number of milliseconds which the application layer should wait after receiving a busy response from the table.
Number of milliseconds to wait before resubmitting the application layer retry during table handling. This is most useful for handling the meter is busy (BSY) and data is not ready (DNR) response codes.
ApplicationLayerRetryDelay is different from ApplicationLayerProcedureRetryDelay which specifies the application retries when the request is a procedure.
|
inline |
Defines whether to process Terminate service on Application Layer error.
This property enables automatic handling of protocols with sessions. When such protocol encounters an error within the session, and this property is true, it is possible to enable the attempt of closing the session prior to throwing the error to the user.
|
virtual |
Whether the start session will include the security service or the authenticate service.
When it is set to False, neither the security nor the authenticate service is sent, allowing data that is not password protected to be accessed without the password.
MeteringSDK has a check prior to sending the authenticate service. When an identify service is sent (always the first service sent in a start session sequence), the device responds with what it supports. If it says that it does not support authentication, then MeteringSDK aborts the start session sequence and throws the error "Meter does not support authentication".
Refer to the ANSI protocol standards for more information on the start session, security, and authenticate services.
Reimplemented in MProtocolC1222.
|
inline |
Number of link layer retries.
The link layer retry takes place if an error occurs in the data transfer. For protocols that break application layer into link layer packets, such as C12.18, C12.21, and serial C12.22, this is the number of times to re-send a packet after a link layer NAK (negative-acknowledge) or timeout before giving up. The most common causes are incorrect CRC or noise in the line (data lost on the line, extra garbage characters, framing errors, bits tweaked, etc.)
For C12.22 protocol, this property only applies when the channel is of type MChannelSocketUdp, in which case this is the number of resends of the outgoing UDP packet.
void MProtocolC12::SetProcedureSequenceNumber | ( | unsigned | number | ) |
Sequence number byte to use in the next C12 procedure.
Procedure sequence number is a dynamic property, not persistent, and it will always be set to zero at the creation of the protocol object. During the lifespan of the protocol, the property can either be modified by the user (the caller), or by the incoming packet that relates to ANSI C12 procedure as defined in ANSI C12.19 standard paper.
In client protocols the user (the caller) can modify this property at any moment before a desired FUNCTION is executed to change SEQ_NBR field of ST7 write. The following ST8 read will modify this property with the SEQ_NBR value. The compliant protocol implementation will always respond with the same value for SEQ_NBR. Currently MeteringSDK client does not check by itself if sequence numbers in ST7 write and in the following ST8 read match, as this can possibly break some C12 implementations. The behavior can be reconsidered later after the extensive testing.
In the server implementation, ST7 write arrives first, and it changes the value of this property with the incoming SEQ_NBR. The same value is sent back in ST8 unless the user modifies the property to a different value in the function handler, in which case a noncompliant value of SEQ_NBR is sent back. This can be helpful for testing purposes.
|
inline |
The number of milliseconds to wait before the computer sends data to the meter on the link layer.
The data may be an ACK or NAK to a packet received from the meter or it may be the next request to send to the meter. The delay is required so that the UART and firmware in the meter has time to switch from transmit to receive and to process the last transmission it received. If the data is sent to too soon, the meter may not receive it, which results in communication failures and retry attempts. The actual amount of delay will depend on the computer and the number of tasks running (for example, the Sleep method causes a task switch). Faster machines will approach the specified time more closely.
void MProtocolC12::SetUser | ( | const MByteString & | userName | ) |
Get the user name that will be used during logon service of the protocol.
Value used in the "user" parameter of the ANSI C12 logon service. The logon service is part of QStartSession. The User as defined by the ANSI C12 standard is a utility supplied name of the operator requesting the access to the device.
The User property can have a maximum of 10 characters. If the User property is specified with less than 10 characters, then during communications the remaining characters are filled with blank spaces. For example, if User is specified as "METER1", then "METER1 " is used in the user field of the logon service, but the property User reports "METER1".
|
inline |
Whether to use table read for session keeping instead of C12 Wait. This property has no effect if KEEP_SESSION_ALIVE is False.
void MProtocolC12::SetUserId | ( | unsigned | userId | ) |
User identity number reported to device.
User ID is used in logon services of all variants of ANSI C12, and in sessionless mode Security service of ANSI C12.22. The User ID as defined by the ANSI C12 standard is a code indicating a utility supplied identity of the operator requesting the creation of the session. If the metering device supports Events and History logs, it has the option of storing the User ID as defined in the "Utility Industry End Device Data Tables" document.
|
static |
Compute checksum of the byte string given as parameters.
The checksum is calculated based on the C12 rules.
|
static |
Compute checksum of the buffer and length given as parameters.
The checksum is calculated based on the C12 rules.
|
static |
Two-byte CRC calculation static procedure specific to C12 protocol.
The algorithm itself uses a set of shifts and xor operators for efficiency. When executing on Intel, or other Little Endian architectures, the bytes are swapped after polynom calculation.
Note that there is also a virtual variation of this service, CalculateCRC16FromBuffer, which is used externally by interfaces which do not care about particular protocols.
|
virtual |
Perform ANSI C12 Terminate service.
This standard service is part of MProtocol::EndSession(), but it can also be called directly by the user for any purpose such as testing, or custom implementation of End Session sequence.
|
virtual |
Perform ANSI C12 Wait service.
ANSI C12 Wait extends the session to the given number of seconds, so in case of inactivity of the communication the session does not time out.