提交 | 用户 | 时间
|
149dd0
|
1 |
package com.iailab.netsdk.demo.module; |
H |
2 |
|
|
3 |
import java.text.SimpleDateFormat; |
|
4 |
|
|
5 |
import com.iailab.netsdk.lib.NetSDKLib.CtrlType; |
|
6 |
import com.iailab.netsdk.lib.NetSDKLib.NET_TIME; |
|
7 |
import com.iailab.netsdk.lib.ToolKits; |
|
8 |
|
|
9 |
|
|
10 |
/** |
|
11 |
* \if ENGLISH_LANG |
|
12 |
* Device Control Interface |
|
13 |
* contains:reboot device、setup device time and query device time |
|
14 |
* \else |
|
15 |
* 设备控制接口实现 |
|
16 |
* 包含: 重启、时间同步、获取时间功能 |
|
17 |
* \endif |
|
18 |
*/ |
|
19 |
public class DeviceControlModule { |
|
20 |
|
|
21 |
/** |
|
22 |
* \if ENGLISH_LANG |
|
23 |
* Reboot Device |
|
24 |
* \else |
|
25 |
* 重启设备 |
|
26 |
* \endif |
|
27 |
*/ |
|
28 |
public static boolean reboot() { |
|
29 |
|
|
30 |
if (!LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, CtrlType.CTRLTYPE_CTRL_REBOOT, null, 3000)) { |
|
31 |
System.err.println("CLIENT_ControlDevice Failed!" + ToolKits.getErrorCodePrint()); |
|
32 |
return false; |
|
33 |
} |
|
34 |
return true; |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* \if ENGLISH_LANG |
|
39 |
* Setup Device Time |
|
40 |
* \else |
|
41 |
* 时间同步 |
|
42 |
* \endif |
|
43 |
*/ |
|
44 |
public static boolean setTime(String date) { |
|
45 |
NET_TIME deviceTime = new NET_TIME(); |
|
46 |
if (date == null) { |
|
47 |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
48 |
date = dateFormat.format(new java.util.Date()); |
|
49 |
} |
|
50 |
|
|
51 |
String[] dateTime = date.split(" "); |
|
52 |
String[] arrDate = dateTime[0].split("-"); |
|
53 |
String[] arrTime = dateTime[1].split(":"); |
|
54 |
deviceTime.dwYear = Integer.parseInt(arrDate[0]); |
|
55 |
deviceTime.dwMonth = Integer.parseInt(arrDate[1]); |
|
56 |
deviceTime.dwDay = Integer.parseInt(arrDate[2]); |
|
57 |
deviceTime.dwHour = Integer.parseInt(arrTime[0]); |
|
58 |
deviceTime.dwMinute = Integer.parseInt(arrTime[1]); |
|
59 |
deviceTime.dwSecond = Integer.parseInt(arrTime[2]); |
|
60 |
|
|
61 |
if (!LoginModule.netsdk.CLIENT_SetupDeviceTime(LoginModule.m_hLoginHandle, deviceTime)) { |
|
62 |
System.err.println("CLIENT_SetupDeviceTime Failed!" + ToolKits.getErrorCodePrint()); |
|
63 |
return false; |
|
64 |
} |
|
65 |
return true; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* \if ENGLISH_LANG |
|
70 |
* Get Device Current Time |
|
71 |
* \else |
|
72 |
* 获取设备当前时间 |
|
73 |
* \endif |
|
74 |
*/ |
|
75 |
public static String getTime() { |
|
76 |
NET_TIME deviceTime = new NET_TIME(); |
|
77 |
|
|
78 |
if (!LoginModule.netsdk.CLIENT_QueryDeviceTime(LoginModule.m_hLoginHandle, deviceTime, 3000)) { |
|
79 |
System.err.println("CLIENT_QueryDeviceTime Failed!" + ToolKits.getErrorCodePrint()); |
|
80 |
return null; |
|
81 |
} |
|
82 |
|
|
83 |
String date = deviceTime.toStringTime(); |
|
84 |
date = date.replace("/", "-"); |
|
85 |
|
|
86 |
return date; |
|
87 |
} |
|
88 |
} |