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 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 # 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", "device_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) paramVal = libgmsec_python.I32Field("DEVICE.1.PARAM.1.VALUE", 79) param = libgmsec_python.DeviceParam("DEV parameter 1", "parameter 1 timestamp", paramVal) device1 = libgmsec_python.Device("device 1", libgmsec_python.Device.RED) device1.setGroup("group") device1.setRole("role") device1.setModel("model") device1.setSerial("1138") device1.setVersion("1.4.5.2.3.4.5") devInfo = libgmsec_python.I16Field("info", 5) device1.setInfo(devInfo) devNum = libgmsec_python.I16Field("num", 5) device1.setNumber(devNum) device1.addParam(param) # Construct an DEV Message and add the Device values to it devMessage = libgmsec_python.DeviceMessage( DEV_MESSAGE_SUBJECT, connManager.getSpecification()) devMessage.addDevice(device1) connManager.addStandardFields(devMessage) libgmsec_python.logInfo("Publishing DEV message:\n" + devMessage.toXML()) connManager.publish(devMessage) 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()) # Begin the steps necessary to create a GMSEC-compliant LOG # message using the ConnectionManager # 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", "log_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) # Use MistMessage to construct a GMSEC LOG message based off # of the latest XML templates provided with the GMSEC API. # This will automatically populate the Message with all of the # Fields which have specific values defined for them in the XML # template files. For more information on which Fields have # values defined for them, please review the XML template files # located in GMSEC_API/templates. # Note: The second parameter is an identifier for the type of # message to construct. logMsg = libgmsec_python.MistMessage(LOG_MESSAGE_SUBJECT, "MSG.LOG", connManager.getSpecification()) # Add the LOG-specific fields to the LOG message # 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. eventTime = "YYYY-DDD-HH:MM:SS.sss" libgmsec_python.TimeUtil.formatTime(libgmsec_python.TimeUtil.getCurrentTime(), eventTime); logMsg.addField(libgmsec_python.I16Field("SEVERITY",1)) logMsg.setValue("MSG-TEXT", "Creating an example GMSEC LOG Message") logMsg.setValue("OCCURRENCE-TYPE", "SYS") logMsg.setValue("SUBCLASS", "AST") logMsg.setValue("EVENT-TIME", eventTime) # Add the standard fields to the LOG message connManager.addStandardFields(logMsg) libgmsec_python.logInfo("Publishing LOG message:\n" + logMsg.toXML()) connManager.publish(logMsg) except libgmsec_python.Exception as e: libgmsec_python.logError(e.what()) return -1 return 0
def main(argv=None): 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() missionField = libgmsec_python.StringField("MISSION-ID", "GMSEC") facilityField = libgmsec_python.StringField("FACILITY", "GMSEC Lab") componentField = libgmsec_python.StringField("COMPONENT", "heartbeat_service") 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) # Note: Fields are immutable, so plan appropriately if you wish # to re-use variable names! # Create all of the GMSEC Message header Fields which # will be used by all GMSEC HB Messages hbStandardFields = libgmsec_python.FieldList() pubRateField = libgmsec_python.U16Field("PUB-RATE", 30) counterField = libgmsec_python.U16Field("COUNTER", 1) # Note: COMPONENT-STATUS is an optional field used to # denote the operating status of the component, the # values are as follows: # 0 - Debug # 1 - Normal / Green # 2 - Warning / Yellow # 3 - Orange # 4 - Error / Red componentStatusField = libgmsec_python.I16Field("COMPONENT-STATUS", 0) hbStandardFields.append(pubRateField) hbStandardFields.append(counterField) hbStandardFields.append(componentStatusField) # Create and publish a Heartbeat message using # createLogMessage() and publish() # Note: This is useful for applications which may need # to create proxy heartbeats on behalf of a subsystem, # as creating multiple ConnectionManagers can consume # more memory than necessary. In this case, extra # logic would need to be added to handle the timing of # the publications. hbMsg = connManager.createHeartbeatMessage(HB_MESSAGE_SUBJECT, hbStandardFields) libgmsec_python.logInfo( "Publishing the GMSEC C2CX HB message which was just created using createHeartbeatMessage():\n" + hbMsg.toXML()) connManager.publish(hbMsg) # Kick off the Heartbeat Service -- This will publish # heartbeat messages automatically every X seconds, # where Xis the value which was provided for PUB-RATE # Note: If PUB-RATE was not provided, it will default # to 30 seconds per automatic Heartbeat publication libgmsec_python.logInfo( "Starting the Heartbeat service, a message will be published every " + pubRateField.getStringValue() + " seconds") connManager.startHeartbeatService(HB_MESSAGE_SUBJECT, hbStandardFields) # Use setHeartbeatServiceField to change the state of the # COMPONENT-STATUS Field to indicate that the component has # transitioned from a startup/debug state to a running/green # state. componentStatusField = libgmsec_python.I16Field("COMPONENT-STATUS", 1) connManager.setHeartbeatServiceField(componentStatusField) libgmsec_python.logInfo( "Publishing C2CX Heartbeat Messages indefinitely, press <enter> to exit the program" ) raw_input("") # Stop the Heartbeat Service connManager.stopHeartbeatService() # Cleanup connManager.cleanup() except libgmsec_python.Exception as e: libgmsec_python.logError(e.what()) return -1 return 0