Merge pull request #14 from Azure/develop

merge develop to master for package release
This commit is contained in:
Anton Ovechkin 2016-10-21 01:07:51 +08:00 коммит произвёл GitHub
Родитель 97270794e7 e043897629
Коммит 8b06a5936b
8 изменённых файлов: 89 добавлений и 54 удалений

Просмотреть файл

@ -3,6 +3,7 @@ Copyright (c) Microsoft Corporation
All rights reserved. All rights reserved.
MIT License MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the ""Software""), to deal of this software and associated documentation files (the ""Software""), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights

Просмотреть файл

@ -1,6 +1,6 @@
{ {
"name": "device-discovery-cli", "name": "device-discovery-cli",
"version": "0.5.5", "version": "0.5.6",
"description": "device discovery and management command line utility", "description": "device discovery and management command line utility",
"bin": { "bin": {
"devdisco": "./dist/devdisco.js" "devdisco": "./dist/devdisco.js"
@ -25,7 +25,7 @@
"url": "https://github.com/Azure/device-discovery-cli" "url": "https://github.com/Azure/device-discovery-cli"
}, },
"dependencies": { "dependencies": {
"az-iot-bi-test": "0.0.3", "az-iot-bi": "0.1.7",
"dns": "^0.2.2", "dns": "^0.2.2",
"mdns-js": "^0.5.0", "mdns-js": "^0.5.0",
"node-arp": "^1.0.5", "node-arp": "^1.0.5",

Просмотреть файл

@ -27,11 +27,11 @@ $ npm install --global device-discovery-cli
devdisco list --usb list the USB serial devices devdisco list --usb list the USB serial devices
devdisco list --wifi list the Wi-Fi devices devdisco list --wifi list the Wi-Fi devices
devdisco@0.5.0 /usr/bin/devdisco devdisco@0.5.5 /usr/bin/devdisco
## Sample Output ## Sample Output
##### Ethernet Devices ##### Ethernet LAN Devices:
IP Address MAC Address Type Host Name IP Address MAC Address Type Host Name
@ -52,7 +52,7 @@ $ npm install --global device-discovery-cli
10.172.15.148 94:57:a5:cc:99:86 ? 10.172.15.148 94:57:a5:cc:99:86 ?
##### USB UART Devices ##### USB UART Devices:
COM Port Device Name\Manufacturer Device Type (Friendly Name) COM Port Device Name\Manufacturer Device Type (Friendly Name)
@ -68,4 +68,4 @@ $ npm install --global device-discovery-cli
## License ## License
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) [MIT License](./LICENSE.txt)

Просмотреть файл

@ -18,7 +18,7 @@
'use strict'; 'use strict';
var bi = require('az-iot-bi-test'); var bi = require('az-iot-bi');
var path = require('path'); var path = require('path');
var UsbUartTransport = require('./lib/usb-uart-transport'); var UsbUartTransport = require('./lib/usb-uart-transport');
@ -30,7 +30,7 @@ var VERSION = require('../package.json').version;
function main(argv) { function main(argv) {
bi.trackEvent('command_line_arguments', { bi.trackEvent('command_line_arguments', {
argv: argv info: argv.join(' ')
}); });
if (argv.length === 1) { if (argv.length === 1) {
@ -197,13 +197,24 @@ function cmd_list_wifi_ap() {
function cmd_list_usb_uart() { function cmd_list_usb_uart() {
console.log(''); console.log('');
console.log('USB Devices:'); console.log('USB UART Devices:');
console.log(''); console.log('');
console.log(rpad('COM Port', 28), rpad('Device Name\\Manufacturer', 40), rpad('Device Type (Friendly Name)', 46)); console.log(rpad('COM Port', 28), rpad('Device Name\\Manufacturer', 40), rpad('Device Type (Friendly Name)', 46));
console.log(''); console.log('');
UsbUartTransport.beginDiscovery(onDeviceDiscovered); UsbUartTransport.beginDiscovery(onDeviceDiscovered);
} }
bi.start(); var domain = require('domain').create();
main(process.argv.slice(1)); domain.on('error', function(err){
bi.flush(); bi.trackEvent('unknown_error', {
error: err.message
});
bi.flush();
console.log(err);
})
domain.run(function(){
bi.start();
main(process.argv.slice(1));
bi.flush();
})

Просмотреть файл

@ -1,6 +1,7 @@
'use-strict'; 'use-strict';
var arp = require('node-arp'); var arp = require('node-arp');
var bi = require('az-iot-bi');
var dns = require('dns'); var dns = require('dns');
var mdns = require('mdns-js'); var mdns = require('mdns-js');
var vow = require('vow'); var vow = require('vow');
@ -11,6 +12,9 @@ function resolveIpAddressToHostNameAsync(address) {
return new vow.Promise(function(resolve, reject /*, notify */) { return new vow.Promise(function(resolve, reject /*, notify */) {
dns.reverse(address, function(err, domains) { dns.reverse(address, function(err, domains) {
if(err) { if(err) {
bi.trackEvent('ethernet_error', {
error: err.message
});
reject(err); reject(err);
return; return;
} }
@ -23,6 +27,9 @@ function resolveIpAddressToMacAddressAsync(address) {
return new vow.Promise(function(resolve, reject /*, notify */) { return new vow.Promise(function(resolve, reject /*, notify */) {
arp.getMAC(address, function(err, mac) { arp.getMAC(address, function(err, mac) {
if(err) { if(err) {
bi.trackEvent('ethernet_error', {
error: err.message
});
reject(err); reject(err);
return; return;
} }

Просмотреть файл

@ -10,7 +10,7 @@ USB\VID_10C4&PID_EA60\ Silicon Labs CP210x USB to UART Bridge huzzah
# for Adafruit Feather M0 # for Adafruit Feather M0
USB\VID_239A&PID_800B&MI_00\ USB Serial Device adafruit_feather_m0_usb USB\VID_239A&PID_800B&MI_00\ USB Serial Device adafruit_feather_m0_usb
# for SparkFun ESP8266 Thing Dev # for SparkFun ESP8266 Thing Dev
FTDIBUS\VID_0403+PID_6015+DN01AIYZA\ USB Serial Port thingdev FTDIBUS\VID_0403+PID_6015+ USB Serial Port thingdev
# for Linux # for Linux
# for Intel Edison # for Intel Edison

1 # USB mapping
10 USB\VID_239A&PID_800B&MI_00\ USB Serial Device adafruit_feather_m0_usb
11 # for SparkFun ESP8266 Thing Dev
12 FTDIBUS\VID_0403+PID_6015+DN01AIYZA\ USB Serial Port thingdev FTDIBUS\VID_0403+PID_6015+ USB Serial Port thingdev
13 # for Linux
14 # for Intel Edison
15 usb-Intel_Edison_ Intel Edison Virtual Com Port edison
16 usb-FTDI_FT232R_USB_UART_ Intel Edison USB Composite Device edison

Просмотреть файл

@ -1,32 +1,41 @@
'use-strict'; 'use-strict';
var bi = require('az-iot-bi');
var serialPort = require('serialport'); var serialPort = require('serialport');
var UsbLookup = require('./usb-lookup'); var UsbLookup = require('./usb-lookup');
exports.beginDiscovery = function beginDiscovery(callback) { exports.beginDiscovery = function beginDiscovery(callback) {
serialPort.list(function (err, ports) { return new Promise(function(resolve, reject) {
if(err){ serialPort.list(function (err, ports) {
return; if(err){
} bi.trackEvent('usb_error', {
ports.forEach(function(port) { error: err.message
var pnpId = port.pnpId; });
if(!pnpId && port.vendorId && port.productId){ reject(err);
pnpId = 'usb-VID_' + port.vendorId.split('0x')[1] + '&PID_' + port.productId.split('0x')[1]; return;
} }
var deviceName = UsbLookup.resolveUsbName(pnpId);
var deviceType = UsbLookup.resolveDeviceType(pnpId); ports.forEach(function(port) {
var deviceNameOrManufacturer = deviceName ? deviceName : port.manufacturer; var pnpId = port.pnpId;
(function(com_name, device_name_or_manufacturer, device_type) { if(!pnpId && port.vendorId && port.productId){
if(com_name && device_name_or_manufacturer) { pnpId = 'usb-VID_' + port.vendorId.split('0x')[1] + '&PID_' + port.productId.split('0x')[1];
var record = {
com_name: com_name,
device_name_or_manufacturer: device_name_or_manufacturer,
device_type: device_type,
transport: 'usb-uart',
};
callback(record);
} }
})(port.comName, deviceNameOrManufacturer, deviceType); var deviceName = UsbLookup.resolveUsbName(pnpId);
var deviceType = UsbLookup.resolveDeviceType(pnpId);
var deviceNameOrManufacturer = deviceName ? deviceName : port.manufacturer;
(function(com_name, device_name_or_manufacturer, device_type) {
if(com_name && device_name_or_manufacturer) {
var record = {
com_name: com_name,
device_name_or_manufacturer: device_name_or_manufacturer,
device_type: device_type,
transport: 'usb-uart',
};
callback(record);
}
})(port.comName, deviceNameOrManufacturer, deviceType);
});
resolve(ports);
}); });
}); });
}; };

Просмотреть файл

@ -1,29 +1,36 @@
'use-strict'; 'use-strict';
var bi = require('az-iot-bi');
var wifiscanner = require('node-wifiscanner'); var wifiscanner = require('node-wifiscanner');
var OuiLookup = require('./oui-lookup'); var OuiLookup = require('./oui-lookup');
exports.beginDiscovery = function beginDiscovery(callback) { exports.beginDiscovery = function beginDiscovery(callback) {
wifiscanner.scan(function(err, data) { return new Promise(function(resolve, reject) {
if (err) { wifiscanner.scan(function(err, data) {
return; if (err) {
} bi.trackEvent('wifi_error', {
for (var i = 0; i < data.length; i++) { error: err.message
(function(ssid, mac_address, channel, signal_level) { });
var device_type = OuiLookup.resolveMacToDeviceType(mac_address); reject('\nProbably no Wi-Fi module on this computer.\n' + err.message);
var record = { return;
channel: channel, }
device_type: device_type, for (var i = 0; i < data.length; i++) {
mac_address: mac_address, (function(ssid, mac_address, channel, signal_level) {
signal_level: signal_level, var device_type = OuiLookup.resolveMacToDeviceType(mac_address);
ssid: ssid, var record = {
transport: 'wifi-ap', channel: channel,
}; device_type: device_type,
callback(record); mac_address: mac_address,
})(data[i].ssid, data[i].mac, data[i].channel, data[i].signal_level); signal_level: signal_level,
} ssid: ssid,
}); transport: 'wifi-ap',
};
callback(record);
})(data[i].ssid, data[i].mac, data[i].channel, data[i].signal_level);
}
resolve(data);
});
})
}; };
exports.endDiscovery = function endDiscovery(/* callback */) { exports.endDiscovery = function endDiscovery(/* callback */) {