-
Notifications
You must be signed in to change notification settings - Fork 1
WebSocket API
In order to read a vehicle, you use read, specifying the vehicle model and its id. The reponse stores the requested vehicle in the value field, here is how to read the vehicle from a socket
var vehicle;
socket.onmessage = function(msg){
var resp = msg.data;
vehicle = resp.model.value;
};
var msg = {
"read":{
"model":"Vehicle",
"id":4
}
};
socket.send(Json.stringify(msg));
For the request, you specify the Vehicle type and provide the id of the desired Vehicle
{
"read": {
"model":"Vehicle",
"id":4,
}
}
The response has a model object that contains the vehicle as the value
{
"model":{
"model":"Vehicle",
"value":{
"id":4,
"longitude":2,
"latitude":7,
"capacity":6
}
}
}
A new vehicle requires a latitude, longitude, capacity, and clusterId
{
"create":{
"model":"Vehicle",
"value":{
"latitude":0.123,
"longitude":0.456,
"capacity":4,
"clusterId":3
}
}
}
The response is an object with created which has the vehicle as the value
{
"created":{
"model":"Vehicle",
"value":{
"id":20,
"latitude":0.123,
"longitude":0.456,
"capacitor":4
}
}
}
An update is similar to a create except you need so specify the id of the row that you are updating, for an update, no fields are required for a vehicle.
{
"update":{
"model":"Vehicle",
"id":6,
"value":{
"latitude":1.2,
"longitude":66
}
}
}
{
"updated":{
"model":"Vehicle",
"value":{
"id":6,
"latitude":0.123,
"longitude":0.456,
"capacitor":4
}
}
}
{
"delete":{
"model":"Vehicle",
"id":4
}
}
{
"deleted":{
"model":"Vehicle",
"value":{
"id":4,
"latitude":40,
"longitude":30,
"capacity": 10
}
}
}
Reading Commodities is similar to reading vehicles, you just use Commodity instead of Vehicle for the type field
{
"read": {
"model":"Commodity",
"id":4
}
}
The response has a model object that contains the commodity
{
"model":{
"model":"Commodity",
"value":{
"id":4,
"longitude":2,
"latitude":7,
"capacity":6
}
}
}
A new commodity requires a startLatitude, startLongitude, endLatitude, endLongitude, a param, and a clusterId
{
"create":{
"model":"Commodity",
"value":{
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":0.789,
"endLongitude":0.101
"param":4,
"clusterId":5
}
}
}
The response is an object with created which has the Commodity
{
"created":{
"model":"Commodity",
"value":{
"id":20,
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":0.789,
"endLongitude":0.101
"param":4
}
}
}
An update is similar to a create except you need so specify the id of the row that you are updating, for an update, no fields are required for a commodity.
{
"update":{
"model":"Commodity",
"id":6,
"value":{
"endLatitude":1.2,
"endLongitude":66
}
}
}
{
"updated":{
"model":"Vehicle",
"value":{
"id":6
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":1.2,
"endLongitude":66
"param":4
}
}
}
Like a vehicle, you delete the commodity by specifying its id
{
"delete":{
"model":"Commodity",
"id":4
}
}
{
"deleted":{
"model":"Commodity",
"value":{
"id":6,
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":1.2,
"endLongitude":66,
"param":4
}
}
}
Clusters can read, created and deleted
{
"read":{
"model":"Cluster",
"id":8
}
}
{
"model":{
"model":"Cluster",
"value":{
"id": 10,
"parent":8,
"vehicles":[
{ "id": 1, "latitude":19, "longitude":77, "capacity":3 },
{ "id": 2, "latitude":10, "longitude":22, "capacity":4 },
{ "id": 3, "latitude":21, "longitude":31, "capacity":2 }
],
"commodities":[
{ "id":6, "param":4,
"startLatitude":0.123, "startLongitude":0.456,
"endLatitude":1.2, "endLongitude":66 },
{ "id":8, "param":3,
"startLatitude":923, "startLongitude":5.756,
"endLatitude":77, "endLongitude":606 }
]
}
}
}
clusters can be created from an empty object
{
"create": {
"model":"Cluster",
"value":{ }
}
}
{
"created": {
"model":"Cluster"
"value":{
"id":10,
"commodities":[],
"vehicles":[]
}
}
}
Deleting a cluster is similar to deleting a commodity or a vehicle
{
"delete":{
"model":"Cluster",
"id":10
}
}
{
"deleted":{
"model":"Cluster",
"value":{
"id": 10,
"parent":8,
"vehicles":[
{ "id": 1, "latitude":19, "longitude":77, "capacity":3 },
{ "id": 2, "latitude":10, "longitude":22, "capacity":4 },
{ "id": 3, "latitude":21, "longitude":31, "capacity":2 }
],
"commodities":[
{ "id":6, "param":4,
"startLatitude":0.123, "startLongitude":0.456,
"endLatitude":1.2, "endLongitude":66 },
{ "id":8, "param":3,
"startLatitude":923, "startLongitude":5.756,
"endLatitude":77, "endLongitude":606 }
]
}
}
}
The user can obtain a route for any vehicle or commodity
The route request requires the vehicle id
{
"route":{
"model":"Vehicle"
"id":78
}
}
The route contains an array of actions which each have a position and a commodity id
{
"routed":{
"model":"Vehicle"
"value":{
"Vehicle":{"id":78, "latitude":100, "longitude":-150, "capacity":3},
"actions":[
{ "action":"start","latitude":100,"longitude":-150 },
{ "action":"pickup","latitude":20,"longitude":5,
"commodity":{ "id":20, "startLatitude":20, "startLongitude":5, "endLatitude":5, "endLongitude":12, "param":3},
{ "action":"pickup","latitude":12,"longitude":20,"commodity":{ "id":21, \\ other commodity fields } },
{ "action":"dropoff","latitude":2,"longitude":30,"commodityId":{ "id":21, \\ other commodity fields } },
{ "action":"dropoff","latitude":5,"longitude":12,"commodityId":{ "id":20, \\ other commodity fields } }
]
}
}
}