changed named pipe default name processing
parent
8bd22e4023
commit
d22e3ad785
|
@ -1,14 +1,14 @@
|
|||
/*
|
||||
* i2c bus with both unix and tcp socket using defaults. For TCP that is host OS name and port 8080
|
||||
* Basic i2c bus listening at 1776 (by default when tcp:true) and also named pipe
|
||||
*
|
||||
*/
|
||||
import Bus from '../src/bus-packet'
|
||||
// const PATH = ''
|
||||
|
||||
// can use SOCKETS_DIR='' env variable to get a 'i2c-bus.sock' in the given environment variable path
|
||||
// SOCKETS_DIR=/opt/sockets node -r @std/esm i2cbus
|
||||
;
|
||||
(async () => {
|
||||
|
||||
let i2cbus = new Bus({id:'i2c-bus'})
|
||||
let i2cbus = new Bus({id:'i2c-bus',tcp:true})
|
||||
|
||||
await i2cbus.init()
|
||||
|
||||
|
|
|
@ -3,10 +3,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
const PATH = '/opt/sockets/i2c-bus.sock'
|
||||
const PATH = 'i2c-bus'
|
||||
|
||||
import Base from '../../uci-base/src/base'
|
||||
// import Base from '@uci/base'
|
||||
import Base from '@uci/base'
|
||||
|
||||
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
||||
;
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
import Base from '../../uci-base/src/base'
|
||||
import Base from '@uci/base'
|
||||
|
||||
const PATH = '/opt/sockets/i2c-bus.sock'
|
||||
const PATH = 'i2c-bus'
|
||||
|
||||
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
||||
;
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* A tcp customer/client to talk with the i2c bus and scan the bus for devices
|
||||
*
|
||||
*/
|
||||
|
||||
const HOST = 'sbc'
|
||||
|
||||
import Base from '../../uci-base/src/base'
|
||||
// import Base from '@uci/base'
|
||||
|
||||
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
||||
;
|
||||
(async () => {
|
||||
|
||||
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)
|
||||
console.log(`response from relays for ${packet.cmd_sent}:`,packet.args, `was ${packet.response}`)
|
||||
}
|
||||
await relays.init()
|
||||
console.log('=============sending============')
|
||||
let packet = {cmd:'read', args:{address:39 ,cmd: 0} }
|
||||
console.dir(packet)
|
||||
await relays.send(packet)
|
||||
packet = {cmd:'write', args:{address:39,cmd: 0, byte:0} }
|
||||
console.dir(packet)
|
||||
await relays.send(packet)
|
||||
packet = {cmd:'read', args:{address:39 ,cmd:0} }
|
||||
console.dir(packet)
|
||||
await relays.send(packet)
|
||||
packet = {cmd:'write', args:{address:39,cmd: 9, byte:255} }
|
||||
console.dir(packet)
|
||||
await relays.send(packet)
|
||||
packet = {cmd:'read', args:{address:39 ,cmd:9} }
|
||||
console.dir(packet)
|
||||
await relays.send(packet)
|
||||
await delay(1000)
|
||||
packet = {cmd:'write', args:{address:39,cmd: 9, byte:0} }
|
||||
console.dir(packet)
|
||||
await relays.send(packet)
|
||||
packet = {cmd:'read', args:{address:39 ,cmd:9} }
|
||||
console.dir(packet)
|
||||
await relays.send(packet)
|
||||
|
||||
await delay(1000)
|
||||
process.kill(process.pid, 'SIGTERM')
|
||||
|
||||
|
||||
})().catch(err => {
|
||||
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
||||
})
|
|
@ -2,13 +2,13 @@
|
|||
* A tcp customer/client to talk with the i2c bus and scan the bus for devices
|
||||
*
|
||||
*/
|
||||
import Base from '../../uci-base/src/base'
|
||||
const HOST = 'sbc'
|
||||
import Base from '@uci/base'
|
||||
// const HOST = ''
|
||||
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
||||
;
|
||||
(async () => {
|
||||
|
||||
let scanner = new Base({id:'tcp-i2c-client', sockets:'tc#c>t', tc:{port: 1776, host:HOST}})
|
||||
let scanner = new Base({id:'tcp-i2c-client', sockets:'tc#c>t', tc:{port: 1776}})
|
||||
|
||||
scanner.reply = function (packet) {
|
||||
let addresses = packet.response.map(device => {
|
||||
|
|
13
package.json
13
package.json
|
@ -4,9 +4,11 @@
|
|||
"description": "I2c Bus Classes for Communication to I2C bus via socket or direct call",
|
||||
"main": "src/bus-packet.mjs",
|
||||
"scripts": {
|
||||
"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",
|
||||
"irelay": "node --require @std/esm examples/ipc-relay",
|
||||
"iscan": "node --require @std/esm examples/ipc-scan || true",
|
||||
"tscan": "node --require @std/esm examples/tcp-scan || true",
|
||||
"bus": "node --require @std/esm examples/bus",
|
||||
"busl": "DEBUG=true node --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"
|
||||
|
@ -28,10 +30,13 @@
|
|||
},
|
||||
"homepage": "https://github.com/uCOMmandIt/i2c#readme",
|
||||
"@std/esm": "cjs",
|
||||
"optionalDependencies": {
|
||||
"i2c-bus": "^1.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uci/base": "^0.1.0",
|
||||
"@uci/logger": "0.0.1",
|
||||
"better-try-catch": "^0.6.2",
|
||||
"i2c-bus": "^1.x",
|
||||
"pify": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -3,9 +3,7 @@ import i2c from 'i2c-bus'
|
|||
import pify from 'pify'
|
||||
import btc from 'better-try-catch'
|
||||
import Base from '@uci/base'
|
||||
// import Base from '../../uci-base/src/base'
|
||||
|
||||
// import logger from '../../uci-logger/src/logger'
|
||||
import logger from '@uci/logger'
|
||||
let log = {}
|
||||
const LOG_OPTS = {
|
||||
|
@ -21,7 +19,7 @@ export default class Bus extends Base {
|
|||
constructor(opts) {
|
||||
log = logger.child(LOG_OPTS)
|
||||
if (opts.path) opts.ns ={path:opts.path}
|
||||
if(!opts.ns) opts.ns = {path: (process.env.SOCKETS_DIR || __dirname) + '/i2c-bus.sock'}
|
||||
if(!opts.ns) opts.ns = {path:'i2c-bus'}
|
||||
opts.sockets = (opts.sockets ? (opts.sockets+',') : '') + 'ns#s>n'
|
||||
if(opts.tcp) {
|
||||
if (typeof opts.tcp==='number') opts.ts ={port:opts.tcp}
|
||||
|
|
Loading…
Reference in New Issue