forked from piedras77/centralized_smart_dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.py
163 lines (121 loc) · 5.68 KB
/
routes.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from flask import render_template, json, abort, request
from model.src.centralized_dashboard.src.rover import Rover, GPSPoint
GPS_ERROR_VALUE = None
my_rover = Rover("rover1")
# Render templates
def home():
return render_template('homepage.html')
def ai_navigation():
return render_template('AINavigation.html')
def equipment_servicing():
return render_template("EquipmentServicing.html")
def erdm():
return render_template("ERDM.html")
def maintenance():
return render_template("Maintenance.html")
def cameras():
return render_template("Cameras.html")
def coming_soon():
return render_template("ComingSoon.html")
def coming_soon():
return render_template('ComingSoon.html')
# helper method for getting the route in format for
def get_format_route():
route = my_rover.route_state
route_to_send = []
for point in route:
route_to_send.append({"lat": point.lati, "long": point.longt})
return route_to_send
# API routes
def api_add_notifications():
response = json.loads(request.data.decode())
my_rover.remark = response["notifications"]
return json.jsonify({"success": True, "notifications": my_rover.remark})
#adds
def api_update_ips():
response = json.loads(request.data.decode())
my_rover.update_ips(response["ips"])
ips = my_rover.ips
return json.jsonify({"success": True, "ips": ips})
def api_get_ips():
ips = my_rover.ips
return json.jsonify({"success": True, "ips": ips})
def api_maintenance_set_wheels():
response = json.loads(request.data.decode())
new_speed = my_rover.set_new_speed(response["wheels"])
return json.jsonify({"success": True, "wheels": my_rover.speed})
def api_maintenance_set_arm():
response = json.loads(request.data.decode())
my_rover.set_new_arm(response["arm"])
return json.jsonify({"success": True, "arm": my_rover.arm})
def api_maintenance_get_arm():
return json.jsonify({"success": True, "arm": my_rover.arm})
def api_maintenance_get_wheels():
return json.jsonify({"success": True, "wheels": my_rover.speed})
# send the notification to rover
def api_send_notifications():
notifications = my_rover.remark
return json.jsonify({"success": True, "notifications": notifications})
# send rover to next waypoint
def api_go_button():
if len(my_rover.route_state) > 0:
my_rover.set_new_target(my_rover.route_state[0])
return json.jsonify({"success": True})
else:
return json.jsonify({"success": False})
# emergency stop not implemented yet
def api_emergency_stop():
my_rover.emergent_stop()
return json.jsonify({"success": True})
# returns full list of all waypoint on route
def api_get_route():
route_to_send = get_format_route()
if len(route_to_send) > 0:
return json.jsonify({"success": True, "waypoints": route_to_send})
else:
return json.jsonify({"success": False})
# sets the new route
def api_set_route():
new_route = json.loads(request.data.decode())
route_to_set = []
for point in new_route["waypoints"]:
route_to_set.append(GPSPoint(point["lat"], point["long"]))
my_rover.route_state = route_to_set
return json.jsonify({"success": True, "waypoints": get_format_route()})
# route for getting the latitude and longitude of the rover
def api_gps():
lat = my_rover.gps_lati
long = my_rover.gps_longt
# get in format specified by server
#try:
return json.jsonify({"success": True, "lat": lat, "long": long})
#except ValueError:
#else:
# return json.jsonify({"success": False})
# TODO: might be useful to add server-side error handlers
def error_handler(error):
return render_template('ComingSoon.html')
def init_website_routes(app):
if app:
app.add_url_rule('/', 'home', home, methods=['GET'])
app.add_url_rule('/home', 'home', home, methods=['GET'])
app.add_url_rule('/ai-navigation', 'ai_navigation', ai_navigation, methods=['GET'])
app.add_url_rule('/equipment-servicing', 'equipment_servicing', equipment_servicing, methods=['GET'])
app.add_url_rule('/erdm', 'erdm', erdm, methods=['GET'])
app.add_url_rule('/maintenance', 'maintenance', maintenance, methods=['GET'])
app.add_url_rule('/cameras', 'cameras', cameras, methods=['GET'])
app.add_url_rule('/coming-soon', 'coming-soon', coming_soon, methods=['GET'])
app.add_url_rule('/api/ips', 'api_update_ips', api_update_ips, methods=['POST'])
app.add_url_rule('/api/ips', 'api_get_ips', api_get_ips, methods=['GET'])
app.add_url_rule('/api/maintenance/wheels', 'api_maintenance_get_wheels', api_maintenance_get_wheels, methods=['GET'])
app.add_url_rule('/api/maintenance/arm', 'api_maintenance_get_arm', api_maintenance_get_arm, methods=['GET'])
app.add_url_rule('/api/maintenance/wheels', 'api_maintenance_set_wheels', api_maintenance_set_wheels, methods=['POST'])
app.add_url_rule('/api/maintenance/arm', 'api_maintenance_set_arm', api_maintenance_set_arm, methods=['POST'])
app.add_url_rule('/api/notifications', 'api_send_notifications', api_send_notifications, methods=['GET'])
app.add_url_rule('/api/notifications', 'api_add_notifications', api_add_notifications, methods=['POST'])
app.add_url_rule('/api/emergency-stop', 'api_emergency_stop', api_emergency_stop, methods=['GET'])
app.add_url_rule('/api/gps', 'api_gps', api_gps, methods=['GET'])
app.add_url_rule('/api/route', 'api_set_route', api_set_route, methods=['POST'])
app.add_url_rule('/api/route', 'api_get_route', api_get_route, methods=['GET'])
app.add_url_rule('/api/go-button', 'api_go_button', api_go_button, methods=['GET'])
app.register_error_handler(404, error_handler)