Nespresso coffee demo working on the Arch Pro

Dependencies:   EthernetInterface mbed-rtos mbed nsdl rgb_sensor_buffer

Fork of mbed_nsdl by Nespresso RGB Sensor

Committer:
bjblazkowicz
Date:
Wed Oct 29 18:28:59 2014 +0000
Revision:
9:9d5b0c43579b
Parent:
8:27e94f52810b
Child:
11:2a853cd96bf7
Switched to using MODSERIAL.; Added BLE beacon resource.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GeofferyOmlette 0:345864e9ee85 1 #include "mbed.h"
bjblazkowicz 9:9d5b0c43579b 2 #include "MODSERIAL.h"
GeofferyOmlette 0:345864e9ee85 3 #include "EthernetInterface.h"
GeofferyOmlette 0:345864e9ee85 4 #include "nsdl_support.h"
GeofferyOmlette 0:345864e9ee85 5 #include "dbg.h"
bjblazkowicz 6:8729a0db0e25 6 #include "buffered_rgb_resource.h"
bjblazkowicz 9:9d5b0c43579b 7 #include "beacon_resource.h"
GeofferyOmlette 0:345864e9ee85 8
bjblazkowicz 9:9d5b0c43579b 9 MODSERIAL console(USBTX, USBRX); // tx, rx
GeofferyOmlette 0:345864e9ee85 10
GeofferyOmlette 0:345864e9ee85 11 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 12 // Configuration section
GeofferyOmlette 0:345864e9ee85 13
GeofferyOmlette 0:345864e9ee85 14 // Ethernet configuration
GeofferyOmlette 0:345864e9ee85 15 /* Define this to enable DHCP, otherwise manual address configuration is used */
GeofferyOmlette 0:345864e9ee85 16 #define DHCP
GeofferyOmlette 0:345864e9ee85 17
GeofferyOmlette 0:345864e9ee85 18 /* Manual IP configurations, if DHCP not defined */
GeofferyOmlette 0:345864e9ee85 19 #define IP "10.45.0.206"
GeofferyOmlette 0:345864e9ee85 20 #define MASK "255.255.255.0"
GeofferyOmlette 0:345864e9ee85 21 #define GW "10.45.0.1"
GeofferyOmlette 0:345864e9ee85 22
GeofferyOmlette 0:345864e9ee85 23 // NSP configuration
bjblazkowicz 9:9d5b0c43579b 24 /* Change this create_beacon_resource IP address to that of your NanoService Platform installation */
bjblazkowicz 9:9d5b0c43579b 25 static const char* NSP_ADDRESS = "191.239.5.150";
GeofferyOmlette 0:345864e9ee85 26 static const int NSP_PORT = 5683;
bjblazkowicz 4:ab3c8d25260e 27 char endpoint_name[] = "nespresso-client";
GeofferyOmlette 0:345864e9ee85 28 uint8_t ep_type[] = {"mbed_device"};
GeofferyOmlette 0:345864e9ee85 29 uint8_t lifetime_ptr[] = {"1200"};
GeofferyOmlette 0:345864e9ee85 30
GeofferyOmlette 0:345864e9ee85 31 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 32 // Ethernet initialization
GeofferyOmlette 0:345864e9ee85 33
GeofferyOmlette 0:345864e9ee85 34 EthernetInterface eth;
GeofferyOmlette 0:345864e9ee85 35
GeofferyOmlette 0:345864e9ee85 36 static void ethernet_init()
GeofferyOmlette 0:345864e9ee85 37 {
GeofferyOmlette 0:345864e9ee85 38 /* Initialize network */
GeofferyOmlette 0:345864e9ee85 39 #ifdef DHCP
GeofferyOmlette 0:345864e9ee85 40 NSDL_DEBUG("DHCP in use\r\n");
GeofferyOmlette 0:345864e9ee85 41 eth.init();
GeofferyOmlette 0:345864e9ee85 42 #else
GeofferyOmlette 0:345864e9ee85 43 eth.init(IP, MASK, GW);
GeofferyOmlette 0:345864e9ee85 44 #endif
bjblazkowicz 9:9d5b0c43579b 45 if(eth.connect(30000) == 0) {
bjblazkowicz 9:9d5b0c43579b 46 console.printf("Connect OK\n\r");
bjblazkowicz 9:9d5b0c43579b 47 }
GeofferyOmlette 0:345864e9ee85 48
GeofferyOmlette 0:345864e9ee85 49 NSDL_DEBUG("IP Address:%s ", eth.getIPAddress());
GeofferyOmlette 0:345864e9ee85 50 }
GeofferyOmlette 0:345864e9ee85 51
GeofferyOmlette 0:345864e9ee85 52 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 53 // NSP initialization
GeofferyOmlette 0:345864e9ee85 54
GeofferyOmlette 0:345864e9ee85 55 UDPSocket server;
GeofferyOmlette 0:345864e9ee85 56 Endpoint nsp;
GeofferyOmlette 0:345864e9ee85 57
GeofferyOmlette 0:345864e9ee85 58 static void nsp_init()
GeofferyOmlette 0:345864e9ee85 59 {
GeofferyOmlette 0:345864e9ee85 60 server.init();
GeofferyOmlette 0:345864e9ee85 61 server.bind(NSP_PORT);
GeofferyOmlette 0:345864e9ee85 62
GeofferyOmlette 0:345864e9ee85 63 nsp.set_address(NSP_ADDRESS, NSP_PORT);
bjblazkowicz 9:9d5b0c43579b 64
GeofferyOmlette 0:345864e9ee85 65 NSDL_DEBUG("name: %s", endpoint_name);
GeofferyOmlette 0:345864e9ee85 66 NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
GeofferyOmlette 0:345864e9ee85 67 }
GeofferyOmlette 0:345864e9ee85 68
GeofferyOmlette 0:345864e9ee85 69 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 70 // Resource creation
GeofferyOmlette 0:345864e9ee85 71
GeofferyOmlette 0:345864e9ee85 72 static int create_resources()
GeofferyOmlette 0:345864e9ee85 73 {
GeofferyOmlette 0:345864e9ee85 74 sn_nsdl_resource_info_s *resource_ptr = NULL;
GeofferyOmlette 0:345864e9ee85 75 sn_nsdl_ep_parameters_s *endpoint_ptr = NULL;
bjblazkowicz 9:9d5b0c43579b 76
GeofferyOmlette 0:345864e9ee85 77 NSDL_DEBUG("Creating resources");
GeofferyOmlette 0:345864e9ee85 78
GeofferyOmlette 0:345864e9ee85 79 /* Create resources */
GeofferyOmlette 0:345864e9ee85 80 resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s));
GeofferyOmlette 0:345864e9ee85 81 if(!resource_ptr)
GeofferyOmlette 0:345864e9ee85 82 return 0;
GeofferyOmlette 0:345864e9ee85 83 memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s));
GeofferyOmlette 0:345864e9ee85 84
GeofferyOmlette 0:345864e9ee85 85 resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s));
bjblazkowicz 9:9d5b0c43579b 86 if(!resource_ptr->resource_parameters_ptr) {
GeofferyOmlette 0:345864e9ee85 87 nsdl_free(resource_ptr);
GeofferyOmlette 0:345864e9ee85 88 return 0;
GeofferyOmlette 0:345864e9ee85 89 }
GeofferyOmlette 0:345864e9ee85 90 memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
GeofferyOmlette 0:345864e9ee85 91
bjblazkowicz 9:9d5b0c43579b 92 create_beacon_resource(resource_ptr);
bjblazkowicz 6:8729a0db0e25 93 create_buffered_rgb_resource(resource_ptr);
GeofferyOmlette 0:345864e9ee85 94
GeofferyOmlette 2:88a30cc88a86 95 /* Register with NSP */
GeofferyOmlette 0:345864e9ee85 96 endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
GeofferyOmlette 0:345864e9ee85 97 if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
bjblazkowicz 9:9d5b0c43579b 98 console.printf("NSP registering failed\r\n");
GeofferyOmlette 0:345864e9ee85 99 else
bjblazkowicz 9:9d5b0c43579b 100 console.printf("NSP registering OK\r\n");
GeofferyOmlette 0:345864e9ee85 101 nsdl_clean_register_endpoint(&endpoint_ptr);
GeofferyOmlette 0:345864e9ee85 102
GeofferyOmlette 0:345864e9ee85 103 nsdl_free(resource_ptr->resource_parameters_ptr);
GeofferyOmlette 0:345864e9ee85 104 nsdl_free(resource_ptr);
GeofferyOmlette 0:345864e9ee85 105 return 1;
GeofferyOmlette 0:345864e9ee85 106 }
GeofferyOmlette 0:345864e9ee85 107
GeofferyOmlette 0:345864e9ee85 108 // ****************************************************************************
GeofferyOmlette 0:345864e9ee85 109 // Program entry point
GeofferyOmlette 0:345864e9ee85 110
GeofferyOmlette 0:345864e9ee85 111 int main()
GeofferyOmlette 0:345864e9ee85 112 {
bjblazkowicz 9:9d5b0c43579b 113 console.baud(115200);
bjblazkowicz 6:8729a0db0e25 114
GeofferyOmlette 0:345864e9ee85 115 // Initialize Ethernet interface first
bjblazkowicz 9:9d5b0c43579b 116 console.printf("Initializing ethernet... ");
GeofferyOmlette 0:345864e9ee85 117 ethernet_init();
bjblazkowicz 9:9d5b0c43579b 118 console.printf("done.\r\n");
bjblazkowicz 9:9d5b0c43579b 119
GeofferyOmlette 0:345864e9ee85 120 // Initialize NSP node
bjblazkowicz 9:9d5b0c43579b 121 console.printf("Initializing nsp node... ");
GeofferyOmlette 0:345864e9ee85 122 nsp_init();
bjblazkowicz 9:9d5b0c43579b 123 console.printf("done.\r\n");
bjblazkowicz 9:9d5b0c43579b 124
GeofferyOmlette 0:345864e9ee85 125 // Initialize NSDL stack
bjblazkowicz 9:9d5b0c43579b 126 console.printf("Initializing NSDL stack... ");
GeofferyOmlette 0:345864e9ee85 127 nsdl_init();
bjblazkowicz 9:9d5b0c43579b 128 console.printf("done.\r\n");
bjblazkowicz 9:9d5b0c43579b 129
GeofferyOmlette 0:345864e9ee85 130 // Create NSDL resources
bjblazkowicz 9:9d5b0c43579b 131 console.printf("Initializing resources... ");
GeofferyOmlette 0:345864e9ee85 132 create_resources();
bjblazkowicz 9:9d5b0c43579b 133 console.printf("done.\r\n");
bjblazkowicz 9:9d5b0c43579b 134
GeofferyOmlette 0:345864e9ee85 135 // Run the NSDL event loop (never returns)
GeofferyOmlette 0:345864e9ee85 136 nsdl_event_loop();
GeofferyOmlette 0:345864e9ee85 137 }