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:
Mon Jul 14 10:45:33 2014 +0000
Revision:
4:ab3c8d25260e
Parent:
3:8e1117ec91ba
Child:
6:8729a0db0e25
First successful end-to-end integration.

Who changed what in which revision?

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