LED Demo for Tech Con 2014

Dependencies:   EthernetInterface PololuLedStripx mbed-rtos mbed nanoservice_client_1_12_X

Fork of LPC1768_LWM2M_Client by MBED_DEMOS

Files at this revision

API Documentation at this revision

Comitter:
michaeljkoster
Date:
Tue Sep 30 03:31:19 2014 +0000
Parent:
9:a580c20d6bb5
Child:
11:3e5ac016a106
Child:
13:23ea6a3cf55e
Commit message:
Unique mac address based on serial number

Changed in this revision

IAP.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/IAP.lib	Mon Sep 29 21:11:33 2014 +0000
+++ b/IAP.lib	Tue Sep 30 03:31:19 2014 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/jaerts/code/IAP/#7484398d50ea
+http://developer.mbed.org/users/sam_grove/code/IAP/#f794a51897b8
--- a/main.cpp	Mon Sep 29 21:11:33 2014 +0000
+++ b/main.cpp	Tue Sep 30 03:31:19 2014 +0000
@@ -4,7 +4,7 @@
 #include "dbg.h"
 // Include resources
 #include "light.h"
-
+#include "IAP.h"
 #include "PololuLedStrip.h"
 PololuLedStrip ledStrip(P0_4);
 //#define LED_COUNT 60
@@ -25,6 +25,32 @@
 #define MASK    "255.255.255.0"
 #define GW      "10.0.0.1"
 
+extern "C" void mbed_mac_address(char *mac)
+{
+    static char buf[64] = {0};
+    IAP iap;
+    int32_t *block = iap.read_serial();
+    uint32_t serial_number[5] = {0};
+    
+    memset(buf, 0, sizeof(buf));
+    serial_number[0] = *(block);
+    serial_number[1] = *(block+1);
+    // we only want bottom 16 bits of word1 (MAC bits 32-47)
+    // and bit 9 forced to 1, bit 8 forced to 0
+    // Locally administered MAC, reduced conflicts
+    // http://en.wikipedia.org/wiki/MAC_address
+    //serial_number[0] |= 0x00000200;
+    //serial_number[0] &= 0x0000FEFF;
+    memcpy(mac, (uint8_t*) &serial_number[0], 6);
+    mac[0] |= 0x02;
+    mac[0] &= 0xFE;
+    mac[5] |= 0x02;
+    mac[5] &= 0xFE;
+     
+    // snprintf(buf, 16, "%4X%08X", serial_number[0], serial_number[1]);
+}  
+
+ 
 // NSP configuration
 /* Change this IP address to that of your NanoService Platform installation */
 //static const char* NSP_ADDRESS = "217.140.101.20"; /* public mbed demo server */ 
@@ -34,9 +60,6 @@
 char endpoint_name[24] = "LED-booth-";
 uint8_t ep_type[] = {"LED-STRIP"};
 uint8_t lifetime_ptr[] = {"60"};
-char mac[6];
-char macstring[13] ;
-
 
 // ****************************************************************************
 // Ethernet initialization
@@ -44,7 +67,6 @@
 EthernetInterface eth;
 static void ethernet_init()
 {
-
     /* Initialize network */
 #ifdef DHCP
     NSDL_DEBUG("DHCP in use\r\n");
@@ -172,6 +194,14 @@
 
 int main()
 {
+    char foo[6] = {0};
+    
+    mbed_mac_address(foo);
+    
+    pc.printf("mac:\r\n");
+    for (int i = 0; i < 6; i++) {
+      pc.printf("%x, ", foo[i]);    
+    }
 
     NSDL_DEBUG("mbed NanoService Example App 0.1\n");