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.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the ""Software""), to deal
in the Software without restriction, including without limitation the rights

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

@ -1,6 +1,6 @@
{
"name": "device-discovery-cli",
"version": "0.5.5",
"version": "0.5.6",
"description": "device discovery and management command line utility",
"bin": {
"devdisco": "./dist/devdisco.js"
@ -25,7 +25,7 @@
"url": "https://github.com/Azure/device-discovery-cli"
},
"dependencies": {
"az-iot-bi-test": "0.0.3",
"az-iot-bi": "0.1.7",
"dns": "^0.2.2",
"mdns-js": "^0.5.0",
"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 --wifi list the Wi-Fi devices
devdisco@0.5.0 /usr/bin/devdisco
devdisco@0.5.5 /usr/bin/devdisco
## Sample Output
##### Ethernet Devices
##### Ethernet LAN Devices:
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 ?
##### USB UART Devices
##### USB UART Devices:
COM Port Device Name\Manufacturer Device Type (Friendly Name)
@ -68,4 +68,4 @@ $ npm install --global device-discovery-cli
## License
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
[MIT License](./LICENSE.txt)

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

@ -18,7 +18,7 @@
'use strict';
var bi = require('az-iot-bi-test');
var bi = require('az-iot-bi');
var path = require('path');
var UsbUartTransport = require('./lib/usb-uart-transport');
@ -30,7 +30,7 @@ var VERSION = require('../package.json').version;
function main(argv) {
bi.trackEvent('command_line_arguments', {
argv: argv
info: argv.join(' ')
});
if (argv.length === 1) {
@ -197,13 +197,24 @@ function cmd_list_wifi_ap() {
function cmd_list_usb_uart() {
console.log('');
console.log('USB Devices:');
console.log('USB UART Devices:');
console.log('');
console.log(rpad('COM Port', 28), rpad('Device Name\\Manufacturer', 40), rpad('Device Type (Friendly Name)', 46));
console.log('');
UsbUartTransport.beginDiscovery(onDeviceDiscovered);
}
bi.start();
main(process.argv.slice(1));
bi.flush();
var domain = require('domain').create();
domain.on('error', function(err){
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';
var arp = require('node-arp');
var bi = require('az-iot-bi');
var dns = require('dns');
var mdns = require('mdns-js');
var vow = require('vow');
@ -11,6 +12,9 @@ function resolveIpAddressToHostNameAsync(address) {
return new vow.Promise(function(resolve, reject /*, notify */) {
dns.reverse(address, function(err, domains) {
if(err) {
bi.trackEvent('ethernet_error', {
error: err.message
});
reject(err);
return;
}
@ -23,6 +27,9 @@ function resolveIpAddressToMacAddressAsync(address) {
return new vow.Promise(function(resolve, reject /*, notify */) {
arp.getMAC(address, function(err, mac) {
if(err) {
bi.trackEvent('ethernet_error', {
error: err.message
});
reject(err);
return;
}

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

@ -10,7 +10,7 @@ USB\VID_10C4&PID_EA60\ Silicon Labs CP210x USB to UART Bridge huzzah
# for Adafruit Feather M0
USB\VID_239A&PID_800B&MI_00\ USB Serial Device adafruit_feather_m0_usb
# 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 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';
var bi = require('az-iot-bi');
var serialPort = require('serialport');
var UsbLookup = require('./usb-lookup');
exports.beginDiscovery = function beginDiscovery(callback) {
serialPort.list(function (err, ports) {
if(err){
return;
}
ports.forEach(function(port) {
var pnpId = port.pnpId;
if(!pnpId && port.vendorId && port.productId){
pnpId = 'usb-VID_' + port.vendorId.split('0x')[1] + '&PID_' + port.productId.split('0x')[1];
return new Promise(function(resolve, reject) {
serialPort.list(function (err, ports) {
if(err){
bi.trackEvent('usb_error', {
error: err.message
});
reject(err);
return;
}
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);
ports.forEach(function(port) {
var pnpId = port.pnpId;
if(!pnpId && port.vendorId && port.productId){
pnpId = 'usb-VID_' + port.vendorId.split('0x')[1] + '&PID_' + port.productId.split('0x')[1];
}
})(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';
var bi = require('az-iot-bi');
var wifiscanner = require('node-wifiscanner');
var OuiLookup = require('./oui-lookup');
exports.beginDiscovery = function beginDiscovery(callback) {
wifiscanner.scan(function(err, data) {
if (err) {
return;
}
for (var i = 0; i < data.length; i++) {
(function(ssid, mac_address, channel, signal_level) {
var device_type = OuiLookup.resolveMacToDeviceType(mac_address);
var record = {
channel: channel,
device_type: device_type,
mac_address: mac_address,
signal_level: signal_level,
ssid: ssid,
transport: 'wifi-ap',
};
callback(record);
})(data[i].ssid, data[i].mac, data[i].channel, data[i].signal_level);
}
});
return new Promise(function(resolve, reject) {
wifiscanner.scan(function(err, data) {
if (err) {
bi.trackEvent('wifi_error', {
error: err.message
});
reject('\nProbably no Wi-Fi module on this computer.\n' + err.message);
return;
}
for (var i = 0; i < data.length; i++) {
(function(ssid, mac_address, channel, signal_level) {
var device_type = OuiLookup.resolveMacToDeviceType(mac_address);
var record = {
channel: channel,
device_type: device_type,
mac_address: mac_address,
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 */) {