def populateMessage(message, count): # Note: If a field of the same name is added to an existing message, # the value passed when calling add_field will overwrite the existing # value. message.add_field("CHAR-FIELD", 'c') message.add_field("BOOL-FIELD-TRUE", True) message.add_field("BOOL-FIELD-FALSE", False) message.add_field(libgmsec_python3.I8Field("I8-FIELD", count)) message.add_field(libgmsec_python3.I16Field("I16-FIELD", count)) message.add_field(libgmsec_python3.I32Field("I32-FIELD", count)) message.add_field(libgmsec_python3.I64Field("I64-FIELD", count)) message.add_field(libgmsec_python3.U8Field("U8-FIELD", count)) message.add_field(libgmsec_python3.U16Field("U16-FIELD", count)) message.add_field(libgmsec_python3.U32Field("U32-FIELD", count)) message.add_field(libgmsec_python3.U64Field("U64-FIELD", count)) message.add_field(libgmsec_python3.StringField("STRING-FIELD", "This is a test")) message.add_field(libgmsec_python3.F32Field("F32-FIELD", (1 + 1. / count))) message.add_field(libgmsec_python3.F64Field("F64-FIELD", (1 + 1. / count))) message.add_field(libgmsec_python3.BinaryField("BIN-FIELD", "JLMNOPQ", 7))
def populateMessage(message): # Add Fields of varying data types to the Message value = 1 message.add_field(libgmsec_python3.CharField("CHAR-FIELD", 'c')) message.add_field(libgmsec_python3.BooleanField("BOOL-FIELD-TRUE", True)) message.add_field(libgmsec_python3.BooleanField("BOOL-FIELD-FALSE", False)) message.add_field(libgmsec_python3.I8Field("I8-FIELD", value)) message.add_field(libgmsec_python3.I16Field("I16-FIELD", value)) message.add_field(libgmsec_python3.I32Field("I32-FIELD", value)) message.add_field(libgmsec_python3.I64Field("I64-FIELD", value)) message.add_field(libgmsec_python3.U8Field("U8-FIELD", value)) message.add_field(libgmsec_python3.U16Field("U16-FIELD", value)) message.add_field(libgmsec_python3.U32Field("U32-FIELD", value)) message.add_field(libgmsec_python3.U64Field("U64-FIELD", value)) message.add_field( libgmsec_python3.StringField("STRING-FIELD", "This is a test")) message.add_field(libgmsec_python3.F32Field("F32-FIELD", (1 + 1. / value))) message.add_field(libgmsec_python3.F64Field("F64-FIELD", (1 + 1. / value))) message.add_field(libgmsec_python3.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.add_field(libgmsec_python3.CharField("CHAR-FIELD", 'c')) message.add_field(libgmsec_python3.BooleanField("BOOL-FIELD-TRUE", True)) message.add_field(libgmsec_python3.BooleanField("BOOL-FIELD-FALSE", False)) message.add_field(libgmsec_python3.I8Field("I8-FIELD", value % 128)) message.add_field(libgmsec_python3.I16Field("I16-FIELD", value)) message.add_field(libgmsec_python3.I32Field("I32-FIELD", value)) message.add_field(libgmsec_python3.I64Field("I64-FIELD", value)) message.add_field(libgmsec_python3.U8Field("U8-FIELD", value % 256)) message.add_field(libgmsec_python3.U16Field("U16-FIELD", value)) message.add_field(libgmsec_python3.U32Field("U32-FIELD", value)) message.add_field(libgmsec_python3.U64Field("U64-FIELD", value)) message.add_field( libgmsec_python3.StringField("STRING-FIELD", "This is a test")) message.add_field(libgmsec_python3.F32Field("F32-FIELD", (1 + 1. / value))) message.add_field(libgmsec_python3.F64Field("F64-FIELD", (1 + 1. / value))) message.add_field(libgmsec_python3.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_python3.Config(sys.argv) # 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_python3.log_info( libgmsec_python3.ConnectionManager.get_API_version()) try: # Create a ConnectionManager object connManager = libgmsec_python3.ConnectionManager(config) # Open the connection to the middleware libgmsec_python3.log_info( "Opening the connection to the middleware server") connManager.initialize() # Output middleware client library version libgmsec_python3.log_info(connManager.get_library_version()) # 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_python3.FieldList() missionField = libgmsec_python3.StringField("MISSION-ID", "MISSION") # Note: SAT-ID-PHYSICAL is an optional header Field, according # to the GMSEC ISD. satIdField = libgmsec_python3.StringField("SAT-ID-PHYSICAL", "SPACECRAFT") facilityField = libgmsec_python3.StringField("FACILITY", "GMSEC Lab") componentField = libgmsec_python3.StringField("COMPONENT", "device_message") definedFields.append(missionField) definedFields.append(satIdField) definedFields.append(facilityField) definedFields.append(componentField) # Use set_standard_fields to define a set of header fields for # all messages which are created or published on the # ConnectionManager using the following functions: # create_log_message, publish_log, create_heartbeat_message, # start_heartbeat_service, create_resource_message, # publishResourceMessage, or start_resource_message_service connManager.set_standard_fields(definedFields) paramVal = libgmsec_python3.I32Field("DEVICE.1.PARAM.1.VALUE", 79) param = libgmsec_python3.DeviceParam("DEV parameter 1", "parameter 1 timestamp", paramVal) device1 = libgmsec_python3.Device("device 1", libgmsec_python3.Device.RED) device1.set_group("group") device1.set_role("role") device1.set_model("model") device1.set_serial("1138") device1.set_version("1.4.5.2.3.4.5") devInfo = libgmsec_python3.I16Field("info", 5) device1.set_info(devInfo) devNum = libgmsec_python3.I16Field("num", 5) device1.set_number(devNum) device1.add_param(param) # Construct an DEV Message and add the Device values to it devMessage = libgmsec_python3.DeviceMessage( DEV_MESSAGE_SUBJECT, connManager.get_specification()) devMessage.add_device(device1) connManager.add_standard_fields(devMessage) libgmsec_python3.log_info("Publishing DEV message:\n" + devMessage.to_XML()) connManager.publish(devMessage) except libgmsec_python3.GmsecError as e: libgmsec_python3.log_error(str(e)) 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_python3.Config(sys.argv) # 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_python3.log_info( libgmsec_python3.ConnectionManager.get_API_version()) try: # Create a ConnectionManager object connManager = libgmsec_python3.ConnectionManager(config) # Open the connection to the middleware libgmsec_python3.log_info( "Opening the connection to the middleware server") connManager.initialize() # Output middleware client library version libgmsec_python3.log_info(connManager.get_library_version()) # 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_python3.FieldList() missionField = libgmsec_python3.StringField("MISSION-ID", "MISSION") # Note: SAT-ID-PHYSICAL is an optional header Field, according # to the GMSEC ISD. satIdField = libgmsec_python3.StringField("SAT-ID-PHYSICAL", "SPACECRAFT") facilityField = libgmsec_python3.StringField("FACILITY", "GMSEC Lab") componentField = libgmsec_python3.StringField("COMPONENT", "mnemonic_message") definedFields.append(missionField) definedFields.append(satIdField) definedFields.append(facilityField) definedFields.append(componentField) # Use set_standard_fields to define a set of header fields for # all messages which are created or published on the # ConnectionManager using the following functions: # create_log_message, publish_log, create_heartbeat_message, # start_heartbeat_service, create_resource_message, # publishResourceMessage, or start_resource_message_service connManager.set_standard_fields(definedFields) # Populate the Mnemonic Sample(s) mSample = libgmsec_python3.MnemonicSample( "MS1", libgmsec_python3.I32Field("MS1", 15)) mSample.set_EU_value(libgmsec_python3.F32Field("My EU", 15.0)) mSample.set_flags(1) mSample.set_limit(libgmsec_python3.MnemonicSample.RED_HIGH) # Implicitly set limit enable/disable with setting of limit mSample.set_quality(True) mSample.set_staleness_status(False) mSample.set_text_value("15") mnemonic_samples = libgmsec_python3.MnemonicSampleList() mnemonic_samples.append(mSample) # Add the Mnemonic values to a Mnemonic object mnemonic = libgmsec_python3.Mnemonic("M1", mnemonic_samples) statusField = libgmsec_python3.I16Field("status", 5) mnemonic.set_status(statusField) mnemonic.set_units("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_python3.MnemonicMessage( MVAL_MESSAGE_SUBJECT, schemaId, connManager.get_specification()) mvalMessage.add_mnemonic(mnemonic) # Add the header fields to the MVAL message connManager.add_standard_fields(mvalMessage) libgmsec_python3.log_info("Publishing MVAL message:\n" + mvalMessage.to_XML()) connManager.publish(mvalMessage) except libgmsec_python3.GmsecError as e: libgmsec_python3.log_error(str(e)) 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_python3.Config(sys.argv) # 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_python3.log_info( libgmsec_python3.ConnectionManager.get_API_version()) try: # Create a ConnectionManager object connManager = libgmsec_python3.ConnectionManager(config) # Open the connection to the middleware libgmsec_python3.log_info( "Opening the connection to the middleware server") connManager.initialize() # Output middleware client library version libgmsec_python3.log_info(connManager.get_library_version()) # 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_python3.FieldList() missionField = libgmsec_python3.StringField("MISSION-ID", "MISSION") # Note: SAT-ID-PHYSICAL is an optional header Field, according # to the GMSEC ISD. satIdField = libgmsec_python3.StringField("SAT-ID-PHYSICAL", "SPACECRAFT") facilityField = libgmsec_python3.StringField("FACILITY", "GMSEC Lab") componentField = libgmsec_python3.StringField("COMPONENT", "log_message") definedFields.append(missionField) definedFields.append(satIdField) definedFields.append(facilityField) definedFields.append(componentField) # Use set_standard_fields to define a set of header fields for # all messages which are created or published on the # ConnectionManager using the following functions: # create_log_message, publish_log, create_heartbeat_message, # start_heartbeat_service, create_resource_message, # publishResourceMessage, or start_resource_message_service connManager.set_standard_fields(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_python3.MistMessage(LOG_MESSAGE_SUBJECT, "MSG.LOG", connManager.get_specification()) # 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 = libgmsec_python3.TimeUtil.format_time( libgmsec_python3.TimeUtil.get_current_time()) logMsg.add_field(libgmsec_python3.I16Field("SEVERITY", 1)) logMsg.set_value("MSG-TEXT", "Creating an example GMSEC LOG Message") logMsg.set_value("OCCURRENCE-TYPE", "SYS") logMsg.set_value("SUBCLASS", "AST") logMsg.set_value("EVENT-TIME", eventTime) # Add the standard fields to the LOG message connManager.add_standard_fields(logMsg) libgmsec_python3.log_info("Publishing LOG message:\n" + logMsg.to_XML()) connManager.publish(logMsg) except libgmsec_python3.GmsecError as e: libgmsec_python3.log_error(str(e)) 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_python3.Config(sys.argv) # 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_python3.log_info(libgmsec_python3.ConnectionManager.get_API_version()) try: # Create a ConnectionManager object connManager = libgmsec_python3.ConnectionManager(config) # Open the connection to the middleware libgmsec_python3.log_info("Opening the connection to the middleware server") connManager.initialize() # Output middleware client library version libgmsec_python3.log_info(connManager.get_library_version()) # Create all of the GMSEC Message header Fields which will # be used by all GMSEC Messages headerFields = libgmsec_python3.FieldList() version = connManager.get_specification().get_version() missionField = libgmsec_python3.StringField("MISSION-ID", "MY-MISSION") facilityField = libgmsec_python3.StringField("FACILITY", "MY-FACILITY") componentField = libgmsec_python3.StringField("COMPONENT", "HEARTBEAT-SERVICE") domain1Field = libgmsec_python3.StringField("DOMAIN1", "MY-DOMAIN-1") domain2Field =libgmsec_python3.StringField("DOMAIN2", "MY-DOMAIN-2") msgID = libgmsec_python3.StringField("MSG-ID", "MY-MSG-ID") headerFields.append(missionField) headerFields.append(facilityField) headerFields.append(componentField) if (version == 201400): headerFields.append(msgID) elif (version >= 201800): headerFields.append(domain1Field) headerFields.append(domain2Field) # Use set_standard_fields to define a set of header fields for # all messages which are created or published on the # ConnectionManager using the following functions: # create_log_message, publish_log, create_heartbeat_message, # start_heartbeat_service, create_resource_message, # publishResourceMessage, or start_resource_message_service connManager.set_standard_fields(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_python3.FieldList() pubRateField = libgmsec_python3.U16Field("PUB-RATE", HB_PUBLISH_RATE) counterField = libgmsec_python3.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_python3.I16Field("COMPONENT-STATUS", 0) hbStandardFields.append(pubRateField) hbStandardFields.append(counterField) hbStandardFields.append(componentStatusField) # Create and publish a Heartbeat message using # create_log_message() 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.create_heartbeat_message(HB_MESSAGE_SUBJECT, hbStandardFields) libgmsec_python3.log_info("Publishing the GMSEC C2CX HB message which was just created using create_heartbeat_message():\n" + hbMsg.to_XML()) 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_python3.log_info("Starting the Heartbeat service, a message will be published every " + pubRateField.get_string_value() + " seconds") connManager.start_heartbeat_service(HB_MESSAGE_SUBJECT, hbStandardFields) # Use set_heartbeat_service_field 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_python3.I16Field("COMPONENT-STATUS", 1) connManager.set_heartbeat_service_field(componentStatusField) libgmsec_python3.log_info("Publishing C2CX Heartbeat Messages indefinitely, press <enter> to exit the program") input("") # Stop the Heartbeat Service connManager.stop_heartbeat_service() # Cleanup connManager.cleanup() except libgmsec_python3.GmsecError as e: libgmsec_python3.log_error(str(e)) return -1 return 0