Ejemplo n.º 1
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",
                                                      "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
Ejemplo n.º 2
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
    config = libgmsec_python3.Config()

    for arg in sys.argv[1:]:
        value = arg.split('=')
        config.add_value(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.add_value("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.add_value("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.add_value("GMSEC-SCHEMA-PATH", "templates")

    # Since this example relies on the 2016.00 version of the templates,
    # we indicate such within the configuration object.
    config.add_value("GMSEC-SPECIFICATION-VERSION", "201600")

    libgmsec_python3.log_info(
        libgmsec_python3.ConnectionManager.get_API_version())

    try:
        connMgr = libgmsec_python3.ConnectionManager(config)

        libgmsec_python3.log_info(
            "Opening the connection to the middleware server")
        connMgr.initialize()

        libgmsec_python3.log_info(connMgr.get_library_version())

        definedFields = libgmsec_python3.FieldList()

        missionField = libgmsec_python3.StringField("MISSION-ID", "MISSION")
        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)

        connMgr.set_standard_fields(definedFields)

        # Create a Message using a subject defined in the XML template
        # outlining our example addendum message definitions
        message = libgmsec_python3.MistMessage(EXAMPLE_MESSAGE_SUBJECT,
                                               "MSG.LOG",
                                               connMgr.get_specification())

        # Add all of the necessary Fields to our message
        message.add_field(libgmsec_python3.U16Field("NUM-OF-EVENTS", 2))
        message.set_value("EVENT.1", addTimeToString("AOS occurred at: "))
        message.set_value("EVENT.2",
                          addTimeToString("Telemetry downlink began at: "))

        connMgr.add_standard_fields(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_python3.log_info("Published message:\n" + message.to_XML())

        # Setup a new message without some of the Required Fields and
        # attempt to publish it (i.e. Trigger a validation failure)
        badMessage = libgmsec_python3.MistMessage(EXAMPLE_MESSAGE_SUBJECT,
                                                  "MSG.LOG",
                                                  connMgr.get_specification())

        try:
            connMgr.publish(badMessage)
        except libgmsec_python3.GmsecError as e:
            libgmsec_python3.log_error("This error is expected:\n" + str(e))

        # Disconnect from the middleware and clean up the Connection
        connMgr.cleanup()

    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1

    return 0
Ejemplo n.º 3
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
Ejemplo n.º 4
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
        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",
                                                      "RESOURCE-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)

        # Create and publish a Resource message using
        # create_resource_message() 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.create_resource_message(RSRC_MESSAGE_SUBJECT)
        libgmsec_python3.log_info(
            "Publishing the GMSEC C2CX RSRC message which was created using create_resource_message():\n"
            + rsrcMsg.to_XML())
        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 start_resource_message_service() function.
        # If an interval is not provided, the service will default to
        # publishing a message every 60 seconds.
        libgmsec_python3.log_info(
            "Starting the Resource Message service, a message will be published every "
            + str(RSRC_PUBLISH_RATE) + " seconds")

        connManager.start_resource_message_service(RSRC_MESSAGE_SUBJECT,
                                                   RSRC_PUBLISH_RATE)

        # Wait for user input to end the program
        libgmsec_python3.log_info(
            "Publishing C2CX Resource Messages indefinitely, press <enter> to exit the program"
        )
        input("")

        # Stop the Heartbeat Service
        connManager.stop_resource_message_service()

        # Cleanup
        connManager.cleanup()

    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1

    return 0
Ejemplo n.º 5
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_python3.Config(sys.argv)

    # Unless otherwise configured, setup configuration that allows us to
    # log messages to stderr.
    initializeLogging(config)

    # Display the version number of the GMSEC API
    libgmsec_python3.log_info(libgmsec_python3.ConnectionManager.get_API_version())

    # Obtain the specification version that we are running with; if not provided, default to GMSEC_ISD_CURRENT
    specVersion = config.get_integer_value("gmsec-specification-version", libgmsec_python3.GMSEC_ISD_CURRENT)

    # Define standard fields that will be included with the heartbeat messages
    standardFields = libgmsec_python3.FieldList()

    component = libgmsec_python3.StringField("COMPONENT", "HEARTBEAT-GENERATOR")
    mission   = libgmsec_python3.StringField("MISSION-ID", "MY-MISSION")
    satellite = libgmsec_python3.StringField("SAT-ID-PHYSICAL", "MY-SAT-ID")
    facility  = libgmsec_python3.StringField("FACILITY", "MY-FACILITY")

    standardFields.push_back(component)
    standardFields.push_back(mission)
    standardFields.push_back(satellite)
    standardFields.push_back(facility)

    if specVersion == libgmsec_python3.GMSEC_ISD_2014_00:
        msgID = libgmsec_python3.StringField("MSG-ID", "MY-MSG-ID")
        standardFields.push_back(msgID)

    elif specVersion >= libgmsec_python3.GMSEC_ISD_2018_00:
        domain1 = libgmsec_python3.StringField("DOMAIN1", "MY-DOMAIN-1")
        domain2 = libgmsec_python3.StringField("DOMAIN2", "MY-DOMAIN-2")
        standardFields.push_back(domain1)
        standardFields.push_back(domain2)

    try:
        # Instantiate the heartbeat generator
        hbgen = libgmsec_python3.HeartbeatGenerator(config, HB_MESSAGE_SUBJECT, HB_PUBLISH_RATE, standardFields)

        # Start the heartbeat generator
        hbgen.start()
        libgmsec_python3.log_info("Heartbeat Generator is running; use gmsub or other utility to monitor messages.")

        # Wait for input from user to stop the heartbeat generator
        libgmsec_python3.log_info("Press <enter> to stop the heartbeat generator")
        input("")

        # Stop the heartbeat generator
        hbgen.stop();
        libgmsec_python3.log_info("Heartbeat Generator has been stopped.")

    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1

    return 0
Ejemplo n.º 6
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

        satIdField = libgmsec_python3.StringField("SAT-ID-PHYSICAL", "SPACECRAFT")
        facilityField = libgmsec_python3.StringField("FACILITY", "GMSEC Lab")
        componentField = libgmsec_python3.StringField("COMPONENT", "product_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)

        # Create a ProductFile object with the product name,
        # description, version, file format, and the URI
        externalFile = libgmsec_python3.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_python3.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_python3.ProductFileMessage(PROD_MESSAGE_SUBJECT, libgmsec_python3.ResponseStatus.SUCCESSFUL_COMPLETION, libgmsec_python3.Message.PUBLISH, "AUTO", "DM", connManager.get_specification())
        productMessage.add_product_file(externalFile)
        productMessage.add_product_file(binaryFile)

        connManager.add_standard_fields(productMessage)

        libgmsec_python3.log_info("Publishing DEV message:\n" + productMessage.to_XML())
        connManager.publish(productMessage)
        
    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1

    return 0
Ejemplo n.º 7
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
Ejemplo n.º 8
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