Serial number identifier program for Mbed

Dependencies:   MODSERIAL mbed

Fork of serial_number_identifier by Adhithya Rajasekaran

Committer:
adhithyan15
Date:
Mon Apr 20 11:11:28 2015 +0000
Revision:
0:7c4e4ad6bdf9
Initial build

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adhithyan15 0:7c4e4ad6bdf9 1 // This program is a modification of the program get_serial_number
adhithyan15 0:7c4e4ad6bdf9 2 // by Dan Minear
adhithyan15 0:7c4e4ad6bdf9 3 #include "mbed.h"
adhithyan15 0:7c4e4ad6bdf9 4 #include <string>
adhithyan15 0:7c4e4ad6bdf9 5 #include <sstream>
adhithyan15 0:7c4e4ad6bdf9 6 #include <algorithm>
adhithyan15 0:7c4e4ad6bdf9 7 #include "MODSERIAL.h"
adhithyan15 0:7c4e4ad6bdf9 8 #define IAP_LOCATION 0x1FFF1FF1
adhithyan15 0:7c4e4ad6bdf9 9
adhithyan15 0:7c4e4ad6bdf9 10 typedef void (*IAP)(unsigned long [], unsigned long[] );
adhithyan15 0:7c4e4ad6bdf9 11 IAP iap_entry = (IAP) IAP_LOCATION;
adhithyan15 0:7c4e4ad6bdf9 12
adhithyan15 0:7c4e4ad6bdf9 13 MODSERIAL pc(USBTX,USBRX);
adhithyan15 0:7c4e4ad6bdf9 14
adhithyan15 0:7c4e4ad6bdf9 15 string get_serial_number(){
adhithyan15 0:7c4e4ad6bdf9 16 unsigned long command[5] = {0,0,0,0,0};
adhithyan15 0:7c4e4ad6bdf9 17 unsigned long result[5] = {0,0,0,0,0};
adhithyan15 0:7c4e4ad6bdf9 18 command[0] = 58; // read device serial number
adhithyan15 0:7c4e4ad6bdf9 19 iap_entry(command, result);
adhithyan15 0:7c4e4ad6bdf9 20 string output;
adhithyan15 0:7c4e4ad6bdf9 21 stringstream out;
adhithyan15 0:7c4e4ad6bdf9 22 if (result[0] == 0) {
adhithyan15 0:7c4e4ad6bdf9 23 for(int i = 1; i < 5; i++) {
adhithyan15 0:7c4e4ad6bdf9 24 out << result[i];
adhithyan15 0:7c4e4ad6bdf9 25 }
adhithyan15 0:7c4e4ad6bdf9 26 } else {
adhithyan15 0:7c4e4ad6bdf9 27 printf("Status error!\r\n");
adhithyan15 0:7c4e4ad6bdf9 28 }
adhithyan15 0:7c4e4ad6bdf9 29 output = out.str();
adhithyan15 0:7c4e4ad6bdf9 30 return output;
adhithyan15 0:7c4e4ad6bdf9 31
adhithyan15 0:7c4e4ad6bdf9 32 }
adhithyan15 0:7c4e4ad6bdf9 33
adhithyan15 0:7c4e4ad6bdf9 34 int main() {
adhithyan15 0:7c4e4ad6bdf9 35 string serial = get_serial_number();
adhithyan15 0:7c4e4ad6bdf9 36 while(1){
adhithyan15 0:7c4e4ad6bdf9 37 if(pc.readable()){
adhithyan15 0:7c4e4ad6bdf9 38 pc.printf(serial.c_str());
adhithyan15 0:7c4e4ad6bdf9 39 break;
adhithyan15 0:7c4e4ad6bdf9 40 }
adhithyan15 0:7c4e4ad6bdf9 41 }
adhithyan15 0:7c4e4ad6bdf9 42 }