nsp specific components for the NSP version of the impact endpoint

Dependents:   mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet mbed_nsp_endpoint_nxp

Committer:
ansond
Date:
Wed Mar 26 19:51:29 2014 +0000
Revision:
0:e1c4378df3fe
Child:
6:edf306673e54
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:e1c4378df3fe 1 /* Copyright C2013 Doug Anson, MIT License
ansond 0:e1c4378df3fe 2 *
ansond 0:e1c4378df3fe 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:e1c4378df3fe 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:e1c4378df3fe 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:e1c4378df3fe 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:e1c4378df3fe 7 * furnished to do so, subject to the following conditions:
ansond 0:e1c4378df3fe 8 *
ansond 0:e1c4378df3fe 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:e1c4378df3fe 10 * substantial portions of the Software.
ansond 0:e1c4378df3fe 11 *
ansond 0:e1c4378df3fe 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:e1c4378df3fe 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:e1c4378df3fe 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:e1c4378df3fe 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:e1c4378df3fe 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:e1c4378df3fe 17 */
ansond 0:e1c4378df3fe 18
ansond 0:e1c4378df3fe 19 #include "NSPTransport.h"
ansond 0:e1c4378df3fe 20
ansond 0:e1c4378df3fe 21 // NSP Support
ansond 0:e1c4378df3fe 22 #include "EthernetInterface.h"
ansond 0:e1c4378df3fe 23 #include "nsdl_support.h"
ansond 0:e1c4378df3fe 24
ansond 0:e1c4378df3fe 25 // Endpoint support
ansond 0:e1c4378df3fe 26 #include "MBEDEndpoint.h"
ansond 0:e1c4378df3fe 27
ansond 0:e1c4378df3fe 28 // default constructor
ansond 0:e1c4378df3fe 29 NSPTransport::NSPTransport(ErrorHandler *error_handler,void *endpoint) : Transport(error_handler,endpoint) {
ansond 0:e1c4378df3fe 30 this->initNSP();
ansond 0:e1c4378df3fe 31 }
ansond 0:e1c4378df3fe 32
ansond 0:e1c4378df3fe 33 // default destructor
ansond 0:e1c4378df3fe 34 NSPTransport::~NSPTransport() {
ansond 0:e1c4378df3fe 35 this->disconnect();
ansond 0:e1c4378df3fe 36 }
ansond 0:e1c4378df3fe 37
ansond 0:e1c4378df3fe 38 // Initialize NSP
ansond 0:e1c4378df3fe 39 void NSPTransport::initNSP() {
ansond 0:e1c4378df3fe 40 server.init();
ansond 0:e1c4378df3fe 41 }
ansond 0:e1c4378df3fe 42
ansond 0:e1c4378df3fe 43 // check transport and process stuff
ansond 0:e1c4378df3fe 44 void NSPTransport::checkAndProcess() {
ansond 0:e1c4378df3fe 45 // Run the NSDL event loop (never returns)
ansond 0:e1c4378df3fe 46 nsdl_event_loop();
ansond 0:e1c4378df3fe 47 }
ansond 0:e1c4378df3fe 48
ansond 0:e1c4378df3fe 49 // connect up NSP
ansond 0:e1c4378df3fe 50 bool NSPTransport::connect() {
ansond 0:e1c4378df3fe 51 if (!this->m_connected) {
ansond 0:e1c4378df3fe 52 // get our NSP address
ansond 0:e1c4378df3fe 53 MBEDEndpoint *endpoint = (MBEDEndpoint *)this->logger()->getEndpoint();
ansond 0:e1c4378df3fe 54 char *nsp_address = endpoint->getNSPAddress();
ansond 0:e1c4378df3fe 55
ansond 0:e1c4378df3fe 56 // bind to the NSP
ansond 0:e1c4378df3fe 57 server.bind(NSP_PORT);
ansond 0:e1c4378df3fe 58 nsp.set_address(nsp_address,NSP_PORT);
ansond 0:e1c4378df3fe 59
ansond 0:e1c4378df3fe 60 // DEBUG
ansond 0:e1c4378df3fe 61 this->logger()->log("Connecting... NSP IP Address: %s Port: %d", nsp_address, NSP_PORT);
ansond 0:e1c4378df3fe 62
ansond 0:e1c4378df3fe 63 // Initialize NSDL stack
ansond 0:e1c4378df3fe 64 nsdl_init();
ansond 0:e1c4378df3fe 65
ansond 0:e1c4378df3fe 66 // we are connected
ansond 0:e1c4378df3fe 67 this->m_connected = true;
ansond 0:e1c4378df3fe 68 }
ansond 0:e1c4378df3fe 69
ansond 0:e1c4378df3fe 70 // return the connection status
ansond 0:e1c4378df3fe 71 return this->m_connected;
ansond 0:e1c4378df3fe 72 }
ansond 0:e1c4378df3fe 73
ansond 0:e1c4378df3fe 74 // disconnect from NSP
ansond 0:e1c4378df3fe 75 bool NSPTransport::disconnect() { return true; }