-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsLocalNetDateTime.c
90 lines (77 loc) · 2.36 KB
/
clsLocalNetDateTime.c
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the ig-logger project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Original author: Christian Kaiser <[email protected]>
*/
bool clsLocalNet::QueryLoggerDateTime(clsSYSTEMTIME& ST)
{
bool bRes(false);
clsResult<bool> APILog("clsLocalNet::QueryLoggerDateTime",bRes);
for (int nTry = 0; nTry < 3 && !bRes && !bUserAbortRequested(); ++nTry)
{
clsIGMessage MsgQuery( IGID_PC,
IGID_DATALOGGER,
clsIGMessage::IGCMD_DL_GET_DATETIME);
clsIGMessage MsgResponse;
Log(">%-8s: %s","query", (LPCTSTR)MsgQuery.AsString());
if (Query(MsgQuery,MsgResponse))
{
if (MsgResponse.PayloadSize() == 7)
{
const BYTE* pPayload = MsgResponse.Payload();
ST.wYear = 2000+pPayload[5];
ST.wMonth = pPayload[4];
ST.wDay = pPayload[3];
ST.wHour = pPayload[2];
ST.wMinute = pPayload[1];
ST.wSecond = pPayload[0];
ST.wDayOfWeek = pPayload[6] % 7;
bRes = true;
}
else
{
throw clsExcept("bad response: bad payload size (%d/%d)",MsgResponse.PayloadSize(),7);
}
}
}
return(bRes);
}
bool clsLocalNet::SetLoggerDateTime(const clsSYSTEMTIME& ST)
{
bool bRes(false);
clsResult<bool> APILog("clsLocalNet::QueryLoggerDateTime",bRes);
clsIGMessage MsgQuery( IGID_PC,
IGID_DATALOGGER,
clsIGMessage::IGCMD_DL_SET_DATETIME);
clsIGMessage MsgResponse;
MsgQuery.SetPayload(6,ST.wSecond,ST.wMinute,ST.wHour,ST.wDay,ST.wMonth,ST.wYear-2000);
Log(">%-8s: %s","query", (LPCTSTR)MsgQuery.AsString());
if (Query(MsgQuery,MsgResponse))
{
if (MsgResponse.PayloadSize() == 7)
{
const BYTE* pPayload = MsgResponse.Payload();
clsSYSTEMTIME STRsp;
STRsp.wYear = 2000+pPayload[5];
STRsp.wMonth = pPayload[4];
STRsp.wDay = pPayload[3];
STRsp.wHour = pPayload[2];
STRsp.wMinute = pPayload[1];
STRsp.wSecond = pPayload[0];
STRsp.wDayOfWeek = pPayload[6] % 7;
printf("new time: %s\n",(LPCTSTR)STRsp.sValue());
bRes = true;
}
else
{
throw clsExcept("bad response: bad payload size (%d/%d)",MsgResponse.PayloadSize(),7);
}
}
return(bRes);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */