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.
departure_board.cpp@0:bf04f62339a4, 2016-04-21 (annotated)
- Committer:
- Leigh_LbR
- Date:
- Thu Apr 21 12:02:57 2016 +0000
- Revision:
- 0:bf04f62339a4
- Child:
- 4:7e8a23454d85
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?
User | Revision | Line number | New contents of line |
---|---|---|---|
Leigh_LbR | 0:bf04f62339a4 | 1 | #include "departure_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 | Departure_Board::Departure_Board(Departure* _departures) |
Leigh_LbR | 0:bf04f62339a4 | 7 | { |
Leigh_LbR | 0:bf04f62339a4 | 8 | departures = _departures; |
Leigh_LbR | 0:bf04f62339a4 | 9 | } |
Leigh_LbR | 0:bf04f62339a4 | 10 | |
Leigh_LbR | 0:bf04f62339a4 | 11 | Departure_Board::~Departure_Board() |
Leigh_LbR | 0:bf04f62339a4 | 12 | { |
Leigh_LbR | 0:bf04f62339a4 | 13 | delete departures; |
Leigh_LbR | 0:bf04f62339a4 | 14 | delete messages; |
Leigh_LbR | 0:bf04f62339a4 | 15 | } |
Leigh_LbR | 0:bf04f62339a4 | 16 | |
Leigh_LbR | 0:bf04f62339a4 | 17 | Departure_Board depBoardFromJson(const string& jsonObject) |
Leigh_LbR | 0:bf04f62339a4 | 18 | { |
Leigh_LbR | 0:bf04f62339a4 | 19 | Departure_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.departures = new Departure[trainServices.size()]; |
Leigh_LbR | 0:bf04f62339a4 | 27 | board.num_departures = 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 | Departure d; |
Leigh_LbR | 0:bf04f62339a4 | 34 | |
Leigh_LbR | 0:bf04f62339a4 | 35 | d.crs = trainServices[i]["destination"]["crs"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 36 | d.locationName = trainServices[i]["destination"]["locationName"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 37 | d.std = trainServices[i]["std"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 38 | d.etd = trainServices[i]["etd"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 39 | d.platform = trainServices[i]["platform"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 40 | d.operatorName = trainServices[i]["operator"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 41 | d.operatorCode = trainServices[i]["operatorCode"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 42 | |
Leigh_LbR | 0:bf04f62339a4 | 43 | board.departures[i] = d; |
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 | } |