-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpy_cgr_client.py
61 lines (51 loc) · 1.72 KB
/
py_cgr_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from py_cgr.py_cgr_lib.py_cgr_lib import *
import zmq
import time
import sys
import random
import json
import re
import getopt
argumentList = sys.argv[1:]
# Options
options = "hc"
try:
# Parsing argument
arguments, values = getopt.getopt(argumentList, options)
# checking each argument
for currentArgument, currentValue in arguments:
if currentArgument in ("-h"):
print ("Use the option -m to specify the contact plan file location ")
sys.exit(0)
elif currentArgument in ("-c"):
print ("Contact plan file :", sys.argv[2])
except getopt.error as err:
# output error, and return with an error code
print (str(err))
port = "4555"
context = zmq.Context()
socket = context.socket(zmq.PAIR)
socket.bind("tcp://127.0.0.1:%s" % port) #localhost caused error
contact_plan = cp_load(sys.argv[2], 5000)
#contact_plan = cp_load('module/scheduler/src/contactPlan.json', 5000)
curr_time = 0
while True:
msg = socket.recv()
# msg = "1|4|0"
print("message received by server")
splitMessage = re.findall('[0-9]+', msg.decode('utf-8'))
# splitMessage = re.findall('[0-9]+', msg)
splitMessage = list(filter(None, splitMessage))
sourceId = int(splitMessage[0])
destinationId = int(splitMessage[1])
startTime = int(splitMessage[2])
root_contact = Contact(sourceId, sourceId, 0, sys.maxsize, 100, 1, 0)
root_contact.arrival_time = startTime
route = cgr_dijkstra(root_contact, destinationId, contact_plan)
print("***Here's the route")
print(route)
print("***Sending next hop: " + str(route.next_node))
socket.send_string(str(route.next_node))
# print("***Sending next hop: 100")
# socket.send_string(str(100))
time.sleep(1)