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: arrival_board.cpp
- Revision:
- 0:bf04f62339a4
- Child:
- 3:a287e75a2121
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arrival_board.cpp Thu Apr 21 12:02:57 2016 +0000 @@ -0,0 +1,51 @@ +#include "arrival_board.h" +#include "MbedJSONValue.h" + +using std::string; + +Arrival_Board::Arrival_Board(Arrival* _arrivals) +{ + arrivals = _arrivals; +} + +Arrival_Board::~Arrival_Board() +{ + delete arrivals; + delete messages; +} + +Arrival_Board arrBoardFromJson(const string& jsonObject) +{ + Arrival_Board board; + + MbedJSONValue json (jsonObject); + + MbedJSONValue trainServices = json["trainServices"].get<MbedJSONValue>(); + MbedJSONValue messages = json["nrccMessages"].get<MbedJSONValue>(); + + board.arrivals = new Arrival[trainServices.size()]; + board.num_arrivals = trainServices.size(); + + board.messages = new string[messages.size()]; + board.num_messages = messages.size(); + + for(int i = 0; i < trainServices.size(); ++i) { + Arrival a; + + a.crs = trainServices[i]["origin"]["crs"].get<string>(); + a.locationName = trainServices[i]["origin"]["locationName"].get<string>(); + a.sta = trainServices[i]["sta"].get<string>(); + a.eta = trainServices[i]["eta"].get<string>(); + a.platform = trainServices[i]["platform"].get<string>(); + a.operatorName = trainServices[i]["operator"].get<string>(); + a.operatorCode = trainServices[i]["operatorCode"].get<string>(); + + board.arrivals[i] = a; + } + + for(int i = 0; i < messages.size(); ++i) { + board.messages[i] = messages[i]["value"].get<string>(); + } + + return board; +} \ No newline at end of file