-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial support for Snell Kahuna K360 Tally #589
Draft
peternewman
wants to merge
2
commits into
josephdadams:master
Choose a base branch
from
peternewman:snell-k360
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { logger } from ".."; | ||
import { RegisterTallyInput } from "../_decorators/RegisterTallyInput.decorator"; | ||
import { FreePort, UsePort } from "../_decorators/UsesPort.decorator"; | ||
import { Source } from '../_models/Source'; | ||
import { TallyInputConfigField } from "../_types/TallyInputConfigField"; | ||
import { TallyInput } from './_Source'; | ||
import packet from 'packet'; | ||
import net from "net"; | ||
import dgram from "dgram"; | ||
import { jspack } from "jspack"; | ||
import hexdump from 'hexdump-nodejs'; | ||
|
||
@RegisterTallyInput("59a3c890", "Snell K360", "Uses port 50009 or 50001? normally", [ | ||
{ fieldName: 'ip', fieldLabel: 'IP Address', fieldType: 'text' }, | ||
{ fieldName: 'port', fieldLabel: 'Port', fieldType: 'port' }, | ||
]) | ||
export class SnellK360Source extends TallyInput { | ||
private client: any; | ||
private port: number; // AnalogWay Livecore TCP port number | ||
private last_heartbeat: number; | ||
// private tallydata_snellk360: any[] = []; | ||
private heartbeat_interval: NodeJS.Timer; | ||
constructor(source: Source) { | ||
super(source); | ||
this.port = source.data.port; | ||
|
||
this.client = new net.Socket(); | ||
|
||
let parser = packet.createParser(); | ||
// parser.packet('k360', "b8 => type, b16 => zero1, b8 => unknown1, b8 => unknown2, b8 => me, b16 => address, b32 => tally, b8[12]{0}z|str('ascii') => label"); | ||
parser.packet('k360', "b8 => command, b16 => zero1, b8 => direction, b8 => type, b8 => me, b16 => address, b8{b1 => tally8, b1 => tally7, b1 => tally6, b1 => tally5, b1 => tally4, b1 => tally3, b1 => tally2, b1 => tally1}, b8 => maybetally1, b8 => maybetally2, b8 => maybetally3, b8[12]{0}z|str('ascii') => label"); | ||
|
||
this.client.on('connect', () => { | ||
this.connected.next(true); | ||
|
||
this.last_heartbeat = Date.now(); | ||
this.heartbeat_interval = setInterval(() => { | ||
if (Date.now() - this.last_heartbeat > 5000) { | ||
clearInterval(this.heartbeat_interval); | ||
logger(`Source: ${source.name} Snell K360 connection heartbeat timed out`, 'error'); | ||
// this.client.end(); | ||
// this.client.destroy(); | ||
// this.connected.next(false); | ||
} | ||
}, 1000); | ||
}); | ||
|
||
this.client.on('data', (data) => { | ||
logger(`Source: ${source.name} Snell K360 data received ${data.length} bytes.`, 'info-quiet'); | ||
// logger('\n' + hexdump(data), 'info-quiet'); | ||
parser.extract('k360', (result) => { | ||
this.last_heartbeat = Date.now(); | ||
if (result.command == 241) { | ||
logger(`Got "${result.label}" AKA ${result.address} on ME ${result.me} of direction ${result.direction} and type ${result.type}`, 'info-quiet'); | ||
|
||
if (result.zero1 != 0) { | ||
logger(`Got non-zero zero1`, 'info-quiet'); | ||
logger(hexdump(data), 'info-quiet'); | ||
} | ||
|
||
if (result.direction == 0 && result.type == 1) { | ||
this.addAddress(result.label, result.address); | ||
|
||
const busses = []; | ||
if (result.tally8) { | ||
busses.push("program"); | ||
} | ||
if (result.tally7) { | ||
busses.push("preview"); | ||
} | ||
// TODO: Handle MEs/Stores etc? | ||
this.setBussesForAddress(result.address, busses); | ||
|
||
this.sendTallyData(); | ||
} | ||
} else { | ||
logger(`Got unexpected command ${result.command}`, 'info-quiet'); | ||
logger(hexdump(data), 'info-quiet'); | ||
} | ||
// logger(`Remaining buffer size ${data.length}`, 'info-quiet'); | ||
}); | ||
|
||
parser.parse(data); | ||
}); | ||
|
||
this.client.on('close', () => { | ||
this.connected.next(false); | ||
}); | ||
|
||
this.client.on('error', (error) => { | ||
logger(`Source: ${source.name} Snell K360 Connection Error occurred: ${error}`, 'error'); | ||
}); | ||
|
||
this.connect(); | ||
} | ||
|
||
|
||
private connect(): void { | ||
this.client.connect(this.port, this.source.data.ip); | ||
} | ||
|
||
|
||
public reconnect(): void { | ||
this.connect(); | ||
} | ||
|
||
|
||
public exit(): void { | ||
super.exit(); | ||
clearInterval(this.heartbeat_interval); | ||
this.client.end(); | ||
this.client.destroy(); | ||
this.connected.next(false); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this from the AnalogWayLivecore but I see there's also some more central/higher level stuff done too so maybe this isn't required...