This commit is contained in:
Eugene Pankov
2021-07-11 22:59:39 +02:00
parent 37e564130e
commit ff18926bf9
28 changed files with 112 additions and 51 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "tabby-serial",
"version": "1.0.147-nightly.1",
"version": "1.0.147-nightly.2",
"description": "Serial connections for Tabby",
"keywords": [
"tabby-builtin-plugin"

View File

@@ -4,6 +4,7 @@ import { LogService, NotificationsService, Profile } from 'tabby-core'
import { Subject, Observable } from 'rxjs'
import { Injector, NgZone } from '@angular/core'
import { BaseSession, LoginScriptsOptions, StreamProcessingOptions, TerminalStreamProcessor } from 'tabby-terminal'
import { SerialService } from './services/serial.service'
export interface SerialProfile extends Profile {
options: SerialProfileOptions
@@ -38,9 +39,12 @@ export class SerialSession extends BaseSession {
private streamProcessor: TerminalStreamProcessor
private zone: NgZone
private notifications: NotificationsService
private serialService: SerialService
constructor (injector: Injector, public profile: SerialProfile) {
super(injector.get(LogService).create(`serial-${profile.options.port}`))
this.serialService = injector.get(SerialService)
this.zone = injector.get(NgZone)
this.notifications = injector.get(NotificationsService)
@@ -57,6 +61,10 @@ export class SerialSession extends BaseSession {
}
async start (): Promise<void> {
if (!this.profile.options.port) {
this.profile.options.port = (await this.serialService.listPorts())[0].name
}
this.serial = new SerialPort(this.profile.options.port, {
autoOpen: false,
baudRate: parseInt(this.profile.options.baudrate as any),

View File

@@ -3,7 +3,7 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
a(ngbNavLink) General
ng-template(ngbNavContent)
.row
.col-6
.col-6(ng:if='hostApp.platform !== Platform.Web')
.form-group
label Device
input.form-control(

View File

@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Component } from '@angular/core'
import { debounceTime, distinctUntilChanged, map } from 'rxjs'
import { ProfileSettingsComponent } from 'tabby-core'
import { HostAppService, Platform, ProfileSettingsComponent } from 'tabby-core'
import { SerialPortInfo, BAUD_RATES, SerialProfile } from '../api'
import { SerialService } from '../services/serial.service'
@@ -12,9 +12,11 @@ import { SerialService } from '../services/serial.service'
export class SerialProfileSettingsComponent implements ProfileSettingsComponent {
profile: SerialProfile
foundPorts: SerialPortInfo[]
Platform = Platform
constructor (
private serial: SerialService,
public hostApp: HostAppService,
) { }
portsAutocomplete = text$ => text$.pipe(map(() => {

View File

@@ -8,7 +8,7 @@
.mr-auto
button.btn.btn-sm.btn-link.mr-3((click)='changeBaudRate()', *ngIf='session && session.open')
button.btn.btn-sm.btn-link.mr-3((click)='changeBaudRate()', *ngIf='session && session.open && hostApp.platform !== Platform.Web')
span Change baud rate
button.btn.btn-sm.btn-link((click)='reconnect()', *ngIf='!session || !session.open')

View File

@@ -2,7 +2,7 @@
import colors from 'ansi-colors'
import { Component, Injector } from '@angular/core'
import { first } from 'rxjs'
import { SelectorService } from 'tabby-core'
import { Platform, SelectorService } from 'tabby-core'
import { BaseTerminalTabComponent } from 'tabby-terminal'
import { SerialSession, BAUD_RATES, SerialProfile } from '../api'
@@ -17,6 +17,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
profile?: SerialProfile
session: SerialSession|null = null
serialPort: any
Platform = Platform
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor (

View File

@@ -1,8 +1,9 @@
import slugify from 'slugify'
import SerialPort from 'serialport'
import WSABinding from 'serialport-binding-webserialapi'
import deepClone from 'clone-deep'
import { Injectable } from '@angular/core'
import { ProfileProvider, NewTabParameters, SelectorService } from 'tabby-core'
import { InputMode, NewlineMode } from 'tabby-terminal'
import { ProfileProvider, NewTabParameters, SelectorService, HostAppService, Platform } from 'tabby-core'
import { SerialProfileSettingsComponent } from './components/serialProfileSettings.component'
import { SerialTabComponent } from './components/serialTab.component'
import { SerialService } from './services/serial.service'
@@ -35,44 +36,43 @@ export class SerialProfilesService extends ProfileProvider {
constructor (
private selector: SelectorService,
private serial: SerialService,
) { super() }
private hostApp: HostAppService,
) {
super()
if (hostApp.platform === Platform.Web) {
SerialPort.Binding = WSABinding
}
}
async getBuiltinProfiles (): Promise<SerialProfile[]> {
if (this.hostApp.platform === Platform.Web) {
return [
{
id: `serial:web`,
type: 'serial',
name: 'Serial connection',
icon: 'fas fa-microchip',
isBuiltin: true,
} as SerialProfile,
]
}
return [
{
id: `serial:template`,
type: 'serial',
name: 'Serial connection',
icon: 'fas fa-microchip',
options: {
port: '',
databits: 8,
parity: 'none',
rtscts: false,
stopbits: 1,
xany: false,
xoff: false,
xon: false,
inputMode: 'local-echo' as InputMode,
outputMode: null,
inputNewlines: null,
outputNewlines: 'crlf' as NewlineMode,
},
isBuiltin: true,
isTemplate: true,
},
} as SerialProfile,
...(await this.serial.listPorts()).map(p => ({
id: `serial:port-${slugify(p.name).replace('.', '-')}`,
type: 'serial',
name: p.description ? `Serial: ${p.description}` : 'Serial',
icon: 'fas fa-microchip',
isBuiltin: true,
options: {
port: p.name,
inputMode: 'local-echo' as InputMode,
outputNewlines: 'crlf' as NewlineMode,
},
})),
} as SerialProfile)),
]
}

View File

@@ -2,6 +2,20 @@
# yarn lockfile v1
"@serialport/binding-abstract@^9.0.2":
version "9.0.7"
resolved "https://registry.yarnpkg.com/@serialport/binding-abstract/-/binding-abstract-9.0.7.tgz#d2c7ecea0f100bdf20187bfc0d34ba90f5504e1e"
integrity sha512-g1ncCMIG9rMsxo/28ObYmXZcHThlvtZygsCANmyMUuFS7SwXY4+PhcEnt2+ZcMkEDNRiOklT+ngtIVx5GGpt/A==
dependencies:
debug "^4.3.1"
"@serialport/stream@^9.0.2":
version "9.0.7"
resolved "https://registry.yarnpkg.com/@serialport/stream/-/stream-9.0.7.tgz#0bf023eb0233a714fcc5a86de09e381e466d9882"
integrity sha512-c/h7HPAeFiryD9iTGlaSvPqHFHSZ0NMQHxC4rcmKS2Vu3qJuEtkBdTLABwsMp7iWEiSnI4KC3s7bHapaXP06FQ==
dependencies:
debug "^4.3.1"
"@types/node@14.14.14":
version "14.14.14"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.14.tgz#f7fd5f3cc8521301119f63910f0fb965c7d761ae"
@@ -11,3 +25,23 @@ ansi-colors@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==
debug@^4.3.1:
version "4.3.2"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b"
integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==
dependencies:
ms "2.1.2"
ms@2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
serialport-binding-webserialapi@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/serialport-binding-webserialapi/-/serialport-binding-webserialapi-1.0.3.tgz#cf4348c075da2de8f6cf9936c0b95645f3ae657b"
integrity sha512-TS7dsvetVoTeiWlzpsT/akjtljiYPO56FoJWSFyJSoO/E8icYJ2neQ7CW5NW/sHZDnMqAxULyAny47UFhWz9oQ==
dependencies:
"@serialport/binding-abstract" "^9.0.2"
"@serialport/stream" "^9.0.2"