August 21, 2020 at 3:06 pm #251723ParticipantTopics: 1Replies: 1Points: 16Rank: Member
Here is a strange one. It’s been driving me nuts for a day or so. I’m trying to write an interface for a paging terminal that accepts message in TAP format. Part of the message string includes a 7 bit checksum. A nice explenation is located here: https://everything2.com/title/Telocator+Alphanumeric+Protocol
The only part giving me grief is the checksum. I’ve duplicated their example and the result is never correct. I’m probably missing something stupid. I’ve search all over and so far no one seems to have done this in PowerShell.
The process is pretty simple, take a line of text, do a 7 bit binary conversion, convert that to a decimal value, add it together and get a sum. Take that sum and convert it into a 3 character checksum. This is all outlined in the previously noted link and in the protocol specification here: https://www.telemessage.com/developer/wp-content/uploads/2014/11/TAP-1.8.pdf
Here is the part of the code giving me issues. I broke it out into just the checksum code:PowerShell12345678910111213141516$sum = 379Write-Host “The sum is:” $sum -ForegroundColor cyanWrite-host ‘The checksum should be “17;”‘`n$sum = [int]$sum$d3 = 48 + $sum – ([int]($sum / 16)) * 16$sum = [int]($sum / 16)write-host “sum = $sum d3 = $d3”$d2 = 48 + $sum – ([int]($sum / 16)) * 16$sum = [int]($sum / 16)write-host “sum = $sum d2 = $d2”$d1 = 48 + $sum – ([int]($sum / 16)) * 16write-host “sum = $sum d1 = $d1”write-host ” : $d1 $d2 $d3″$checksum =[string]([CHAR]$d1)+[string]([char]$d2)+[string]([char]$d3)write-host “Checksum : ” -ForegroundColor Yellow -NoNewlineWrite-host $checksum -ForegroundColor CyanThe “sum” is taken from their example, 379. That should produce a checksum value of “17;”. By juggling the formulas I get a lot of different things, mostly “2(+”, which seems to be what it wants to produce. Any thoughts or suggestions will be appreciated.I’m using Windows 10 with PS v 7.0.3.
August 22, 2020 at 7:58 am #251861ParticipantTopics: 0Replies: 15Points: 203Rank: Participant
The notes for the example BASIC program explain the behaviour expected from using INT – ‘returns the integer portion of a number’. Using [int] in PowerShell leads to the result being rounded. Use [math]::truncate to achieve the result you need. I was able to obtain the correct checksum using this method.
- This reply was modified 2 months ago by Stuart Squibb.
August 24, 2020 at 6:24 pm #252227ParticipantTopics: 1Replies: 1Points: 16Rank: Member
I’ll give that a try as soon as I can get back to fighting that particular fire…
- You must be logged in to reply to this topic.