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

    i = 123

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

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

    # Publish Message
    connMgr.publish(message)

    # Output the Message's XML string representation by invoking Log macro
    libgmsec_python3.log_info("Sent:\n" + message.to_XML())
Beispiel #3
0
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))
Beispiel #4
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.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))
Beispiel #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
    # 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