Skip to content

Commit

Permalink
1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec committed Jun 3, 2024
1 parent da99710 commit 918a6be
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 39 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $ npm install -g ember-zli
$ ember-zli COMMAND
running command...
$ ember-zli (--version)
ember-zli/1.0.4 win32-x64 node-v20.10.0
ember-zli/1.0.5 win32-x64 node-v20.10.0
$ ember-zli --help [COMMAND]
USAGE
$ ember-zli COMMAND
Expand All @@ -71,10 +71,9 @@ Interact with the Gecko bootloader in the adapter via serial.

```
USAGE
$ ember-zli bootloader [-a] [-f <value>] [-r]
$ ember-zli bootloader [-f <value>] [-r]
FLAGS
-a, --ask Ask conf questions, even if conf file present (override file with new answers).
-f, --file=<value> Path to a firmware file. If not provided, will be set via interactive prompt when entering
relevant menu.
-r, --forceReset Try to force reset into bootloader.
Expand All @@ -86,7 +85,7 @@ EXAMPLES
$ ember-zli bootloader
```

_See code: [src/commands/bootloader/index.ts](https://github.com/Nerivec/ember-zli/blob/v1.0.4/src/commands/bootloader/index.ts)_
_See code: [src/commands/bootloader/index.ts](https://github.com/Nerivec/ember-zli/blob/v1.0.5/src/commands/bootloader/index.ts)_

## `ember-zli help [COMMAND]`

Expand Down Expand Up @@ -114,10 +113,7 @@ Interact with the EmberZNet stack in the adapter.

```
USAGE
$ ember-zli stack [-a]
FLAGS
-a, --ask Ask conf questions, even if conf file present (override file with new answers).
$ ember-zli stack
DESCRIPTION
Interact with the EmberZNet stack in the adapter.
Expand All @@ -126,7 +122,7 @@ EXAMPLES
$ ember-zli stack
```

_See code: [src/commands/stack/index.ts](https://github.com/Nerivec/ember-zli/blob/v1.0.4/src/commands/stack/index.ts)_
_See code: [src/commands/stack/index.ts](https://github.com/Nerivec/ember-zli/blob/v1.0.5/src/commands/stack/index.ts)_

## `ember-zli version`

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ember-zli",
"description": "Interact with EmberZNet-based adapters using zigbee-herdsman 'ember' driver",
"version": "1.0.4",
"version": "1.0.5",
"author": "Nerivec",
"bin": {
"ember-zli": "bin/run.js"
Expand All @@ -17,7 +17,7 @@
"cli-progress": "^3.12.0",
"crc-32": "^1.2.2",
"winston": "^3.13.0",
"zigbee-herdsman": "0.49.1"
"zigbee-herdsman": "0.49.2"
},
"devDependencies": {
"@oclif/prettier-config": "^0.2.1",
Expand Down
10 changes: 1 addition & 9 deletions src/commands/bootloader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { join } from 'node:path'

import { DATA_FOLDER, logger } from '../../index.js'
import { BootloaderEvent, BootloaderMenu, GeckoBootloader } from '../../utils/bootloader.js'
import { TCP_REGEX } from '../../utils/consts.js'
import { FirmwareSource, FirmwareValidation } from '../../utils/enums.js'
import { getPortConf } from '../../utils/port.js'
import { AdapterModel, FirmwareMetadata, FirmwareVersion } from '../../utils/types.js'
Expand Down Expand Up @@ -121,20 +120,13 @@ export default class Bootloader extends Command {
]

static override flags = {
ask: Flags.boolean({ char: 'a', description: 'Ask conf questions, even if conf file present (override file with new answers).' }),
file: Flags.file({ char: 'f', description: 'Path to a firmware file. If not provided, will be set via interactive prompt when entering relevant menu.', exists: true }),
forceReset: Flags.boolean({ char: 'r', default: false, description: 'Try to force reset into bootloader.' }),
}

public async run(): Promise<void> {
const {flags} = await this.parse(Bootloader)
const portConf = await getPortConf(!flags.ask)

if (TCP_REGEX.test(portConf.path)) {
logger.error(`Interacting with bootloader over TCP is not supported.`)
return this.exit(1)
}

const portConf = await getPortConf(true/* no TCP */)
logger.debug(`Using port conf: ${JSON.stringify(portConf)}`)

const adapterModelChoices: { name: string, value: AdapterModel | undefined }[] = [{ name: 'Not in this list', value: undefined }]
Expand Down
7 changes: 3 additions & 4 deletions src/commands/stack/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { checkbox, confirm, input, select } from '@inquirer/prompts'
import { Command, Flags } from '@oclif/core'
import { Command } from '@oclif/core'
import { Presets, SingleBar } from 'cli-progress'
import { existsSync, readFileSync, readdirSync, renameSync, writeFileSync } from 'node:fs'
import { dirname, extname, join } from 'node:path'
Expand Down Expand Up @@ -56,12 +56,11 @@ export default class Stack extends Command {
]

static override flags = {
ask: Flags.boolean({ char: 'a', description: 'Ask conf questions, even if conf file present (override file with new answers).' }),
}

public async run(): Promise<void> {
const {flags} = await this.parse(Stack)
const portConf = await getPortConf(!flags.ask)
// const {flags} = await this.parse(Stack)
const portConf = await getPortConf()
logger.debug(`Using port conf: ${JSON.stringify(portConf)}`)

let ezsp = await emberStart(this, portConf)
Expand Down
65 changes: 57 additions & 8 deletions src/utils/port.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
import { input, select } from '@inquirer/prompts'
import { readFileSync, writeFileSync } from 'node:fs'
import { confirm, input, select } from '@inquirer/prompts'
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
import { SerialPort } from 'zigbee-herdsman/dist/adapter/serialPort.js'

import { CONF_PORT_PATH, logger } from '../index.js'
import { BAUDRATES, TCP_REGEX } from './consts.js'
import { BaudRate, PortConf, PortType } from './types.js'

export const getPortConf = async(useFile: boolean = true): Promise<PortConf> => {
if (useFile) {
try {
const conf = readFileSync(CONF_PORT_PATH, 'utf8')
export const getPortConfFile = async (noTCP: boolean = false): Promise<PortConf | undefined> => {
if (!existsSync(CONF_PORT_PATH)) {
return undefined
}

const file = readFileSync(CONF_PORT_PATH, 'utf8')

const conf: PortConf = JSON.parse(file)

if (!conf.baudRate || !BAUDRATES.includes(conf.baudRate)) {
logger.error(`Cached config does not include a valid baudrate value.`)
return undefined
}

if (!conf.path) {
logger.error(`Cached config does not include a valid path value.`)
return undefined
}

if (TCP_REGEX.test(conf.path)) {
if (noTCP) {
throw new Error(`Interacting with bootloader over TCP is not supported.`)
}
} else {
const portList = await SerialPort.list()

if (portList.length === 0) {
throw new Error('No serial device found.')
}

return JSON.parse(conf)
} catch {}
if (!portList.some((p) => p.path === conf.path)) {
logger.error(`Cached config path does not match a currently connected serial device.`)
return undefined
}
}

if (conf.rtscts !== true && conf.rtscts !== false) {
logger.error(`Cached config does not include a valid rtscts value.`)
return undefined
}

return conf
}

export const getPortConf = async (noTCP: boolean = false): Promise<PortConf> => {
const portConfFile = await getPortConfFile(noTCP)

if (portConfFile !== undefined) {
const usePortConfFile = await confirm({
default: true,
message: `Baudrate: ${portConfFile.baudRate}, Path: ${portConfFile.path}, RTS/CTS: ${portConfFile.rtscts}. Use this config?`,
})

if (usePortConfFile) {
return portConfFile
}
}

const baudrateChoices = []
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xmodem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class XModemCRC extends EventEmitter {
if (this.waitForBlock !== this.blockNum) {
logger.warning(`Received out of sequence data: ${recdData.toString('hex')} (blockNum=${this.blockNum}, expected=${this.waitForBlock}).`, NS)
this.retries--

if (this.retries === 0) {
logger.error(`Maximum retries ${MAX_RETRIES} reached. Giving up.`, NS)
this.emit(XEvent.STOP, XExitStatus.FAIL)
Expand Down

0 comments on commit 918a6be

Please sign in to comment.