Skip to content

Commit

Permalink
feat: update for protocol v1.11 (firmware V7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Feb 14, 2021
1 parent 1b08a8e commit 680b3ea
Show file tree
Hide file tree
Showing 14 changed files with 467 additions and 7 deletions.
19 changes: 19 additions & 0 deletions src/asyncHandlers/displayTimecode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ResponseMessage } from '../message'
import { IHandler } from './iHandler'
import { AsynchronousCode } from '../codes'

export interface DisplayTimecodeChangeResponse {
displayTimecode: string
}

export class DisplayTimecodeChange implements IHandler {
responseCode = AsynchronousCode.DisplayTimecode
eventName = 'notify.displayTimecode'

deserialize(msg: ResponseMessage): DisplayTimecodeChangeResponse {
const res: DisplayTimecodeChangeResponse = {
displayTimecode: msg.params['display timecode'],
}
return res
}
}
19 changes: 19 additions & 0 deletions src/asyncHandlers/timelinePosition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ResponseMessage } from '../message'
import { IHandler } from './iHandler'
import { AsynchronousCode } from '../codes'

export interface TimelinePositionChangeResponse {
timelinePosition: string
}

export class TimelinePositionChange implements IHandler {
responseCode = AsynchronousCode.TimelinePosition
eventName = 'notify.timelinePosition'

deserialize(msg: ResponseMessage): TimelinePositionChangeResponse {
const res: TimelinePositionChangeResponse = {
timelinePosition: msg.params['timeline position'],
}
return res
}
}
8 changes: 8 additions & 0 deletions src/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,24 @@ export enum SynchronousCode {
OK = 200,
SlotInfo = 202,
DeviceInfo = 204,
ClipsGet = 205,
DiskList = 206,
TransportInfo = 208,
Notify = 209,
FormatReady = 216,
PlayOnStartup = 218,
Playrange = 219,
PlayOption = 220,
CacheInfo = 221,
DynamicRange = 222,
}

export enum AsynchronousCode {
ConnectionInfo = 500,
SlotInfo = 502,
TransportInfo = 508,
DisplayTimecode = 513,
TimelinePosition = 514,
}

export enum ResponseCodeType {
Expand Down
31 changes: 31 additions & 0 deletions src/commands/cacheInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { SynchronousCode } from '../codes'
import { ResponseMessage, NamedMessage } from '../message'
import { AbstractCommand } from './abstractCommand'

export interface CacheInfoCommandResponse {
status: string
transferringSlotId: number
recordingTime: number
}

export class CacheInfoGetCommand extends AbstractCommand {
expectedResponseCode = SynchronousCode.CacheInfo

deserialize(msg: ResponseMessage): CacheInfoCommandResponse {
const res: CacheInfoCommandResponse = {
status: msg.params['status'],
transferringSlotId: parseInt(msg.params['transferring slot id']),
recordingTime: parseInt(msg.params['recording time']),
}
return res
}

serialize(): NamedMessage {
const res: NamedMessage = {
name: 'cache info',
params: {},
}

return res
}
}
103 changes: 103 additions & 0 deletions src/commands/clips.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { SynchronousCode } from '../codes'
import { NamedMessage, ResponseMessage } from '../message'
import { AbstractCommand, AbstractCommandNoResponse } from './abstractCommand'

export interface Clip {
clipId: string
name: string
startTime: string
duration: string
in?: string
out?: string
}
export interface ClipsGetCommandResponse {
clipCount: number
clips: Clip[]
}

export class ClipsGetCommand extends AbstractCommand {
expectedResponseCode = SynchronousCode.ClipsGet

constructor(public clip?: number, public count?: number, public readonly version?: 1 | 2) {
super()
}

deserialize(msg: ResponseMessage): ClipsGetCommandResponse {
const clipIds = Object.keys(msg.params).filter((x) => x !== 'clip count')
const clips = clipIds.map<Clip>((x) => {
if (this.version === 2) {
return {
clipId: x,
name: msg.params[x].substr(48),
startTime: msg.params[x].substr(0, 11),
duration: msg.params[x].substr(12, 11),
in: msg.params[x].substr(24, 11),
out: msg.params[x].substr(35, 11),
}
} else {
// v1
return {
clipId: x,
name: msg.params[x].slice(0, -24),
startTime: msg.params[x].substr(-23, 11),
duration: msg.params[x].substr(-11, 11),
}
}
})

const res: ClipsGetCommandResponse = {
clipCount: parseInt(msg.params['clip count'], 10),
clips,
}

return res
}
serialize(): NamedMessage {
const res: NamedMessage = {
name: 'clips get',
params: {},
}

if (this.clip !== undefined) res.params['clip id'] = this.clip + ''
if (this.count !== undefined) res.params['count'] = this.count + ''
if (this.version !== undefined) res.params['version'] = this.version + ''

return res
}
}

export class ClipsAddCommand extends AbstractCommandNoResponse {
constructor(public name: string, public clip?: string, public inPoint?: string, public outPoint?: string) {
super()
}

serialize(): NamedMessage {
const res: NamedMessage = {
name: 'clips add',
params: {
name: this.name,
},
}

if (this.clip) res.params['clip'] = this.clip
if (this.inPoint) res.params['inPoint'] = this.inPoint
if (this.outPoint) res.params['outPoint'] = this.outPoint

return res
}
}

export class ClipsClearCommand extends AbstractCommandNoResponse {
constructor() {
super()
}

serialize(): NamedMessage {
const res: NamedMessage = {
name: 'clips clear',
params: {},
}

return res
}
}
45 changes: 45 additions & 0 deletions src/commands/dynamicRange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { SynchronousCode } from '../codes'
import { ResponseMessage, NamedMessage } from '../message'
import { AbstractCommand, AbstractCommandNoResponse } from './abstractCommand'
import { DynamicRange } from '../enums'

export interface DynamicRangeCommandResponse {
playbackOverride: DynamicRange
}

export class DynamicRangeGetCommand extends AbstractCommand {
expectedResponseCode = SynchronousCode.DynamicRange

deserialize(msg: ResponseMessage): DynamicRangeCommandResponse {
const res: DynamicRangeCommandResponse = {
playbackOverride: msg.params['playback override'] as DynamicRange,
}
return res
}

serialize(): NamedMessage {
const res: NamedMessage = {
name: 'dynamic range',
params: {},
}

return res
}
}

export class DynamicRangeSetCommand extends AbstractCommandNoResponse {
constructor(public override: DynamicRange) {
super()
}

serialize(): NamedMessage {
const res: NamedMessage = {
name: 'dynamic range',
params: {
'playback override': this.override,
},
}

return res
}
}
25 changes: 25 additions & 0 deletions src/commands/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export interface NotifyCommandResponse {
slot: boolean
configuration: boolean
droppedFrames: boolean
// v1.11 onwards:
displayTimecode?: boolean
timelinePosition?: boolean
playrange?: boolean
cache?: boolean
dynamicRange?: boolean
}

export class NotifyGetCommand extends AbstractCommand {
Expand All @@ -22,6 +28,13 @@ export class NotifyGetCommand extends AbstractCommand {
configuration: msg.params['configuration'] === 'true',
droppedFrames: msg.params['dropped frames'] === 'true',
}

if (msg.params['display timecode']) res.displayTimecode = msg.params['display timecode'] === 'true'
if (msg.params['timeline position']) res.timelinePosition = msg.params['timeline position'] === 'true'
if (msg.params['playrange']) res.playrange = msg.params['playrange'] === 'true'
if (msg.params['cache']) res.cache = msg.params['cache'] === 'true'
if (msg.params['dynamic range']) res.dynamicRange = msg.params['dynamic range'] === 'true'

return res
}
serialize(): NamedMessage {
Expand All @@ -40,6 +53,12 @@ export class NotifySetCommand extends AbstractCommandNoResponse {
slot?: boolean
configuration?: boolean
droppedFrames?: boolean
// v1.11 onwards
displayTimecode?: boolean
timelinePosition?: boolean
playrange?: boolean
cache?: boolean
dynamicRange?: boolean

serialize(): NamedMessage {
const res: NamedMessage = {
Expand All @@ -53,6 +72,12 @@ export class NotifySetCommand extends AbstractCommandNoResponse {
SetBoolIfDefined(res, 'configuration', this.configuration)
SetBoolIfDefined(res, 'dropped frames', this.droppedFrames)

SetBoolIfDefined(res, 'display timecode', this.displayTimecode)
SetBoolIfDefined(res, 'timeline position', this.timelinePosition)
SetBoolIfDefined(res, 'playrange', this.playrange)
SetBoolIfDefined(res, 'cache', this.cache)
SetBoolIfDefined(res, 'dynamic range', this.dynamicRange)

return res
}
}
45 changes: 45 additions & 0 deletions src/commands/playOnStartup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { SynchronousCode } from '../codes'
import { NamedMessage, ResponseMessage } from '../message'
import { AbstractCommand, AbstractCommandNoResponse } from './abstractCommand'

export interface PlayOnStartupCommandResponse {
enable: boolean
singleClip: boolean
}

export class PlayOnStartupGetCommand extends AbstractCommand {
expectedResponseCode = SynchronousCode.Playrange

deserialize(msg: ResponseMessage): PlayOnStartupCommandResponse {
const res: PlayOnStartupCommandResponse = {
enable: msg.params['enable'] === 'true',
singleClip: msg.params['single clip'] === 'true',
}
return res
}
serialize(): NamedMessage {
const res: NamedMessage = {
name: 'play on startup',
params: {},
}

return res
}
}

export class PlayOnStartupSetCommand extends AbstractCommandNoResponse {
enable?: boolean
singleClip?: boolean

serialize(): NamedMessage {
const res: NamedMessage = {
name: 'playrange set',
params: {},
}

if (this.enable !== false) res.params['enable'] = this.enable + ''
if (this.singleClip !== false) res.params['single clip'] = this.singleClip + ''

return res
}
}
43 changes: 43 additions & 0 deletions src/commands/playOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { SynchronousCode } from '../codes'
import { NamedMessage, ResponseMessage } from '../message'
import { AbstractCommand, AbstractCommandNoResponse } from './abstractCommand'

export interface PlayOptionCommandResponse {
stopMode: 'lastframe' | 'nextframe' | 'black'
}

export class PlayOptionGetCommand extends AbstractCommand {
expectedResponseCode = SynchronousCode.PlayOption

deserialize(msg: ResponseMessage): PlayOptionCommandResponse {
const res: PlayOptionCommandResponse = {
stopMode: msg.params['stop mode'] as PlayOptionCommandResponse['stopMode'],
}
return res
}
serialize(): NamedMessage {
const res: NamedMessage = {
name: 'play option',
params: {},
}

return res
}
}

export class PlayOptionSetCommand extends AbstractCommandNoResponse {
constructor(public stopMode: 'lastframe' | 'nextframe' | 'black') {
super()
}

serialize(): NamedMessage {
const res: NamedMessage = {
name: 'play option',
params: {},
}

if (this.stopMode !== undefined) res.params['stop mode'] = this.stopMode

return res
}
}
Loading

0 comments on commit 680b3ea

Please sign in to comment.