/** * * User: Martin Donnelly * Date: 2016-05-20 * Time: 10:13 * */ /* global CAPABILITY, inheritsFrom, capabilityManager */ /* global ble */ /* jshint browser: true , devel: true*/ var GENERICACCESS = function(p) { this.name = 'GenericAccess'; this.deviceID = p.deviceID || null; this.target = p.target || null; this.capabilityID = '1800'; this.serviceDef = { service: '1800', deviceName: '2A00', appearance: '2A01', PPCP: '2A04' }; this.data = { deviceName: '', appearance: '', ppcp: { min_conn_int: 0, max_conn_int: 0, slave_latency: 0, conn_super_timeout_multi: 0 } }; this.appearance_category = { 0: 'Unknown None', 64: 'Generic Phone', 128: 'Generic Computer ', 192: 'Generic Watch ', 193: 'Watch: Sports Watch ', 256: 'Generic Clock ', 320: 'Generic Display ', 384: 'Generic Remote Control ', 448: 'Generic Eye-glasses ', 512: 'Generic Tag ', 576: 'Generic Keyring ', 640: 'Generic Media Player ', 704: 'Generic Barcode Scanner ', 768: 'Generic Thermometer ', 769: 'Thermometer: Ear ', 832: 'Generic Heart rate Sensor ', 833: 'Heart Rate Sensor: Heart Rate Belt ', 896: 'Generic Blood Pressure ', 897: 'Blood Pressure: Arm Blood ', 898: 'Blood Pressure: Wrist Blood ', 960: 'Human Interface Device (HID) ', 961: 'Keyboard ', 962: 'Mouse ', 963: 'Joystick ', 964: 'Gamepad ', 965: 'Digitizer Tablet ', 966: 'Card Reader ', 967: 'Digital Pen ', 968: 'Barcode Scanner ', 1024: 'Generic Glucose Meter ', 1088: 'Generic: Running Walking Sensor ', 1089: 'Running Walking Sensor: In-Shoe Running ', 1090: 'Running Walking Sensor: On-Shoe Running ', 1091: 'Running Walking Sensor: On-Hip Running ', 1152: 'Generic: Cycling ', 1153: 'Cycling: Cycling Computer ', 1154: 'Cycling: Speed Sensor ', 1155: 'Cycling: Cadence Sensor ', 1156: 'Cycling: Power Sensor ', 1157: 'Cycling: Speed and Cadence Sensor ', 3136: 'Generic: Pulse Oximeter ', 3137: 'Fingertip ', 3138: 'Wrist Worn ', 3200: 'Generic: Weight Scale ', 5184: 'Generic: Outdoor Sports Activity ', 5185: 'Location Display Device ', 5186: 'Location and Navigation Display Device ', 5187: 'Location Pod ', 5188: 'Location and Navigation Pod ' }; this.onDeviceName = function(data) { var a = new Uint8Array(data); this.data.deviceName = this.arrayToAscii(a); console.log('Device Name', this.data.deviceName); }; this.onAppearance = function(data) { var a = new Uint16Array(data); var id = a[0]; this.data.appearance = this.appearance_category[id]; console.log('Appearance', this.data.appearance); }; this.onPPCP = function(data) { var a = new Uint16Array(data); this.data = { ppcp: { min_conn_int: (a[0] * 1.25), max_conn_int: (a[1] * 1.25), slave_latency: a[2], conn_super_timeout_multi: a[3] } }; console.log('PPCP', this.data.ppcp); }; this.readDeviceName = function() { console.log('readDeviceName'); ble.read(this.deviceID, this.serviceDef.service, this.serviceDef.deviceName, this.onDeviceName.bind(this), this.onError); }; this.readAppearance = function() { console.log('readAppearance'); ble.read(this.deviceID, this.serviceDef.service, this.serviceDef.appearance, this.onAppearance.bind(this), this.onError); }; /** * Peripheral Preferred Connection Parameters */ this.readPPCP = function() { console.log('readPPCP'); ble.read(this.deviceID, this.serviceDef.service, this.serviceDef.PPCP, this.onPPCP.bind(this), this.onError); }; this.startService = function() { 'use strict'; if (this.deviceID !== null) { console.log('Starting Generic Access on ', this.deviceID); console.log(this.serviceDef); this.readDeviceName(); this.readAppearance(); this.readPPCP(); } }; }; inheritsFrom(GENERICACCESS, CAPABILITY); capabilityManager.register({id: '1800', module: GENERICACCESS});