Message parsing and processing – Grass Valley Switcher Products User Manual
Page 28

28
Switcher Products — Protocols Manual
Section 1 — Tally Protocol
Message Parsing and Processing
Message code recognition and parsing can use the following algorithm:
messageCode = INVALID
lastChar = 0
bytesReceived = 0
dataConsistent = FALSE
repeat forever
currentChar = next byte on input stream
// message header – set up for new message
if (currentChar > 128 && currentChar == lastChar)
messageCode = currentChar >> 4 // message code is 4 MSBs
instance = currentChar & 0xF // instance is 4 LSBs
bytesReceived = 0
if (messageCode == UPDATE)
switch (instance) // instance is really update type
case INITIALIZE:
invalidateAllData
()
dataConsistent = FALSE
break
case DATA_CONSISTENT:
if ( allDataValid ())
dataConsistent = TRUE
processTally
()
break
end switch
// prevent tally processing while receiving tally updates
// but source name updates shouldn’t prevent tally calcs
else if (messageCode < SOURCE_NAME)
dataConsistent = FALSE
// assemble message starting with message code and instance ID
if (messageCode != INVALID)
messageBuffer[bytesReceived++] = currentChar
if (bytesReceived == messageLength (messageCode) + 1)
copyTally
(messageBuffer, messageCode, instance)
messageCode = INVALID // end of message
else
// waiting for valid message header - discard char
lastChar = currentChar
end repeat
onSerialTimeout
((76,800 / baudRate) * 100mS)
invalidateAllData
()
dataConsistent = FALSE