C12Adapter Opensource C++ Interface
MProtocolC12 Class Reference

Generic ANSI C12 abstract protocol, base for C12.18, C12.21, and C12.22. More...

Inheritance diagram for MProtocolC12:

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
}
 
- Public Types inherited from MProtocol
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< TableRawDataTableRawDataVector
 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 MByteStringGetUser () 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
 
- Public Member Functions inherited from MProtocol
virtual MProtocolCreateClone () 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...
 
MProgressActionCreateRootProgressAction ()
 Create root of the progress actions hierarchy. More...
 
MProgressActionGetLocalProgressAction ()
 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)
 
MChannelGetChannel () 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 MByteStringVectorGetPasswordList () const
 
void SetPasswordList (const MByteStringVector &passwordList)
 
MProgressMonitorGetProgressMonitor () 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 ()
 
- Public Member Functions inherited from MCOMObject
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...
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () 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 &params)
 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 &params)
 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 Public Member Functions inherited from MProtocol
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 Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 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...
 
- Protected Member Functions inherited from MProtocol
 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...
 
- Protected Member Functions inherited from MCOMObject
 MCOMObject ()
 Object constructor, protected as the class is abstract.
 
- Protected Member Functions inherited from MObject
 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 Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 

Detailed Description

Generic ANSI C12 abstract protocol, base for C12.18, C12.21, and C12.22.

Member Enumeration Documentation

anonymous enum
Enumerator
READ_SERVICE_OVERHEAD 

Comprises of: ok8 count16 data chksum8.

WRITE_SERVICE_OVERHEAD 

Comprises of: 0x40 tableid16 count16 data chksum8.

PARTIAL_WRITE_SERVICE_OVERHEAD 

Comprises of: 0x4F tableid16 offset24 count16 data chksum8.

Logic of when ST8 has to be read during execution of function.

See also
GetAlwaysReadFunctionResponse - property where this enumeration is used.
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.

Constructor & Destructor Documentation

MProtocolC12::MProtocolC12 ( MChannel channel,
bool  channelIsOwned = true 
)
protected

Create a new abstract ANSI C12 protocol with the channel given.

The service is protected because the class is abstract.

Parameters
channelChannel 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.
channelIsOwnedWhether 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 MProtocolC12::~MProtocolC12 ( )
virtual

Destroy the C12 protocol object.

If the channel is owned, MProtocol::IsChannelOwned is true, the channel is also destroyed.

Member Function Documentation

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.

Precondition
The request corresponds to the correct C12 service packet of the given command. The channel is functioning, the state allows such request. Otherwise the exception is thrown. Any nonzero status code will be thrown as C12 exception.
Parameters
commandC12 command of the application layer.
requestRequest buffer of the command.
Returns
Response buffer, excluding the status code.
virtual void MProtocolC12::ApplyChannelParameters ( )
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 unsigned MProtocolC12::CalculateChecksumFromBuffer ( const char *  buffer,
unsigned  length 
) const
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.

Precondition
The buffer designated with the pointer and the length is valid.
Parameters
bufferPointer to the beginning of buffer.
lengthLength of the buffer in bytes.
Returns
Value of checksum.

Reimplemented from MProtocol.

virtual Muint16 MProtocolC12::CalculateCRC16FromBuffer ( const char *  buffer,
unsigned  length 
) const
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 unsigned MProtocolC12::CRC16 ( const MByteString buffer)
static

Same as above, but taking byte string, reflected.

Precondition
Same as StaticCalculateCRC16FromBuffer.
virtual void MProtocolC12::FullLogin ( )
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.

Precondition
The channel is open, and the protocol state allows Security or Authenticate to be called.

Reimplemented in MProtocolC1221.

ReadFunctionResponseEnum MProtocolC12::GetAlwaysReadFunctionResponse ( ) const
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.

Since
MeteringSDK Version 2.1.27. However, the type changed from Boolean to INT32 in MeteringSDK Version 5.4.0. All versions can accept the value as Boolean or INT32, so no changes are needed to existing applications built using older versions.
Default value:
  • 2 for MeteringSDK Versions 5.4.0 and later.
  • 1 {True} for MeteringSDK Versions prior to 5.4.0.
Possible values:
  • False, or 0 : ST-8 is NOT read when the function does not have a response. This behavior is available for all versions. Applications that set the value to 0, or False, will behave exactly the same in any version.
  • True, 1, 2, or -1 : ST-8 is read for ALL functions.
bool MProtocolC12::GetAlwaysUsePartial ( ) const
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.

Since
MeteringSDK Version 5.2.0.1720.
Default value:
Possible values:
  • False : perform full table reads and writes if they fit in the application layer.
  • True : replace full table reads and writes with partial operations for all tables except ST7 and ST8.
unsigned MProtocolC12::GetApplicationLayerProcedureRetries ( ) const
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.

Since
MeteringSDK Version 2.1.27.
Default value:
20
Possible values:
  • 1 .. MAXINT
unsigned MProtocolC12::GetApplicationLayerProcedureRetryDelay ( ) const
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.

Since
MeteringSDK Version 2.1.27.
Default value:
500 milliseconds
Possible values:
  • 1 .. MAXINT
See also
GetApplicationLayerRetryDelay that works for table retry delays.
unsigned MProtocolC12::GetApplicationLayerRetries ( ) const
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.

Since
MeteringSDK Version 2.1.27.
Default value:
20
See also
GetApplicationLayerProcedureRetries that works for procedure retries.
unsigned MProtocolC12::GetApplicationLayerRetryDelay ( ) const
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.

Since
MeteringSDK Version 2.1.27.
Default value:
2000 milliseconds
See also
GetApplicationLayerProcedureRetryDelay that works for procedure retry delays.
bool MProtocolC12::GetEndSessionOnApplicationLayerError ( ) const
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.

Since
MeteringSDK Version 5.2.0.1720.
Default value:
false
Possible values:
  • True [1] : The end session services are sent to the device after an Application Layer error.
  • False [0] : The end session services are NOT sent to the device after an Application Layer error. The session timeouts according to the protocol rules.
bool MProtocolC12::GetIssueSecurityOnStartSession ( ) const
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.

  • ANSI Std C12.18-1995 "PROTOCOL SPECIFICATION FOR ANSI TYPE 2 OPTICAL PORT"
  • ANSI Std C12.21-1998 "PROTOCOL SPECIFICATION FOR TELEPHONE MODEM COMMUNICATION"
  • ANSI Std C12.22-2008 "PROTOCOL SPECIFICATION FOR INTERFACING TO DATA COMMUNICATION NETWORKS"
Since
MeteringSDK Version 2.1.27.
Default value:
True
Possible values:
  • True [1] : The security or authenticate service is issued with the password.
  • False [0] : The security or authenticate service is NOT issued. Data that does not require a password can be read. Attempting to access data that requires a password will generate an error.
unsigned MProtocolC12::GetLinkLayerRetries ( ) const
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.

Since
MeteringSDK Version 2.1.27.
Default value:
3
unsigned MProtocolC12::GetMaximumReadTableSize ( ) const
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.

unsigned MProtocolC12::GetProcedureSequenceNumber ( ) const
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.

Since
MeteringSDK Version 6.6.0.5882.
Default value:
0
Possible values: 0 .. 255
unsigned MProtocolC12::GetTurnAroundDelay ( ) const
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.

0.12 Identify
0.17 Tx> EE 00 00 00 00 01 20 13 10
0.20 Rx> 06 EE 00 00 00 00 05 00 00 01 00 00 C6 B5
// Turn around delay, approximately 60 msec before
// ACK (0x06) transmitted to the meter
0.26 Tx> 06
0.26 Identify success
// Turn around delay, approximately 60 msec before
// next request (Negotiate) transmitted to the meter
0.26 Negotiate
0.32 Tx> EE 00 20 00 00 05 61 04 00 80 06 C2 29
0.35 Rx> 06 EE 00 20 00 00 05 00 04 00 80 06 35 83
0.41 Tx> 06
0.41 Negotiate success
Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • 1 .. MAXINT in milliseconds.
const MByteString& MProtocolC12::GetUser ( ) const
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".

Since
MeteringSDK Version 2.1.27.
Default value:
10 characters with binary zero values.
Possible values:
  • Any string containing 10 or less bytes, i.e. "1234567890".
bool MProtocolC12::GetUseReadInKeepSessionAlive ( ) const
inline

Whether to use table read for session keeping instead of C12 Wait. This property has no effect if KEEP_SESSION_ALIVE is False.

Since
MeteringSDK Version 4.0.54.
Default value:
False
Possible values:
  • True [1] : The first byte of ST1 will be read to keep the session alive.
  • False [0] : The C12 Wait service will be used to keep the session alive.
unsigned MProtocolC12::GetUserId ( ) const
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.

Since
MeteringSDK Version 2.1.27.
Default value:
0
Possible values: 0 .. 65535
virtual void MProtocolC12::Logoff ( )
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.

Precondition
The channel is open, and the protocol state allows Logoff to be called.
virtual void MProtocolC12::Logon ( )
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.

Precondition
The channel is open, and the protocol state allows Logon to be called.

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.

Precondition
The packet was received successfully, and it has data available.
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.

Precondition
The packet was received successfully, and it has data available.
char MProtocolC12::ReceiveServiceCode ( )

Read a code of the incoming application layer data packet.

Precondition
The packet was received successfully, and it has the code data available.
MByteString MProtocolC12::ReceiveServiceRemainingBytes ( )

Read bytes of the incoming application layer data packet.

Returned buffer has a remaining size.

Precondition
The packet was received successfully, and it has data available.
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.

Precondition
The packet was received successfully, and it has data available, parameter size is no more than 4.
virtual void MProtocolC12::Security ( )
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.

Precondition
The channel is open, and the protocol state allows Logon to be called.
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.

Since
MeteringSDK Version 2.1.27. However, the type changed from Boolean to INT32 in MeteringSDK Version 5.4.0. All versions can accept the value as Boolean or INT32, so no changes are needed to existing applications built using older versions.
Default value:
  • 2 for MeteringSDK Versions 5.4.0 and later.
  • 1 {True} for MeteringSDK Versions prior to 5.4.0.
Possible values:
  • False, or 0 : ST-8 is NOT read when the function does not have a response. This behavior is available for all versions. Applications that set the value to 0, or False, will behave exactly the same in any version.
  • True, 1, 2, or -1 : ST-8 is read for ALL functions.
void MProtocolC12::SetAlwaysUsePartial ( bool  yes)
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.

Since
MeteringSDK Version 5.2.0.1720.
Default value:
Possible values:
  • False : perform full table reads and writes if they fit in the application layer.
  • True : replace full table reads and writes with partial operations for all tables except ST7 and ST8.
void MProtocolC12::SetApplicationLayerProcedureRetries ( unsigned  retries)
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.

Since
MeteringSDK Version 2.1.27.
Default value:
20
Possible values:
  • 1 .. MAXINT
void MProtocolC12::SetApplicationLayerProcedureRetryDelay ( unsigned  milliseconds)
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.

Since
MeteringSDK Version 2.1.27.
Default value:
500 milliseconds
Possible values:
  • 1 .. MAXINT
See also
GetApplicationLayerRetryDelay that works for table retry delays.
void MProtocolC12::SetApplicationLayerRetries ( unsigned  retries)
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.

Since
MeteringSDK Version 2.1.27.
Default value:
20
See also
GetApplicationLayerProcedureRetries that works for procedure retries.
void MProtocolC12::SetApplicationLayerRetryDelay ( unsigned  milliseconds)
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.

Since
MeteringSDK Version 2.1.27.
Default value:
2000 milliseconds
See also
GetApplicationLayerProcedureRetryDelay that works for procedure retry delays.
void MProtocolC12::SetEndSessionOnApplicationLayerError ( bool  endSessionOnApplicationLayerError)
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.

Since
MeteringSDK Version 5.2.0.1720.
Default value:
false
Possible values:
  • True [1] : The end session services are sent to the device after an Application Layer error.
  • False [0] : The end session services are NOT sent to the device after an Application Layer error. The session timeouts according to the protocol rules.
virtual void MProtocolC12::SetIssueSecurityOnStartSession ( bool  )
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.

  • ANSI Std C12.18-1995 "PROTOCOL SPECIFICATION FOR ANSI TYPE 2 OPTICAL PORT"
  • ANSI Std C12.21-1998 "PROTOCOL SPECIFICATION FOR TELEPHONE MODEM COMMUNICATION"
  • ANSI Std C12.22-2008 "PROTOCOL SPECIFICATION FOR INTERFACING TO DATA COMMUNICATION NETWORKS"
Since
MeteringSDK Version 2.1.27.
Default value:
True
Possible values:
  • True [1] : The security or authenticate service is issued with the password.
  • False [0] : The security or authenticate service is NOT issued. Data that does not require a password can be read. Attempting to access data that requires a password will generate an error.

Reimplemented in MProtocolC1222.

void MProtocolC12::SetLinkLayerRetries ( unsigned  retries)
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.

Since
MeteringSDK Version 2.1.27.
Default value:
3
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.

Since
MeteringSDK Version 6.6.0.5882.
Default value:
0
Possible values: 0 .. 255
void MProtocolC12::SetTurnAroundDelay ( unsigned  delay)
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.

0.12 Identify
0.17 Tx> EE 00 00 00 00 01 20 13 10
0.20 Rx> 06 EE 00 00 00 00 05 00 00 01 00 00 C6 B5
// Turn around delay, approximately 60 msec before
// ACK (0x06) transmitted to the meter
0.26 Tx> 06
0.26 Identify success
// Turn around delay, approximately 60 msec before
// next request (Negotiate) transmitted to the meter
0.26 Negotiate
0.32 Tx> EE 00 20 00 00 05 61 04 00 80 06 C2 29
0.35 Rx> 06 EE 00 20 00 00 05 00 04 00 80 06 35 83
0.41 Tx> 06
0.41 Negotiate success
Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • 1 .. MAXINT in milliseconds.
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".

Since
MeteringSDK Version 2.1.27.
Default value:
10 characters with binary zero values.
Possible values:
  • Any string containing 10 or less bytes, i.e. "1234567890".
void MProtocolC12::SetUseReadInKeepSessionAlive ( bool  yes)
inline

Whether to use table read for session keeping instead of C12 Wait. This property has no effect if KEEP_SESSION_ALIVE is False.

Since
MeteringSDK Version 4.0.54.
Default value:
False
Possible values:
  • True [1] : The first byte of ST1 will be read to keep the session alive.
  • False [0] : The C12 Wait service will be used to keep the session alive.
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.

Since
MeteringSDK Version 2.1.27.
Default value:
0
Possible values: 0 .. 65535
static unsigned MProtocolC12::StaticCalculateChecksum ( const MByteString buff)
static

Compute checksum of the byte string given as parameters.

The checksum is calculated based on the C12 rules.

static unsigned MProtocolC12::StaticCalculateChecksumFromBuffer ( const char *  data,
unsigned  size 
)
static

Compute checksum of the buffer and length given as parameters.

The checksum is calculated based on the C12 rules.

See also
StaticCalculateChecksum for the variation with the byte string given as byte string.
static Muint16 MProtocolC12::StaticCalculateCRC16FromBuffer ( const char *  buffer,
unsigned  length 
)
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.

Precondition
The buffer designated with the pointer and the length is valid.
virtual void MProtocolC12::Terminate ( )
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.

Precondition
The channel is open, and the protocol state allows Terminate to be called.
virtual void MProtocolC12::Wait ( unsigned  seconds)
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.

Precondition
The channel is open, and the protocol state allows Wait to be called. Seconds are no bigger than 255.