Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Wed Jun 05 17:29:31 2019 +0000
Revision:
125:ce4045184366
Parent:
119:b3d7699d0eb0
Added SnRateListner proto-class, publishing this version of the code in order to enable exporting of most recent features.

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 119:b3d7699d0eb0 49 //fake mac address for testing
uci1 119:b3d7699d0eb0 50 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 51 return true;
uci1 116:8099b754fbb4 52 } else if ( (uid[0]==0x0A01300B) && (uid[1]==0xAE2A9126) && (uid[2]==0x52B29DC5) && (uid[3]==0xF5001E84) ) {
uci1 116:8099b754fbb4 53 // SST104, stn14
uci1 116:8099b754fbb4 54 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0x0A; mac[5]=0x9C;
uci1 119:b3d7699d0eb0 55 //fake mac address for testing
uci1 119:b3d7699d0eb0 56 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 57 return true;
uci1 116:8099b754fbb4 58 } else if ( (uid[0]==0x0A000002) && (uid[1]==0xAE299840) && (uid[2]==0x52A26AFA) && (uid[3]==0xF5001E82) ) {
uci1 116:8099b754fbb4 59 // SST110, stn15
uci1 116:8099b754fbb4 60 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF7; mac[5]=0xA8;
uci1 119:b3d7699d0eb0 61 //fake mac address for testing
uci1 119:b3d7699d0eb0 62 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 63 return true;
uci1 116:8099b754fbb4 64 } else if ( (uid[0]==0x0A000010) && (uid[1]==0xAE2A9126) && (uid[2]==0x52B2A03B) && (uid[3]==0xF5001E80) ) {
uci1 116:8099b754fbb4 65 // SST109, stn17
uci1 116:8099b754fbb4 66 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0x02; mac[5]=0xC1;
uci1 119:b3d7699d0eb0 67 //fake mac address for testing
uci1 119:b3d7699d0eb0 68 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 69 return true;
uci1 116:8099b754fbb4 70 } else if ( (uid[0]==0x0DFFC013) && (uid[1]==0xAE2A9126) && (uid[2]==0x52B2B04A) && (uid[3]==0xF5001E87) ) {
uci1 116:8099b754fbb4 71 // SST111, stn18
uci1 116:8099b754fbb4 72 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0x1A; mac[5]=0x8A;
uci1 119:b3d7699d0eb0 73 //fake mac address for testing
uci1 119:b3d7699d0eb0 74 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 75 return true;
uci1 116:8099b754fbb4 76 } else if ( (uid[0]==0x0E00D01E) && (uid[1]==0xAE2A9126) && (uid[2]==0x52B3DEC1) && (uid[3]==0xF5001E80) ) {
uci1 116:8099b754fbb4 77 // SST105, stn19
uci1 116:8099b754fbb4 78 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0x24; mac[5]=0x44;
uci1 119:b3d7699d0eb0 79 //fake mac address for testing
uci1 119:b3d7699d0eb0 80 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 81 return true;
uci1 116:8099b754fbb4 82 } else if ( (uid[0]==0x17006008) && (uid[1]==0xAE299840) && (uid[2]==0x52A2BD7C) && (uid[3]==0xF5001E80) ) {
uci1 116:8099b754fbb4 83 // SST107, stn31
uci1 116:8099b754fbb4 84 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF6; mac[5]=0x34;
uci1 119:b3d7699d0eb0 85 //fake mac address for testing
uci1 119:b3d7699d0eb0 86 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 87 return true;
uci1 116:8099b754fbb4 88 } else if ( (uid[0]==0x12013009) && (uid[1]==0xAE2A8CA7) && (uid[2]==0x52C35FA6) && (uid[3]==0xF5001E85) ) {
uci1 116:8099b754fbb4 89 // SST113, stn30
uci1 116:8099b754fbb4 90 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF2; mac[5]=0x12;
uci1 119:b3d7699d0eb0 91 //fake mac address for testing
uci1 119:b3d7699d0eb0 92 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 93 return true;
uci1 116:8099b754fbb4 94 } else if ( (uid[0]==0x1200B00D) && (uid[1]==0xAE2A8CA7) && (uid[2]==0x52C36348) && (uid[3]==0xF5001E84) ) {
uci1 116:8099b754fbb4 95 // SST112, stn32
uci1 116:8099b754fbb4 96 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF2; mac[5]=0x1A;
uci1 119:b3d7699d0eb0 97 //fake mac address for testing
uci1 119:b3d7699d0eb0 98 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 99 return true;
uci1 116:8099b754fbb4 100 } else if ( (uid[0]==0x07FFA008) && (uid[1]==0xAE299840) && (uid[2]==0x52A25792) && (uid[3]==0xF5001E87) ) {
uci1 117:fd6798ba2e26 101 // SST108, HCR Station 40. this mbed doesn't keep time properly.
uci1 116:8099b754fbb4 102 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xE9; mac[5]=0xED;
uci1 119:b3d7699d0eb0 103 //fake mac address for testing
uci1 119:b3d7699d0eb0 104 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 105 return true;
uci1 116:8099b754fbb4 106 } else if ( (uid[0]==0x0A003002) && (uid[1]==0xAE299840) && (uid[2]==0x52A269C6) && (uid[3]==0xF5001E81) ) {
uci1 117:fd6798ba2e26 107 // SST101, CR Station 41
uci1 116:8099b754fbb4 108 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF7; mac[5]=0xC6;
uci1 119:b3d7699d0eb0 109 //fake mac address for testing
uci1 119:b3d7699d0eb0 110 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 116:8099b754fbb4 111 return true;
uci1 116:8099b754fbb4 112 } else if ( (uid[0]==0x07010008) && (uid[1]==0xAE299840) && (uid[2]==0x52A25466) && (uid[3]==0xF5001E82) ) {
uci1 116:8099b754fbb4 113 // SST114, bad SST - not deployed. here in case this mbed gets put on a different board
uci1 116:8099b754fbb4 114 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xE9; mac[5]=0xE1;
uci1 119:b3d7699d0eb0 115 //fake mac address for testing
uci1 119:b3d7699d0eb0 116 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xBB; mac[3]=0xBB; mac[4]=0xBB; mac[5]=0xBB;
uci1 119:b3d7699d0eb0 117 return true;
uci1 119:b3d7699d0eb0 118 } else if ( (uid[0]==0x05FFB009) && (uid[1]==0xAEC584E3) && (uid[2]==0x56A2CCAA) && (uid[3]==0xF50020C1) ) {
uci1 119:b3d7699d0eb0 119 // 8Ch SST 201
uci1 119:b3d7699d0eb0 120 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF1; mac[4]=0xF6; mac[5]=0x34;
uci1 119:b3d7699d0eb0 121 //fake mac address for testing
uci1 119:b3d7699d0eb0 122 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xCC; mac[3]=0xCC; mac[4]=0xCC; mac[5]=0xCC;
uci1 119:b3d7699d0eb0 123 return true;
uci1 119:b3d7699d0eb0 124 } else if ( (uid[0]==0x0BFF900A) && (uid[1]==0xAEBD1906) && (uid[2]==0x5642E55D) && (uid[3]==0xF5002145) ) {
uci1 119:b3d7699d0eb0 125 // 8Ch SST 202
uci1 119:b3d7699d0eb0 126 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0xE2; mac[5]=0x4B;
uci1 119:b3d7699d0eb0 127 //fake mac address for testing
uci1 119:b3d7699d0eb0 128 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xCC; mac[3]=0xCC; mac[4]=0xCC; mac[5]=0xCC;
uci1 119:b3d7699d0eb0 129 return true;
uci1 119:b3d7699d0eb0 130 } else if ( (uid[0]==0x0301100F) && (uid[1]==0xAEC510A3) && (uid[2]==0x56AA8DE5) && (uid[3]==0xF50020C4) ) {
uci1 119:b3d7699d0eb0 131 // 8Ch SST 203
uci1 119:b3d7699d0eb0 132 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0xE7; mac[5]=0xB9;
uci1 119:b3d7699d0eb0 133 //fake mac address for testing
uci1 119:b3d7699d0eb0 134 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xCC; mac[3]=0xCC; mac[4]=0xCC; mac[5]=0xCC;
uci1 119:b3d7699d0eb0 135 return true;
uci1 119:b3d7699d0eb0 136 } else if ( (uid[0]==0x0EFFB01E) && (uid[1]==0xAEBD1866) && (uid[2]==0x5641DCF6) && (uid[3]==0xF500214B) ) {
uci1 119:b3d7699d0eb0 137 // 8Ch SST 204
uci1 119:b3d7699d0eb0 138 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0xE1; mac[5]=0xCE;
uci1 119:b3d7699d0eb0 139 //fake mac address for testing
uci1 119:b3d7699d0eb0 140 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xCC; mac[3]=0xCC; mac[4]=0xCC; mac[5]=0xCC;
uci1 119:b3d7699d0eb0 141 return true;
uci1 119:b3d7699d0eb0 142 } else if ( (uid[0]==0x08FFF002) && (uid[1]==0xAEBD1866) && (uid[2]==0x5641C554) && (uid[3]==0xF5002147) ) {
uci1 119:b3d7699d0eb0 143 // 8Ch SST 205
uci1 119:b3d7699d0eb0 144 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0xDA; mac[5]=0x83;
uci1 119:b3d7699d0eb0 145 //fake mac address for testing
uci1 119:b3d7699d0eb0 146 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xCC; mac[3]=0xCC; mac[4]=0xCC; mac[5]=0xCC;
uci1 119:b3d7699d0eb0 147 return true;
uci1 119:b3d7699d0eb0 148 } else if ( (uid[0]==0x02FF7015) && (uid[1]==0xAEC510A3) && (uid[2]==0x56AA8BA8) && (uid[3]==0xF50020C1) ) {
uci1 119:b3d7699d0eb0 149 // 8Ch SST 207
uci1 119:b3d7699d0eb0 150 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0xEC; mac[5]=0x55;
uci1 119:b3d7699d0eb0 151 //fake mac address for testing
uci1 119:b3d7699d0eb0 152 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xCC; mac[3]=0xCC; mac[4]=0xCC; mac[5]=0xCC;
uci1 119:b3d7699d0eb0 153 return true;
uci1 119:b3d7699d0eb0 154 } else if ( (uid[0]==0x02FF5014) && (uid[1]==0xAEC510A3) && (uid[2]==0x56AA8C15) && (uid[3]==0xF50020C2) ) {
uci1 119:b3d7699d0eb0 155 // 8Ch SST 208
uci1 119:b3d7699d0eb0 156 mac[0]=0x00; mac[1]=0x02; mac[2]=0xF7; mac[3]=0xF2; mac[4]=0xED; mac[5]=0xFF;
uci1 119:b3d7699d0eb0 157 //fake mac address for testing
uci1 119:b3d7699d0eb0 158 //mac[0]=0x00; mac[1]=0x02; mac[2]=0xCC; mac[3]=0xCC; mac[4]=0xCC; mac[5]=0xCC;
uci1 116:8099b754fbb4 159 return true;
uci1 116:8099b754fbb4 160 }
uci1 116:8099b754fbb4 161
uci1 116:8099b754fbb4 162 // not in the "lookup table"
uci1 116:8099b754fbb4 163 return false;
uci1 116:8099b754fbb4 164 }
uci1 116:8099b754fbb4 165
uci1 116:8099b754fbb4 166 void SnUIDtoMac::GetMacFromCRCofUID(const uint32_t uid[SnLPC1768UID::kUIDlen],
uci1 116:8099b754fbb4 167 char mac[kNumMacBytes] ) {
uci1 116:8099b754fbb4 168 // take 2 bytes from the start of the UID and then add on a 32bit CRC of the
uci1 116:8099b754fbb4 169 // while UID in order to get a fake 48bit "mac address"
uci1 116:8099b754fbb4 170
uci1 116:8099b754fbb4 171 const uint32_t crc = SnCRCUtils::GetCRC32for(uid, SnLPC1768UID::kUIDlen);
uci1 116:8099b754fbb4 172 #ifdef DEBUG
uci1 116:8099b754fbb4 173 printf("Got UID crc = %u\r\n", crc);
uci1 116:8099b754fbb4 174 printf("len=%d, byte=%d\r\n", int(SnLPC1768UID::kUIDlen),
uci1 116:8099b754fbb4 175 int(SnLPC1768UID::kUIDlen*sizeof(char)));
uci1 116:8099b754fbb4 176 #endif
uci1 116:8099b754fbb4 177 union {
uci1 116:8099b754fbb4 178 uint32_t x;
uci1 116:8099b754fbb4 179 char c[sizeof(uint32_t)];
uci1 116:8099b754fbb4 180 } d;
uci1 116:8099b754fbb4 181 d.x = uid[0];
uci1 116:8099b754fbb4 182 mac[0] = d.c[0];
uci1 116:8099b754fbb4 183 mac[1] = d.c[1];
uci1 116:8099b754fbb4 184 d.x = crc;
uci1 116:8099b754fbb4 185 memmove(mac+2, d.c, SnLPC1768UID::kUIDlen*sizeof(char));
uci1 116:8099b754fbb4 186 #ifdef DEBUG
uci1 116:8099b754fbb4 187 printf("generated MAC = %02X %02X %02X %02X %02X %02X\r\n",
uci1 116:8099b754fbb4 188 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
uci1 116:8099b754fbb4 189 #endif
uci1 116:8099b754fbb4 190 }