Created
May 21, 2013 12:16
-
-
Save anthonyeden/5619384 to your computer and use it in GitHub Desktop.
RDS Decoder Psudocode (See: http://mediarealm.com.au/articles/2013/05/parsing-rds-group-data-with-pira-p175-and-python/ for more details and explanation of what's happening)
This file contains hidden or 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
| while True: | |
| line = ser.readline() | |
| if (line.find("-") < 0) and (line.__len__() > 16): | |
| hexdata = line.rstrip() | |
| #We need five bits to detect the group type, so turn it into binary: | |
| binaryLine = bin(int(hexdata, 16))[2:].zfill(64) | |
| #RadioText-A: | |
| if binaryLine[16:21] == "00100": | |
| #current RadioText-A Start Position: | |
| position = int(bin(int(hexdata[7:8], 16))[2:].zfill(4), 2) | |
| text[position * 4] = hexdata[8:].decode('hex')[:1] | |
| text[position * 4 + 1] = hexdata[8:].decode('hex')[1:2] | |
| text[position * 4 + 2] = hexdata[8:].decode('hex')[2:3] | |
| text[position * 4 + 3] = hexdata[8:].decode('hex')[3:4] | |
| # PS (Name of the station): | |
| elif binaryLine[16:21] == "00000": | |
| #work out the starting position for this group's PS | |
| psPos = int(bin(int(hexdata[7:8], 16))[2:].zfill(2)[2:4], 2) | |
| ps[psPos * 2] = hexdata[8:].decode('hex')[2:3] | |
| ps[psPos * 2 + 1] = hexdata[8:].decode('hex')[3:4] | |
| print text | |
| print ps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment