API for linking to the Huxley National Rail REST proxy for the retrieval of live National Rail data. Still needs work (sadly), but works well for the time being!

Dependencies:   EthernetInterface

National Rail Huxley Integration Interface

This API provides a clear link between the National Rail Huxley Integration JSON interface (available at https://huxley.unop.uk/), and mbed devices, over an Ethernet connection. This project is still very much a work-in-progress, but hopefully I will be able to provide a comprehensive method of retrieving live National Rail departures data in a simple and effective way.

/media/uploads/Leigh_LbR/nre_powered_logo.jpg

Committer:
Leigh_LbR
Date:
Thu Apr 21 12:02:57 2016 +0000
Revision:
0:bf04f62339a4
Child:
3:a287e75a2121
Created the Huxley Integration API. This links up to an implementation of the Huxley National Rail REST proxy to create an easy way to generate real-time departures/arrivals info easily on an mbed device.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Leigh_LbR 0:bf04f62339a4 1 #include "arrival_board.h"
Leigh_LbR 0:bf04f62339a4 2 #include "MbedJSONValue.h"
Leigh_LbR 0:bf04f62339a4 3
Leigh_LbR 0:bf04f62339a4 4 using std::string;
Leigh_LbR 0:bf04f62339a4 5
Leigh_LbR 0:bf04f62339a4 6 Arrival_Board::Arrival_Board(Arrival* _arrivals)
Leigh_LbR 0:bf04f62339a4 7 {
Leigh_LbR 0:bf04f62339a4 8 arrivals = _arrivals;
Leigh_LbR 0:bf04f62339a4 9 }
Leigh_LbR 0:bf04f62339a4 10
Leigh_LbR 0:bf04f62339a4 11 Arrival_Board::~Arrival_Board()
Leigh_LbR 0:bf04f62339a4 12 {
Leigh_LbR 0:bf04f62339a4 13 delete arrivals;
Leigh_LbR 0:bf04f62339a4 14 delete messages;
Leigh_LbR 0:bf04f62339a4 15 }
Leigh_LbR 0:bf04f62339a4 16
Leigh_LbR 0:bf04f62339a4 17 Arrival_Board arrBoardFromJson(const string& jsonObject)
Leigh_LbR 0:bf04f62339a4 18 {
Leigh_LbR 0:bf04f62339a4 19 Arrival_Board board;
Leigh_LbR 0:bf04f62339a4 20
Leigh_LbR 0:bf04f62339a4 21 MbedJSONValue json (jsonObject);
Leigh_LbR 0:bf04f62339a4 22
Leigh_LbR 0:bf04f62339a4 23 MbedJSONValue trainServices = json["trainServices"].get<MbedJSONValue>();
Leigh_LbR 0:bf04f62339a4 24 MbedJSONValue messages = json["nrccMessages"].get<MbedJSONValue>();
Leigh_LbR 0:bf04f62339a4 25
Leigh_LbR 0:bf04f62339a4 26 board.arrivals = new Arrival[trainServices.size()];
Leigh_LbR 0:bf04f62339a4 27 board.num_arrivals = trainServices.size();
Leigh_LbR 0:bf04f62339a4 28
Leigh_LbR 0:bf04f62339a4 29 board.messages = new string[messages.size()];
Leigh_LbR 0:bf04f62339a4 30 board.num_messages = messages.size();
Leigh_LbR 0:bf04f62339a4 31
Leigh_LbR 0:bf04f62339a4 32 for(int i = 0; i < trainServices.size(); ++i) {
Leigh_LbR 0:bf04f62339a4 33 Arrival a;
Leigh_LbR 0:bf04f62339a4 34
Leigh_LbR 0:bf04f62339a4 35 a.crs = trainServices[i]["origin"]["crs"].get<string>();
Leigh_LbR 0:bf04f62339a4 36 a.locationName = trainServices[i]["origin"]["locationName"].get<string>();
Leigh_LbR 0:bf04f62339a4 37 a.sta = trainServices[i]["sta"].get<string>();
Leigh_LbR 0:bf04f62339a4 38 a.eta = trainServices[i]["eta"].get<string>();
Leigh_LbR 0:bf04f62339a4 39 a.platform = trainServices[i]["platform"].get<string>();
Leigh_LbR 0:bf04f62339a4 40 a.operatorName = trainServices[i]["operator"].get<string>();
Leigh_LbR 0:bf04f62339a4 41 a.operatorCode = trainServices[i]["operatorCode"].get<string>();
Leigh_LbR 0:bf04f62339a4 42
Leigh_LbR 0:bf04f62339a4 43 board.arrivals[i] = a;
Leigh_LbR 0:bf04f62339a4 44 }
Leigh_LbR 0:bf04f62339a4 45
Leigh_LbR 0:bf04f62339a4 46 for(int i = 0; i < messages.size(); ++i) {
Leigh_LbR 0:bf04f62339a4 47 board.messages[i] = messages[i]["value"].get<string>();
Leigh_LbR 0:bf04f62339a4 48 }
Leigh_LbR 0:bf04f62339a4 49
Leigh_LbR 0:bf04f62339a4 50 return board;
Leigh_LbR 0:bf04f62339a4 51 }