-
Notifications
You must be signed in to change notification settings - Fork 7
/
cp56time.cpp
71 lines (58 loc) · 1.47 KB
/
cp56time.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "cp56time.h"
#include <QDateTime>
CP56Time::CP56Time()
{
for (int i=0; i<7; i++)
rawData[i]=0;
}
bool CP56Time::IsValid(){
if ((GetMinute()&128) == 0)
return true;
else return false;
}
CP56Time::CP56Time(QByteArray data, int offset=0){
for(int i=0; i<7; i++){
rawData[i] = data[i+offset];
}
}
quint16 CP56Time::GetMS(){
return (quint16(rawData[1])<<8)+rawData[0];
}
char CP56Time::GetHour(){
return rawData[3]&31;
}
char CP56Time::GetMinute(){
return rawData[2]&63;
}
char CP56Time::GetDay(){
return rawData[4]&31;
}
char CP56Time::GetMonth(){
return rawData[5]&15;
}
char CP56Time::GetYear(){
return rawData[6]&127;
}
QString CP56Time::GetTimeString()
{
return QString::number(GetDay()) + "-"+
QString::number(GetMonth()) + "-" +
QString::number(GetYear()) + " " +
QString::number(GetHour())+":"+
QString::number(GetMinute())+":"+
QString::number((float)GetMS()/1000.f);
}
QByteArray CP56Time::GetTimestamp()
{
QDateTime currentDT = QDateTime::currentDateTime();
char data[7];
data[6] = currentDT.date().year()-2000;
data[5] = currentDT.date().month();
data[4] = currentDT.date().day();
data[3] = currentDT.time().hour();
data[2] = currentDT.time().minute();
int msec = currentDT.time().msec() + currentDT.time().second()*1000;
data[1] = msec >> 8;
data[0] = msec & 0xff;
return QByteArray(data,7);
}