14 changed files with 751 additions and 104 deletions
-
12.vscode/settings.json
-
18CMakeLists.txt
-
2dep/iflytopcpp
-
12src/main.cpp
-
32src/service/device_io_service.cpp
-
81src/service/device_io_service.hpp
-
68src/service/device_io_service_mock.cpp
-
52src/service/device_io_service_mock.hpp
-
107src/service/main_control_service.cpp
-
3src/service/main_control_service.hpp
-
241webapp/debug/device_test.html
-
88webapp/debug/index.html
-
20webapp/debug/logger.html
-
95webapp/js/zcmd.js
@ -1 +1 @@ |
|||
Subproject commit 574b15ad972bcaae593cfc434f9f60e6d6a13ca8 |
|||
Subproject commit ea4118ddeb8238ccc065a2c11237ad7be056f89e |
@ -0,0 +1,68 @@ |
|||
#include "device_io_service_mock.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
using namespace std; |
|||
using namespace core; |
|||
|
|||
#if 0
|
|||
class DeviceIOServiceMock : public DeviceIOService { |
|||
public: |
|||
DeviceIOServiceMock() : DeviceIOService(){}; |
|||
virtual ~DeviceIOServiceMock() {} |
|||
|
|||
virtual void initialize() override; |
|||
virtual uint16_t getReg(int index) override; |
|||
virtual void relayControl(relay_device_type_t type, bool value) override; |
|||
virtual RelayDeviceState relayStateGet() override; |
|||
virtual InputDeviceState getinputState() override; |
|||
virtual uint32_t getInterTemperature() override; |
|||
virtual env_sensor_state_t getEnvSensorState() override; |
|||
virtual void fanGetState(int id, float& power, uint16_t& error) override; |
|||
virtual float fanGetState(int id) override; |
|||
virtual void fanSetState(int id, float power) override; |
|||
virtual void idcardread(bool& state, string& info) override; |
|||
}; |
|||
#endif
|
|||
|
|||
void DeviceIOServiceMock::initialize() {} |
|||
uint16_t DeviceIOServiceMock::getReg(int index) { return 9973; } |
|||
void DeviceIOServiceMock::relayControl(relay_device_type_t type, bool value) { |
|||
logger->info("relayControl type:{}, value:{}", relay_device_type2str(type), value); |
|||
} |
|||
DeviceIOServiceMock::RelayDeviceState DeviceIOServiceMock::relayStateGet() { |
|||
RelayDeviceState state; |
|||
state.state = 0x55; |
|||
return state; |
|||
} |
|||
DeviceIOServiceMock::InputDeviceState DeviceIOServiceMock::getinputState() { |
|||
InputDeviceState state; |
|||
state.state = 0x55; |
|||
return state; |
|||
} |
|||
uint32_t DeviceIOServiceMock::getInterTemperature() { return 50; } |
|||
DeviceIOService::env_sensor_state_t DeviceIOServiceMock::getEnvSensorState() { |
|||
env_sensor_state_t state; |
|||
|
|||
state.wind_speed = 9973; |
|||
state.wind_direction = 9973; |
|||
state.temperature = 9973; |
|||
state.humidity = 9973; |
|||
state.noise = 9973; |
|||
state.pm2_5 = 9973; |
|||
state.pm10 = 9973; |
|||
state.co2 = 9973; |
|||
state.atmospheric_pressure = 9973; |
|||
state.tvoc = 9973; |
|||
state.hcho = 9973; |
|||
return state; |
|||
} |
|||
void DeviceIOServiceMock::fanGetState(int id, float& power, uint16_t& error) { |
|||
power = 0; |
|||
error = 0; |
|||
} |
|||
float DeviceIOServiceMock::fanGetState(int id) { return 9973; } |
|||
void DeviceIOServiceMock::fanSetState(int id, float power) { logger->info("fanSetState id:{}, power:{}", id, power); } |
|||
void DeviceIOServiceMock::idcardread(bool& state, string& info) { |
|||
state = true; |
|||
info = "mockinfo"; |
|||
} |
@ -0,0 +1,52 @@ |
|||
//
|
|||
// Created by zwsd
|
|||
//
|
|||
|
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
#include "service/device_io_service.hpp"
|
|||
/**
|
|||
* @brief |
|||
* |
|||
* service: DeviceIOService |
|||
* |
|||
* 监听事件: |
|||
* 依赖状态: |
|||
* 依赖服务: |
|||
* 作用: |
|||
* |
|||
* 编写参考:http://192.168.1.3:3000/project_intelligent_light_pole/subboard
|
|||
*/ |
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
using namespace core; |
|||
using namespace nod; |
|||
class DeviceIOServiceMock : public DeviceIOService { |
|||
ENABLE_LOGGER(DeviceIOServiceMock); |
|||
public: |
|||
DeviceIOServiceMock() : DeviceIOService(){}; |
|||
virtual ~DeviceIOServiceMock() {} |
|||
|
|||
virtual void initialize() override; |
|||
virtual uint16_t getReg(int index) override; |
|||
virtual void relayControl(relay_device_type_t type, bool value) override; |
|||
virtual RelayDeviceState relayStateGet() override; |
|||
virtual InputDeviceState getinputState() override; |
|||
virtual uint32_t getInterTemperature() override; |
|||
virtual env_sensor_state_t getEnvSensorState() override; |
|||
virtual void fanGetState(int id, float& power, uint16_t& error) override; |
|||
virtual float fanGetState(int id) override; |
|||
virtual void fanSetState(int id, float power) override; |
|||
virtual void idcardread(bool& state, string& info) override; |
|||
}; |
|||
} // namespace iflytop
|
@ -0,0 +1,241 @@ |
|||
<!doctype html> |
|||
<html> |
|||
|
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script> |
|||
<script src="../js/zcmd.js"></script> |
|||
<meta name="viewport" content="width=device-width,initial-scale=1"> |
|||
<title>日志配置</title> |
|||
<style> |
|||
</style> |
|||
<script> |
|||
</script> |
|||
</head> |
|||
|
|||
<body> |
|||
<script> |
|||
var zcmd = new ZCommand(); |
|||
zcmd.set_onSendraw(function (data) { |
|||
console.log("zcmd send:" + JSON.stringify(data, null, 0)); |
|||
}); |
|||
zcmd.set_onReceipt(function (tx, rx) { |
|||
console.log("zcmd receipt:" + JSON.stringify(rx, null, 0)); |
|||
}); |
|||
</script> |
|||
<!-- |
|||
/******************************************************************************************************************* |
|||
* =================================================deviceStates================================================== * |
|||
*******************************************************************************************************************/ |
|||
--> |
|||
<div> |
|||
<h1>deviceStates</h1> |
|||
<select id="RefreshPeriod"> |
|||
<option value=1000>1s</option> |
|||
<option value=2000>2s</option> |
|||
<option value=3000>3s</option> |
|||
<option value=4000>4s</option> |
|||
<option value=5000>5s</option> |
|||
</select> |
|||
<!-- 开始刷新 --> |
|||
<button id="startRefresh">Start Refresh</button> |
|||
<!-- 停止刷新 --> |
|||
<button id="stopRefresh">Stop Refresh</button> |
|||
<table id="deviceStates"> |
|||
<tr> |
|||
<td>Key</td> |
|||
<td>Value</td> |
|||
<td>单位</td> |
|||
</tr> |
|||
<tr> |
|||
<td>----</td> |
|||
<td>----</td> |
|||
<td>----</td> |
|||
</tr> |
|||
</table> |
|||
|
|||
<script> |
|||
zcmd.set_onConnect(function () { |
|||
alert("connect to server"); |
|||
}); |
|||
var refreshId; |
|||
$("#startRefresh").click(function () { |
|||
if (refreshId) |
|||
clearInterval(refreshId); |
|||
refreshId = setInterval(function () { |
|||
zcmd.send_message({ |
|||
"command": "getDeviceState", |
|||
"need_receipt": true, |
|||
}, 4000).then((data) => { |
|||
console.log(data); |
|||
var html = ""; |
|||
html += "<tr>"; |
|||
html += "<td>Key</td>"; |
|||
html += "<td>Value</td>"; |
|||
html += "<td>单位</td>"; |
|||
html += "</tr>"; |
|||
for (var i = 0; i < data.deviceState.length; i++) { |
|||
html += "<tr>"; |
|||
html += "<td>" + data.deviceState[i].id + "</td>"; |
|||
html += "<td>" + data.deviceState[i].value + "</td>"; |
|||
html += "<td>" + data.deviceState[i].unit + "</td>"; |
|||
html += "</tr>"; |
|||
} |
|||
$("#deviceStates").html(html); |
|||
}); |
|||
}, $("#RefreshPeriod").val()); |
|||
}); |
|||
|
|||
$("#stopRefresh").click(function () { |
|||
clearInterval(refreshId); |
|||
}); |
|||
</script> |
|||
</div> |
|||
|
|||
|
|||
<!-- |
|||
/******************************************************************************************************************* |
|||
* ==================================================测试按键=================================================== * |
|||
*******************************************************************************************************************/ |
|||
--> |
|||
<!-- |
|||
type(option),value(false,true),relayControl |
|||
type->option: |
|||
0,kRouterPower, |
|||
1,kTouchScreenPower, |
|||
2,kUsbChargerPower, |
|||
3,kCameraPower, |
|||
4,kLightPower, |
|||
--> |
|||
<div> |
|||
<h1>测试</h1> |
|||
<table> |
|||
<tr> |
|||
<td>relayControl type value</td> |
|||
<td> |
|||
<select id="relayControl_type"> |
|||
<option value=0>kRouterPower</option> |
|||
<option value=1>kTouchScreenPower</option> |
|||
<option value=2>kUsbChargerPower</option> |
|||
<option value=3>kCameraPower</option> |
|||
<option value=4>kLightPower</option> |
|||
</select> |
|||
<select id="relayControl_value"> |
|||
<option value=0>false</option> |
|||
<option value=1>true</option> |
|||
</select> |
|||
</td> |
|||
<td> <button id="relayControl">Trigger</button> </td> |
|||
<script> |
|||
$("#relayControl").click(function () { |
|||
zcmd.send_message({ |
|||
"command": "relayControl", |
|||
"need_receipt": true, |
|||
"type": Number($("#relayControl_type").val()), |
|||
"value": ($("#relayControl_value").val() == 'true'), |
|||
}, 4000); |
|||
}); |
|||
</script> |
|||
</tr> |
|||
|
|||
|
|||
<tr> |
|||
<td>fanSetState id value</td> |
|||
<td> |
|||
<select id="fanSetState_id"> |
|||
<option value=0>0</option> |
|||
<option value=1>1</option> |
|||
</select> |
|||
<select id="fanSetState_power"> |
|||
<option value=0>0</option> |
|||
<option value=10>10</option> |
|||
<option value=20>20</option> |
|||
<option value=30>30</option> |
|||
<option value=40>40</option> |
|||
<option value=50>50</option> |
|||
<option value=60>60</option> |
|||
<option value=70>70</option> |
|||
<option value=80>80</option> |
|||
<option value=90>90</option> |
|||
<option value=100>100</option> |
|||
</select> |
|||
</td> |
|||
<td> <button id="fanSetState">Trigger</button> </td> |
|||
|
|||
<script> |
|||
$("#fanSetState").click(function () { |
|||
zcmd.send_message({ |
|||
"command": "fanSetState", |
|||
"need_receipt": true, |
|||
"id": Number($("#fanSetState_id").val()), |
|||
"power": Number($("#fanSetState_power").val()), |
|||
}, 4000).then((data) => { |
|||
// console.log(data); |
|||
}); |
|||
}); |
|||
</script> |
|||
</tr> |
|||
|
|||
<tr> |
|||
<td>relayStateGet</td> |
|||
<td>-</td> |
|||
<td><button |
|||
onclick='zcmd.send_message({"command": "relayStateGet"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button> |
|||
</td> |
|||
</tr> |
|||
|
|||
<tr> |
|||
<td>inputStateGet</td> |
|||
<td>-</td> |
|||
<td><button |
|||
onclick='zcmd.send_message({"command": "inputStateGet"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button> |
|||
</td> |
|||
</tr> |
|||
|
|||
<tr> |
|||
<td>idcardread</td> |
|||
<td>-</td> |
|||
<td><button |
|||
onclick='zcmd.send_message({"command": "idcardread"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button> |
|||
</td> |
|||
</tr> |
|||
|
|||
<tr> |
|||
<td>getInterTemperature</td> |
|||
<td>-</td> |
|||
<td><button |
|||
onclick='zcmd.send_message({"command": "getInterTemperature"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button> |
|||
</td> |
|||
</tr> |
|||
|
|||
<tr> |
|||
<td>getExterTemperature</td> |
|||
<td>-</td> |
|||
<td><button |
|||
onclick='zcmd.send_message({"command": "getExterTemperature"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button> |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td>fanGetState</td> |
|||
<td>-</td> |
|||
<td><button |
|||
onclick='zcmd.send_message({"command": "fanGetState"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button> |
|||
</td> |
|||
</tr> |
|||
|
|||
|
|||
</table> |
|||
</div> |
|||
|
|||
|
|||
|
|||
<script> |
|||
$(function () { |
|||
ZWSURL = "ws://127.0.0.1:19000"; |
|||
zcmd.start_auto_connect(ZWSURL); |
|||
}); |
|||
</script> |
|||
|
|||
</body> |
|||
|
|||
</html> |
@ -0,0 +1,88 @@ |
|||
<!doctype html> |
|||
<html> |
|||
|
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script> |
|||
<script src="../js/zcmd.js"></script> |
|||
<meta name="viewport" content="width=device-width,initial-scale=1"> |
|||
<title>日志配置</title> |
|||
<style> |
|||
</style> |
|||
<script> |
|||
</script> |
|||
</head> |
|||
|
|||
<body> |
|||
<!-- |
|||
|
|||
选择框:main,service |
|||
选择框:等级(debug,info,warning,error) |
|||
设置日志等级:按钮 |
|||
|
|||
--> |
|||
<div> |
|||
<select id="logger"> |
|||
<option value="main">main</option> |
|||
<option value="service">service</option> |
|||
</select> |
|||
<select id="level"> |
|||
<option value=0>trace</option> |
|||
<option value=1>debug</option> |
|||
<option value=2>info</option> |
|||
<option value=3>warning</option> |
|||
<option value=4>error</option> |
|||
<option value=5>critical</option> |
|||
</select> |
|||
<button id="set">设置日志等级</button> |
|||
</div> |
|||
<script> |
|||
$(function () { |
|||
var zcmd = new ZCommand(); |
|||
zcmd.onsendraw = function (data/*json*/) { |
|||
console.log("zcmd send:" + JSON.stringify(data, null, 0)); |
|||
} |
|||
zcmd.onreceipt = function (tx, rx) { |
|||
console.log("zcmd receipt:" + JSON.stringify(rx, null, 0)); |
|||
} |
|||
ZWSURL = "ws://127.0.0.1:19000"; |
|||
|
|||
//连接后端 |
|||
zcmd.start_auto_connect(ZWSURL, () => { |
|||
console.log("zcmd connected"); |
|||
|
|||
//请求日志名称 |
|||
zcmd.send_message({ |
|||
"command": "loggerGetAllLoggers", |
|||
"need_receipt": true, |
|||
}, 4000).then((data) => { |
|||
console.log(data); |
|||
var html = ""; |
|||
for (var i = 0; i < data.loggers.length; i++) { |
|||
html += "<option value='" + data.loggers[i] + "'>" + data.loggers[i] + "</option>"; |
|||
} |
|||
$("#logger").html(html); |
|||
}); |
|||
|
|||
$("#set").click(function () { |
|||
zcmd.send_message({ |
|||
"command": "loggerSetLevel", |
|||
"need_receipt": true, |
|||
"loggerLevel": Number($("#level").val()), |
|||
"loggerName": $("#logger").val(), |
|||
}, 4000).then((data) => { |
|||
if (data.success) { |
|||
alert("设置成功"); |
|||
} else { |
|||
alert("设置失败") |
|||
} |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
</script> |
|||
|
|||
|
|||
</body> |
|||
|
|||
</html> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue