コード例 #1
0
    def main(self):
        from lxml import etree
        while True:
            time.sleep(0.1)
            command = self.receive_command_data(self.pipe)
            if command:
                try:
                    self.m_SendConnectionHandler.Handle(self, command)
                except Exception as e:
                    pass
            else:
                pass
            try:
                data = self.receive_data_from_federate(1)
            except ssl.SSLWantReadError:
                data = None
            if data:
                for protobuf_object in data:
                    # TODO: clean all of this up as it's just a PoC

                    # event = etree.Element('event')
                    # SpecificCoTObj = XMLCoTController().categorize_type(protobuf_object.type)
                    try:
                        detail = etree.fromstring(protobuf_object.event.other)
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer(
                        ).from_format_to_fts_object(protobuf_object,
                                                    Event.FederatedCoT())
                        specific_obj = SendOther()
                        event = XmlSerializer().from_fts_object_to_format(
                            fts_obj)
                        xmlstring = event
                        xmlstring.find('detail').remove(
                            xmlstring.find('detail').find('remarks'))
                        xmlstring.find('detail').extend(
                            [child for child in detail])
                        # specific_obj.xmlString = etree.tostring(xmlstring)
                        print(etree.tostring(xmlstring))
                        specific_obj.xmlString = etree.tostring(xmlstring)
                        self.pipe.send(specific_obj)
                    except Exception as e:
                        pass
                    """if isinstance(SpecificCoTObj, SendOtherController):
                        detail = protobuf_object.event.other
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, Event.Other())
                        protobuf_object.event.other = detail
                        SpecificCoTObj.object = fts_obj
                        SpecificCoTObj.Object =
                    else:
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, SpecificCoTObj().object)
                        self.pipe.send(data)"""
            else:
                pass
コード例 #2
0
    def main(self):
        from defusedxml import ElementTree as etree
        import time
        while True:
            time.sleep(0.1)
            command = self.receive_command_data(self.pipe)
            if command:
                try:
                    self.m_SendConnectionHandler.Handle(self, command)
                except Exception as e:
                    logger.debug("exception in command chain " + str(e))
            else:
                pass

            data = self.receive_data_from_federate(1)
            if data:
                for protobuf_object in data:
                    # TODO: clean all of this up as it's just a PoC

                    try:
                        detail = etree.fromstring(protobuf_object.event.other)
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer(
                        ).from_format_to_fts_object(protobuf_object,
                                                    Event.FederatedCoT())
                        specific_obj = SendOther()
                        event = XmlSerializer().from_fts_object_to_format(
                            fts_obj)
                        xmlstring = event
                        xmlstring.find('detail').remove(
                            xmlstring.find('detail').find('remarks'))
                        xmlstring.find('detail').extend(
                            [child for child in detail])
                        # specific_obj.xmlString = etree.tostring(xmlstring)
                        print(etree.tostring(xmlstring))
                        specific_obj.xmlString = etree.tostring(xmlstring)
                        self.pipe.send(specific_obj)
                    except Exception as e:
                        pass
                    """if isinstance(SpecificCoTObj, SendOtherController):
                        detail = protobuf_object.event.other
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, Event.Other())
                        protobuf_object.event.other = detail
                        SpecificCoTObj.object = fts_obj
                        SpecificCoTObj.Object =
                    else:
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, SpecificCoTObj().object)
                        self.pipe.send(data)"""
            else:
                pass
コード例 #3
0
    def receive_data_from_federates(self):
        # returns data received from federate
        # the following logic receives data from the federate and processes the protobuf
        # up to 100 CoT's
        dataCount = 0
        dataArray = []
        # 100 is the limit of data which can be received from a federate in one iteration
        while dataCount < 100:
            dataCount += 1
            try:
                try:
                    self.connection.settimeout(0.01)
                    data = self.connection.recv(self.buffer)
                    self.connection.settimeout(0)
                except TimeoutError:
                    break

                except Exception as e:
                    self.disconnect()
                    self.killSwitch = True
                    return 0
                if data != [b'']:
                    header = data[0]
                    content = self.connection.recv(
                        self.get_header_length(header))
                    EmptyFTSObject = Event.FederatedCoT()
                    protoObject = FederatedEvent().FromString(content)
                    print(protoObject)
                    FTSObject = FederatedCoTController(
                    ).serialize_main_contentv1(protoObject, EmptyFTSObject)
                    print('received data from Federate')
                    print(content)
                else:
                    self.killSwitch = True

                dataArray.append(FTSObject)

            except Exception as e:
                pass
コード例 #4
0
                ftssetter(nestedObject)

            else:
                #get setter for associated fts object attribute
                FTSSetter = getattr(ftsobject, 'set'+field.name)

                # get the protobuf objects nested message
                protoObjectValue = getattr(protoobject, field.name)

                # call the fts setter with the object value
                FTSSetter(protoObjectValue)

        return ftsobject

if __name__ == "__main__":
    ftsobj = Event.FederatedCoT()

    msga = fig_pb2.FederatedEvent()
    geo = msga.event
    geo.sendTime = 1
    geo.startTime = 2
    geo.staleTime = 3
    geo.lat = 4
    geo.lon = 5
    geo.hae = 6
    geo.ce = 7
    geo.le = 8
    geo.uid = '9'
    geo.type = '10'
    geo.coordSource = '11'
    geo.other = '<detail/>'