Ethernet-based network support for mbedConnectorInterface.

Dependencies:   libnsdl EthernetInterface mbed-rtos

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

Committer:
ansond
Date:
Mon Feb 02 06:37:09 2015 +0000
Revision:
2:c7a1aad25a18
Parent:
1:cb681dfa1678
Child:
3:3e1ad8ab5071
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:31292d956e92 1 /**
ansond 0:31292d956e92 2 * @file network_stubs.cpp
ansond 0:31292d956e92 3 * @brief mbed Endpoint network stubs implementation (Ethernet)
ansond 0:31292d956e92 4 * @author Doug Anson
ansond 0:31292d956e92 5 * @version 1.0
ansond 0:31292d956e92 6 * @see
ansond 0:31292d956e92 7 *
ansond 0:31292d956e92 8 * Copyright (c) 2014
ansond 0:31292d956e92 9 *
ansond 0:31292d956e92 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 0:31292d956e92 11 * you may not use this file except in compliance with the License.
ansond 0:31292d956e92 12 * You may obtain a copy of the License at
ansond 0:31292d956e92 13 *
ansond 0:31292d956e92 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 0:31292d956e92 15 *
ansond 0:31292d956e92 16 * Unless required by applicable law or agreed to in writing, software
ansond 0:31292d956e92 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 0:31292d956e92 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 0:31292d956e92 19 * See the License for the specific language governing permissions and
ansond 0:31292d956e92 20 * limitations under the License.
ansond 0:31292d956e92 21 */
ansond 0:31292d956e92 22
ansond 0:31292d956e92 23 #include "network_stubs.h"
ansond 0:31292d956e92 24
ansond 0:31292d956e92 25 extern "C" {
ansond 0:31292d956e92 26
ansond 0:31292d956e92 27 // plumb out the network
ansond 0:31292d956e92 28 void net_stubs_plumb_network(bool canActAsRouterNode)
ansond 0:31292d956e92 29 {
ansond 0:31292d956e92 30 // ethernet initialize
ansond 0:31292d956e92 31 ethernet.init(); // DHCP
ansond 0:31292d956e92 32 ethernet.connect(); // connect
ansond 0:31292d956e92 33
ansond 0:31292d956e92 34 // our IP address
ansond 0:31292d956e92 35 DBG("Ethernet Address: %s\r\n",ethernet.getIPAddress());
ansond 0:31292d956e92 36 }
ansond 0:31292d956e92 37
ansond 0:31292d956e92 38 // create a suitable main event loop for this specific network
ansond 0:31292d956e92 39 void net_stubs_create_main_loop(void)
ansond 0:31292d956e92 40 {
ansond 1:cb681dfa1678 41 // we simply configure the endpoint
ansond 1:cb681dfa1678 42 DBG("initNetwork: configuring endpoint...\r\n");
ansond 1:cb681dfa1678 43 configure_endpoint();
ansond 0:31292d956e92 44 }
ansond 0:31292d956e92 45
ansond 0:31292d956e92 46 // register the endpoint
ansond 0:31292d956e92 47 void net_stubs_register_endpoint(void)
ansond 0:31292d956e92 48 {
ansond 2:c7a1aad25a18 49 // initialize NSDL
ansond 2:c7a1aad25a18 50 DBG("initNetwork: initializing NSP..\r\n.");
ansond 2:c7a1aad25a18 51 nsdl_init();
ansond 2:c7a1aad25a18 52
ansond 1:cb681dfa1678 53 // NSP registration
ansond 1:cb681dfa1678 54 DBG("initNetwork: calling NSP registration...\r\n");
ansond 0:31292d956e92 55 register_endpoint(true);
ansond 1:cb681dfa1678 56 DBG("initNetwork: NSP registration completed\r\n");
ansond 0:31292d956e92 57 }
ansond 0:31292d956e92 58
ansond 0:31292d956e92 59 // begin the main loop for processing network events
ansond 0:31292d956e92 60 void net_stubs_begin_main_loop(void)
ansond 0:31292d956e92 61 {
ansond 0:31292d956e92 62 // NDSL main loop
ansond 0:31292d956e92 63 nsdl_event_loop();
ansond 0:31292d956e92 64 }
ansond 0:31292d956e92 65
ansond 0:31292d956e92 66 }