Esempio n. 1
0
def test_pack_unpack():
    struct = Struct()
    struct.fields["key"].number_value = 0.1212121921839893438974837
    struct.fields["value"].number_value = 90.0
    struct.fields["string"].string_value = "0.1212121921839893438974837"

    message = Message()
    message.pack(struct)
    unpacked = message.unpack(Struct)

    assert message.content_type == ContentType.PROTOBUF
    assert str(struct) == str(unpacked)
    assert struct == unpacked

    message.content_type = ContentType.JSON
    message.pack(struct)
    unpacked = message.unpack(Struct)

    assert message.content_type == ContentType.JSON
    assert str(struct) == str(unpacked)
    assert struct == unpacked

    # test pack/unpack for dict object with default serializtion as JSON
    dictionary = {"key": 0.1233444444, "hodor": "hold the door", "default": 0}
    message = Message(content=dictionary)
    assert message.content_type == ContentType.JSON
    unpacked = message.unpack()
    assert dictionary == unpacked

    # test pack/unpack for dict object with protobuf content-type
    message = Message()
    message.content_type = ContentType.PROTOBUF
    message.pack(dictionary)
    unpacked = message.unpack()
    assert dictionary == unpacked
Esempio n. 2
0
                msg.timeout = DEADLINE_SEC
                channel.publish(msg, topic='SkeletonsDetector.Detect')
                requests[msg.correlation_id] = {
                    'content': pb_image,
                    'base_name': base_name,
                    'frame_id': frame_id,
                    'requested_at': time.time()
                }
        continue

    elif state == State.RECV_REPLIES:

        try:
            msg = channel.consume(timeout=1.0)
            if msg.status.ok():
                annotations = msg.unpack(ObjectAnnotations)
                cid = msg.correlation_id
                if cid in requests:
                    base_name = requests[cid]['base_name']
                    frame_id = requests[cid]['frame_id']
                    annotations_received[base_name][frame_id] = MessageToDict(
                        annotations,
                        preserving_proto_field_name=True,
                        including_default_value_fields=True)
                    del requests[cid]

            state = State.CHECK_END_OF_VIDEO_AND_SAVE
        except socket.timeout:
            state = State.CHECK_FOR_TIMEOUTED_REQUESTS
        continue
Esempio n. 3
0
from is_wire.core import Channel, Subscription, Message, Logger
from is_wire.core.wire.status import StatusCode
from is_msgs.common_pb2 import FieldSelector
from is_msgs.camera_pb2 import CameraConfigFields, CameraConfig
from google.protobuf.json_format import Parse

uri = 'amqp://10.10.2.15:30000'
channel = Channel(uri)
subscription = Subscription(channel)
log = Logger(name='GetConfig')
camera_id = 0

get_config = FieldSelector()
get_config.fields.append(CameraConfigFields.Value('SAMPLING_SETTINGS'))
get_config.fields.append(CameraConfigFields.Value('IMAGE_SETTINGS'))

msg = Message()
msg.topic = 'CameraGateway.{}.GetConfig'.format(camera_id)
msg.reply_to = subscription
msg.pack(get_config)
channel.publish(msg)

while True:
    msg = channel.consume()
    if msg.status.code == StatusCode.OK:
        config = msg.unpack(CameraConfig)
        log.info('Configuration received from camera \'{}\'\n{}', camera_id, config)
    else:
        log.warn('Can\'t apply configuration:\n{}', msg.status)
    sys.exit(0)
Esempio n. 4
0
elif args.type == 'eight':
    task = lemniscate_of_bernoulli(shape=(args.x, args.y),
                                   center=(0, 0),
                                   lap_time=25,
                                   rate=args.rate)
else:
    task = stop()

channel = Channel(options["broker_uri"])
subscription = Subscription(channel)

prefix = "RobotController.{}".format(options["parameters"]["robot_id"])
set_task_topic = "{}.SetTask".format(prefix)
progress_topic = "{}.Progress".format(prefix)

message = Message(content=task, reply_to=subscription)
channel.publish(message, topic=set_task_topic)
reply = channel.consume(timeout=1.0)
if not reply.status.ok():
    raise Exception(reply.status.why)
print(reply.unpack(RobotTaskReply))

subscription.subscribe(progress_topic)
while True:
    try:
        message = channel.consume()
        if message.topic == progress_topic:
            print(message.unpack(RobotControllerProgress))
    except KeyboardInterrupt:
        channel.publish(Message(content=stop()), topic=set_task_topic)
        sys.exit()