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@4:7e8a23454d85, 2016-04-21 (annotated)
- Committer:
- Leigh_LbR
- Date:
- Thu Apr 21 15:02:20 2016 +0000
- Revision:
- 4:7e8a23454d85
- Parent:
- 0:bf04f62339a4
- Child:
- 6:dae1cdf19e90
Finished documentation
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 | 4:7e8a23454d85 | 6 | Departure_Board::Departure_Board(Departure* _departures, const int& _num_departures, std::string* _messages, const int& _num_messages) |
Leigh_LbR | 0:bf04f62339a4 | 7 | { |
Leigh_LbR | 0:bf04f62339a4 | 8 | departures = _departures; |
Leigh_LbR | 4:7e8a23454d85 | 9 | num_departures = _num_departures; |
Leigh_LbR | 4:7e8a23454d85 | 10 | messages = _messages; |
Leigh_LbR | 4:7e8a23454d85 | 11 | num_messages = _num_messages; |
Leigh_LbR | 0:bf04f62339a4 | 12 | } |
Leigh_LbR | 0:bf04f62339a4 | 13 | |
Leigh_LbR | 0:bf04f62339a4 | 14 | Departure_Board::~Departure_Board() |
Leigh_LbR | 0:bf04f62339a4 | 15 | { |
Leigh_LbR | 0:bf04f62339a4 | 16 | delete departures; |
Leigh_LbR | 0:bf04f62339a4 | 17 | delete messages; |
Leigh_LbR | 0:bf04f62339a4 | 18 | } |
Leigh_LbR | 0:bf04f62339a4 | 19 | |
Leigh_LbR | 0:bf04f62339a4 | 20 | Departure_Board depBoardFromJson(const string& jsonObject) |
Leigh_LbR | 0:bf04f62339a4 | 21 | { |
Leigh_LbR | 0:bf04f62339a4 | 22 | Departure_Board board; |
Leigh_LbR | 0:bf04f62339a4 | 23 | |
Leigh_LbR | 0:bf04f62339a4 | 24 | MbedJSONValue json (jsonObject); |
Leigh_LbR | 0:bf04f62339a4 | 25 | |
Leigh_LbR | 0:bf04f62339a4 | 26 | MbedJSONValue trainServices = json["trainServices"].get<MbedJSONValue>(); |
Leigh_LbR | 0:bf04f62339a4 | 27 | MbedJSONValue messages = json["nrccMessages"].get<MbedJSONValue>(); |
Leigh_LbR | 0:bf04f62339a4 | 28 | |
Leigh_LbR | 0:bf04f62339a4 | 29 | board.departures = new Departure[trainServices.size()]; |
Leigh_LbR | 0:bf04f62339a4 | 30 | board.num_departures = trainServices.size(); |
Leigh_LbR | 0:bf04f62339a4 | 31 | |
Leigh_LbR | 0:bf04f62339a4 | 32 | board.messages = new string[messages.size()]; |
Leigh_LbR | 0:bf04f62339a4 | 33 | board.num_messages = messages.size(); |
Leigh_LbR | 0:bf04f62339a4 | 34 | |
Leigh_LbR | 0:bf04f62339a4 | 35 | for(int i = 0; i < trainServices.size(); ++i) { |
Leigh_LbR | 0:bf04f62339a4 | 36 | Departure d; |
Leigh_LbR | 0:bf04f62339a4 | 37 | |
Leigh_LbR | 0:bf04f62339a4 | 38 | d.crs = trainServices[i]["destination"]["crs"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 39 | d.locationName = trainServices[i]["destination"]["locationName"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 40 | d.std = trainServices[i]["std"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 41 | d.etd = trainServices[i]["etd"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 42 | d.platform = trainServices[i]["platform"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 43 | d.operatorName = trainServices[i]["operator"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 44 | d.operatorCode = trainServices[i]["operatorCode"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 45 | |
Leigh_LbR | 0:bf04f62339a4 | 46 | board.departures[i] = d; |
Leigh_LbR | 0:bf04f62339a4 | 47 | } |
Leigh_LbR | 0:bf04f62339a4 | 48 | |
Leigh_LbR | 0:bf04f62339a4 | 49 | for(int i = 0; i < messages.size(); ++i) { |
Leigh_LbR | 0:bf04f62339a4 | 50 | board.messages[i] = messages[i]["value"].get<string>(); |
Leigh_LbR | 0:bf04f62339a4 | 51 | } |
Leigh_LbR | 0:bf04f62339a4 | 52 | |
Leigh_LbR | 0:bf04f62339a4 | 53 | return board; |
Leigh_LbR | 0:bf04f62339a4 | 54 | } |