gccDppConsole Test C++ SDK  20170920
DPP C++ Console Demonstration
DeviceIO/DppUtilities.cpp
Go to the documentation of this file.
00001 #include "DppUtilities.h"
00002 #include "stringex.h"
00003 
00004 CDppUtilities::CDppUtilities(void)
00005 {
00006 }
00007 
00008 CDppUtilities::~CDppUtilities(void)
00009 {
00010 }
00011 
00012 // convert a 4 byte long word to a double
00013 // lwStart - starting index of longword
00014 // buffer - byte buffer
00015 double CDppUtilities::LongWordToDouble(int lwStart, unsigned char buffer[])
00016 {
00017         double dblVal;
00018         int idx;
00019         double ByteMask;
00020         dblVal = 0;
00021         for(idx=0;idx<4;idx++) {                // build 4 bytes (lwStart-lwStart+3) into double 
00022                 ByteMask = pow(2.0,(8 * idx));
00023                 dblVal = dblVal + (buffer[(lwStart + idx)] * ByteMask);
00024         }
00025         return dblVal;
00026 }
00027 
00028 // calculate major.minor version from unsigned char, convert/save to double
00029 double CDppUtilities::BYTEVersionToDouble(unsigned char Version)
00030 {
00031         double dblVersion = 0.0;
00032         stringex strfn;
00033         string strTemp;
00034         strTemp = strfn.Format("%d.%02d",((Version & 240) / 16),(Version & 15));
00035         dblVersion = atof(strTemp.c_str());
00036         return dblVersion;
00037 }
00038 
00039 // calculate major.minor version from unsigned char, convert/save to string
00040 string CDppUtilities::BYTEVersionToString(unsigned char Version)
00041 {
00042         string strTemp;
00043         stringex strfn;
00044         strTemp = strfn.Format("%d.%02d",((Version & 240) / 16),(Version & 15));
00045         return strTemp;
00046 }