Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Tue May 03 02:01:35 2016 +0000
Revision:
116:8099b754fbb4
Child:
117:fd6798ba2e26
One program for all stns via UID/MAC lookup table or generation. Status sends number trg/evt and livetime, not rates. Add 512 sample evt and RFFT-LUTs. Add L1Scaledown trg bit. Allow skip SST reset at start. Fix dt at end of seq. End of comm signal.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 116:8099b754fbb4 1 #include "SnUIDtoMac.h"
uci1 116:8099b754fbb4 2
uci1 116:8099b754fbb4 3 #include "SnCRCUtils.h"
uci1 116:8099b754fbb4 4 #include "SnConstants.h"
uci1 116:8099b754fbb4 5
uci1 116:8099b754fbb4 6 void SnUIDtoMac::GetMacAddress( char mac[SnUIDtoMac::kNumMacBytes] ) {
uci1 116:8099b754fbb4 7 // this first gets the UID of the ARM chip (LPC1768)
uci1 116:8099b754fbb4 8 // it then tries to see if the UID is in the lookup table of known MAC addresses
uci1 116:8099b754fbb4 9 // (the lookup table is found in GetMacFromUIDtable)
uci1 116:8099b754fbb4 10 // if not, it constructs a fake MAC address given the UID (see GetMacFromCRCofUID)
uci1 116:8099b754fbb4 11
uci1 116:8099b754fbb4 12 uint32_t uid[SnLPC1768UID::kUIDlen];
uci1 116:8099b754fbb4 13 const bool uidOk = SnLPC1768UID::GetUID(uid);
uci1 116:8099b754fbb4 14 if (uidOk) {
uci1 116:8099b754fbb4 15
uci1 116:8099b754fbb4 16 #ifdef DEBUG
uci1 116:8099b754fbb4 17 printf("got UID = %08X %08X %08X %08X\r\n",
uci1 116:8099b754fbb4 18 uid[0], uid[1], uid[2], uid[3]);
uci1 116:8099b754fbb4 19 #endif
uci1 116:8099b754fbb4 20
uci1 116:8099b754fbb4 21 const bool uidInLookupTable = GetMacFromUIDtable(uid, mac);
uci1 116:8099b754fbb4 22 if (uidInLookupTable==false) {
uci1 116:8099b754fbb4 23 #ifdef DEBUG
uci1 116:8099b754fbb4 24 printf("UID not in lookup table. Constructing MAC.\r\n");
uci1 116:8099b754fbb4 25 #endif
uci1 116:8099b754fbb4 26 GetMacFromCRCofUID(uid, mac);
uci1 116:8099b754fbb4 27 }
uci1 116:8099b754fbb4 28 #ifdef DEBUG
uci1 116:8099b754fbb4 29 else {
uci1 116:8099b754fbb4 30 printf("UID found in lookup table.\r\n");
uci1 116:8099b754fbb4 31 }
uci1 116:8099b754fbb4 32 #endif
uci1 116:8099b754fbb4 33
uci1 116:8099b754fbb4 34 } else {
uci1 116:8099b754fbb4 35 #ifdef DEBUG
uci1 116:8099b754fbb4 36 printf("mac/uid lookup failed.\r\n");
uci1 116:8099b754fbb4 37 #endif
uci1 116:8099b754fbb4 38 // otherwise we failed. use the default
uci1 116:8099b754fbb4 39 memmove(mac, kDefaultMacAdress, sizeof(kDefaultMacAdress));
uci1 116:8099b754fbb4 40 }
uci1 116:8099b754fbb4 41 }
uci1 116:8099b754fbb4 42
uci1 116:8099b754fbb4 43 bool SnUIDtoMac::GetMacFromUIDtable(const uint32_t uid[SnLPC1768UID::kUIDlen],
uci1 116:8099b754fbb4 44 char mac[kNumMacBytes] ) {
uci1 116:8099b754fbb4 45
uci1 116:8099b754fbb4 46 if ( (uid[0]==0x0A015013) && (uid[1]==0xAE2A8CA0) && (uid[2]==0x52B77AA3) && (uid[3]==0xF5001E84) ) {
uci1 116:8099b754fbb4 47 // SST102, stn13
uci1 116:8099b754fbb4 48 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0x24; mac[5]=0x4B;
uci1 116:8099b754fbb4 49 return true;
uci1 116:8099b754fbb4 50 } else if ( (uid[0]==0x0A01300B) && (uid[1]==0xAE2A9126) && (uid[2]==0x52B29DC5) && (uid[3]==0xF5001E84) ) {
uci1 116:8099b754fbb4 51 // SST104, stn14
uci1 116:8099b754fbb4 52 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0x0A; mac[5]=0x9C;
uci1 116:8099b754fbb4 53 return true;
uci1 116:8099b754fbb4 54 } else if ( (uid[0]==0x0A000002) && (uid[1]==0xAE299840) && (uid[2]==0x52A26AFA) && (uid[3]==0xF5001E82) ) {
uci1 116:8099b754fbb4 55 // SST110, stn15
uci1 116:8099b754fbb4 56 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF7; mac[5]=0xA8;
uci1 116:8099b754fbb4 57 return true;
uci1 116:8099b754fbb4 58 } else if ( (uid[0]==0x0A000010) && (uid[1]==0xAE2A9126) && (uid[2]==0x52B2A03B) && (uid[3]==0xF5001E80) ) {
uci1 116:8099b754fbb4 59 // SST109, stn17
uci1 116:8099b754fbb4 60 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0x02; mac[5]=0xC1;
uci1 116:8099b754fbb4 61 return true;
uci1 116:8099b754fbb4 62 } else if ( (uid[0]==0x0DFFC013) && (uid[1]==0xAE2A9126) && (uid[2]==0x52B2B04A) && (uid[3]==0xF5001E87) ) {
uci1 116:8099b754fbb4 63 // SST111, stn18
uci1 116:8099b754fbb4 64 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0x1A; mac[5]=0x8A;
uci1 116:8099b754fbb4 65 return true;
uci1 116:8099b754fbb4 66 } else if ( (uid[0]==0x0E00D01E) && (uid[1]==0xAE2A9126) && (uid[2]==0x52B3DEC1) && (uid[3]==0xF5001E80) ) {
uci1 116:8099b754fbb4 67 // SST105, stn19
uci1 116:8099b754fbb4 68 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0x24; mac[5]=0x44;
uci1 116:8099b754fbb4 69 return true;
uci1 116:8099b754fbb4 70 } else if ( (uid[0]==0x17006008) && (uid[1]==0xAE299840) && (uid[2]==0x52A2BD7C) && (uid[3]==0xF5001E80) ) {
uci1 116:8099b754fbb4 71 // SST107, stn31
uci1 116:8099b754fbb4 72 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF6; mac[5]=0x34;
uci1 116:8099b754fbb4 73 return true;
uci1 116:8099b754fbb4 74 } else if ( (uid[0]==0x12013009) && (uid[1]==0xAE2A8CA7) && (uid[2]==0x52C35FA6) && (uid[3]==0xF5001E85) ) {
uci1 116:8099b754fbb4 75 // SST113, stn30
uci1 116:8099b754fbb4 76 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF2; mac[5]=0x12;
uci1 116:8099b754fbb4 77 return true;
uci1 116:8099b754fbb4 78 } else if ( (uid[0]==0x1200B00D) && (uid[1]==0xAE2A8CA7) && (uid[2]==0x52C36348) && (uid[3]==0xF5001E84) ) {
uci1 116:8099b754fbb4 79 // SST112, stn32
uci1 116:8099b754fbb4 80 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF2; mac[5]=0x1A;
uci1 116:8099b754fbb4 81 return true;
uci1 116:8099b754fbb4 82 } else if ( (uid[0]==0x07FFA008) && (uid[1]==0xAE299840) && (uid[2]==0x52A25792) && (uid[3]==0xF5001E87) ) {
uci1 116:8099b754fbb4 83 // SST108, stn16. this mbed doesn't keep time properly. used by engineers for testing.
uci1 116:8099b754fbb4 84 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xE9; mac[5]=0xED;
uci1 116:8099b754fbb4 85 return true;
uci1 116:8099b754fbb4 86 } else if ( (uid[0]==0x0A003002) && (uid[1]==0xAE299840) && (uid[2]==0x52A269C6) && (uid[3]==0xF5001E81) ) {
uci1 116:8099b754fbb4 87 // SST101, bad bias tees - not deployed. here in case this mbed gets put on a different board
uci1 116:8099b754fbb4 88 // or the board is fixed and deployed
uci1 116:8099b754fbb4 89 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF7; mac[5]=0xC6;
uci1 116:8099b754fbb4 90 return true;
uci1 116:8099b754fbb4 91 } else if ( (uid[0]==0x07010008) && (uid[1]==0xAE299840) && (uid[2]==0x52A25466) && (uid[3]==0xF5001E82) ) {
uci1 116:8099b754fbb4 92 // SST114, bad SST - not deployed. here in case this mbed gets put on a different board
uci1 116:8099b754fbb4 93 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xE9; mac[5]=0xE1;
uci1 116:8099b754fbb4 94 return true;
uci1 116:8099b754fbb4 95 }
uci1 116:8099b754fbb4 96
uci1 116:8099b754fbb4 97 // not in the "lookup table"
uci1 116:8099b754fbb4 98 return false;
uci1 116:8099b754fbb4 99 }
uci1 116:8099b754fbb4 100
uci1 116:8099b754fbb4 101 void SnUIDtoMac::GetMacFromCRCofUID(const uint32_t uid[SnLPC1768UID::kUIDlen],
uci1 116:8099b754fbb4 102 char mac[kNumMacBytes] ) {
uci1 116:8099b754fbb4 103 // take 2 bytes from the start of the UID and then add on a 32bit CRC of the
uci1 116:8099b754fbb4 104 // while UID in order to get a fake 48bit "mac address"
uci1 116:8099b754fbb4 105
uci1 116:8099b754fbb4 106 const uint32_t crc = SnCRCUtils::GetCRC32for(uid, SnLPC1768UID::kUIDlen);
uci1 116:8099b754fbb4 107 #ifdef DEBUG
uci1 116:8099b754fbb4 108 printf("Got UID crc = %u\r\n", crc);
uci1 116:8099b754fbb4 109 printf("len=%d, byte=%d\r\n", int(SnLPC1768UID::kUIDlen),
uci1 116:8099b754fbb4 110 int(SnLPC1768UID::kUIDlen*sizeof(char)));
uci1 116:8099b754fbb4 111 #endif
uci1 116:8099b754fbb4 112 union {
uci1 116:8099b754fbb4 113 uint32_t x;
uci1 116:8099b754fbb4 114 char c[sizeof(uint32_t)];
uci1 116:8099b754fbb4 115 } d;
uci1 116:8099b754fbb4 116 d.x = uid[0];
uci1 116:8099b754fbb4 117 mac[0] = d.c[0];
uci1 116:8099b754fbb4 118 mac[1] = d.c[1];
uci1 116:8099b754fbb4 119 d.x = crc;
uci1 116:8099b754fbb4 120 memmove(mac+2, d.c, SnLPC1768UID::kUIDlen*sizeof(char));
uci1 116:8099b754fbb4 121 #ifdef DEBUG
uci1 116:8099b754fbb4 122 printf("generated MAC = %02X %02X %02X %02X %02X %02X\r\n",
uci1 116:8099b754fbb4 123 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
uci1 116:8099b754fbb4 124 #endif
uci1 116:8099b754fbb4 125 }