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.
Diff: departure_board.cpp
- Revision:
- 0:bf04f62339a4
- Child:
- 4:7e8a23454d85
diff -r 000000000000 -r bf04f62339a4 departure_board.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/departure_board.cpp Thu Apr 21 12:02:57 2016 +0000 @@ -0,0 +1,51 @@ +#include "departure_board.h" +#include "MbedJSONValue.h" + +using std::string; + +Departure_Board::Departure_Board(Departure* _departures) +{ + departures = _departures; +} + +Departure_Board::~Departure_Board() +{ + delete departures; + delete messages; +} + +Departure_Board depBoardFromJson(const string& jsonObject) +{ + Departure_Board board; + + MbedJSONValue json (jsonObject); + + MbedJSONValue trainServices = json["trainServices"].get<MbedJSONValue>(); + MbedJSONValue messages = json["nrccMessages"].get<MbedJSONValue>(); + + board.departures = new Departure[trainServices.size()]; + board.num_departures = trainServices.size(); + + board.messages = new string[messages.size()]; + board.num_messages = messages.size(); + + for(int i = 0; i < trainServices.size(); ++i) { + Departure d; + + d.crs = trainServices[i]["destination"]["crs"].get<string>(); + d.locationName = trainServices[i]["destination"]["locationName"].get<string>(); + d.std = trainServices[i]["std"].get<string>(); + d.etd = trainServices[i]["etd"].get<string>(); + d.platform = trainServices[i]["platform"].get<string>(); + d.operatorName = trainServices[i]["operator"].get<string>(); + d.operatorCode = trainServices[i]["operatorCode"].get<string>(); + + board.departures[i] = d; + } + + for(int i = 0; i < messages.size(); ++i) { + board.messages[i] = messages[i]["value"].get<string>(); + } + + return board; +} \ No newline at end of file