|
应用会议室监控
应用示例可查看_MATRIX 和_AUDIO方法,可自行修改相关方法属性及添加方法属性。有任何问题建议可在下方留言,功能持续改进更新
附:
function _RMS(vPort,vRoom,vKey,fnGetData)
{
this.fnButton = "";
this.fnChmute = "";
this.port = vPort
if(vPort.indexOf('MOD')!=-1)
{
this.port = GetCurrentIOName();
}
this.cnum = vRoom;
this.key = vKey;
this.action = "";
this.ordearray = new Array();
this.getCommand = function()
{
var strtemp = {"cnum":this.cnum,"key":this.key,"action":this.action,"order":this.ordearray};
var strjson = JSON.stringify(strtemp);
return strjson+"\r\n";
}
this.update = function()
{
this.ordearray = new Array();
for(var i = 0;i<arguments.length;i++)
{
this.ordearray.push(arguments[i]);
}
sendCodeString(this.port,this.getCommand())
}
this.setPower = function(vTrue)
{
if(vTrue)
{
this.action = "System power on";
sendCodeString(this.port,'{\"cnum\":\"'+this.cnum+'\",\"key\":\"'+this.key+'\",\"action\":\"'+this.action+'\",\"order\":[{\"type\":\"power_on\"}]}');
}
else
{
this.action = "System power off";
sendCodeString(this.port,'{\"cnum\":\"'+this.cnum+'\",\"key\":\"'+this.key+'\",\"action\":\"'+this.action+'\",\"order\":[{\"type\":\"power_off\"}]}');
}
}
this.setRelease = function()
{
this.action = "system run";
sendCodeString(this.port,'{\"cnum\":\"'+this.cnum+'\",\"key\":\"'+this.key+'\",\"action\":\"'+this.action+'\",\"order\":[{\"type\":\"release\"}]}');
}
this.setPlay = function(vData)
{
this.action = "system run";
sendCodeString(this.port,'{\"cnum\":\"'+this.cnum+'\",\"key\":\"'+this.key+'\",\"action\":\"'+this.action+'\",\"order\":[{\"type\":\"voice_control\",\"data\":{\"text\":\"'+setGBK(vData)+'\",\"msg\":\"success\"}}]}');
}
this.getRev = function(vData)
{
sendLog("**********************************RMS***********************************",vData);
if(vData.indexOf("speedtext")!=-1)
{
var voiceJson = JSON.parse(vData);
var voiceText = voiceJson.voice[0].speedtext;
fnGetData("Voice",voiceText,0,0);
}
else if(vData.indexOf("type\":\"switch_video")!=-1)
{
var switchJson = JSON.parse(vData);
var vInput = parseInt(switchJson.data.input);
var vdevid = switchJson.devid
for(var i =0;i<switchJson.data.output.length;i++)
{
//sendLog("input"+vInput,"output"+switchJson.data.output[i]);
fnGetData("MatrixSet",vInput,parseInt(switchJson.data.output[i]),vdevid);
}
}
else if(vData.indexOf("type\":\"total_volume")!=-1)
{
var volJson = JSON.parse(vData);
var vLevel = parseInt(volJson.data);
var vdevid = volJson.devid
//sendLog("All volume",vLevel);
fnGetData("VolAllLevel",0,vLevel,vdevid);
}
else if(vData.indexOf("type\":\"total_mute")!=-1)
{
var muteJson = JSON.parse(vData);
var vMute = parseInt(muteJson.data);
var vdevid = muteJson.devid
//sendLog("All mute",vMute);
fnGetData("VolAllMute",0,vMute,vdevid);
}
else if(vData.indexOf("type\":\"device_volume")!=-1)
{
var loadType = ["Out","In"];
var volJson = JSON.parse(vData);
var vLoad = parseInt(volJson.data.putNum);
var vLevel = parseInt(volJson.data.volume);
var vType = parseInt(volJson.data.putType);
var vdevid = volJson.devid
//sendLog(loadType[vType]+"volume"+vLoad,vLevel);
fnGetData("Vol"+loadType[vType]+"Level",vLoad,vLevel,vdevid);
}
else if(vData.indexOf("type\":\"device_mute")!=-1)
{
var loadType = ["Out","In"];
var muteJson = JSON.parse(vData);
var vLoad = parseInt(muteJson.data.putNum);
var vMute = parseInt(muteJson.data.mute);
var vType = parseInt(muteJson.data.putType);
var vdevid = muteJson.devid
//sendLog(loadType[vType]+"volume"+vLoad,vMute);
fnGetData("Vol"+loadType[vType]+"Mute:",vLoad,vMute,vdevid);
}
else if(vData.indexOf("\"control\"")!=-1)
{
var ctrJson = JSON.parse(vData);
var vButton = parseInt(ctrJson.control[0].btnid);
var vStatus = parseInt(ctrJson.control[0].status);
var vdevid = ctrJson.devid
//sendLog("Button"+vButton,vStatus);
fnGetData("CtrButton",vButton,vStatus,vdevid);
}
else if(vData.indexOf("type\":\"power_on")!=-1)
{
fnGetData("Power",1,0,0);
}
else if(vData.indexOf("type\":\"power_off")!=-1)
{
fnGetData("Power",0,0,0);
}
}
if(arguments.length>=4)
{
sendCodeString(this.port,'{\"cnum\":\"'+this.cnum+'\",\"key\":\"'+this.key+'\",\"action\":\"'+this.action+'\",\"order\":[{\"type\":\"query\"}]}');
setStringReceive(this.port,this.getRev);
}
this.setRev = function(vEnable)
{
if(vEnable)
{
setStringReceive(this.port,this.getRev);
}
}
}
function _RMS_BUTTON(iNum)
{
this.btnMax = iNum;
this.power = new Array();
this.name = new Array();
for(var i=0;i<=this.btnMax;i++)
{
this.power[i] = 1;
this.name[i] = "Button"+i;
}
this.setbtnData = function(iNum)
{
var sTemp = {"btnname":this.name[iNum],"status":this.power[iNum],"btnid":iNum};
return sTemp;
}
this.btnData = new Array();
this.getData = function()
{
this.btnData = new Array();
for(var i = 1;i<=this.btnMax;i++)
{
this.btnData.push(this.setbtnData(i));
}
var strtemp = {"type":"pattern","data":this.btnData,"operating":2};
return strtemp;
}
}
function _RMS_POWER(iNum,vdevid)
{
this.powerMax = iNum;
this.devId = 1;
if(arguments.length>=2)
{
this.devId = vdevid;
}
this.online = new Array();
this.power = new Array();
this.current = new Array();
for(var i=0;i<=this.powerMax;i++)
{
this.online[i] = 1;
this.power[i] = 1;
this.current[i] = "";
}
this.setPowerData = function(iNum)
{
var sTemp = {"num":String(iNum),"status":this.online[iNum],"power":this.power[iNum],"level":this.current[iNum]};
return sTemp;
}
this.powerData = new Array();
this.getData = function()
{
this.powerData = new Array();
for(var i = 1;i<=this.powerMax;i++)
{
this.powerData.push(this.setPowerData(i));
}
var strtemp = {"type":"connect","device":"power","devid":this.devId,"data":this.powerData};
return strtemp;
}
}
function _RMS_LAN(vType,iNum,vdevid)
{
this.lanMax = iNum;
this.devId = 1;
if(arguments.length>=3)
{
this.devId = vdevid;
}
this.typeNum = vType;
this.lanType = ["router","switches"];
this.online = new Array();
for(var i=0;i<=this.lanMax;i++)
{
this.online[i] = 1;
}
this.setLanData = function(iNum)
{
var sTemp = {"num":String(iNum),"status":this.online[iNum]};
return sTemp;
}
this.netData = new Array();
this.getData = function()
{
this.netData = new Array();
for(var i = 1;i<=this.lanMax;i++)
{
this.netData.push(this.setLanData(i));
}
var strtemp = {"type":"connect","device":this.lanType[this.typeNum],"devid":this.devId,"data":this.netData};
return strtemp;
}
}
function _RMS_ENV()
{
this.type = "env"
this.pm25 = 0;
this.co2 = 45;
this.temp = 23;
this.humi = 43;
this.form =12;
this.poll = 11;
this.getData = function()
{
var strtemp = {"type":this.type,"data":{"pm25":String(this.pm25),"co2":String(this.co2),"temperature":String(this.temp),"humidity":String(this.humi),"formal":String(this.form),"pollution":String(this.poll)}};
return strtemp;
}
}
function _RMS_CONTROL(vdevid)
{
this.devId = 1;
if(arguments.length>=1)
{
this.devId = vdevid;
}
this.controlData = new Array();
this.getData = function()
{
this.controlData = new Array();
for(var i = 0;i<arguments.length;i++)
{
this.controlData.push(arguments[i]);
}
var strtemp = {"type":"connect","device":"control","devid":this.devId,"data":this.controlData};
return strtemp;
}
}
function _RMS_CONTROL_TYPE(sType)
{
this.type = sType;
this.online = 1;
this.power = 1;
this.error = 0;
this.action = "";
this.lamphour = "";
this.lineType =0;
this.number =0;
this.getData = function(iCom)
{
var sTemp;
if(iCom.indexOf('COM')!=-1)
{
this.lineType =0;
this.number = parseInt(setRemoveString(iCom,'COM'));
}
else if(iCom.indexOf('IO')!=-1)
{
this.lineType =1;
this.number = parseInt(setRemoveString(iCom,'IO'));
}
else if(iCom.indexOf('IR')!=-1)
{
this.lineType =2;
this.number = parseInt(setRemoveString(iCom,'IR'));
}
else if(iCom.indexOf('BUS')!=-1)
{
this.lineType =3;
this.number = parseInt(setRemoveString(iCom,'BUS'));
}
else if(iCom.indexOf('RELAY')!=-1)
{
this.lineType =4;
this.number = parseInt(setRemoveString(iCom,'RELAY'));
}
else if(iCom.indexOf('NET')!=-1)
{
this.lineType =5;
this.number = parseInt(setRemoveString(iCom,'NET'));
}
switch (this.type)
{
case 'PROJ':
sTemp = {"lineType":this.lineType,"num":this.number,"status":this.online,"power":this.power,"error":this.error,"action":this.action,"devicetype":"projector","lamphour":this.lamphour};
break;
case 'PLAY':
sTemp = {"lineType":this.lineType,"num":this.number,"status":this.online,"power":this.power,"error":this.error,"action":this.action,"devicetype":"play"};
break;
case 'MONI':
sTemp = {"lineType":this.lineType,"num":this.number,"status":this.online,"power":this.power,"error":this.error,"action":this.action,"devicetype":"monitor"};
break;
case 'SOUR':
sTemp = {"lineType":this.lineType,"num":this.number,"status":this.online,"power":this.power,"error":this.error,"action":this.action,"devicetype":"source"};
break;
case 'COMM':
sTemp = {"lineType":this.lineType,"num":this.number,"status":this.online,"power":this.power,"error":this.error,"action":this.action,"devicetype":"common"};
break;
}
return sTemp;
}
}
function _RMS_AUDIO(iInputMax,iOutputMax,vdevid)
{
this.devId = 1;
if(arguments.length>=3)
{
this.devId = vdevid;
}
this.inputMax = iInputMax;
this.outputMax = iOutputMax;
this.inputOnline = new Array();
this.inputDb = new Array();
this.inputVolume = new Array();
this.inputMute = new Array();
this.allVolume = 0;
this.allMute = 0;
for(var i=0;i<=this.inputMax;i++)
{
this.inputOnline[i] = 1;
this.inputDb[i] = "";
this.inputVolume[i] = 0;
this.inputMute[i] = 0;
}
this.outputOnline = new Array();
this.outputDb = new Array();
this.outputVolume = new Array();
this.outputMute = new Array();
for(var i=0;i<=this.outputMax;i++)
{
this.outputOnline[i] = 1;
this.outputDb[i] = "";
this.outputVolume[i] = 0;
this.outputMute[i] = 0;
}
this.audioData = new Array();
this.setInputData = function(iNum)
{
var sTemp = {"lineType":1,"num":String(iNum),"status":this.inputOnline[iNum],"dbvalue":this.inputDb[iNum],"volume":this.inputVolume[iNum],"mute":this.inputMute[iNum]};
return sTemp;
}
this.setOutputData = function(iNum)
{
var sTemp = {"lineType":0,"num":String(iNum),"status":this.outputOnline[iNum],"dbvalue":this.outputDb[iNum],"volume":this.outputVolume[iNum],"mute":this.outputMute[iNum]};
return sTemp;
}
this.getData = function()
{
this.audioData = new Array();
for(var i=1;i<=this.inputMax;i++)
{
this.audioData.push(this.setInputData(i))
}
for(var i=1;i<=this.outputMax;i++)
{
this.audioData.push(this.setOutputData(i))
}
this.audioData.push({"lineType":2,"volume":this.allVolume,"mute":this.allMute})
var strtemp = {"type":"connect","device":"audio","devid":this.devId,"data":this.audioData};
return strtemp;
}
}
function _RMS_MATRIX(iInputMax,iOutputMax,vdevid)
{
this.devId = 1;
if(arguments.length>=3)
{
this.devId = vdevid;
}
this.inputMax = iInputMax;
this.outputMax = iOutputMax;
this.inputOnline = new Array();
for(var i=0;i<=this.inputMax;i++)
{
this.inputOnline[i] = 1;
}
this.outputOnline = new Array();
this.outputToInput = new Array();
for(var i=0;i<=this.outputMax;i++)
{
this.outputOnline[i] = 1;
this.outputToInput[i] = 0;
}
this.matrixData = new Array();
this.setInputData = function(iNum)
{
var sTemp = {"lineType":1,"num":String(iNum),"status":this.inputOnline[iNum]};
return sTemp;
}
this.setOutputData = function(iNum)
{
var sTemp = {"lineType":0,"num":String(iNum),"status":this.outputOnline[iNum],"lineinput":this.outputToInput[iNum]};
return sTemp;
}
this.getData = function()
{
this.matrixData = new Array();
for(var i=1;i<=this.inputMax;i++)
{
this.matrixData.push(this.setInputData(i))
}
for(var i=1;i<=this.outputMax;i++)
{
this.matrixData.push(this.setOutputData(i))
}
var strtemp = {"type":"connect","device":"matrix","devid":this.devId,"data":this.matrixData};
return strtemp;
}
}
|
|