Serial number identifier program for Mbed

Dependencies:   MODSERIAL mbed

Fork of serial_number_identifier by Adhithya Rajasekaran

Revision:
0:7c4e4ad6bdf9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Apr 20 11:11:28 2015 +0000
@@ -0,0 +1,42 @@
+// This program is a modification of the program get_serial_number
+// by Dan Minear
+#include "mbed.h"
+#include <string>
+#include <sstream>
+#include <algorithm>
+#include "MODSERIAL.h"
+#define IAP_LOCATION 0x1FFF1FF1
+
+typedef void (*IAP)(unsigned long [], unsigned long[] );
+IAP iap_entry = (IAP) IAP_LOCATION;
+
+MODSERIAL pc(USBTX,USBRX);
+
+string get_serial_number(){
+   unsigned long command[5] = {0,0,0,0,0};
+    unsigned long result[5] = {0,0,0,0,0};
+    command[0] = 58;  // read device serial number
+    iap_entry(command, result);
+    string output;
+    stringstream out;
+    if (result[0] == 0) {
+        for(int i = 1; i < 5; i++) {
+            out << result[i];
+        }
+    } else {
+        printf("Status error!\r\n");
+    }
+    output = out.str();     
+    return output;
+
+}
+
+int main() {
+    string serial = get_serial_number();
+    while(1){
+      if(pc.readable()){
+        pc.printf(serial.c_str());
+        break;
+      }   
+    }
+}