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:
Tue May 10 13:18:25 2016 +0000
Revision:
10:d178bc9eb95a
Parent:
8:6e063a3827c0
Added licensing information (code is distributed under the MIT license)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Leigh_LbR 0:bf04f62339a4 1 #ifndef NR_NETWORK_H
Leigh_LbR 0:bf04f62339a4 2 #define NR_NETWORK_H
Leigh_LbR 0:bf04f62339a4 3
Leigh_LbR 0:bf04f62339a4 4 #include "arrival_board.h"
Leigh_LbR 0:bf04f62339a4 5 #include "departure_board.h"
Leigh_LbR 1:1de042ff6324 6 #include "EthernetInterface.h"
Leigh_LbR 0:bf04f62339a4 7 #include <string>
Leigh_LbR 0:bf04f62339a4 8
Leigh_LbR 10:d178bc9eb95a 9 /*
Leigh_LbR 10:d178bc9eb95a 10 * This project is distributed by Leigh Brooks under the MIT license.
Leigh_LbR 10:d178bc9eb95a 11 *
Leigh_LbR 10:d178bc9eb95a 12 * MIT License
Leigh_LbR 10:d178bc9eb95a 13 *
Leigh_LbR 10:d178bc9eb95a 14 * Copyright (c) 2016 Leigh Brooks
Leigh_LbR 10:d178bc9eb95a 15 *
Leigh_LbR 10:d178bc9eb95a 16 * Permission is hereby granted, free of charge, to any person obtaining a copy
Leigh_LbR 10:d178bc9eb95a 17 * of this software and associated documentation files (the "Software"), to deal
Leigh_LbR 10:d178bc9eb95a 18 * in the Software without restriction, including without limitation the rights
Leigh_LbR 10:d178bc9eb95a 19 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Leigh_LbR 10:d178bc9eb95a 20 * copies of the Software, and to permit persons to whom the Software is
Leigh_LbR 10:d178bc9eb95a 21 * furnished to do so, subject to the following conditions:
Leigh_LbR 10:d178bc9eb95a 22 *
Leigh_LbR 10:d178bc9eb95a 23 * The above copyright notice and this permission notice shall be included in all
Leigh_LbR 10:d178bc9eb95a 24 * copies or substantial portions of the Software.
Leigh_LbR 10:d178bc9eb95a 25 *
Leigh_LbR 10:d178bc9eb95a 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Leigh_LbR 10:d178bc9eb95a 27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Leigh_LbR 10:d178bc9eb95a 28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Leigh_LbR 10:d178bc9eb95a 29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Leigh_LbR 10:d178bc9eb95a 30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Leigh_LbR 10:d178bc9eb95a 31 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Leigh_LbR 10:d178bc9eb95a 32 * SOFTWARE.
Leigh_LbR 10:d178bc9eb95a 33 */
Leigh_LbR 10:d178bc9eb95a 34
Leigh_LbR 1:1de042ff6324 35 /** NR_Network_Conn
Leigh_LbR 1:1de042ff6324 36 * Used for establishing a connection to the Huxley NR SOAP proxy and to generate departure/arrivals data
Leigh_LbR 1:1de042ff6324 37 */
Leigh_LbR 0:bf04f62339a4 38 class NR_Network_Conn
Leigh_LbR 0:bf04f62339a4 39 {
Leigh_LbR 0:bf04f62339a4 40 private:
Leigh_LbR 0:bf04f62339a4 41 void init(const char* address, const char* mask, const char* gateway);
Leigh_LbR 0:bf04f62339a4 42 EthernetInterface conn;
Leigh_LbR 0:bf04f62339a4 43 TCPSocketConnection socket;
Leigh_LbR 0:bf04f62339a4 44 char _address[17];
Leigh_LbR 0:bf04f62339a4 45 char _sub_mask[17];
Leigh_LbR 0:bf04f62339a4 46 char _gateway[17];
Leigh_LbR 0:bf04f62339a4 47
Leigh_LbR 0:bf04f62339a4 48 public:
Leigh_LbR 1:1de042ff6324 49 /** Make a connection. The empty constructor creates a connection using DHCP.
Leigh_LbR 1:1de042ff6324 50 */
Leigh_LbR 0:bf04f62339a4 51 NR_Network_Conn();
Leigh_LbR 1:1de042ff6324 52 /** Make a connection. This constructor creates a connection with the specified IP address, subnet and gateway
Leigh_LbR 1:1de042ff6324 53 * @param address the IP address of this device (in the format "192.168.1.101"
Leigh_LbR 1:1de042ff6324 54 * @param mask the subnet mask of this device (in the format "255.255.255.0"
Leigh_LbR 1:1de042ff6324 55 * @param gateway the gatway of this device (in the format "192.168.1.1"
Leigh_LbR 1:1de042ff6324 56 */
Leigh_LbR 0:bf04f62339a4 57 NR_Network_Conn(const char* address, const char* mask, const char* gateway);
Leigh_LbR 1:1de042ff6324 58 /** Get the socket (an object of type TCPSocketConnection)
Leigh_LbR 1:1de042ff6324 59 */
Leigh_LbR 0:bf04f62339a4 60 TCPSocketConnection GetSocket();
Leigh_LbR 2:071bf3c7f2a2 61 /** Get the IP address of the current connection
Leigh_LbR 2:071bf3c7f2a2 62 */
Leigh_LbR 0:bf04f62339a4 63 char* GetIP();
Leigh_LbR 2:071bf3c7f2a2 64 /** Establish a connection to the API
Leigh_LbR 2:071bf3c7f2a2 65 */
Leigh_LbR 8:6e063a3827c0 66 int Connect(const char* url);
Leigh_LbR 2:071bf3c7f2a2 67 /** Disconnect from the API
Leigh_LbR 2:071bf3c7f2a2 68 */
Leigh_LbR 0:bf04f62339a4 69 void Disconnect();
Leigh_LbR 4:7e8a23454d85 70 /** Request a list of arrivals from the API and format them into an Arrival_Board object.
Leigh_LbR 4:7e8a23454d85 71 * @param code_stn the station code to get arrivals from
Leigh_LbR 4:7e8a23454d85 72 * @param number the number of arrivals to retrieve
Leigh_LbR 4:7e8a23454d85 73 * @return an Arrival_Board object containing all the arrivals to this station
Leigh_LbR 4:7e8a23454d85 74 */
Leigh_LbR 0:bf04f62339a4 75 Arrival_Board GetArrivals(const std::string& code_stn, const std::string& number);
Leigh_LbR 4:7e8a23454d85 76 /** Request a list of departures from the API and format them into a Departure_Board object.
Leigh_LbR 4:7e8a23454d85 77 * @param code_stn the station code to get departures from
Leigh_LbR 4:7e8a23454d85 78 * @param number the number of departures to retrieve
Leigh_LbR 4:7e8a23454d85 79 * @return a Departure_Board object containing all the departures from this station
Leigh_LbR 4:7e8a23454d85 80 */
Leigh_LbR 0:bf04f62339a4 81 Departure_Board GetDepartures(const std::string& code_stn, const std::string& number);
Leigh_LbR 0:bf04f62339a4 82 };
Leigh_LbR 0:bf04f62339a4 83
Leigh_LbR 0:bf04f62339a4 84 #endif