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 binascii import unhexlify
14
15
16def send(msg, ip_send, port_send):
17 sk_send = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
18 sk_send.sendto(msg, (ip_send, port_send))
19 # print("Sent: ", msg)
20 sk_send.close()
21
22def listen(ip_listen, port_listen):
23 listen_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
24 listen_socket.bind((ip_listen, port_listen))
25
26 return listen_socket
27
28
29def main():
30 # declarations
31 print('Starting intersect.')
32 ip_listen = '127.0.0.1'
33 ip_send = '192.168.0.146'
34 port_listen = 1516 # listen to Immediate Forward Plugin
35 port_send = 5398 # send to CARMA listening_port
36
37 sk_listen = listen(ip_listen, port_listen)
38
39 print("Waiting to receive data\n")
40 while(1):
41 data = sk_listen.recvfrom(10000)[0]
42 data = data.decode('ascii')
43 # print(data)
44
45 idx = data.find("Payload=")
46 payload = data[idx+8:-1]
47 encoded = payload.encode('utf-8')
48 msgBytes = unhexlify(encoded)
49
50 # send
51 send(msgBytes, ip_send, port_send)
52
53if __name__=="__main__":
54 main()
def listen(ip_listen, port_listen)
Definition: msgIntersect.py:22
def send(msg, ip_send, port_send)
Definition: msgIntersect.py:16