Example #1
0
def main():
    # print eCAL version and date
    print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate()))

    # initialize eCAL API
    ecal_core.initialize(sys.argv, "py_minimal_snd")

    # set process state
    ecal_core.set_process_state(1, 1, "I feel good")

    # create publisher
    pub = StringPublisher("Hello")
    msg = "HELLO WORLD FROM PYTHON"

    # send messages
    i = 0
    while ecal_core.ok():
        i = i + 1
        current_message = "{} {:6d}".format(msg, i)
        print("Sending: {}".format(current_message))
        pub.send(current_message)
        time.sleep(0.01)

    # finalize eCAL API
    ecal_core.finalize()
Example #2
0
def main():
    # print eCAL version and date
    print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate()))

    # initialize eCAL API
    ecal_core.initialize(sys.argv, "py_person_rec")

    # set process state
    ecal_core.set_process_state(1, 1, "I feel good")

    # create publisher
    sub = ProtoSubscriber("person", person_pb2.Person)

    # receive messages
    while ecal_core.ok():
        ret, person, time = sub.receive(500)

        # deserialize person from message buffer
        if ret > 0:
            # print person content
            print("")
            print("Received person ..")
            print("person id    : {}".format(person.id))
            print("person name  : {}".format(person.name))
            print("person stype : {}".format(person.stype))
            print("person email : {}".format(person.email))
            print("dog.name     : {}".format(person.dog.name))
            print("house.rooms  : {}".format(person.house.rooms))

    # finalize eCAL API
    ecal_core.finalize()
Example #3
0
def do_run():

  # initialize eCAL API
  ecal_core.initialize(sys.argv, "py_latency_rec_cb")

  # create publisher/subscriber
  pub = ecal_core.publisher('pkg_reply')
  sub = ecal_core.subscriber('pkg_send')

  # prepare globals
  global msg_num, msg_size, diff_array
  diff_array = []
  msg_num    = 0
  msg_size   = 0

  # define message callback
  def callback(topic_name, msg, snt_time):
    global msg_num, msg_size, diff_array
    diff_array.append(ecal_core.getmicroseconds()[1] - snt_time)
    msg_num += 1
    msg_size = len(msg)
    # reply
    pub.send(msg)

  # apply message callback to subscriber
  sub.set_callback(callback)

  # idle until no more messages are received
  msg_last = 0
  while ecal_core.ok():
    if msg_num > 0 and msg_last == msg_num: break
    else: msg_last = msg_num
    time.sleep(1)

  sum_time = sum(diff_array)
  avg_time = sum_time / len(diff_array)

  print("")
  print("-------------------------------")
  print(" LATENCY / THROUGHPUT TEST")
  print("-------------------------------")
  print("Received buffer size             : {:.0f} kB".format(msg_size / 1024))
  print("Received messages                : {:d}".format(msg_num))
  print("Message average receive time     : {:.0f} us".format(int(avg_time)))
  print("Throughput                       : {:.2f} kB/s".format(((msg_size * msg_num) / 1024) / (sum_time / 1000000.0)))
  print("Throughput                       : {:.2f} MB/s".format(((msg_size * msg_num) / (1024 * 1024)) / (sum_time / 1000000.0)))
  print("Throughput                       : {:.2f} msg/s".format(msg_num / (sum_time / 1000000.0)))
  sys.stdout.flush()
  time.sleep(5)

  ecal_core.finalize()
Example #4
0
def do_run():

    # initialize eCAL API
    ecal_core.initialize(sys.argv, "py_latency_rec")

    # create publisher/subscriber
    pub = ecal_core.publisher('pkg_reply')
    sub = ecal_core.subscriber('pkg_send')

    # prepare timestamp list
    diff_array = []

    # loop over number of runs
    rec_timeout = -1
    msg_num = 0
    while True:
        # receive
        ret, msg, snt_time = sub.receive(rec_timeout)

        if ret > 0:
            diff_array.append(ecal_core.getmicroseconds()[1] - snt_time)
            msg_num += 1
            # reply
            pub.send(msg)
            # reduce timeout
            rec_timeout = 1000
            msg_size = len(msg)
        else:
            break

    sum_time = sum(diff_array)
    avg_time = sum_time / len(diff_array)

    print("")
    print("-------------------------------")
    print(" LATENCY / THROUGHPUT TEST")
    print("-------------------------------")
    print("Received buffer size             : {:.0f} kB".format(msg_size /
                                                                1024))
    print("Received messages                : {:d}".format(msg_num))
    print("Message average receive time     : {:.0f} us".format(int(avg_time)))
    print("Throughput                       : {:.2f} kB/s".format(
        ((msg_size * msg_num) / 1024) / (sum_time / 1000000.0)))
    print("Throughput                       : {:.2f} MB/s".format(
        ((msg_size * msg_num) / (1024 * 1024)) / (sum_time / 1000000.0)))
    print("Throughput                       : {:.2f} msg/s".format(
        msg_num / (sum_time / 1000000.0)))
    sys.stdout.flush()

    ecal_core.finalize()
Example #5
0
def main():
    # print eCAL version and date
    print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate()))

    # initialize eCAL API
    ecal_core.initialize(sys.argv, "py_minimal_rec_cb")

    # set process state
    ecal_core.set_process_state(1, 1, "I feel good")

    # create subscriber and connect callback
    sub = StringSubscriber("Hello")
    sub.set_callback(callback)

    # idle main thread
    while ecal_core.ok():
        time.sleep(0.1)

    # finalize eCAL API
    ecal_core.finalize()
Example #6
0
def main():
    # print eCAL version and date
    print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate()))

    # initialize eCAL API
    ecal_core.initialize(sys.argv, "py_person_rec_json")

    # set process state
    ecal_core.set_process_state(1, 1, "I feel good")

    # create publisher
    sub = ecal_core.subscriberDynJSON("person")
    sub.set_callback(callback)

    # receive messages
    while ecal_core.ok():
        time.sleep(0.1)

    # finalize eCAL API
    ecal_core.finalize()
Example #7
0
def main():
    # print eCAL version and date
    print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate()))

    # initialize eCAL API
    ecal_core.initialize(sys.argv, "monitoring")

    # initialize eCAL monitoring API
    ecal_core.mon_initialize()
    time.sleep(2)

    # print eCAL entities
    while ecal_core.ok():
        pprint.pprint(ecal_core.mon_monitoring())
        time.sleep(5.0)

    # finalize eCAL monitoring API
    ecal_core.mon_finalize()

    # finalize eCAL API
    ecal_core.finalize()
Example #8
0
def main():
    # print eCAL version and date
    print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate()))

    # initialize eCAL API
    ecal_core.initialize(sys.argv, "py_minimal_rec")

    # set process state
    ecal_core.set_process_state(1, 1, "I feel good")

    # create subscriber
    sub = StringSubscriber("Hello")

    # receive messages
    while ecal_core.ok():
        ret, msg, time = sub.receive(500)
        if ret > 0:
            print("Received:  {} ms   {}".format(time, msg))
        else:
            print("Subscriber timeout ..")

    # finalize eCAL API
    ecal_core.finalize()
Example #9
0
def main():
  # print eCAL version and date
  print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate()))
  
  # initialize eCAL API
  ecal_core.initialize(sys.argv, "py_person_snd")
  
  # set process state
  ecal_core.set_process_state(1, 1, "I feel good")

  # create publisher
  pub = ProtoPublisher("person", person_pb2.Person)
  
  # create person instance and set content
  person = person_pb2.Person()
  person.name        = "Max"
  person.stype       = person_pb2.Person.MALE
  person.email       = "*****@*****.**"
  person.dog.name    = "Brandy"
  person.house.rooms = 4
  
  # send messages
  while ecal_core.ok():
  
    # change person id
    person.id = person.id + 1
  
    # send person
    print("Sending person {}".format(person.id))
    pub.send(person)
  
    # sleep 100 ms
    time.sleep(0.1)
  
  # finalize eCAL API
  ecal_core.finalize()
Example #10
0
        super(StringPublisher, self).__init__(name, topic_type, topic_desc)

    def send(self, msg, time=-1):
        self.c_publisher.send(msg.encode(), time)


if __name__ == '__main__':
    """Test the publisher API
  """

    import time

    # initialize eCAL API
    ecal_core.initialize([], "publisher demo")

    # create publisher
    pub = StringPublisher("Hello")
    msg = "HELLO WORLD FROM PYTHON"

    # send messages
    i = 0
    while ecal_core.ok() and i < 1000:
        i = i + 1
        current_message = "{} {:6d}".format(msg, i)
        print("Sending: {}".format(current_message))
        pub.send(current_message)
        time.sleep(0.1)

    # finalize eCAL API
    ecal_core.finalize()
Example #11
0
def main():
  # print eCAL version and date
  print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate()))
  
  # initialize eCAL API
  ecal_core.initialize(sys.argv, "py_minimal_service")
  
  # set process state
  ecal_core.set_process_state(1, 1, "I feel good")

  # create server "Ping"
  server = ecal_service.Server("DemoServer")

  # define the server method "foo" function
  def foo_req_callback(method_name, req_type, resp_type, request):
    print("'DemoService' method '{}' called with {}".format(method_name, request))
    return 0, bytes("thank you for calling foo :-)", "ascii")

  # define the server method "ping" function
  def ping_req_callback(method_name, req_type, resp_type, request):
    print("'DemoService' method '{}' called with {}".format(method_name, request))
    return 0, bytes("pong", "ascii")

  # define the server methods and connect them to the callbacks
  server.add_method_callback("foo",  "string",    "string",    foo_req_callback)
  server.add_method_callback("ping", "ping_type", "pong_type", ping_req_callback)

  # create a client for the "DemoServer" service
  client = ecal_service.Client("DemoServer")

  # define the client response callback to catch server responses
  def client_resp_callback(service_info, response):
    if (service_info["call_state"] == "call_state_executed"):
      print("'DemoService' method '{}' responded : '{}'".format(service_info["method_name"], response))
      print()
    else:
      print("server {} response failed, error : '{}'".format(service_info["host_name"], service_info["error_msg"]))
      print()

  # and add it to the client
  client.add_response_callback(client_resp_callback)

  # match all
  time.sleep(2.0)
  
  # call foo method
  i = 0
  while ecal_core.ok() and i < 20:
    i = i + 1
    request = bytes("hello foo {}".format(i), "ascii")
    print("'DemoService' method 'foo' requested with : {}".format(request))
    client.call_method("foo", request)
    time.sleep(1.0)

  # call ping method
  i = 0
  while ecal_core.ok() and i < 20:
    i = i + 1
    request = bytes("ping number {}".format(i), "ascii")
    print("'DemoService' method 'ping' requested with : {}".format(request))
    client.call_method("ping", request)
    time.sleep(1.0)

  # destroy client and server
  client.destroy()
  server.destroy()
  
  # finalize eCAL API
  ecal_core.finalize()