Skip to content

Commit

Permalink
Update ask infrastructure to new specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas-Menzel committed Mar 21, 2023
1 parent ffcc113 commit f9800da
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 82 deletions.
21 changes: 5 additions & 16 deletions app/js/informationHolders/Corridor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,11 @@ class Corridor {
}


updateValues() {
const payload = '{"corridor_id": "' + this.#id + '","data_type": "corridor_location"}';
const handleResponse = () => {
const response = JSON.parse(xhttp.responseText);

if(response['executed']) {
this.#dataValid = true;

this.#intersectionAId = response['response_data']['intersection_a'];
this.#intersectionBId = response['response_data']['intersection_b'];
}
};
const xhttp = new XMLHttpRequest();
xhttp.onload = () => { handleResponse() };
xhttp.open('GET', trafficControlUrl + 'ask/corridor_location?payload=' + payload + '&rand=' + new Date().getTime(), true);
xhttp.send();
setValues(intersectionAId, intersectionBId) {
this.#dataValid = true;

this.#intersectionAId = intersectionAId;
this.#intersectionBId = intersectionBId;
}


Expand Down
24 changes: 7 additions & 17 deletions app/js/informationHolders/Intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,13 @@ class Intersection {
}


updateValues() {
const payload = '{"intersection_id": "' + this.#id + '","data_type": "intersection_location"}';
const handleResponse = () => {
const response = JSON.parse(xhttp.responseText);
if(response['executed']) {
this.#dataValid = true;

this.#gpsLat = response['response_data']['gps_lat'];
this.#gpsLon = response['response_data']['gps_lon'];

this.#altitude = response['response_data']['altitude'];
}
};
const xhttp = new XMLHttpRequest();
xhttp.onload = () => { handleResponse() };
xhttp.open('GET', trafficControlUrl + 'ask/intersection_location?payload=' + payload + '&rand=' + new Date().getTime(), true);
xhttp.send();
setValues(gpsLat, gpsLon, altitude) {
this.#dataValid = true;

this.#gpsLat = gpsLat;
this.#gpsLon = gpsLon;

this.#altitude = altitude;
}


Expand Down
109 changes: 60 additions & 49 deletions app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ function setAppletWrapperHeightsWithControlPanel() {


function toBoolean(stringValue) {
if(typeof(stringValue) === 'string') {
if (typeof (stringValue) === 'string') {
switch (stringValue?.toLowerCase()?.trim()) {
case "true":
case "yes":
case "1":
return true;

case "false":
case "no":
case "0":
case null:
case undefined:
return false;

default:
return JSON.parse(stringValue);
}
Expand Down Expand Up @@ -99,56 +99,67 @@ function updateDroneList() {

function updateIntersectionList() {
const payload = '{"intersection_id": "%","data_type": "intersection_list"}';
const handleResponse = () => {
const response = JSON.parse(xhttp.responseText);
if(response['executed']) {
const intersectionIds = response['response_data']['intersection_ids'];
const myIntersectionIds = Object.keys(intersections);

const intersectionsToAdd = intersectionIds.filter(x => !myIntersectionIds.includes(x));
const intersectionsToRemove = myIntersectionIds.filter(x => !intersectionIds.includes(x));

for(newInt in intersectionsToAdd) {
const newIntId = intersectionsToAdd[newInt];
intersections[newIntId] = new Intersection(newIntId);
}
for(remInt in intersectionsToRemove) {
const remIntId = intersectionsToRemove[remInt];
delete intersections[remIntId];
}
const handleResponse = () => {
const response = JSON.parse(xhttp.responseText);
if (response['executed']) {
const intersectionIds = Object.keys(response['response_data']);
const myIntersectionIds = Object.keys(intersections);

const intersectionsToAdd = intersectionIds.filter(x => !myIntersectionIds.includes(x));
const intersectionsToRemove = myIntersectionIds.filter(x => !intersectionIds.includes(x));

for (newIntId of intersectionsToAdd) {
intersections[newIntId] = new Intersection(newIntId);
}
for (remIntId of intersectionsToRemove) {
delete intersections[remIntId];
}

for (intId of intersectionIds) {
const gpsLat = response['response_data'][intId]['gps_lat'];
const gpsLon = response['response_data'][intId]['gps_lon'];
const altitude = response['response_data'][intId]['altitude'];

intersections[intId].setValues(gpsLat, gpsLon, altitude);
}
};
const xhttp = new XMLHttpRequest();
xhttp.onload = () => { handleResponse() };
xhttp.open('GET', trafficControlUrl + 'ask/intersection_list?payload=' + payload, true);
xhttp.send();
}
};
const xhttp = new XMLHttpRequest();
xhttp.onload = () => { handleResponse() };
xhttp.open('GET', trafficControlUrl + 'ask/intersection_list?payload=' + payload, true);
xhttp.send();
}

function updateCorridorList() {
const payload = '{"corridor_id": "%","data_type": "corridor_list"}';
const handleResponse = () => {
const response = JSON.parse(xhttp.responseText);
if(response['executed']) {
const corridorIds = response['response_data']['corridor_ids'];
const myCorridorIds = Object.keys(corridors);

const corridorsToAdd = corridorIds.filter(x => !myCorridorIds.includes(x));
const corridorsToRemove = myCorridorIds.filter(x => !corridorIds.includes(x));

for(newCor in corridorsToAdd) {
const newCorId = corridorsToAdd[newCor];
corridors[newCorId] = new Corridor(newCorId);
}
for(remCor in corridorsToRemove) {
const remCorId = corridorsToRemove[remCor];
delete corridors[remCorId];
}
const handleResponse = () => {
const response = JSON.parse(xhttp.responseText);
if (response['executed']) {
const corridorIds = Object.keys(response['response_data']);
const myCorridorIds = Object.keys(corridors);

const corridorsToAdd = corridorIds.filter(x => !myCorridorIds.includes(x));
const corridorsToRemove = myCorridorIds.filter(x => !corridorIds.includes(x));

for (newCorId of corridorsToAdd) {
corridors[newCorId] = new Corridor(newCorId);
}
for (remCorId of corridorsToRemove) {
delete corridors[remCorId];
}
};
const xhttp = new XMLHttpRequest();
xhttp.onload = () => { handleResponse() };
xhttp.open('GET', trafficControlUrl + 'ask/corridor_list?payload=' + payload, true);
xhttp.send();

for (corId of corridorIds) {
const intersectionAId = response['response_data'][corId]['intersection_a'];
const intersectionBId = response['response_data'][corId]['intersection_b'];

corridors[corId].setValues(intersectionAId, intersectionBId);
}
}
};
const xhttp = new XMLHttpRequest();
xhttp.onload = () => { handleResponse() };
xhttp.open('GET', trafficControlUrl + 'ask/corridor_list?payload=' + payload, true);
xhttp.send();
}


Expand All @@ -172,10 +183,10 @@ function updateInfrastructure() {
// TODO: Update infrastructure list
// TODO: Add / remove intersections / corridors

for(intersectionId in intersections) {
for (intersectionId in intersections) {
intersections[intersectionId].updateValues();
}
for(corridorId in corridors) {
for (corridorId in corridors) {
corridors[corridorId].updateValues();
}
}
Expand Down

0 comments on commit f9800da

Please sign in to comment.