×
Namespaces

Variants
Actions
Revision as of 05:10, 26 July 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

To get the serial number of a SD card on Symbian OS v9

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: kamaljaiswal (14 Nov 2007)
Last edited: hamishwillee (26 Jul 2012)
class TCidDecoder
{
public:
#define LO_NIBBLE(val) (val & 0x0F)
#define HI_NIBBLE(val) ((val >> 4) & 0x0F)
#define IS_ASCII(val) (val >= 0x20 && val < 0x7F)
 
public:
TCidDecoder(TDesC8& aBuf, TBool aSDCard)
{
iBuf.Copy(aBuf);
iSDCard = aSDCard;
};
 
// constructor which tries to deduce whether card is an MMC or SD card
TCidDecoder(TDesC8& aBuf)
{
iBuf.Copy(aBuf);
iSDCard = ETrue;
if (HI_NIBBLE(iBuf[2]) != 0)
iSDCard = EFalse;
TInt sdMonth = LO_NIBBLE(iBuf[1]);
if (sdMonth == 0 || sdMonth > 12)
iSDCard = EFalse;
 
// get this year so we can check for daft years
TTime now;
now.HomeTime();
TDateTime dateTime = now.DateTime();
TInt year = dateTime.Year();
 
TInt sdYear = HI_NIBBLE(iBuf[1]) + (LO_NIBBLE(iBuf[2]) << 4) + 2000;
if (sdYear > year) // stupid year ?
iSDCard = EFalse;
 
// // Oid should be ascii for SD and binary for MMC - but this isn't always true
// if (!IS_ASCII(iBuf[13]) || !IS_ASCII(iBuf[14]))
// iSDCard = EFalse;
};
 
void ManufacturingDate(TInt& aYear, TInt& aMonth)
{
if (iSDCard)
{
aYear = HI_NIBBLE(iBuf[1]) + (LO_NIBBLE(iBuf[2]) << 4) + 2000;
aMonth = LO_NIBBLE(iBuf[1]);
}
else
{
aYear = LO_NIBBLE(iBuf[1]) + 1997;
aMonth = HI_NIBBLE(iBuf[1]);
}
}
 
TUint32 SerialNumber()
{
if (iSDCard)
return( (iBuf[6]<<24) | (iBuf[5]<<16) | (iBuf[4]<<8) | (iBuf[3]) );
else
return( (iBuf[5]<<24) | (iBuf[4]<<16) | (iBuf[3]<<8) | (iBuf[2]) );
}
 
void ProductRevision(TInt& aMajor, TInt& aMinor)
{
if (iSDCard)
{
aMajor = (iBuf[7] & 0xF0) >> 4;
aMinor = iBuf[7] & 0x0F;
}
else
{
aMajor = (iBuf[6] & 0xF0) >> 4;
aMinor = iBuf[6] & 0x0F;
}
}
 
void ProductName(TBuf<6>& aName)
{
aName.SetLength(5);
aName[0] = iBuf[12];
aName[1] = iBuf[11];
aName[2] = iBuf[10];
aName[3] = iBuf[9];
aName[4] = iBuf[8];
if (!iSDCard)
aName.Append(iBuf[7]);
};
 
void Oid(TBuf<2>& aOid)
{
aOid.SetLength(2);
aOid[0] = iBuf[14];
aOid[1] = iBuf[13];
};
 
TUint8 ManufactureID()
{
return iBuf[15];
}
TBool IsSdCard()
{
return iSDCard;
};
 
 
public:
TBuf8<16> iBuf;
TBool iSDCard; // MMC card if false, SD card otherwise
};
 
This page was last modified on 26 July 2012, at 05:10.
52 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×