Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
formatted version with fixed env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewshatnyy committed Apr 21, 2017
1 parent 51d1d02 commit 2e0508a
Show file tree
Hide file tree
Showing 26 changed files with 2,077 additions and 2,138 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,19 @@ invocation is shown below:
3 passing (95ms)


ESLint
Code Climate
------

The Airbnb JavaScript style guide is used as a reference. The eslint
linting tool can be run on the source code for validation. For
example:
The [Airbnb JavaScript](https://github.com/airbnb/javascript) style guide is used as a reference.

$ `npm bin`/eslint.js src/adapter.js

JSHint
Lint
------
Use [standard](https://github.com/feross/standard) for linting `npm install -g standard`

To lint do `standard src/**/*.js src/*js`

The JavaScript code quality tool JSHint can be executed using the
following command:
To auto format files use `standard --fix src/filename.js`

$ npm run jshint

Error and Exception Handling
----------------------------
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"dev": "$(npm bin)/node-dev ./server.js",
"simulator": "$(npm bin)/nf start simulator",
"start": "DEBUG=node-ssdp* node server.js",
"eslint": "./node_modules/eslint/bin/eslint.js src/*",
"jshint": "jshint --reporter=node_modules/jshint-stylish src/*",
"tc:test": "./node_modules/istanbul/lib/cli.js cover _mocha",
"tc:version": "node version"
},
Expand Down
6 changes: 3 additions & 3 deletions src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ app.use(function * lastResort (next) {
let server

function start () {
if (server) return new Promise((s) => s())
if (server) return new Promise((resolve, reject) => resolve())
aggregator.start()
return new Promise((success) => {
return new Promise((resolve, reject) => {
server = app.listen(agentPort, '0.0.0.0', () => {
log.debug(`Starting agent on port: ${agentPort}`)
success()
resolve()
})
})
}
Expand Down
90 changes: 45 additions & 45 deletions src/aggregator.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// In charge of sniffing network and pulling devices into the db
const co = require('co');
const config = require('./config/config');
const through = require('through');
const { deviceXML } = require('./utils');
const Finder = require('./finder');
const lokijs = require('./lokijs');
const log = require('./config/logger');
const common = require('./common');
const devices = require('./store');
const { urnSearch, deviceSearchInterval, path } = config.app.agent;
const query = `urn:schemas-mtconnect-org:service:${urnSearch}`;
const finder = new Finder({ query, frequency: deviceSearchInterval });
const request = require('request');
const co = require('co')
const config = require('./config/config')
const through = require('through')
const { deviceXML } = require('./utils')
const Finder = require('./finder')
const lokijs = require('./lokijs')
const log = require('./config/logger')
const common = require('./common')
const devices = require('./store')
const { urnSearch, deviceSearchInterval, path } = config.app.agent
const query = `urn:schemas-mtconnect-org:service:${urnSearch}`
const finder = new Finder({ query, frequency: deviceSearchInterval })
const request = require('request')
/**
* processSHDR() process SHDR string
*
Expand All @@ -20,18 +20,18 @@ const request = require('request');
* return uuid
*
*/
function processSHDR(uuid) {
function processSHDR (uuid) {
return through((data) => {
log.debug(data.toString());
const stirng = String(data).trim();
const parsed = common.inputParsing(stirng, uuid);
lokijs.dataCollectionUpdate(parsed, uuid);
});
log.debug(data.toString())
const stirng = String(data).trim()
const parsed = common.inputParsing(stirng, uuid)
lokijs.dataCollectionUpdate(parsed, uuid)
})
}

devices.on('delete', (obj) => {
lokijs.updateBufferOnDisconnect(obj.uuid);
});
lokijs.updateBufferOnDisconnect(obj.uuid)
})

/**
* connectToDevice() create socket connection to device
Expand All @@ -43,22 +43,22 @@ devices.on('delete', (obj) => {
*
*/

function connectToDevice({ ip, port, uuid }) {
const response = request(`http://${ip}:${port}`);
response.pipe(processSHDR(uuid));
function connectToDevice ({ ip, port, uuid }) {
const response = request(`http://${ip}:${port}`)
response.pipe(processSHDR(uuid))
response.on('error', (err) => { // Remove device
if (err.errno !== 'ECONNREFUSED') return;
const found = devices.find({ $and: [{ address: err.address }, { port: err.port }] });
if (found.length > 0) devices.remove(found);
});
if (err.errno !== 'ECONNREFUSED') return
const found = devices.find({ $and: [{ address: err.address }, { port: err.port }] })
if (found.length > 0) devices.remove(found)
})

response.on('close', () => {
const found = devices.find({ $and: [{ address: ip }, { port }] });
if (found.length > 0) { devices.remove(found); }
log.debug('Connection closed');
});
const found = devices.find({ $and: [{ address: ip }, { port }] })
if (found.length > 0) { devices.remove(found) }
log.debug('Connection closed')
})

devices.insert({ address: ip, port, uuid });
devices.insert({ address: ip, port, uuid })
}

/**
Expand All @@ -70,22 +70,22 @@ function connectToDevice({ ip, port, uuid }) {
*
* returns null
*/
function handleDevice({ ip, port, uuid }) {
return function addDevice(xml) {
if (!common.mtConnectValidate(xml)) return;
if (lokijs.updateSchemaCollection(xml)) return;
const found = devices.find({ $and: [{ hostname: ip }, { port }] });
const uuidFound = common.duplicateUuidCheck(uuid, devices);
function handleDevice ({ ip, port, uuid }) {
return function addDevice (xml) {
if (!common.mtConnectValidate(xml)) return
if (lokijs.updateSchemaCollection(xml)) return
const found = devices.find({ $and: [{ hostname: ip }, { port }] })
const uuidFound = common.duplicateUuidCheck(uuid, devices)
if ((found.length < 1) && (uuidFound.length < 1)) {
connectToDevice({ ip, port, uuid });
connectToDevice({ ip, port, uuid })
}
};
}
}

function onDevice(info) {
co(deviceXML(Object.assign({ path }, info))).then(handleDevice(info));
function onDevice (info) {
co(deviceXML(Object.assign({ path }, info))).then(handleDevice(info))
}

finder.on('device', onDevice);
finder.on('device', onDevice)

module.exports = finder;
module.exports = finder
Loading

0 comments on commit 2e0508a

Please sign in to comment.