Skip to content

Commit

Permalink
feat: slot info command
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Oct 11, 2018
1 parent 83815ab commit af7c0ce
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export enum ErrorCode {

export enum SynchronousCode {
OK = 200,
SlotInfo = 202,
DeviceInfo = 204,
TransportInfo = 208,
Notify = 209
}

export enum AsynchronousCode {
ConnectionInfo = 500,
SlotInfo = 502,
TransportInfo = 508
}

Expand Down
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
58 changes: 58 additions & 0 deletions src/commands/slotInfo.ts
Original file line number Diff line number Diff line change
@@ -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<SlotInfoCommandResponse> {
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
}
}
7 changes: 7 additions & 0 deletions src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 14 additions & 5 deletions src/hyperdeck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit af7c0ce

Please sign in to comment.