better socket default port (1776) and path (using SOCKETS_DIR environment variable
added loggermaster
parent
bc75af050b
commit
615586173d
|
@ -8,7 +8,7 @@ const PATH = '/opt/uci/unix.sock'
|
|||
;
|
||||
(async () => {
|
||||
|
||||
let i2cbus = new Bus({id:'i2c-bus', us:{path:PATH} })
|
||||
let i2cbus = new Bus({id:'i2c-bus'})
|
||||
|
||||
await i2cbus.init()
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
const PATH = '/opt/uci/unix.sock'
|
||||
const PATH = '/opt/sockets/i2c-bus.sock'
|
||||
|
||||
import Base from '../../uci-base/src/base'
|
||||
// import Base from '@uci/base'
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import Base from '../../uci-base/src/base'
|
||||
|
||||
const PATH = '/opt/uci/unix.sock'
|
||||
const PATH = '/opt/sockets/i2c-bus.sock'
|
||||
|
||||
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
||||
;
|
||||
|
|
|
@ -12,7 +12,7 @@ const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
|||
;
|
||||
(async () => {
|
||||
|
||||
let relays = new Base({id:'tcp-i2c-client', sockets:'tc#c>t', tc:{host:HOST}})
|
||||
let relays = new Base({id:'tcp-i2c-client', sockets:'tc#c>t', tc:{port: 1776, host:HOST}})
|
||||
|
||||
relays.reply = function (packet) {
|
||||
// console.log(packet.bus)
|
||||
|
|
|
@ -8,7 +8,7 @@ const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
|||
;
|
||||
(async () => {
|
||||
|
||||
let scanner = new Base({id:'tcp-i2c-client', sockets:'tc#c>t', tc:{host:HOST}})
|
||||
let scanner = new Base({id:'tcp-i2c-client', sockets:'tc#c>t', tc:{port: 1776, host:HOST}})
|
||||
|
||||
scanner.reply = function (packet) {
|
||||
let addresses = packet.response.map(device => {
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
"description": "I2c Bus Classes for Communication to I2C bus via socket or direct call",
|
||||
"main": "src/bus",
|
||||
"scripts": {
|
||||
"bus": "node_modules/.bin/nodemon --require @std/esm --watch ../ examples/bus",
|
||||
"bus2": "node_modules/.bin/nodemon --require @std/esm examples/bus",
|
||||
"busa": "node_modules/.bin/nodemon --require @std/esm --watch ../ examples/bus",
|
||||
"bus": "SOCKET_DIR=/opt/sockets node_modules/.bin/nodemon --require @std/esm examples/bus",
|
||||
"busl": "DEBUG=true SOCKETS_DIR=/opt/sockets node_modules/.bin/nodemon --require @std/esm examples/bus",
|
||||
"test": "mocha -r @std/esm test/*.test.mjs",
|
||||
"testw": "mocha -r @std/esm test/*.test.mjs --watch --recurse --watch-extensions mjs",
|
||||
"testci": "istanbul cover ./node_modules/.bin/_mocha test/ --report lcovonly -- -R spec --recursive && codecov || true"
|
||||
|
|
|
@ -4,22 +4,32 @@ import pify from 'pify'
|
|||
// import Base from '@uci/base'
|
||||
import Base from '../../uci-base/src/base'
|
||||
|
||||
import logger from '../../uci-logger/src/logger'
|
||||
let log = {}
|
||||
const LOG_OPTS = {
|
||||
repo:'uci-i2c-bus',
|
||||
npm:'@uci/i2c-bus',
|
||||
file:'src/bus-packet.mjs',
|
||||
class:'Bus',
|
||||
id:this.id,
|
||||
instance_created:new Date().getTime()
|
||||
}
|
||||
|
||||
export default class Bus extends Base {
|
||||
constructor(opts) {
|
||||
console.log(opts)
|
||||
log = logger.child(LOG_OPTS)
|
||||
opts.sockets = opts.sockets || 'us#s>n,ts#s>t'
|
||||
opts.ts = opts.ts || { port:1776 }
|
||||
opts.us = opts.us || {path: (process.env.SOCKETS_DIR || __dirname) + '/i2c-bus.sock'}
|
||||
log.info({opts:opts},'create bus with these opts')
|
||||
super(opts)
|
||||
this.busnum = opts.busnum || 1
|
||||
this.i2cbus = i2c.open(this.busnum, () => {})
|
||||
// console.log(' ',this._packetProcess)
|
||||
// this._packetProcess = packetProcess
|
||||
// console.log(' ',this._packetProcess)
|
||||
this.bus = bus_funcs
|
||||
// this.init = this.init.bind(this)
|
||||
}
|
||||
|
||||
async init(){
|
||||
this.amendSocketProcessing(bus_funcs)
|
||||
await super.init()
|
||||
}
|
||||
|
||||
|
@ -69,16 +79,14 @@ const validateArgs = function (packet) {
|
|||
}
|
||||
|
||||
if (missing.length > 0) {
|
||||
return {error: `following arguments are missing ${missing}`, packet: packet }
|
||||
return {error: `following bus arguments are missing ${missing}`, packet: packet }
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
const bus_funcs = {
|
||||
|
||||
scan: function () {
|
||||
// console.log(this)
|
||||
return pify(this.i2cbus.scan).bind(this.i2cbus)() },
|
||||
scan: function () { return pify(this.i2cbus.scan).bind(this.i2cbus)() },
|
||||
close: function () { return pify(this.i2cbus.close).bind(this.i2cbus)() },
|
||||
|
||||
readRaw: function (args) {
|
||||
|
|
Loading…
Reference in New Issue