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)) 
Ejemplo n.º 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())
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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_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
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_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