Serial number identifier program for Mbed

Dependencies:   MODSERIAL mbed

Fork of serial_number_identifier by Adhithya Rajasekaran

main.cpp

Committer:
adhithyan15
Date:
2015-04-20
Revision:
0:7c4e4ad6bdf9

File content as of revision 0:7c4e4ad6bdf9:

// 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;
      }   
    }
}