C12Adapter Opensource C++ Interface
MProtocolC1218 Class Reference

ANSI C12 18 protocol implementation, a further specialization of C12 set of protocols. More...

Inheritance diagram for MProtocolC1218:

Public Types

enum  {
  SMALLEST_PACKET_SIZE = 32,
  BIGGEST_PACKET_SIZE = 8192,
  PACKET_HEADER_AND_FOOTER_LENGTH = 8,
  MAXIMUM_BAD_PACKET_LENGTH_SLEEP = 1000,
  MAXIMUM_BAD_TOGGLE_BIT_SLEEP = 1500
}
 
- Public Types inherited from MProtocolC12
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

 MProtocolC1218 (MChannel *channel, bool channelIsOwned=true)
 Create a new C12.18 protocol with the channel given. More...
 
virtual ~MProtocolC1218 ()
 Destroy the C12.18 protocol object.
 
virtual void ApplyChannelParameters ()
 Setup the configuration of the channel according to the C12.18 protocol handshake settings.
 
virtual void Identify ()
 Perform ANSI C12 Identify request. More...
 
virtual void Negotiate ()
 Perform ANSI C12 Negotiate request. More...
 
int GetIdentifiedReferenceStandard () const
 Get the reference standard, as identified by the C12.18 Identify command. More...
 
int GetIdentifiedStandardVersion () const
 Get the standard version, as identified by the C12.18 Identify command. More...
 
int GetIdentifiedStandardRevision () const
 Get the standard revision, as identified by the C12.18 Identify command. More...
 
bool GetIdentifiedPropertiesPresent () const
 Tells if Identify command was successful, and IDENTIFIED properties are available. More...
 
unsigned GetNegotiatedPacketSize () const
 Return the packet size which was negotiated with the meter in the Negotiate command. More...
 
unsigned GetNegotiatedMaximumNumberOfPackets () const
 Return the maximum number of packets, which was negotiated with the meter in the Negotiate command. More...
 
unsigned GetNegotiatedSessionBaud () const
 Return the negotiated session baud, which was returned by the meter in the Negotiate command. More...
 
bool GetNegotiatedPropertiesPresent () const
 Tells if Negotiate command was successful, and negotiated properties are available. More...
 
unsigned GetIntercharacterTimeout () const
 
void SetIntercharacterTimeout (unsigned timeout)
 
unsigned GetAcknowledgementTimeout () const
 
void SetAcknowledgementTimeout (unsigned timeout)
 
unsigned GetChannelTrafficTimeout () const
 
void SetChannelTrafficTimeout (unsigned timeout)
 
unsigned GetPacketSize () const
 
void SetPacketSize (unsigned packetSize)
 
unsigned GetMaximumNumberOfPackets () const
 
void SetMaximumNumberOfPackets (unsigned num)
 
unsigned GetSessionBaud () const
 
void SetSessionBaud (unsigned sessionBaud)
 
bool GetIssueNegotiateOnStartSession () const
 
void SetIssueNegotiateOnStartSession (bool yes)
 
bool GetIssueLogoffOnEndSession () const
 
void SetIssueLogoffOnEndSession (bool yes)
 
unsigned GetProcedureInitiateTimeout () const
 
void SetProcedureInitiateTimeout (unsigned procedureInitiateTimeout)
 
bool GetNextOutgoingToggleBit () const
 
void SetNextOutgoingToggleBit (bool yes)
 
void SetWakeUpSharedOpticalPort (bool wakeUp)
 
bool GetWakeUpSharedOpticalPort () const
 
bool GetCheckIncomingToggleBit () const
 
void SetCheckIncomingToggleBit (bool doCheck)
 
- Public Member Functions inherited from MProtocolC12
virtual ~MProtocolC12 ()
 Destroy the C12 protocol object. 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...
 

Protected Member Functions

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...
 
- Protected Member Functions inherited from MProtocolC12
 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 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 Member Functions inherited from MProtocolC12
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...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 

Detailed Description

ANSI C12 18 protocol implementation, a further specialization of C12 set of protocols.

ANSI Std C12.18-1996 "PROTOCOL SPECIFICATION FOR ANSI Type 2 OPTICAL Port", is intended as a single communications standard for Water, Gas, and Electricity meters that will work on any manufacturer's conforming product. The ANSI C12.18 is a point to point protocol developed to transport table data over an optical connection. A copy of the document can be obtained through NEMA or ANSI. MProtocolC1218 is the protocol implementation of the ANSI C12.18 standard. It inherits properties from the abstract class MProtocol, which is common to all protocols. MProtocolC1218 is intended for communications through the optical probe channel, MChannelOpticalProbe. MProtocolC1221 has extensions for working through modems and multi-drop networks. The Password is 20 characters long, refer to the Password help topic for padding rules.

Member Enumeration Documentation

anonymous enum
Enumerator
SMALLEST_PACKET_SIZE 

Smallest packet size supported by the data link layer It shall be bigger than (BIGGEST_I2C_OPTION_BOARD_COMMAND + BIGGEST_I2C_PACKET_HEADER_OVERHEAD + 1)

BIGGEST_PACKET_SIZE 

Biggest packet size supported by the data link layer.

PACKET_HEADER_AND_FOOTER_LENGTH 

Consists of: stp8 reserved8 ctrl8 seq_nbr8 length16 data crc2.

MAXIMUM_BAD_PACKET_LENGTH_SLEEP 

Maximum time to wait after receiving bad packet length.

MAXIMUM_BAD_TOGGLE_BIT_SLEEP 

Maximum time to wait after receiving bad toggle bit.

Constructor & Destructor Documentation

MProtocolC1218::MProtocolC1218 ( MChannel channel,
bool  channelIsOwned = true 
)

Create a new C12.18 protocol with the channel given.

Precondition
The channel allowed for this type of the protocol is compatible. Otherwise an exception is thrown.

Member Function Documentation

virtual void MProtocolC1218::DoEndSession ( )
protectedvirtual

Synchronously end the session, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol. Depending on the particular protocol this leads to sequence of logoff and terminate commands.

See EndSession, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the protocol state allows ending the session. Otherwise exceptions can be thrown.

Reimplemented from MProtocol.

virtual void MProtocolC1218::DoStartSession ( )
protectedvirtual

Synchronously start the session, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol. Depending on the particular protocol this leads to sequence of handshake and logon commands.

See StartSession, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the protocol state allows starting the session. Otherwise exceptions can be thrown.

Reimplemented from MProtocol.

Reimplemented in MProtocolC1221.

unsigned MProtocolC1218::GetAcknowledgementTimeout ( ) const
inline

The maximum number of milliseconds to wait for the acknowledgement of the packet.

Should this amount of time be exceeded after the packet is sent, and there is no ACK seen (byte 0x06), a timeout condition will occur. Either a retry is triggered, or if the number of retries is zero already, an error is raised.

When MProtocolC1221::TimingSetup gets called, acknowledgement timeout is negotiated with the device to the precision of seconds. See MProtocolC1221::TimingSetup for more details.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values: 0 .. 255000 milliseconds, while values close to zero might not be practical.
The maximum value of 255000 milliseconds is constrained by C12.21 protocol service MProtocolC1221::TimingSetup(), where the timeout is negotiated with the client using byte representation of seconds.
See also
MProtocolC1221::GetIssueTimingSetupOnStartSession - control whether TimingSetup is called at StartSession
MProtocolC1221::TimingSetup() - negotiate timeouts and retries with the client, C12.21 only
unsigned MProtocolC1218::GetChannelTrafficTimeout ( ) const
inline

Maximum number of milliseconds the device waits for a valid packet before terminating the communications session.

Channel traffic timeout applies to the ANSI C12.18 and C12.21 protocols. When C12.21 is used, the value of this property can be agreed with the device by using MProtocolC1221::TimingSetup() service. The agreement leads to approximation of the timeout value to the precision of seconds, and the approximation is done towards the upper value. For example, channel traffic timeouts 5001, 5500 or 5900 will become 6000 after successful MProtocolC1221::TimingSetup(). Because the value is passed to the device as byte value of seconds, the maximum channel traffic timeout value is limited to 255000.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • 0 .. 255000 milliseconds, while the value 0 makes little sense as it assumes the device times out after every request
See also
MProtocolC1221::GetIssueTimingSetupOnStartSession - control whether TimingSetup is called at StartSession
MProtocolC1221::TimingSetup() - negotiate timeouts and retries with the client, C12.21 only
bool MProtocolC1218::GetCheckIncomingToggleBit ( ) const
inline

Whether to check the incoming toggle bit or not.

This property is true by default. If it is false, the incoming toggle bit is ignored.

The ANSI C12.18 and C12.21 protocols define a toggle bit in the control field definition byte. This bit is used to detect duplicate packets. By setting this property to false, MeteringSDK can be forced to not check the toggle bit. This is useful for meters that do not properly implement the ANSI C12 toggle bit.

Since
MeteringSDK Version 3.0.5.
Default value:
True
Possible values:
  • True [1] : The incoming toggle bit is checked.
  • False [0] : The incoming toggle bit is NOT checked.
bool MProtocolC1218::GetIdentifiedPropertiesPresent ( ) const
inline

Tells if Identify command was successful, and IDENTIFIED properties are available.

Specifies whether or not the dynamic identified properties are available. The identified properties are only available after a successful start session sequence.

Since
MeteringSDK Version 2.1.27.
Possible values:
  • True [1] : The identified properties are available.
  • False [0] : The identified properties are not available and querying them will result in an error being raised.
See also
GetIdentifiedReferenceStandard
GetIdentifiedStandardVersion
GetIdentifiedStandardRevision
int MProtocolC1218::GetIdentifiedReferenceStandard ( ) const

Get the reference standard, as identified by the C12.18 Identify command.

Precondition
The Identify is issued successfully, through direct call or through StartSession. Otherwise the exception is thrown.

The ANSI Reference Standard implemented by the meter. This property is available only after the ANSI C12 Identify request is executed (for example, through a start session sequence). The value of this property persists unchanged until the identification of a different meter is performed. If the property is queried before a successful Identify request, an error is raised. The property GetIdentifiedPropertiesPresent can be used to determine if the IdentifiedReferenceStandard is available.

Since
MeteringSDK Version 2.1.27.
Default value:
None. Must be read from meter during the start session sequence.
Possible values:
  • 0 : ANSI C12.18
  • 1 : Used by Industry Canada
  • 2 .. 255 : Reserved
int MProtocolC1218::GetIdentifiedStandardRevision ( ) const

Get the standard revision, as identified by the C12.18 Identify command.

Precondition
The Identify is issued successfully, through direct call or through StartSession. Otherwise the exception is thrown.

The revision of the ANSI C12.xx protocol standard, as implemented by the meter. This property is important for scripts that are affected by the differences between revisions of the ANSI C12.xx standards.

This property is available only after the ANSI C12 Identify request is executed (for example, through a start session sequence). The value of this property persists unchanged until the identification of a different meter is performed. If the property is queried before a successful Identify request, an error is raised. The property GetIdentifiedPropertiesPresent can be used to determine if the IdentifiedStandardRevision is available.

Since
MeteringSDK Version 2.1.27.
Default value:
None. Must be read from meter during the start session sequence.
Possible values:
  • 0 .. 255
int MProtocolC1218::GetIdentifiedStandardVersion ( ) const

Get the standard version, as identified by the C12.18 Identify command.

Precondition
The Identify is issued successfully, through direct call or through StartSession. Otherwise the exception is thrown.

The version of the ANSI C12.xx protocol standard, as implemented by the meter. This property is important for scripts that are affected by the differences between versions of the ANSI C12.xx standards.

This property is available only after the ANSI C12 Identify request is executed (for example, through a start session sequence). The value of this property persists unchanged until the identification of a different meter is performed. If the property is queried before a successful Identify request, an error is raised. The property GetIdentifiedPropertiesPresent can be used to determine if the IdentifiedStandardVersion is available.

Since
MeteringSDK Version 2.1.27.
Default value:
None. Must be read from meter during the start session sequence.
Possible values:
  • 0 .. 255
unsigned MProtocolC1218::GetIntercharacterTimeout ( ) const
inline

The maximum number of milliseconds allowed between individual characters sent or received in the same packet.

Should this amount of time be exceeded in between any two characters in the packet, a timeout condition will occur. Either a retry is triggered, or if the number of retries is zero already, an error is raised.

Intercharacter timeout is not precisely guarded due to hardware constraints, however the implementation guarantees that the actual timeout will not be smaller than the value given to this property. Also, when MProtocolC1221::TimingSetup gets called, intercharacter timeout is negotiated with the device to the precision of seconds. See MProtocolC1221::TimingSetup for more details.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values: 0 .. 255000 milliseconds, while values close to zero might not be practical.
The maximum value of 255000 milliseconds is constrained by C12.21 protocol service MProtocolC1221::TimingSetup(), where the timeout is negotiated with the client using byte representation of seconds.
See also
MProtocolC1221::GetIssueTimingSetupOnStartSession - control whether TimingSetup is called at StartSession
MProtocolC1221::TimingSetup() - negotiate timeouts and retries with the client, C12.21 only
bool MProtocolC1218::GetIssueLogoffOnEndSession ( ) const
inline

Whether the Logoff C12 service shall be applied within EndSession sequence.

A standard C12.18 and C12.21 session can end with Terminate, optionally preceded by Logoff. This property allows omitting of Logoff when EndSession is called. The property has no effect on the Logoff() method that can always be called directly.

Since
MeteringSDK Version 5.2.0.1720.
Default value:
Possible values:
  • True : Logoff service is issued as part of EndSession sequence
  • False : Logoff service is issued as part of EndSession sequence.
bool MProtocolC1218::GetIssueNegotiateOnStartSession ( ) const
inline

Whether the Negotiate C12 service shall be applied within StartSession sequence.

When the negotiate service is issued (GetIssueNegotiateOnStartSession = 1), the values of the protocol properties GetSessionBaud, GetMaximumNumberOfPackets, and GetPacketSize are the communication parameters that are requested in the negotiate service. The device does not have to accept the requested communication parameters and may reject them by specifying different values to be used. To discover what values were actually used during communications, one can query the negotiated properties.

When the negotiate service is not issued (IssueNegotiateOnStartSession = 0), the default values of the protocol properties (as defined by the ANSI C12.18 and C12.21 standard) are used for communications. Setting the values of GetSessionBaud, GetMaximumNumberOfPackets, and GetPacketSize, does not affect communications, and reading these property values does not necessarily reflect the values used during communications.

Set IssueNegotiateOnStartSession to false [0] for devices that do not support the negotiate service. The ANSI C12.18 and C12.21 protocol specifies that the negotiate service is optional and devices can respond with Service Not Supported (SNS). When MeteringSDK receives an SNS from the device, it passes the error back to the caller and does not continue with communications.

Since
MeteringSDK Version 2.2.26.
Default value:
True
Possible values:
  • True [1] : The negotiate service is issued during start session.
  • False [0] : The negotiate service is NOT issued, GetNegotiatedPropertiesPresent is False and the dynamic negotiated properties raise an error if accessed.
unsigned MProtocolC1218::GetMaximumNumberOfPackets ( ) const
inline

Maximum number of link layer packets used by the protocol.

The maximum number of packets that will be requested in the negotiate service sent to the end device. The maximum number of packets is the maximum number of data link layer packets that can be assembled by the implementation into a single service request. After a successful negotiate service, the dynamic property GetNegotiatedMaximumNumberOfPackets contains the actual value that is used during communication.

The MaximumNumberOfPackets property is only used when the negotiate service is sent to the end device. Whether or not the negotiate service is sent to the end device depends on the property GetIssueNegotiateOnStartSession.

If GetIssueNegotiateOnStartSession = 0 [False], then MCOM uses the MaximumNumberOfPackets property value as set, even though the ANSI C12.18 and C12.21 standards define the default value as 1. This is useful for testing firmware.

For more details refer to the ANSI C12.18 and C12.21 standards.

Since
MeteringSDK Version 2.1.27.
Default value:
255 : This is the value that MeteringSDK defaults to. The default maximum number of packets as defined by the ANSI C12.18 and C12.21 standards is 1 packet.
Possible values:
  • 1 .. 255
unsigned MProtocolC1218::GetNegotiatedMaximumNumberOfPackets ( ) const

Return the maximum number of packets, which was negotiated with the meter in the Negotiate command.

Precondition
The Negotiate is issued successfully, through direct call or through StartSession. Otherwise the exception is thrown.

The number of packets that was negotiated with the meter during the start session sequence. This dynamic property is available only after the completion of a successful start session sequence. The value of this property will persist unchanged until another start session sequence. If the property is queried before a successful start session sequence, an error will be raised. The property GetNegotiatedPropertiesPresent can be used to determine if the NegotiatedMaximumNumberOfPackets is available.

During the Negotiate service, if the meter accepts the GetMaximumNumberOfPackets from MeteringSDK, then NegotiatedMaximumNumberOfPackets = MaximumNumberOfPackets.

Since
MeteringSDK Version 2.1.27.
Possible values:
  • 1 .. 255
unsigned MProtocolC1218::GetNegotiatedPacketSize ( ) const

Return the packet size which was negotiated with the meter in the Negotiate command.

Precondition
The Negotiate is issued successfully, through direct call or through StartSession. Otherwise the exception is thrown.

The number of bytes in the packet that was negotiated with the meter during the start session sequence. This dynamic property is available only after the completion of a successful start session sequence. The value of this property will persist unchanged until another start session sequence. If the property is queried before a successful start session sequence, an error is raised. The property GetNegotiatedPropertiesPresent can be used to determine if the NegotiatedPacketSize is available.

During the Negotiate service, if the meter accepts the GetPacketSize from MeteringSDK, then NegotiatedPacketSize = PacketSize.

Since
MeteringSDK Version 2.1.27.
Possible values:
  • 32 .. 65535
bool MProtocolC1218::GetNegotiatedPropertiesPresent ( ) const
inline

Tells if Negotiate command was successful, and negotiated properties are available.

Specifies whether or not the dynamic negotiated properties are available. The negotiated properties are only available after a successful start session sequence.

Since
MeteringSDK Version 2.1.27.
Possible values:
  • True [1] : The negotiated properties are available.
  • False [0] : The negotiated properties are not available and querying them results in an error being raised.
See also
GetNegotiatedMaximumNumberOfPackets
GetNegotiatedPacketSize
GetNegotiatedSessionBaud
unsigned MProtocolC1218::GetNegotiatedSessionBaud ( ) const

Return the negotiated session baud, which was returned by the meter in the Negotiate command.

Precondition
The Negotiate is issued successfully, through direct call or through StartSession. Otherwise the exception is thrown.

The SessionBaud rate that was negotiated with the meter during a start session sequence. This dynamic property is available only after the completion of a successful start session sequence. The value of this property will persist unchanged until another start session sequence. If the property is queried before a successful start session sequence, an error is raised. The property GetNegotiatedPropertiesPresent can be used to determine if the NegotiatedSessionBaud is available.

Since
MeteringSDK Version 2.1.27.
Possible values:
  • 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 128000, 256000
bool MProtocolC1218::GetNextOutgoingToggleBit ( ) const
inline

The value of the toggle bit that will be used in the next outgoing data link packet.

The ANSI C12.18 and C12.21 protocols define a toggle bit in the control field definition byte. The toggle bit is used to detect duplicate packets. The NextOutgoingToggleBit property tells what the state of the next toggle bit will be. When True, the next toggle bit will be set to 1. When False, the next toggle bit will be reset to 0.

The NextOutgoingToggleBit property is useful for clients who want to start a session with the meter using QStartSession, then create their own packet(s) to send to the meter (can be sent using channel WriteBytes service). These clients should set/reset the toggle bit of their control byte based on the value of this property. When they are done sending their own packets, they can set the NextOutgoingToggleBit property and the protocol will use this property to determine how to set the toggle bit in the next package it sends to the meter.

The object sets the NextOutgoingToggleBit to zero after an end session. During normal operations, where clients are using QEndSession to terminate the session, the start session will always start with the toggle bit set to zero making it easier to compare logs from different sessions. However, for clients that want to start the session with the toggle bit set to 1, they can do so by simply setting the NextOutgoingToggleBit to 1 prior to starting the session.

Note that when using the communication queues, the communication is executed on QCommit service. It is important to get the NextOutgoingToggleBit after the QCommit service completes, and to set it before starting the QCommit service.

Since
MeteringSDK Version 3.2.17.
Default value:
False
Possible values:
  • True [1] : The next outgoing toggle bit will be set to 1.
  • False [0] : The next outgoing toggle bit will be reset to 0.
unsigned MProtocolC1218::GetPacketSize ( ) const
inline

Packet size used by the ANSI protocol.

The packet size that will be requested in the negotiate service sent to the end device. The packet size is the maximum number of bytes allowed in the link layer packet. After a successful negotiate service, the dynamic property NegotiatedPacketSize contains the actual value that is used during communication.

If GetIssueNegotiateOnStartSession = 0 [False], then MCOM uses the PacketSize property value as set, even though the ANSI C12.18 and C12.21 standards define the default value as 64 bytes. This is useful for testing firmware.

For more details refer to the ANSI C12.18 and C12.21 standards.

Since
MeteringSDK Version 2.1.27.
Default value:
  • 1024 bytes for MProtocolC1218, different then the ANSI standard which defaults to 64 bytes.
  • 1024 bytes for MProtocolC1221, different then the ANSI standard which defaults to 64 bytes.
Possible values:
  • 32 .. 8192
unsigned MProtocolC1218::GetProcedureInitiateTimeout ( ) const
inline

Number of milliseconds which the application layer should wait while reading the ST_007 table.

The number of milliseconds to wait for the device to respond to a procedure initiate request, which is a table write to ST_007. Some procedures, on some devices, can take a long time to execute a procedure. Typically devices handle this by acknowledging the ST_007 write, then responding to the ST_008 table read (procedure response request) with the response code 'procedure accepted but not fully completed', which allows for GetApplicationLayerProcedureRetries to be utilized. However, some devices do not respond at all while executing the procedure, resulting in channel read timeout errors on the link layer where GetLinkLayerRetries are utilized. The ProcedureInitiateTimeout value corrects this situation by temporarily increasing the number of Link Layer Retries so that GetLinkLayerRetries * GetAcknowledgementTimeout is not less than ProcedureInitiateTimeout.

Since
MeteringSDK Version 5.1.2.1690.
Default value:
20000 milliseconds
Possible values:
  • 0 .. UINT_MAX
unsigned MProtocolC1218::GetSessionBaud ( ) const
inline

Session baud, one which is negotiated with the meter during communication.

When the session baud is nonzero, the suggested baud rate is requested in the negotiate service sent to the device. After a successful negotiate service, the dynamic property GetNegotiatedSessionBaud contains the actual value that is used during communication. Prior to the negotiate service, in case of optical probe the communications start at 9600 bps.

Whether or not the negotiate service is sent to the device depends on the property GetIssueNegotiateOnStartSession. Therefore, to change optical probe baud at negotiate, one shall set SetIssueNegotiateOnStartSession to True, and SetSessionBaud shall be a nonzero value that is a valid baud rate accepted by this property, and by the device.

For more details refer to the ANSI C12.18 and C12.21 standards.

Since
MeteringSDK Version 2.1.27.
Default value:
9600
Possible values:
  • 0 means session baud is not agreed on Negotiate.
  • 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 128000, 256000 - possible session baud rates. Not all optical probes are able to support the higher baud rates. Devices may not support all speeds. Support of 9600 is required because this is the speed that the session starts at. Device support for speeds is not necessarily hierarchical, for example a device might support 128000 but not 115200.
bool MProtocolC1218::GetWakeUpSharedOpticalPort ( ) const
inline

Whether to wake up the shared optical probe on start session.

Determines whether or not a garbage character (0x55) is sent before an identify request to 'wake up' the shared optical port. This property only needs to be set to True when the meter has a shared optical port. Sending the garbage character resolves the problem where the UART is connected to the remote port, the identify command is sent through the optical port, the meter receives the first character (0xEE) while connected to the remote port and switches the UART to the optical port and changes the bit rate, but the meter misses at least the first character of the packet. By sending a garbage character, the meter is given time to switch the UART to the optical port before it receives the first request.

Since
MeteringSDK Version 2.2.26.
Default value:
False
Possible values:
  • True [1] : The garbage character, 0x55, is sent before an identify request in the start session sequence.
  • False [0] : The garbage character is NOT sent before an identify request in the start session sequence.
virtual void MProtocolC1218::Identify ( )
virtual

Perform ANSI C12 Identify request.

This service is called from StartSession, but it can also be called directly by the user for testing purpose.

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

Reimplemented in MProtocolC1221.

virtual void MProtocolC1218::Negotiate ( )
virtual

Perform ANSI C12 Negotiate request.

This service is called from StartSession, but it can also be called directly by the user for testing purpose. The implementation negotiates packet size, number of packets, and one baud rate (command 0x61).

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

Reimplemented in MProtocolC1221.

void MProtocolC1218::SetAcknowledgementTimeout ( unsigned  timeout)

The maximum number of milliseconds to wait for the acknowledgement of the packet.

Should this amount of time be exceeded after the packet is sent, and there is no ACK seen (byte 0x06), a timeout condition will occur. Either a retry is triggered, or if the number of retries is zero already, an error is raised.

When MProtocolC1221::TimingSetup gets called, acknowledgement timeout is negotiated with the device to the precision of seconds. See MProtocolC1221::TimingSetup for more details.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values: 0 .. 255000 milliseconds, while values close to zero might not be practical.
The maximum value of 255000 milliseconds is constrained by C12.21 protocol service MProtocolC1221::TimingSetup(), where the timeout is negotiated with the client using byte representation of seconds.
See also
MProtocolC1221::GetIssueTimingSetupOnStartSession - control whether TimingSetup is called at StartSession
MProtocolC1221::TimingSetup() - negotiate timeouts and retries with the client, C12.21 only
void MProtocolC1218::SetChannelTrafficTimeout ( unsigned  timeout)

Maximum number of milliseconds the device waits for a valid packet before terminating the communications session.

Channel traffic timeout applies to the ANSI C12.18 and C12.21 protocols. When C12.21 is used, the value of this property can be agreed with the device by using MProtocolC1221::TimingSetup() service. The agreement leads to approximation of the timeout value to the precision of seconds, and the approximation is done towards the upper value. For example, channel traffic timeouts 5001, 5500 or 5900 will become 6000 after successful MProtocolC1221::TimingSetup(). Because the value is passed to the device as byte value of seconds, the maximum channel traffic timeout value is limited to 255000.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • 0 .. 255000 milliseconds, while the value 0 makes little sense as it assumes the device times out after every request
See also
MProtocolC1221::GetIssueTimingSetupOnStartSession - control whether TimingSetup is called at StartSession
MProtocolC1221::TimingSetup() - negotiate timeouts and retries with the client, C12.21 only
void MProtocolC1218::SetCheckIncomingToggleBit ( bool  doCheck)
inline

Whether to check the incoming toggle bit or not.

This property is true by default. If it is false, the incoming toggle bit is ignored.

The ANSI C12.18 and C12.21 protocols define a toggle bit in the control field definition byte. This bit is used to detect duplicate packets. By setting this property to false, MeteringSDK can be forced to not check the toggle bit. This is useful for meters that do not properly implement the ANSI C12 toggle bit.

Since
MeteringSDK Version 3.0.5.
Default value:
True
Possible values:
  • True [1] : The incoming toggle bit is checked.
  • False [0] : The incoming toggle bit is NOT checked.
void MProtocolC1218::SetIntercharacterTimeout ( unsigned  timeout)

The maximum number of milliseconds allowed between individual characters sent or received in the same packet.

Should this amount of time be exceeded in between any two characters in the packet, a timeout condition will occur. Either a retry is triggered, or if the number of retries is zero already, an error is raised.

Intercharacter timeout is not precisely guarded due to hardware constraints, however the implementation guarantees that the actual timeout will not be smaller than the value given to this property. Also, when MProtocolC1221::TimingSetup gets called, intercharacter timeout is negotiated with the device to the precision of seconds. See MProtocolC1221::TimingSetup for more details.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values: 0 .. 255000 milliseconds, while values close to zero might not be practical.
The maximum value of 255000 milliseconds is constrained by C12.21 protocol service MProtocolC1221::TimingSetup(), where the timeout is negotiated with the client using byte representation of seconds.
See also
MProtocolC1221::GetIssueTimingSetupOnStartSession - control whether TimingSetup is called at StartSession
MProtocolC1221::TimingSetup() - negotiate timeouts and retries with the client, C12.21 only
void MProtocolC1218::SetIssueLogoffOnEndSession ( bool  yes)
inline

Whether the Logoff C12 service shall be applied within EndSession sequence.

A standard C12.18 and C12.21 session can end with Terminate, optionally preceded by Logoff. This property allows omitting of Logoff when EndSession is called. The property has no effect on the Logoff() method that can always be called directly.

Since
MeteringSDK Version 5.2.0.1720.
Default value:
Possible values:
  • True : Logoff service is issued as part of EndSession sequence
  • False : Logoff service is issued as part of EndSession sequence.
void MProtocolC1218::SetIssueNegotiateOnStartSession ( bool  yes)
inline

Whether the Negotiate C12 service shall be applied within StartSession sequence.

When the negotiate service is issued (GetIssueNegotiateOnStartSession = 1), the values of the protocol properties GetSessionBaud, GetMaximumNumberOfPackets, and GetPacketSize are the communication parameters that are requested in the negotiate service. The device does not have to accept the requested communication parameters and may reject them by specifying different values to be used. To discover what values were actually used during communications, one can query the negotiated properties.

When the negotiate service is not issued (IssueNegotiateOnStartSession = 0), the default values of the protocol properties (as defined by the ANSI C12.18 and C12.21 standard) are used for communications. Setting the values of GetSessionBaud, GetMaximumNumberOfPackets, and GetPacketSize, does not affect communications, and reading these property values does not necessarily reflect the values used during communications.

Set IssueNegotiateOnStartSession to false [0] for devices that do not support the negotiate service. The ANSI C12.18 and C12.21 protocol specifies that the negotiate service is optional and devices can respond with Service Not Supported (SNS). When MeteringSDK receives an SNS from the device, it passes the error back to the caller and does not continue with communications.

Since
MeteringSDK Version 2.2.26.
Default value:
True
Possible values:
  • True [1] : The negotiate service is issued during start session.
  • False [0] : The negotiate service is NOT issued, GetNegotiatedPropertiesPresent is False and the dynamic negotiated properties raise an error if accessed.
void MProtocolC1218::SetMaximumNumberOfPackets ( unsigned  num)

Maximum number of link layer packets used by the protocol.

The maximum number of packets that will be requested in the negotiate service sent to the end device. The maximum number of packets is the maximum number of data link layer packets that can be assembled by the implementation into a single service request. After a successful negotiate service, the dynamic property GetNegotiatedMaximumNumberOfPackets contains the actual value that is used during communication.

The MaximumNumberOfPackets property is only used when the negotiate service is sent to the end device. Whether or not the negotiate service is sent to the end device depends on the property GetIssueNegotiateOnStartSession.

If GetIssueNegotiateOnStartSession = 0 [False], then MCOM uses the MaximumNumberOfPackets property value as set, even though the ANSI C12.18 and C12.21 standards define the default value as 1. This is useful for testing firmware.

For more details refer to the ANSI C12.18 and C12.21 standards.

Since
MeteringSDK Version 2.1.27.
Default value:
255 : This is the value that MeteringSDK defaults to. The default maximum number of packets as defined by the ANSI C12.18 and C12.21 standards is 1 packet.
Possible values:
  • 1 .. 255
void MProtocolC1218::SetNextOutgoingToggleBit ( bool  yes)
inline

The value of the toggle bit that will be used in the next outgoing data link packet.

The ANSI C12.18 and C12.21 protocols define a toggle bit in the control field definition byte. The toggle bit is used to detect duplicate packets. The NextOutgoingToggleBit property tells what the state of the next toggle bit will be. When True, the next toggle bit will be set to 1. When False, the next toggle bit will be reset to 0.

The NextOutgoingToggleBit property is useful for clients who want to start a session with the meter using QStartSession, then create their own packet(s) to send to the meter (can be sent using channel WriteBytes service). These clients should set/reset the toggle bit of their control byte based on the value of this property. When they are done sending their own packets, they can set the NextOutgoingToggleBit property and the protocol will use this property to determine how to set the toggle bit in the next package it sends to the meter.

The object sets the NextOutgoingToggleBit to zero after an end session. During normal operations, where clients are using QEndSession to terminate the session, the start session will always start with the toggle bit set to zero making it easier to compare logs from different sessions. However, for clients that want to start the session with the toggle bit set to 1, they can do so by simply setting the NextOutgoingToggleBit to 1 prior to starting the session.

Note that when using the communication queues, the communication is executed on QCommit service. It is important to get the NextOutgoingToggleBit after the QCommit service completes, and to set it before starting the QCommit service.

Since
MeteringSDK Version 3.2.17.
Default value:
False
Possible values:
  • True [1] : The next outgoing toggle bit will be set to 1.
  • False [0] : The next outgoing toggle bit will be reset to 0.
void MProtocolC1218::SetPacketSize ( unsigned  packetSize)

Packet size used by the ANSI protocol.

The packet size that will be requested in the negotiate service sent to the end device. The packet size is the maximum number of bytes allowed in the link layer packet. After a successful negotiate service, the dynamic property NegotiatedPacketSize contains the actual value that is used during communication.

If GetIssueNegotiateOnStartSession = 0 [False], then MCOM uses the PacketSize property value as set, even though the ANSI C12.18 and C12.21 standards define the default value as 64 bytes. This is useful for testing firmware.

For more details refer to the ANSI C12.18 and C12.21 standards.

Since
MeteringSDK Version 2.1.27.
Default value:
  • 1024 bytes for MProtocolC1218, different then the ANSI standard which defaults to 64 bytes.
  • 1024 bytes for MProtocolC1221, different then the ANSI standard which defaults to 64 bytes.
Possible values:
  • 32 .. 8192
void MProtocolC1218::SetProcedureInitiateTimeout ( unsigned  procedureInitiateTimeout)
inline

Number of milliseconds which the application layer should wait while reading the ST_007 table.

The number of milliseconds to wait for the device to respond to a procedure initiate request, which is a table write to ST_007. Some procedures, on some devices, can take a long time to execute a procedure. Typically devices handle this by acknowledging the ST_007 write, then responding to the ST_008 table read (procedure response request) with the response code 'procedure accepted but not fully completed', which allows for GetApplicationLayerProcedureRetries to be utilized. However, some devices do not respond at all while executing the procedure, resulting in channel read timeout errors on the link layer where GetLinkLayerRetries are utilized. The ProcedureInitiateTimeout value corrects this situation by temporarily increasing the number of Link Layer Retries so that GetLinkLayerRetries * GetAcknowledgementTimeout is not less than ProcedureInitiateTimeout.

Since
MeteringSDK Version 5.1.2.1690.
Default value:
20000 milliseconds
Possible values:
  • 0 .. UINT_MAX
void MProtocolC1218::SetSessionBaud ( unsigned  sessionBaud)

Session baud, one which is negotiated with the meter during communication.

When the session baud is nonzero, the suggested baud rate is requested in the negotiate service sent to the device. After a successful negotiate service, the dynamic property GetNegotiatedSessionBaud contains the actual value that is used during communication. Prior to the negotiate service, in case of optical probe the communications start at 9600 bps.

Whether or not the negotiate service is sent to the device depends on the property GetIssueNegotiateOnStartSession. Therefore, to change optical probe baud at negotiate, one shall set SetIssueNegotiateOnStartSession to True, and SetSessionBaud shall be a nonzero value that is a valid baud rate accepted by this property, and by the device.

For more details refer to the ANSI C12.18 and C12.21 standards.

Since
MeteringSDK Version 2.1.27.
Default value:
9600
Possible values:
  • 0 means session baud is not agreed on Negotiate.
  • 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 128000, 256000 - possible session baud rates. Not all optical probes are able to support the higher baud rates. Devices may not support all speeds. Support of 9600 is required because this is the speed that the session starts at. Device support for speeds is not necessarily hierarchical, for example a device might support 128000 but not 115200.
void MProtocolC1218::SetWakeUpSharedOpticalPort ( bool  wakeUp)
inline

Whether to wake up the shared optical probe on start session.

Determines whether or not a garbage character (0x55) is sent before an identify request to 'wake up' the shared optical port. This property only needs to be set to True when the meter has a shared optical port. Sending the garbage character resolves the problem where the UART is connected to the remote port, the identify command is sent through the optical port, the meter receives the first character (0xEE) while connected to the remote port and switches the UART to the optical port and changes the bit rate, but the meter misses at least the first character of the packet. By sending a garbage character, the meter is given time to switch the UART to the optical port before it receives the first request.

Since
MeteringSDK Version 2.2.26.
Default value:
False
Possible values:
  • True [1] : The garbage character, 0x55, is sent before an identify request in the start session sequence.
  • False [0] : The garbage character is NOT sent before an identify request in the start session sequence.