* @param {*} callBack | * @param {*} callBack | ||||
*/ | */ | ||||
export function ScanDevice(nameFlag, timeOut, callBack) { | export function ScanDevice(nameFlag, timeOut, callBack) { | ||||
JLSDK.scanDevice(nameFlag, timeOut, | |||||
(res) => { | |||||
callBack.call(this, res); | |||||
} | |||||
) | |||||
JLSDK.scanDevice(nameFlag, timeOut, | |||||
(res) => { | |||||
callBack.call(this, res); | |||||
} | |||||
) | |||||
} | } | ||||
/** | /** | ||||
* 停止扫描 | * 停止扫描 | ||||
*/ | */ | ||||
export function StopScanDevice(callBack) { | export function StopScanDevice(callBack) { | ||||
JLSDK.stopScanDevice( | |||||
(res) => { | |||||
callBack.call(this, res); | |||||
} | |||||
); | |||||
JLSDK.stopScanDevice( | |||||
(res) => { | |||||
callBack.call(this, res); | |||||
} | |||||
); | |||||
} | } | ||||
* @param {回调} callBack | * @param {回调} callBack | ||||
*/ | */ | ||||
export function connectDevice(device, callBack) { | export function connectDevice(device, callBack) { | ||||
JLSDK.connectDevice(device, | |||||
(res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
JLSDK.connectDevice(device, | |||||
(res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
} | } | ||||
*/ | */ | ||||
export function disconnectDevice(callBack) { | export function disconnectDevice(callBack) { | ||||
JLSDK.disConnectDevice((res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
JLSDK.disConnectDevice((res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
} | } | ||||
*/ | */ | ||||
export function ESAMReset(callBack) { | export function ESAMReset(callBack) { | ||||
JLSDK.ESAMRset((res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
JLSDK.ESAMRset((res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
} | } | ||||
/** | /** | ||||
* ESAM通道透传 | * ESAM通道透传 | ||||
*/ | */ | ||||
export function ESAMChannel(data, callBack) { | export function ESAMChannel(data, callBack) { | ||||
JLSDK.ESAMChannel(data, (res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
JLSDK.ESAMChannel(data, (res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
} | } | ||||
/** | /** | ||||
* @param {cos指令数组} cmdArray | * @param {cos指令数组} cmdArray | ||||
* @param {结果回掉} callBack | * @param {结果回掉} callBack | ||||
*/ | */ | ||||
export function ESAMChannelArray(cmdArray,callBack){ | |||||
JLSDK.ESAMChannel_CmdArray(cmdArray,callBack); | |||||
export function ESAMChannelArray(cmdArray, callBack) { | |||||
JLSDK.ESAMChannel_CmdArray(cmdArray, callBack); | |||||
} | } | ||||
*/ | */ | ||||
export function ICCReset(callBack) { | export function ICCReset(callBack) { | ||||
JLSDK.ICCReset((res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
JLSDK.ICCReset((res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
} | } | ||||
*/ | */ | ||||
export function ICCChannel(data, callBack) { | export function ICCChannel(data, callBack) { | ||||
JLSDK.ICCChannel(data, (res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
JLSDK.ICCChannel(data, (res) => { | |||||
callBack.call(this, res); | |||||
}) | |||||
} | } | ||||
export function ICCChannelArray(cmdArray,callBack){ | |||||
JLSDK.ICCChannel_CmdArray(cmdArray,callBack); | |||||
export function ICCChannelArray(cmdArray, callBack) { | |||||
JLSDK.ICCChannel_CmdArray(cmdArray, callBack); | |||||
} | } | ||||
export function transCmd(cmdArray, cmdtype, callback) { | export function transCmd(cmdArray, cmdtype, callback) { | ||||
if (cmdtype == '10') { | |||||
JLSDK.ICCChannel_CmdArray(cmdArray, (res) => { | |||||
callback.call(this, res); | |||||
}) | |||||
} | |||||
if (cmdtype == '20') { | |||||
JLSDK.ESAMChannel_CmdArray(cmdArray, (res) => { | |||||
callback.call(this, res); | |||||
}) | |||||
} | |||||
} | |||||
if (cmdtype == '10') { | |||||
JLSDK.ICCChannel_CmdArray(cmdArray, (res) => { | |||||
console.log('卡:', res) | |||||
callback.call(this, res); | |||||
}) | |||||
} | |||||
if (cmdtype == '20') { | |||||
JLSDK.ESAMChannel_CmdArray(cmdArray, (res) => { | |||||
console.log('OBU:', res) | |||||
callback.call(this, res); | |||||
}) | |||||
} | |||||
} |
!function(root,factory){if(typeof module==='object'&&module.exports)module.exports=factory();else root.onfire=factory()}(typeof window!=='undefined'?window:this,function(){var __onfireEvents={},__cnt=0,string_str='string',function_str='function',hasOwnKey=Function.call.bind(Object.hasOwnProperty),slice=Function.call.bind(Array.prototype.slice);function _bind(eventName,callback,is_one,context){if(typeof eventName!==string_str||typeof callback!==function_str){throw new Error('args: '+string_str+', '+function_str+'');}if(!hasOwnKey(__onfireEvents,eventName)){__onfireEvents[eventName]={}}__onfireEvents[eventName][++__cnt]=[callback,is_one,context];return[eventName,__cnt]}function _each(obj,callback){for(var key in obj){if(hasOwnKey(obj,key))callback(key,obj[key])}}function on(eventName,callback,context){return _bind(eventName,callback,0,context)}function one(eventName,callback,context){return _bind(eventName,callback,1,context)}function _fire_func(eventName,args){if(hasOwnKey(__onfireEvents,eventName)){_each(__onfireEvents[eventName],function(key,item){item[0].apply(item[2],args);if(item[1])delete __onfireEvents[eventName][key]})}}function fire(eventName){var args=slice(arguments,1);setTimeout(function(){_fire_func(eventName,args)})}function fireSync(eventName){_fire_func(eventName,slice(arguments,1))}function un(event){var eventName,key,r=false,type=typeof event;if(type===string_str){if(hasOwnKey(__onfireEvents,event)){delete __onfireEvents[event];return true}return false}else if(type==='object'){eventName=event[0];key=event[1];if(hasOwnKey(__onfireEvents,eventName)&&hasOwnKey(__onfireEvents[eventName],key)){delete __onfireEvents[eventName][key];return true}return false}else if(type===function_str){_each(__onfireEvents,function(key_1,item_1){_each(item_1,function(key_2,item_2){if(item_2[0]===event){delete __onfireEvents[key_1][key_2];r=true}})});return r}return true}function clear(){__onfireEvents={}}return{on:on,one:one,un:un,fire:fire,fireSync:fireSync,clear:clear}}); | |||||
! function(root, factory) { | |||||
if (typeof module === 'object' && module.exports) module.exports = factory(); | |||||
else root.onfire = factory() | |||||
}(typeof window !== 'undefined' ? window : this, function() { | |||||
var __onfireEvents = {}, | |||||
__cnt = 0, | |||||
string_str = 'string', | |||||
function_str = 'function', | |||||
hasOwnKey = Function.call.bind(Object.hasOwnProperty), | |||||
slice = Function.call.bind(Array.prototype.slice); | |||||
function _bind(eventName, callback, is_one, context) { | |||||
if (typeof eventName !== string_str || typeof callback !== function_str) { | |||||
throw new Error('args: ' + string_str + ', ' + function_str + ''); | |||||
} | |||||
if (!hasOwnKey(__onfireEvents, eventName)) { | |||||
__onfireEvents[eventName] = {} | |||||
} | |||||
__onfireEvents[eventName][++__cnt] = [callback, is_one, context]; | |||||
return [eventName, __cnt] | |||||
} | |||||
function _each(obj, callback) { | |||||
for (var key in obj) { | |||||
if (hasOwnKey(obj, key)) callback(key, obj[key]) | |||||
} | |||||
} | |||||
function on(eventName, callback, context) { | |||||
return _bind(eventName, callback, 0, context) | |||||
} | |||||
function one(eventName, callback, context) { | |||||
return _bind(eventName, callback, 1, context) | |||||
} | |||||
function _fire_func(eventName, args) { | |||||
if (hasOwnKey(__onfireEvents, eventName)) { | |||||
_each(__onfireEvents[eventName], function(key, item) { | |||||
item[0].apply(item[2], args); | |||||
if (item[1]) delete __onfireEvents[eventName][key] | |||||
}) | |||||
} | |||||
} | |||||
function fire(eventName) { | |||||
var args = slice(arguments, 1); | |||||
setTimeout(function() { | |||||
_fire_func(eventName, args) | |||||
}) | |||||
} | |||||
function fireSync(eventName) { | |||||
_fire_func(eventName, slice(arguments, 1)) | |||||
} | |||||
function un(event) { | |||||
var eventName, key, r = false, | |||||
type = typeof event; | |||||
if (type === string_str) { | |||||
if (hasOwnKey(__onfireEvents, event)) { | |||||
delete __onfireEvents[event]; | |||||
return true | |||||
} | |||||
return false | |||||
} else if (type === 'object') { | |||||
eventName = event[0]; | |||||
key = event[1]; | |||||
if (hasOwnKey(__onfireEvents, eventName) && hasOwnKey(__onfireEvents[eventName], key)) { | |||||
delete __onfireEvents[eventName][key]; | |||||
return true | |||||
} | |||||
return false | |||||
} else if (type === function_str) { | |||||
_each(__onfireEvents, function(key_1, item_1) { | |||||
_each(item_1, function(key_2, item_2) { | |||||
if (item_2[0] === event) { | |||||
delete __onfireEvents[key_1][key_2]; | |||||
r = true | |||||
} | |||||
}) | |||||
}); | |||||
return r | |||||
} | |||||
return true | |||||
} | |||||
function clear() { | |||||
__onfireEvents = {} | |||||
} | |||||
return { | |||||
on: on, | |||||
one: one, | |||||
un: un, | |||||
fire: fire, | |||||
fireSync: fireSync, | |||||
clear: clear | |||||
} | |||||
}); |