292 lines
8.6 KiB
QML
292 lines
8.6 KiB
QML
import QtQuick
|
|
import QtQml
|
|
AbilityForm {
|
|
id: self
|
|
|
|
property var cmdPlans: ({})
|
|
property var planExtendDatas
|
|
property var mapMeasure: ({})
|
|
property var showEnd: true
|
|
property var hasLoaded: false
|
|
property var mapCharts:({})
|
|
property var defaultDevName: "控制盒"
|
|
property var defaultInstructionName: "控制电机"
|
|
property var defaultInterfaceName: "IFB串口"
|
|
property var planInstructionId: ""
|
|
property var planInterfaceIndex: 0
|
|
property var planDeviceId: ""
|
|
property var comIsOpen: true
|
|
property var isAdmin : true
|
|
property var lstRunning: false
|
|
property var curTaskIndex: 0
|
|
property var curTask: []
|
|
property var firstPath: ""
|
|
property var queueJson: ({})
|
|
property var lstPath: "/"+plusFile+"/"+appId+"/lst.json"
|
|
Component.onCompleted: {
|
|
getInstructionId()
|
|
}
|
|
Timer {
|
|
id:timerExecute
|
|
interval: 500; running: false; repeat: false
|
|
onTriggered: {
|
|
if (curTaskIndex < curTask.length)
|
|
{
|
|
executeTask(curTask[curTaskIndex++])
|
|
}
|
|
else
|
|
{
|
|
curTaskIndex = 0
|
|
}
|
|
}
|
|
}
|
|
|
|
function executeTask(param)
|
|
{
|
|
var attr = {
|
|
"deviceId": planDeviceId,
|
|
"param": JSON.stringify(param),
|
|
"interfaceIndex": planInterfaceIndex
|
|
}
|
|
console.info("executeTask:", attr)
|
|
taskActuatorManager.startInstruction(planInstructionId, attr)
|
|
var interval = Number(Number(param.runtime) * 1000)
|
|
console.info("time:", interval)
|
|
if(interval == 0)
|
|
interval = 1000
|
|
timerExecute.interval = interval
|
|
timerExecute.start()
|
|
}
|
|
function selectInterface()
|
|
{
|
|
interfaceNameArray = []
|
|
var interfaces = JSON.parse(interfacesArray[_cbDevice.currentIndex])
|
|
for (var i = 0; i < interfaces.length; i++)
|
|
{
|
|
console.info(interfaces[i])
|
|
interfaceNameArray.push(getInterFaceName(interfaces[i]))
|
|
}
|
|
_cbInterface.model = interfaceNameArray
|
|
_cbInterface.currentIndex = _cbInterface.find(defaultInterfaceName) == -1 ? 0 : _cbInterface.find(defaultInterfaceName)
|
|
planInterfaceIndex = _cbInterface.currentIndex
|
|
}
|
|
|
|
function selectInstruction()
|
|
{
|
|
instructionNameArray = []
|
|
instructionIdArray = []
|
|
var dev_model_id = devModelIdArray[_cbDevice.currentIndex]
|
|
var instructionInfo = getInstructionInfo(dev_model_id)
|
|
for(var i = 0; i < instructionInfo.length; i++)
|
|
{
|
|
instructionNameArray.push(instructionInfo[i].name)
|
|
instructionIdArray.push(instructionInfo[i].id)
|
|
}
|
|
_cbInstruction.model = instructionNameArray
|
|
_cbInstruction.currentIndex = _cbDevice.find(defaultInstructionName) == -1 ? 0 : _cbDevice.find(defaultInstructionName)
|
|
planInstructionId = instructionIdArray[_cbInstruction.currentIndex]
|
|
}
|
|
Connections{
|
|
target: self
|
|
|
|
function onSetPlanClick()
|
|
{
|
|
_setPlanDialog.visible = true
|
|
var deviceInfos = getDeviceInfo()
|
|
|
|
devNameArray = []
|
|
devModelIdArray = []
|
|
interfacesArray = []
|
|
deviceIdArray = []
|
|
for (var i = 0; i < deviceInfos.length; i++)
|
|
{
|
|
devNameArray.push(deviceInfos[i].name)
|
|
devModelIdArray.push(deviceInfos[i].dev_model_id)
|
|
deviceIdArray.push(deviceInfos[i].id)
|
|
interfacesArray.push(deviceInfos[i].interface)
|
|
}
|
|
_cbDevice.model = devNameArray
|
|
_cbDevice.currentIndex = _cbDevice.find(defaultDevName)
|
|
planDeviceId = deviceIdArray[_cbDevice.currentIndex]
|
|
selectInterface()
|
|
selectInstruction()
|
|
}
|
|
|
|
function onCbInterfaceActived()
|
|
{
|
|
selectInterface()
|
|
}
|
|
function onCbDeviceActivated()
|
|
{
|
|
selectInstruction()
|
|
}
|
|
|
|
function onEditPlanListViewClick()
|
|
{
|
|
var key = planLstModel.get( _editPlanListView.currentIndex).name
|
|
if(key != "")
|
|
{
|
|
var cmdSets = queueJson[key]
|
|
planModel.clear()
|
|
for(var i = 0; i < cmdSets.length; ++i)
|
|
{
|
|
var item = cmdSets[i]
|
|
var obj = {
|
|
"speed": item.speed,
|
|
"direction": item.direction,
|
|
"runtime": item.runtime
|
|
}
|
|
planModel.append(obj);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function onUpdatePlans()
|
|
{
|
|
var key = planLstModel.get( _editPlanListView.currentIndex).name
|
|
if(key != "")
|
|
{
|
|
var cmdSets = []
|
|
for(var i = 0; i < planModel.count; ++i)
|
|
{
|
|
var _cmdPlans = planModel.get(i)
|
|
var runtime = Number(_cmdPlans.displayruntime) * 1000
|
|
var cmdplan = {"speed":_cmdPlans.speed,"direction":_cmdPlans.direction,"runtime":_cmdPlans.runtime}
|
|
cmdSets.push(cmdplan)
|
|
}
|
|
queueJson[key] = cmdSets
|
|
save_queues()
|
|
}
|
|
}
|
|
|
|
function onAddCmdPlanClick()
|
|
{
|
|
var cmdPlans = { "speed": "0", "direction": "1", "runtime": "0", "displayruntime": "0"}
|
|
var key = planLstModel.get( _editPlanListView.currentIndex).name
|
|
if(key != "")
|
|
{
|
|
queueJson[key].push(cmdPlans)
|
|
planModel.append(cmdPlans)
|
|
}
|
|
save_queues()
|
|
}
|
|
|
|
function onDelCmdPlanClick(row)
|
|
{
|
|
if(row < planModel.count)
|
|
{
|
|
planModel.remove(row)
|
|
}
|
|
onUpdatePlans()
|
|
save_queues()
|
|
}
|
|
|
|
function onCreatePlanClick()
|
|
{
|
|
_tfPlanName.text = ""
|
|
_createPlanDialog.visible = true
|
|
}
|
|
|
|
function onDeletePlanClick(row)
|
|
{
|
|
if(row < planLstModel.count)
|
|
{
|
|
delete queueJson[planLstModel.get(row).name]
|
|
planLstModel.remove(row)
|
|
planModel.clear()
|
|
}
|
|
save_queues()
|
|
}
|
|
|
|
function onRunPlanClick(row)
|
|
{
|
|
curTask = queueJson[planLstModel.get(row).name]
|
|
executeTask(curTask[curTaskIndex++])
|
|
}
|
|
|
|
function onRunStopPlanClick(row)
|
|
{
|
|
timerExecute.stop()
|
|
}
|
|
|
|
function updateJson()
|
|
{
|
|
firstPath = common.firstPath()
|
|
agr.setJson(firstPath + lstPath, queueJson)
|
|
}
|
|
|
|
function onCreatePlanDialogAcceptClick()
|
|
{
|
|
if (!(_tfPlanName.text in queueJson))
|
|
{
|
|
planLstModel.append({
|
|
"name": _tfPlanName.text,
|
|
"cmd_set":[]
|
|
})
|
|
queueJson[_tfPlanName.text] = []
|
|
}
|
|
save_queues()
|
|
}
|
|
}
|
|
|
|
function getInstructionId()
|
|
{
|
|
var deviceInfos = getDeviceInfo()
|
|
var dev_model_id = ""
|
|
for(var i = 0; i < deviceInfos.length; i++)
|
|
{
|
|
if(deviceInfos[i].name == defaultDevName)
|
|
{
|
|
dev_model_id = deviceInfos[i].dev_model_id
|
|
planDeviceId = deviceInfos[i].id
|
|
break;
|
|
}
|
|
}
|
|
var instructionInfo = getInstructionInfo(dev_model_id)
|
|
for(var i = 0; i < instructionInfo.length; i++)
|
|
{
|
|
if(instructionInfo[i].name == defaultInstructionName)
|
|
planInstructionId = instructionInfo[i].id
|
|
}
|
|
}
|
|
|
|
function getDeviceInfo()
|
|
{
|
|
return deviceManager.getInfo("all")
|
|
}
|
|
|
|
function getInterFaceName(id)
|
|
{
|
|
var interFaceInfos = interfaceManager.getInfo(id)
|
|
if(interFaceInfos.length > 0)
|
|
return interFaceInfos[0].name
|
|
return ""
|
|
}
|
|
|
|
function getInstructionInfo(dev_model_id)
|
|
{
|
|
return instructionManager.getDevmodelInstructions(dev_model_id)
|
|
}
|
|
|
|
function save_queues()
|
|
{
|
|
firstPath = common.firstPath()
|
|
agr.setJson(firstPath + lstPath, queueJson)
|
|
}
|
|
|
|
function get_queues()
|
|
{
|
|
firstPath = common.firstPath()
|
|
queueJson = agr.getJson(firstPath + lstPath)
|
|
planLstModel.clear()
|
|
for (var key in queueJson)
|
|
{
|
|
planLstModel.append({
|
|
"name": key,
|
|
"cmd_set": queueJson[key]
|
|
})
|
|
}
|
|
}
|
|
}
|