@@ -51,16 +51,25 @@ export class TSL3UDPSource extends TallyInput {
51
51
export class TSL3TCPSource extends TallyInput {
52
52
private server : any ;
53
53
constructor ( source : Source ) {
54
- source . reconnect = false ;
55
54
super ( source ) ;
56
55
57
- console . log ( source )
58
-
59
56
let port = source . data . port ;
60
57
61
58
UsePort ( port , this . source . id ) ;
59
+
62
60
this . server = net . createServer ( ( socket ) => {
63
61
socket . on ( 'data' , ( data ) => {
62
+ //split data up delimiter
63
+
64
+ var messages = [ ] ;
65
+ var len = data . length ;
66
+ var i = 0 ;
67
+ let chunkSize = 18 ;
68
+
69
+ while ( i < len ) {
70
+ messages . push ( data . slice ( i , i += chunkSize ) ) ;
71
+ }
72
+
64
73
function getBits ( byte ) {
65
74
let bits = [ ] ;
66
75
@@ -75,30 +84,37 @@ export class TSL3TCPSource extends TallyInput {
75
84
76
85
return bits ;
77
86
}
78
-
79
- //get the control byte
80
- let controlByte = data . readUInt8 ( 1 ) ;
81
- let bits = getBits ( controlByte ) ;
82
-
83
- //parse the data
84
- let address = data . readUInt8 ( 0 ) - 0x80 ;
85
- let brightness = bits [ 2 ] + bits [ 1 ] ;
86
- let tally4 = bits [ 4 ] ;
87
- let tally3 = bits [ 5 ] ;
88
- let tally2 = bits [ 6 ] ;
89
- let tally1 = bits [ 7 ] ;
90
-
91
- let label = data . toString ( 'utf8' , 2 , 1 ) ;
92
-
93
- const busses = [ ] ;
94
- if ( tally1 ) {
95
- busses . push ( "preview" ) ;
96
- }
97
- if ( tally2 ) {
98
- busses . push ( "program" ) ;
87
+
88
+ //parse each message
89
+ for ( let buf of messages ) {
90
+ //get the control byte
91
+ let controlByte = buf . readUInt8 ( 1 ) ;
92
+ let bits = getBits ( controlByte ) ;
93
+
94
+ //parse the data
95
+ let address = buf . readUInt8 ( 0 ) - 0x80 ;
96
+ let brightness = bits [ 2 ] + bits [ 1 ] ;
97
+ let tally4 = bits [ 4 ] ;
98
+ let tally3 = bits [ 5 ] ;
99
+ let tally2 = bits [ 6 ] ;
100
+ let tally1 = bits [ 7 ] ;
101
+
102
+ let label = buf . toString ( 'utf8' , 2 ) . trim ( ) ;
103
+
104
+ this . renameAddress ( address . toString ( ) , address . toString ( ) , label ) ;
105
+
106
+ const busses = [ ] ;
107
+ if ( tally1 ) {
108
+ busses . push ( "preview" ) ;
109
+ }
110
+ if ( tally2 ) {
111
+ busses . push ( "program" ) ;
112
+ }
113
+ //add support here for tally3 and tally4
114
+
115
+ this . setBussesForAddress ( address . toString ( ) , busses ) ;
116
+ this . sendIndividualTallyData ( address . toString ( ) , busses ) ;
99
117
}
100
- this . setBussesForAddress ( address . toString ( ) , busses ) ;
101
- this . sendTallyData ( ) ;
102
118
} ) ;
103
119
104
120
socket . on ( 'close' , ( ) => {
0 commit comments