def setupStandardFields(connMgr): definedFields = libgmsec_python.FieldList() missionField = libgmsec_python.StringField("MISSION-ID", "MISSION") satIdField = libgmsec_python.StringField("SAT-ID-PHYSICAL", "SPACECRAFT") facilityField = libgmsec_python.StringField("FACILITY", "GMSEC Lab") componentField = libgmsec_python.StringField("COMPONENT", "validation_custom") definedFields.append(missionField) definedFields.append(satIdField) definedFields.append(facilityField) definedFields.append(componentField) connMgr.setStandardFields(definedFields)
def setupStandardFields(connMgr): definedFields = libgmsec_python.FieldList() missionField = libgmsec_python.StringField("MISSION-ID", "MISSION") satIdField = libgmsec_python.StringField("SAT-ID-PHYSICAL", "SPACECRAFT") facilityField = libgmsec_python.StringField("FACILITY", "GMSEC Lab") componentField = libgmsec_python.StringField("COMPONENT", "validation_custom") definedFields.append(missionField) definedFields.append(satIdField) definedFields.append(facilityField) definedFields.append(componentField) if (connMgr.getSpecification().getVersion() >= libgmsec_python.GMSEC_ISD_2018_00): domain1 = libgmsec_python.StringField("DOMAIN1", "MY-DOMAIN-1") domain2 = libgmsec_python.StringField("DOMAIN2", "MY-DOMAIN-2") definedFields.append(domain1) definedFields.append(domain2) connMgr.setStandardFields(definedFields)
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 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) # Enable Message validation. This parameter is "false" by default. config.addValue("GMSEC-MSG-CONTENT-VALIDATE", "true") # Tell the API that there is an additional layer of message schema to # validate (The 'EXAMPLE' message definitions). This value is set to # 0 (Only 'GMSEC' specification validation) by default. # Note: These levels for validation are determined by the "LEVEL-X" # attributes defined in the .DIRECTORY.xml file contained in the XML # templates directory. In thise case, Level-0 means GMSEC and Level-1 # means EXAMPLE. # Note: The GMSEC team envisions using message specifications in a # layered hierarchical fashion. For example, the "GMSEC" message # specification would be 'layer 0', followed by an organization-level # message specification at 'layer 1' which builds upon the message # specification outlined in the GMSEC ISD. This would be followed by # a mission-level message specification at 'layer 2' and so on. config.addValue("GMSEC-SCHEMA-LEVEL", "1") # Tell the API where to find all of the schema files. # Note: This example only demonstrates a simple usage case of this # functionality. When using this functionality, if the intent is # to use any of the GMSEC message definitions, then ALL of the XML # template files must be contained in the same directory. # e.g. GMSEC_API/templates/2016.00 (Or the location defined in # GMSEC-SCHEMA-PATH) config.addValue("GMSEC-SCHEMA-PATH", "templates") libgmsec_python.logInfo(libgmsec_python.ConnectionManager.getAPIVersion()) try: connMgr = libgmsec_python.ConnectionManager(config) libgmsec_python.logInfo( "Opening the connection to the middleware server") connMgr.initialize() libgmsec_python.logInfo(connMgr.getLibraryVersion()) definedFields = libgmsec_python.FieldList() missionField = libgmsec_python.StringField("MISSION-ID", "MISSION") 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) connMgr.setStandardFields(definedFields) # Create a Message using a subject defined in the XML template # outlining our example addendum message definitions message = libgmsec_python.MistMessage(EXAMPLE_MESSAGE_SUBJECT, "MSG.LOG", connMgr.getSpecification()) # Add all of the necessary Fields to our message message.addField(libgmsec_python.U16Field("NUM-OF-EVENTS", 2)) message.setValue("EVENT.1", addTimeToString("AOS occurred at: ")) message.setValue("EVENT.2", addTimeToString("Telemetry downlink began at: ")) connMgr.addStandardFields(message) # Publish the message to the middleware bus connMgr.publish(message) # Display the XML string representation of the Message for # the sake of review libgmsec_python.logInfo("Published message:\n" + message.toXML()) # Setup a new message without some of the Required Fields and # attempt to publish it (i.e. Trigger a validation failure) badMessage = libgmsec_python.MistMessage(EXAMPLE_MESSAGE_SUBJECT, "MSG.LOG", connMgr.getSpecification()) try: connMgr.publish(badMessage) except libgmsec_python.Exception as e: libgmsec_python.logError("This is an expected error:\n" + e.what()) # Disconnect from the middleware and clean up the Connection connMgr.cleanup() 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 satIdField = libgmsec_python.StringField("SAT-ID-PHYSICAL", "SPACECRAFT") facilityField = libgmsec_python.StringField("FACILITY", "GMSEC Lab") componentField = libgmsec_python.StringField("COMPONENT", "product_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) # Create a ProductFile object with the product name, # description, version, file format, and the URI externalFile = libgmsec_python.ProductFile("External File", "External File Description", "1.0.0", "TXT", "//hostname/dir/filename") filePayload = bytearray() for i in range(0, 256): filePayload.append(i) # Create a ProductFile object with the product name, # description, version, format, binary array, and file size binaryFile = libgmsec_python.ProductFile("File as Binary", "Binary File Description", "1.0.0", "BIN", filePayload, len(filePayload)) # Create a Product File Message with the subject, # RESPONSE-STATUS Field value, Message type (publish, request, # or reply), PROD-TYPE Field value, PROD-SUBTYPE Field value, # and pass it the Specification object from the Connection # Manager productMessage = libgmsec_python.ProductFileMessage(PROD_MESSAGE_SUBJECT, libgmsec_python.ResponseStatus.SUCCESSFUL_COMPLETION, libgmsec_python.Message.PUBLISH, "AUTO", "DM", connManager.getSpecification()) productMessage.addProductFile(externalFile) productMessage.addProductFile(binaryFile) connManager.addStandardFields(productMessage) libgmsec_python.logInfo("Publishing DEV message:\n" + productMessage.toXML()) connManager.publish(productMessage) 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", "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()) # Create all of the GMSEC Message header Fields which will # be used by all GMSEC Messages headerFields = libgmsec_python.FieldList() version = connManager.getSpecification().getVersion() missionField = libgmsec_python.StringField("MISSION-ID", "MY-MISSION") facilityField = libgmsec_python.StringField("FACILITY", "MY-FACILITY") componentField = libgmsec_python.StringField("COMPONENT", "RESOURCE-SERVICE") domain1Field = libgmsec_python.StringField("DOMAIN1", "MY-DOMAIN-1") domain2Field = libgmsec_python.StringField("DOMAIN2", "MY-DOMAIN-2") msgID = libgmsec_python.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 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. libgmsec_python.logInfo( "Starting the Resource Message service, a message will be published every " + str(RSRC_PUBLISH_RATE) + " seconds") connManager.startResourceMessageService(RSRC_MESSAGE_SUBJECT, RSRC_PUBLISH_RATE) # Wait for user input to end the program libgmsec_python.logInfo( "Publishing C2CX Resource Messages indefinitely, press <enter> to exit the program" ) raw_input("") # Stop the Heartbeat Service connManager.stopResourceMessageService() # Cleanup connManager.cleanup() except libgmsec_python.Exception as e: libgmsec_python.logError(e.what()) return -1 return 0
def main(): if (len(sys.argv) <= 1): print("Usage: " + sys.argv[0] + " mw-id=<middleware ID>") return -1 # Setup configuration with the supplied command line arguments config = libgmsec_python.Config() for arg in sys.argv[1:]: value = arg.split('=') config.addValue(value[0], value[1]) # Unless otherwise configured, setup configuration that allows us to # log messages to stderr. initializeLogging(config) # Display the version number of the GMSEC API libgmsec_python.logInfo(libgmsec_python.ConnectionManager.getAPIVersion()) # Obtain the specification version that we are running with; if not provided, default to GMSEC_ISD_CURRENT specVersion = config.getIntegerValue("gmsec-specification-version", libgmsec_python.GMSEC_ISD_CURRENT) # Define standard fields that will be included with the heartbeat messages standardFields = libgmsec_python.FieldList() component = libgmsec_python.StringField("COMPONENT", "HEARTBEAT-GENERATOR") mission = libgmsec_python.StringField("MISSION-ID", "MY-MISSION") satellite = libgmsec_python.StringField("SAT-ID-PHYSICAL", "MY-SAT-ID") facility = libgmsec_python.StringField("FACILITY", "MY-FACILITY") standardFields.push_back(component) standardFields.push_back(mission) standardFields.push_back(satellite) standardFields.push_back(facility) if specVersion == libgmsec_python.GMSEC_ISD_2014_00: msgID = libgmsec_python.StringField("MSG-ID", "MY-MSG-ID") standardFields.push_back(msgID) elif specVersion >= libgmsec_python.GMSEC_ISD_2018_00: domain1 = libgmsec_python.StringField("DOMAIN1", "MY-DOMAIN-1") domain2 = libgmsec_python.StringField("DOMAIN2", "MY-DOMAIN-2") standardFields.push_back(domain1) standardFields.push_back(domain2) try: # Instantiate the heartbeat generator hbgen = libgmsec_python.HeartbeatGenerator(config, HB_MESSAGE_SUBJECT, HB_PUBLISH_RATE, standardFields) # Start the heartbeat generator hbgen.start() libgmsec_python.logInfo( "Heartbeat Generator is running; use gmsub or other utility to monitor messages." ) # Wait for input from user to stop the heartbeat generator libgmsec_python.logInfo( "Press <enter> to stop the heartbeat generator") raw_input("") # Stop the heartbeat generator hbgen.stop() libgmsec_python.logInfo("Heartbeat Generator has been stopped.") 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