[36]
APPENDIX C – TAP CHECKSUM CALCULATION
THE FOLLOWING IS THE VB .NET CODE THAT CREATES THE STRING TO BE SENT TO THE PAGING
ENCODER WITH THE CHECKSUM APPENDED TO IT:
‘Functions take any values given to them, execute their section of code, and return a value to the caller.
Public Function CreateTapMsg(ByVal PIN As String, ByVal Msg As String)
‘The PIN and Msg values are the Pager Families ID and the message needed to be sent respectively.
Dim Sum As Integer = 0, B As String, D As Integer
‘Variables needed for the code to execute
Dim char3 As Integer, char2 As Integer, char1 As Integer
‘The string that the checksum is calculated on:
Dim TAPMsgBlock As String = Chr(2) & PIN & Chr(13) & MSG & Chr(13) & Chr(3)
‘chr() converts integers to ASCII characters. Chr(2) = <STX> , Chr(3) = <ETX> , Chr(13) = <CR>
‘For loops define how many times and with what range of integers a section of code should be run at.
For j As Integer = 1 To Len(TAPMsgBlock)
‘Len() Function measures the size of strings
B = Mid(TAPMsgBlock, j, 1)
‘Mid() Function pulls parts of strings; in this case, each character individually
D = Asc(B)
‘Asc() Function converts characters to an ASCII decimal integer.
Sum += D
‘+= means take the current value and add to it. In this case, it adds the ASCII
Next
decimal integer value of each character in the entire message block.
‘Create the three characters’ ASCII decimal integer that represents this checksum. The ASCII decimal integers
are generated in reverse order but will be ordered correctly when put together.
char3 = 48 + Sum - Int(Sum / 16) * 16
‘Int() Function converts non-integer values to integers (ex: 4.2 to 4)
Sum = Int(Sum / 16)
char2 = 48 + Sum - Int(Sum / 16) * 16
Sum = Int(Sum / 16)
char1 = 48 + Sum - Int(Sum / 16) * 16
‘Convert the ASCII decimal integers to the actual character
Dim CheckSum As String = Chr(char1) & Chr(char2) & Chr(char3)
TAPMsgBlock = TAPMsgBlock & CheckSum & Chr(13)
'Create complete string to be sent
Return TAPMsgBlock
‘send the new formatted TAP Message Block to whatever called this function.
End Function
‘marks the end of the function’s section of code.