Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
msgIntersect.py
Go to the documentation of this file.
5
6# The script can be run on either PC running V2X Hub or CARMA Messenger. The following configurations must be made:
7# ip_listen, port_listen: IPv4 Address and Port where messages will be received. Must match IP:Port set in Immediate Forward Plugin.
8# ip_send, port_send: IPv4 Address and Port where payload will be sent. Must match IP, Port set in carma-cohda-dsrc-driver dsrc_driver/config/params.yaml.
9# This script assumes both V2X Hub and CARMA Messenger are running on either the same PC or two separate PCs within the same local network.
10
11
12import socket
13from time import sleep
14from binascii import unhexlify
15
16
17def send(msg, ip_send, port_send):
18 sk_send = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
19 sk_send.sendto(msg, (ip_send, port_send))
20 # print("Sent: ", msg)
21 sk_send.close()
22
23def listen(ip_listen, port_listen):
24 listen_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
25 listen_socket.bind((ip_listen, port_listen))
26
27 return listen_socket
28
29
30def main():
31 # declarations
32 print('Starting intersect.')
33 ip_listen = '127.0.0.1'
34 ip_send = '192.168.0.146'
35 port_listen = 1516 # listen to Immediate Forward Plugin
36 port_send = 5398 # send to CARMA listening_port
37
38 sk_listen = listen(ip_listen, port_listen)
39
40 print("Waiting to receive data\n")
41 while(1):
42 data = sk_listen.recvfrom(10000)[0]
43 data = data.decode('ascii')
44 # print(data)
45
46 idx = data.find("Payload=")
47 payload = data[idx+8:-1]
48 encoded = payload.encode('utf-8')
49 msgBytes = unhexlify(encoded)
50
51 # send
52 send(msgBytes, ip_send, port_send)
53 sleep(0.1)
54
55if __name__=="__main__":
56 main()
def listen(ip_listen, port_listen)
Definition: msgIntersect.py:23
def send(msg, ip_send, port_send)
Definition: msgIntersect.py:17