mbed Sensor node for Instrumented Booth over ETH.
Dependencies: EthernetInterface-1 MaxbotixDriver Presence HTU21D_TEMP_HUMID_SENSOR_SAMPLE Resources SHARPIR mbed-rtos mbed-src WDT_K64F nsdl_lib
Fork of Trenton_Switch_LPC1768_ETH by
Diff: NSDL/nsdl_run.cpp
- Revision:
- 26:4cac6b346e4f
- Child:
- 27:6017a643f386
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NSDL/nsdl_run.cpp Wed Dec 03 15:39:09 2014 +0000 @@ -0,0 +1,99 @@ +#include "mbed.h" +#include "nsdl_support.h" +#include "nsdl_dbg.h" + +#include "node_cfg.h" + +#include "door_trip.h" +#include "height.h" +#include "kiosk_presence.h" +#include "motion.h" +#include "temperature.h" +#include "sound_level.h" + + +// **************************************************************************** +// Configuration section + +// NSP configuration +/* Change this IP address to that of your NanoService Platform installation */ +uint8_t NSP_address_bytes[] = NSP_IP_ADDRESS_BYTES; + +uint8_t endpoint_name[24] = NODE_NAME; +uint8_t ep_type[] = ENDPOINT_TYPE; +uint8_t lifetime_ptr[] = LIFE_TIME; + +// **************************************************************************** +// Resource creation + +static int create_resources() +{ + sn_nsdl_resource_info_s *resource_ptr = NULL; + sn_nsdl_ep_parameters_s *endpoint_ptr = NULL; + + NSDL_DEBUG("Creating resources"); + + /* Create resources */ + resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s)); + if(!resource_ptr) + return 0; + memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s)); + + resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s)); + if(!resource_ptr->resource_parameters_ptr) + { + nsdl_free(resource_ptr); + return 0; + } + memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); + + // Static resources + nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0, (uint8_t*) "ARM mbed", sizeof("ARM mbed")-1); + nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0, (uint8_t*) "Ethernet node", sizeof("Ethernet node")-1); + + // Dynamic resources +#if NODE_SENSOR_STATION + create_temperature_resource(resource_ptr); + create_sound_level_resource(resource_ptr); + #if NODE_KIOSK_STATION + create_kiosk_presence_resource(resource_ptr); + #elif NODE_HEIGHT_STATION + create_height_resource(resource_ptr); + #endif + #if NODE_DOOR_TRIP_STATION + create_door_trip_resource(resource_ptr); + #endif + #if NODE_PIR_STATION + create_motion_resource(resource_ptr); + #endif +#endif + + /* Register with NSP */ + endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr); + if(sn_nsdl_register_endpoint(endpoint_ptr) != 0) + printf("NSP registering failed\r\n"); + else + printf("NSP registering OK\r\n"); + nsdl_clean_register_endpoint(&endpoint_ptr); + + nsdl_free(resource_ptr->resource_parameters_ptr); + nsdl_free(resource_ptr); + return 1; +} + +// **************************************************************************** +// Program entry point +// this modified to startup as an option in the Wi-Go demo + +void nsdl_run() +{ + + NSDL_DEBUG("ARM NSP Init\r\n"); + + // Initialize NSDL stack + nsdl_init(); + + // Create NSDL resources + create_resources(); + +}