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 13:32:54 2016 +0000
Revision:
3:a287e75a2121
Parent:
0:bf04f62339a4
Child:
6:dae1cdf19e90
Added more documentation

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 3:a287e75a2121 6 Arrival_Board::Arrival_Board(Arrival* _arrivals, const int& _num_arrivals, std::string* _messages, const int& _num_messages)
Leigh_LbR 0:bf04f62339a4 7 {
Leigh_LbR 0:bf04f62339a4 8 arrivals = _arrivals;
Leigh_LbR 3:a287e75a2121 9 num_arrivals = _num_arrivals;
Leigh_LbR 3:a287e75a2121 10 messages = _messages;
Leigh_LbR 3:a287e75a2121 11 num_messages = _num_messages;
Leigh_LbR 0:bf04f62339a4 12 }
Leigh_LbR 0:bf04f62339a4 13
Leigh_LbR 0:bf04f62339a4 14 Arrival_Board::~Arrival_Board()
Leigh_LbR 0:bf04f62339a4 15 {
Leigh_LbR 0:bf04f62339a4 16 delete arrivals;
Leigh_LbR 0:bf04f62339a4 17 delete messages;
Leigh_LbR 0:bf04f62339a4 18 }
Leigh_LbR 0:bf04f62339a4 19
Leigh_LbR 0:bf04f62339a4 20 Arrival_Board arrBoardFromJson(const string& jsonObject)
Leigh_LbR 0:bf04f62339a4 21 {
Leigh_LbR 0:bf04f62339a4 22 Arrival_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.arrivals = new Arrival[trainServices.size()];
Leigh_LbR 0:bf04f62339a4 30 board.num_arrivals = 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 Arrival a;
Leigh_LbR 0:bf04f62339a4 37
Leigh_LbR 0:bf04f62339a4 38 a.crs = trainServices[i]["origin"]["crs"].get<string>();
Leigh_LbR 0:bf04f62339a4 39 a.locationName = trainServices[i]["origin"]["locationName"].get<string>();
Leigh_LbR 0:bf04f62339a4 40 a.sta = trainServices[i]["sta"].get<string>();
Leigh_LbR 0:bf04f62339a4 41 a.eta = trainServices[i]["eta"].get<string>();
Leigh_LbR 0:bf04f62339a4 42 a.platform = trainServices[i]["platform"].get<string>();
Leigh_LbR 0:bf04f62339a4 43 a.operatorName = trainServices[i]["operator"].get<string>();
Leigh_LbR 0:bf04f62339a4 44 a.operatorCode = trainServices[i]["operatorCode"].get<string>();
Leigh_LbR 0:bf04f62339a4 45
Leigh_LbR 0:bf04f62339a4 46 board.arrivals[i] = a;
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 }