/** * * User: Martin Donnelly * Date: 2016-05-20 * Time: 10:13 * */ /* global CAPABILITY, inheritsFrom, capabilityManager */ /* global ble */ /* jshint browser: true , devel: true*/ var DEVICEINFO = function(p) { this.name = 'Device Information'; this.deviceID = p.deviceID || null; this.target = p.target || null; this.capabilityID = '180A'; this.serviceDef = { service: '180A', manufacturer_name_string: '2A29', model_number_string: '2A24', system_id: '2A23', }; this.data = { manufacturerName: '', modelNumber: '' }; this.onSystemID = function(data) { 'use strict'; this.readRaw('SystemID', data); }; this.onModelNumberString = function(data) { 'use strict'; var a = new Uint8Array(data); this.data.modelNumber = this.arrayToAscii(a); console.log('Model Number', this.data.modelNumber); }; this.readSystemID = function() { console.log('readSystemID'); ble.read(this.deviceID, this.serviceDef.service, this.serviceDef.system_id, this.onSystemID.bind(this), this.onError); }; this.readModelNumberString = function() { console.log('readModelNumberString'); ble.read(this.deviceID, this.serviceDef.service, this.serviceDef.model_number_string, this.onModelNumberString.bind(this), this.onError); }; this.startService = function() { 'use strict'; if (this.deviceID !== null) { console.log('Starting DEVICEINFO Service on ', this.deviceID); console.log(this.serviceDef); this.readSystemID(); this.readModelNumberString(); } }; }; inheritsFrom(DEVICEINFO, CAPABILITY); capabilityManager.register({id: '180A', module: DEVICEINFO});