This library allows to parse and work with data sent by the Paradigma pelletti oven.

ParadigmaDateTime.h

Committer:
leihen
Date:
2013-06-27
Revision:
2:27334bd6dc28
Parent:
1:9c48326ad8c9

File content as of revision 2:27334bd6dc28:

#ifndef __PARADIGMADATETIME_H__
#define __PARADIGMADATETIME_H__

#include <string>

namespace Paradigma {

__packed class ParadigmaDateTime
{
    protected:
        int                 bcdToDec(char n) const { return (((unsigned)n)>>4)*10 + (n&0x0f); }

    private:
        unsigned char       m_Date;
        unsigned char       m_Month;
        unsigned char       m_Minute;
        unsigned char       m_Hour;
        

    public:
        ParadigmaDateTime()  : m_Date(0), m_Month(0), m_Minute(0), m_Hour(0) {}
        
        operator string() const                 { char Buffer[15]; sprintf(Buffer, "%02d.%02d, %02d:%02d", getDate(), getMonth(), getHour(), getMinute()); return Buffer; }
        
        std::string         getDateString()     { char Buffer[15]; sprintf(Buffer, "%02d.%02d", getDate(), getMonth()); return Buffer; }
        std::string         getTimeString()     { char Buffer[15]; sprintf(Buffer, "%02d:%02d", getHour(), getMinute()); return Buffer; }
        
        unsigned char       getDate() const     { return bcdToDec(m_Date); }
        unsigned char       getMonth() const    { return bcdToDec(m_Month); }
        unsigned char       getMinute() const   { return bcdToDec(m_Minute); }
        unsigned char       getHour() const     { return bcdToDec(m_Hour); }
};
}
#endif // __PARADIGMADATETIME_H__