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)) 
Example #2
0
def publishTestMessage(connMgr, subject):

    i = 123

    # Create a Message object
    message = libgmsec_python.Message(subject, libgmsec_python.Message.PUBLISH)

    # Add fields to the Message
    message.addField("F", False)
    message.addField(libgmsec_python.I32Field("I", i))
    message.addField(libgmsec_python.U16Field("K", i))
    message.addField("S", "This is a test")
    message.addField(libgmsec_python.F32Field("D", 1 + 1. / i))
    message.addField(libgmsec_python.BinaryField("X", "JLMNOPQ", 7))

    # Publish Message
    connMgr.publish(message)

    # Output the Message's XML string representation by invoking Log macro
    libgmsec_python.logInfo("Sent:\n" + message.toXML())
Example #3
0
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))
Example #4
0
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))
Example #5
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_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(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