changed named pipe default name processing

master
David Kebler 2018-03-04 15:11:54 -08:00
parent 8bd22e4023
commit d22e3ad785
7 changed files with 21 additions and 71 deletions

View File

@ -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' 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 () => { (async () => {
let i2cbus = new Bus({id:'i2c-bus'}) let i2cbus = new Bus({id:'i2c-bus',tcp:true})
await i2cbus.init() await i2cbus.init()

View File

@ -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)) const delay = time => new Promise(res=>setTimeout(()=>res(),time))
; ;

View File

@ -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)) const delay = time => new Promise(res=>setTimeout(()=>res(),time))
; ;

View File

@ -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)
})

View File

@ -2,13 +2,13 @@
* A tcp customer/client to talk with the i2c bus and scan the bus for devices * A tcp customer/client to talk with the i2c bus and scan the bus for devices
* *
*/ */
import Base from '../../uci-base/src/base' import Base from '@uci/base'
const HOST = 'sbc' // const HOST = ''
const delay = time => new Promise(res=>setTimeout(()=>res(),time)) const delay = time => new Promise(res=>setTimeout(()=>res(),time))
; ;
(async () => { (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) { scanner.reply = function (packet) {
let addresses = packet.response.map(device => { let addresses = packet.response.map(device => {

View File

@ -4,9 +4,11 @@
"description": "I2c Bus Classes for Communication to I2C bus via socket or direct call", "description": "I2c Bus Classes for Communication to I2C bus via socket or direct call",
"main": "src/bus-packet.mjs", "main": "src/bus-packet.mjs",
"scripts": { "scripts": {
"busa": "node_modules/.bin/nodemon --require @std/esm --watch ../ examples/bus", "irelay": "node --require @std/esm examples/ipc-relay",
"bus": "SOCKET_DIR=/opt/sockets node_modules/.bin/nodemon --require @std/esm examples/bus", "iscan": "node --require @std/esm examples/ipc-scan || true",
"busl": "DEBUG=true SOCKETS_DIR=/opt/sockets node_modules/.bin/nodemon --require @std/esm examples/bus", "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", "test": "mocha -r @std/esm test/*.test.mjs",
"testw": "mocha -r @std/esm test/*.test.mjs --watch --recurse --watch-extensions 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" "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", "homepage": "https://github.com/uCOMmandIt/i2c#readme",
"@std/esm": "cjs", "@std/esm": "cjs",
"optionalDependencies": {
"i2c-bus": "^1.x"
},
"dependencies": { "dependencies": {
"@uci/base": "^0.1.0", "@uci/base": "^0.1.0",
"@uci/logger": "0.0.1",
"better-try-catch": "^0.6.2", "better-try-catch": "^0.6.2",
"i2c-bus": "^1.x",
"pify": "^3.0.0" "pify": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {

View File

@ -3,9 +3,7 @@ import i2c from 'i2c-bus'
import pify from 'pify' import pify from 'pify'
import btc from 'better-try-catch' import btc from 'better-try-catch'
import Base from '@uci/base' import Base from '@uci/base'
// import Base from '../../uci-base/src/base'
// import logger from '../../uci-logger/src/logger'
import logger from '@uci/logger' import logger from '@uci/logger'
let log = {} let log = {}
const LOG_OPTS = { const LOG_OPTS = {
@ -21,7 +19,7 @@ export default class Bus extends Base {
constructor(opts) { constructor(opts) {
log = logger.child(LOG_OPTS) log = logger.child(LOG_OPTS)
if (opts.path) opts.ns ={path:opts.path} 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' opts.sockets = (opts.sockets ? (opts.sockets+',') : '') + 'ns#s>n'
if(opts.tcp) { if(opts.tcp) {
if (typeof opts.tcp==='number') opts.ts ={port:opts.tcp} if (typeof opts.tcp==='number') opts.ts ={port:opts.tcp}