From af7c0ce9ec927365d57e422e52bb4c5f7b953e97 Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Thu, 11 Oct 2018 17:44:50 +0100 Subject: [PATCH] feat: slot info command --- src/codes.ts | 2 ++ src/commands/index.ts | 1 + src/commands/slotInfo.ts | 58 ++++++++++++++++++++++++++++++++++++++++ src/enums.ts | 7 +++++ src/hyperdeck.ts | 19 +++++++++---- 5 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 src/commands/slotInfo.ts diff --git a/src/codes.ts b/src/codes.ts index 7244629..2a0c6db 100644 --- a/src/codes.ts +++ b/src/codes.ts @@ -24,6 +24,7 @@ export enum ErrorCode { export enum SynchronousCode { OK = 200, + SlotInfo = 202, DeviceInfo = 204, TransportInfo = 208, Notify = 209 @@ -31,6 +32,7 @@ export enum SynchronousCode { export enum AsynchronousCode { ConnectionInfo = 500, + SlotInfo = 502, TransportInfo = 508 } diff --git a/src/commands/index.ts b/src/commands/index.ts index 2d61a20..907b39b 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -4,5 +4,6 @@ export { ConnectionInfoResponse } from './connect' export * from './deviceInfo' export * from './notify' export * from './record' +export * from './slotInfo' export * from './stop' export * from './transportInfo' diff --git a/src/commands/slotInfo.ts b/src/commands/slotInfo.ts new file mode 100644 index 0000000..3b06891 --- /dev/null +++ b/src/commands/slotInfo.ts @@ -0,0 +1,58 @@ +import { SynchronousCode } from '../codes' +import { SlotId, VideoFormat, SlotStatus } from '../enums' +import { ResponseMessage, NamedMessage } from '../message' +import { AbstractCommandBase } from './abstractCommand' +import { parseIntIfDefined } from './util' + +export interface SlotInfoCommandResponse { + SlotId: SlotId + Status: SlotStatus + VolumeName: string + RecordingTime: number + VideoFormat: VideoFormat +} + +export class SlotInfoCommand extends AbstractCommandBase { + expectedResponseCode = SynchronousCode.SlotInfo + + deserialize (msg: ResponseMessage) { + const res: SlotInfoCommandResponse = { + SlotId: parseInt(msg.Params['slot id'], 10), + Status: msg.Params['status'] as SlotStatus, + VolumeName: msg.Params['volume name'], + RecordingTime: parseInt(msg.Params['recording time'], 10), + VideoFormat: msg.Params['video format'] as VideoFormat + } + return res + } + serialize () { + const res: NamedMessage = { + Name: 'slot info', + Params: {} + } + + return res + } +} + +export interface SlotInfoChangeResponse { + SlotId: SlotId + Status?: SlotStatus + VolumeName?: string + RecordingTime?: number + VideoFormat?: VideoFormat +} + +export class SlotInfoChange { + + deserialize (msg: ResponseMessage) { + const res: SlotInfoChangeResponse = { + SlotId: parseInt(msg.Params['slot id'], 10), + Status: msg.Params['status'] as SlotStatus, + VolumeName: msg.Params['volume name'], + RecordingTime: parseIntIfDefined(msg.Params['recording time']), + VideoFormat: msg.Params['video format'] as VideoFormat + } + return res + } +} diff --git a/src/enums.ts b/src/enums.ts index 0165167..ee219c3 100644 --- a/src/enums.ts +++ b/src/enums.ts @@ -14,6 +14,13 @@ export enum SlotId { SlotTwo = 2 } +export enum SlotStatus { + Empty = 'empty', + Mounting = 'mounting', + Error = 'error', + Mounted = 'mounted' +} + export enum VideoFormat { NTSC = 'NTSC', PAL = 'PAL', diff --git a/src/hyperdeck.ts b/src/hyperdeck.ts index fc51faa..4a16133 100644 --- a/src/hyperdeck.ts +++ b/src/hyperdeck.ts @@ -2,7 +2,7 @@ import { EventEmitter } from 'events' import { Socket } from 'net' import { ResponseCodeType, GetResponseCodeType, AsynchronousCode } from './codes' -import { AbstractCommand, TransportInfoChange } from './commands' +import { AbstractCommand, TransportInfoChange, SlotInfoChange } from './commands' import { ResponseMessage } from './message' import { DummyConnectCommand } from './commands/connect' import { parseResponse, buildMessageStr } from './parser' @@ -181,10 +181,19 @@ export class Hyperdeck extends EventEmitter { // Only received at startup, and handled by a command break case AsynchronousCode.TransportInfo: - const handler = new TransportInfoChange() - const r = handler.deserialize(msg) - this.emit('transportInfo', r) - break + { + const handler = new TransportInfoChange() + const r = handler.deserialize(msg) + this.emit('transportInfo', r) + break + } + case AsynchronousCode.SlotInfo: + { + const handler = new SlotInfoChange() + const r = handler.deserialize(msg) + this.emit('slotInfo', r) + break + } default: this._log('unknown async response:', msg) break