Ethernet-based network support for mbedConnectorInterface.
Dependencies: libnsdl EthernetInterface mbed-rtos
Dependents: IoT_LED_demo ServoTest uWater_Project hackathon ... more
network_stubs/network_stubs.cpp@3:3e1ad8ab5071, 2015-02-02 (annotated)
- Committer:
- ansond
- Date:
- Mon Feb 02 07:02:04 2015 +0000
- Revision:
- 3:3e1ad8ab5071
- Parent:
- 2:c7a1aad25a18
- Child:
- 6:c8ac3efd53cf
updates
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:3e1ad8ab5071 | 36 | |
ansond | 3:3e1ad8ab5071 | 37 | // initialize NSDL |
ansond | 3:3e1ad8ab5071 | 38 | DBG("initNetwork: initializing NSP..\r\n."); |
ansond | 3:3e1ad8ab5071 | 39 | nsdl_init(); |
ansond | 0:31292d956e92 | 40 | } |
ansond | 0:31292d956e92 | 41 | |
ansond | 0:31292d956e92 | 42 | // create a suitable main event loop for this specific network |
ansond | 0:31292d956e92 | 43 | void net_stubs_create_main_loop(void) |
ansond | 0:31292d956e92 | 44 | { |
ansond | 1:cb681dfa1678 | 45 | // we simply configure the endpoint |
ansond | 1:cb681dfa1678 | 46 | DBG("initNetwork: configuring endpoint...\r\n"); |
ansond | 3:3e1ad8ab5071 | 47 | configure_endpoint(); |
ansond | 0:31292d956e92 | 48 | } |
ansond | 0:31292d956e92 | 49 | |
ansond | 0:31292d956e92 | 50 | // register the endpoint |
ansond | 0:31292d956e92 | 51 | void net_stubs_register_endpoint(void) |
ansond | 0:31292d956e92 | 52 | { |
ansond | 3:3e1ad8ab5071 | 53 | // rewrite the NSP address info |
ansond | 3:3e1ad8ab5071 | 54 | nsdl_set_nsp_address(); |
ansond | 2:c7a1aad25a18 | 55 | |
ansond | 1:cb681dfa1678 | 56 | // NSP registration |
ansond | 3:3e1ad8ab5071 | 57 | DBG("net_stubs_register_endpoint: calling NSP registration...\r\n"); |
ansond | 0:31292d956e92 | 58 | register_endpoint(true); |
ansond | 3:3e1ad8ab5071 | 59 | DBG("net_stubs_register_endpoint: NSP registration completed\r\n"); |
ansond | 0:31292d956e92 | 60 | } |
ansond | 0:31292d956e92 | 61 | |
ansond | 0:31292d956e92 | 62 | // begin the main loop for processing network events |
ansond | 0:31292d956e92 | 63 | void net_stubs_begin_main_loop(void) |
ansond | 0:31292d956e92 | 64 | { |
ansond | 0:31292d956e92 | 65 | // NDSL main loop |
ansond | 0:31292d956e92 | 66 | nsdl_event_loop(); |
ansond | 0:31292d956e92 | 67 | } |
ansond | 0:31292d956e92 | 68 | |
ansond | 0:31292d956e92 | 69 | } |