def populateMessage(message): # Add Fields of varying data types to the Message value = 1 message.addField(libgmsec_python.CharField("CHAR-FIELD", 'c')) message.addField(libgmsec_python.BooleanField("BOOL-FIELD-TRUE", True)) message.addField(libgmsec_python.BooleanField("BOOL-FIELD-FALSE", False)) message.addField(libgmsec_python.I8Field("I8-FIELD", value)) message.addField(libgmsec_python.I16Field("I16-FIELD", value)) message.addField(libgmsec_python.I32Field("I32-FIELD", value)) message.addField(libgmsec_python.I64Field("I64-FIELD", value)) message.addField(libgmsec_python.U8Field("U8-FIELD", value)) message.addField(libgmsec_python.U16Field("U16-FIELD", value)) message.addField(libgmsec_python.U32Field("U32-FIELD", value)) message.addField(libgmsec_python.U64Field("U64-FIELD", value)) message.addField(libgmsec_python.StringField("STRING-FIELD", "This is a test")) message.addField(libgmsec_python.F32Field("F32-FIELD", (1 + 1. / value))) message.addField(libgmsec_python.F64Field("F64-FIELD", (1 + 1. / value))) message.addField(libgmsec_python.BinaryField("BIN-FIELD", "JLMNOPQ", 7))
def publishTestMessage(connMgr, subject): i = 123 # Create a Message object message = libgmsec_python.Message(subject, libgmsec_python.Message.PUBLISH) # Add fields to the Message message.addField("F", False) message.addField(libgmsec_python.I32Field("I", i)) message.addField(libgmsec_python.U16Field("K", i)) message.addField("S", "This is a test") message.addField(libgmsec_python.F32Field("D", 1 + 1. / i)) message.addField(libgmsec_python.BinaryField("X", "JLMNOPQ", 7)) # Publish Message connMgr.publish(message) # Output the Message's XML string representation by invoking Log macro libgmsec_python.logInfo("Sent:\n" + message.toXML())
def populateMessage(message, value): # Note: Since C++ is a strongly-typed language, it is possible to use # type casting to add Field objects to a Message without having to # first create a Field object, then add it to the message. message.addField(libgmsec_python.CharField("CHAR-FIELD", 'c')) message.addField(libgmsec_python.BooleanField("BOOL-FIELD-TRUE", True)) message.addField(libgmsec_python.BooleanField("BOOL-FIELD-FALSE", False)) message.addField(libgmsec_python.I8Field("I8-FIELD", value % 128)) message.addField(libgmsec_python.I16Field("I16-FIELD", value)) message.addField(libgmsec_python.I32Field("I32-FIELD", value)) message.addField(libgmsec_python.I64Field("I64-FIELD", value)) message.addField(libgmsec_python.U8Field("U8-FIELD", value % 256)) message.addField(libgmsec_python.U16Field("U16-FIELD", value)) message.addField(libgmsec_python.U32Field("U32-FIELD", value)) message.addField(libgmsec_python.U64Field("U64-FIELD", value)) message.addField( libgmsec_python.StringField("STRING-FIELD", "This is a test")) message.addField(libgmsec_python.F32Field("F32-FIELD", (1 + 1. / value))) message.addField(libgmsec_python.F64Field("F64-FIELD", (1 + 1. / value))) message.addField(libgmsec_python.BinaryField("BIN-FIELD", "JLMNOPQ", 7))
def populateMessage(message, count): # Note: If a field of the same name is added to an existing message, # the value passed when calling addField will overwrite the existing # value. message.addField("CHAR-FIELD", 'c') message.addField("BOOL-FIELD-TRUE", True) message.addField("BOOL-FIELD-FALSE", False) message.addField(libgmsec_python.I8Field("I8-FIELD", count)) message.addField(libgmsec_python.I16Field("I16-FIELD", count)) message.addField(libgmsec_python.I32Field("I32-FIELD", count)) message.addField(libgmsec_python.I64Field("I64-FIELD", count)) message.addField(libgmsec_python.U8Field("U8-FIELD", count)) message.addField(libgmsec_python.U16Field("U16-FIELD", count)) message.addField(libgmsec_python.U32Field("U32-FIELD", count)) message.addField(libgmsec_python.U64Field("U64-FIELD", count)) message.addField( libgmsec_python.StringField("STRING-FIELD", "This is a test")) message.addField(libgmsec_python.F32Field("F32-FIELD", (1 + 1. / count))) message.addField(libgmsec_python.F64Field("F64-FIELD", (1 + 1. / count))) message.addField(libgmsec_python.BinaryField("BIN-FIELD", "JLMNOPQ", 7))
def main(): if (len(sys.argv) <= 1): usageMessage = "usage: " + sys.argv[0] + " mw-id=<middleware ID>" print usageMessage return -1 # Load the command-line input into a GMSEC Config object # A Config object is basically a key-value pair map which is used to # pass configuration options into objects such as Connections, # ConnectionManagers, Subscribe and Publish function calls, Messages, # etc. config = libgmsec_python.Config() for arg in sys.argv[1:]: value = arg.split('=') config.addValue(value[0], value[1]) # If it was not specified in the command-line arguments, set LOGLEVEL # to 'INFO' and LOGFILE to 'stdout' to allow the program report output # on the terminal/command line initializeLogging(config) # Print the GMSEC API version number using the GMSEC Logging # interface # This is useful for determining which version of the API is # configured within the environment libgmsec_python.logInfo(libgmsec_python.ConnectionManager.getAPIVersion()) try: # Create a ConnectionManager object connManager = libgmsec_python.ConnectionManager(config) # Open the connection to the middleware libgmsec_python.logInfo( "Opening the connection to the middleware server") connManager.initialize() # Output middleware client library version libgmsec_python.logInfo(connManager.getLibraryVersion()) # Create all of the GMSEC Message header Fields which will # be used by all GMSEC Messages # Note: Since these Fields contain variable values which are # based on the context in which they are used, they cannot be # automatically populated using MistMessage. definedFields = libgmsec_python.FieldList() missionField = libgmsec_python.StringField("MISSION-ID", "MISSION") # Note: SAT-ID-PHYSICAL is an optional header Field, according # to the GMSEC ISD. satIdField = libgmsec_python.StringField("SAT-ID-PHYSICAL", "SPACECRAFT") facilityField = libgmsec_python.StringField("FACILITY", "GMSEC Lab") componentField = libgmsec_python.StringField("COMPONENT", "mnemonic_message") definedFields.append(missionField) definedFields.append(satIdField) definedFields.append(facilityField) definedFields.append(componentField) # Use setStandardFields to define a set of header fields for # all messages which are created or published on the # ConnectionManager using the following functions: # createLogMessage, publishLog, createHeartbeatMessage, # startHeartbeatService, createResourceMessage, # publishResourceMessage, or startResourceMessageService connManager.setStandardFields(definedFields) # Populate the Mnemonic Sample(s) mSample = libgmsec_python.MnemonicSample( "MS1", libgmsec_python.I32Field("MS1", 15)) mSample.setEUValue(libgmsec_python.F32Field("My EU", 15.0)) mSample.setFlags(1) mSample.setLimit(libgmsec_python.MnemonicSample.RED_HIGH) # Implicitly set limit enable/disable with setting of limit mSample.setQuality(True) mSample.setStalenessStatus(False) mSample.setTextValue("15") mnemonic_samples = libgmsec_python.MnemonicSampleList() mnemonic_samples.append(mSample) # Add the Mnemonic values to a Mnemonic object mnemonic = libgmsec_python.Mnemonic("M1", mnemonic_samples) statusField = libgmsec_python.I16Field("status", 5) mnemonic.setStatus(statusField) mnemonic.setUnits("units") # Build up the Schema ID -- This is used to identify the # specific type of MVAL message to construct schemaId = GMSEC_SPEC_VERSION + ".GMSEC.MSG.MVAL" # Construct an MVAL Message and add the Mnemonic values to it mvalMessage = libgmsec_python.MnemonicMessage( MVAL_MESSAGE_SUBJECT, schemaId, connManager.getSpecification()) mvalMessage.addMnemonic(mnemonic) # Add the header fields to the MVAL message connManager.addStandardFields(mvalMessage) libgmsec_python.logInfo("Publishing MVAL message:\n" + mvalMessage.toXML()) connManager.publish(mvalMessage) except libgmsec_python.Exception as e: libgmsec_python.logError(e.what()) return -1 return 0
def main(): if (len(sys.argv) <= 1): usageMessage = "usage: " + sys.argv[0] + " mw-id=<middleware ID>" print usageMessage return -1 # Load the command-line input into a GMSEC Config object # A Config object is basically a key-value pair map which is used to # pass configuration options into objects such as Connections, # ConnectionManagers, Subscribe and Publish function calls, Messages, # etc. config = libgmsec_python.Config() for arg in sys.argv[1:]: value = arg.split('=') config.addValue(value[0], value[1]) # If it was not specified in the command-line arguments, set LOGLEVEL # to 'INFO' and LOGFILE to 'stdout' to allow the program report output # on the terminal/command line initializeLogging(config) # Print the GMSEC API version number using the GMSEC Logging # interface # This is useful for determining which version of the API is # configured within the environment libgmsec_python.logInfo(libgmsec_python.ConnectionManager.getAPIVersion()) try: # Create a ConnectionManager object connManager = libgmsec_python.ConnectionManager(config) # Open the connection to the middleware libgmsec_python.logInfo( "Opening the connection to the middleware server") connManager.initialize() # Output middleware client library version libgmsec_python.logInfo(connManager.getLibraryVersion()) # Create all of the GMSEC Message header Fields which will # be used by all GMSEC Messages headerFields = libgmsec_python.FieldList() versionField = libgmsec_python.F32Field("HEADER-VERSION", 2010.0) missionField = libgmsec_python.StringField("MISSION-ID", "GMSEC") facilityField = libgmsec_python.StringField("FACILITY", "GMSEC Lab") componentField = libgmsec_python.StringField("COMPONENT", "heartbeat_service") headerFields.append(versionField) headerFields.append(missionField) headerFields.append(facilityField) headerFields.append(componentField) # Use setStandardFields to define a set of header fields for # all messages which are created or published on the # ConnectionManager using the following functions: # createLogMessage, publishLog, createHeartbeatMessage, # startHeartbeatService, createResourceMessage, # publishResourceMessage, or startResourceMessageService connManager.setStandardFields(headerFields) # Create and publish a Resource message using # createResourceMessage() and publish() # Note: This is useful for applications which may need to add # additional Fields to the Resource Messages which are not # currently added by the GMSEC API rsrcMsg = connManager.createResourceMessage(RSRC_MESSAGE_SUBJECT) libgmsec_python.logInfo( "Publishing the GMSEC C2CX RSRC message which was created using createResourceMessage():\n" + rsrcMsg.toXML()) connManager.publish(rsrcMsg) # Kick off the Resource Service -- This will publish resource # messages automatically every X seconds, where X is the second # parameter provided to the startResourceMessageService() function. # If an interval is not provided, the service will default to # publishing a message every 60 seconds. interval_s = 30 libgmsec_python.logInfo( "Starting the Resource Message service, a message will be published every " + str(interval_s) + " seconds") try: libgmsec_python.logInfo( "Publishing C2CX Resource Messages indefinitely, press <enter> to exit the program" ) connManager.startResourceMessageService(RSRC_MESSAGE_SUBJECT, interval_s) # Wait for user input to end the program except KeyboardInterrupt: pass # Stop the Heartbeat Service connManager.stopResourceMessageService() # Cleanup connManager.cleanup() except libgmsec_python.Exception as e: libgmsec_python.logError(e.what()) return -1 return 0