-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransmitter.py
94 lines (79 loc) · 2.96 KB
/
Transmitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import logging
from time import sleep
from datetime import datetime
from config import config
# ===================
# Transmitter Classes
# ===================
# Generic representation of a Transmitter with a common interface
# Includes a common RDSBuffer class
# Specific implementations of both are expected by child classes
# Transmitter
# RDSBuffer
#
# QN8066 (Transmitter)
# PSBuffer (RDSBuffer)
# RTBuffer (RDSBuffer)
class Transmitter:
def __init__(self):
# Common class init
self.active = False
self.PStext = ''
self.RTtext = ''
def startup(self):
# Common elements for starting up the transmitter for broadcast
self.active = True
def update(self):
# For settings that can be updated dynamically
pass
def shutdown(self):
# Common elements for shutting down the transmitter from broadcast
self.active = False
def reset(self, resetdelay=1):
# Used to restart the transmitter
self.shutdown()
sleep(resetdelay)
self.startup()
def status(self):
# Expected to be defined by child class
pass
def updateRDSData(self, PSdata='', RTdata=''):
# Expected to be defined by child class
self.PStext = PSdata
self.RTtext = RTdata
def sendNextRDSGroup(self):
# Expected to be defined by child class
pass
# =============================================
# RDS Buffer Class (Inner class of Transmitter)
# =============================================
# This holds a string of RDS data to send, how much can be displayed at a time, how many chars per RDS group, and how long between updates
# Typically, two instances are created by a transmitter, one for the PS groups and one for the RT groups
# Data - Entire string to show on RDS Screen over time - updateData called once per track, resets all counters
# Fragment - What's on a single RDS Screen - Holds 8 for PS or 32/64 chars for RT - sendNextGroup tracks time to determine when to move to next fragment
# Group - Single RDS Data Packet - Holds 2 or 4 chars - sendNextGroup called multiple times per second
class RDSBuffer:
def __init__(self, data='', frag_size=0, group_size=0, delay=4):
logging.debug('RDSBuffer init')
self.frag_size = frag_size
self.group_size = group_size
self.delay = delay
self.pi_byte1 = int('0x' + config['DynRDSPICode'][0:2], 16)
self.pi_byte2 = int('0x' + config['DynRDSPICode'][2:4], 16)
self.pty = int(config['DynRDSPty'])
self.updateData(data)
self.fragments = []
self.currentFragment = 0
self.lastFragmentTime = 0
self.currentGroup = 0
def updateData(self, data):
logging.debug('RDSBuffer updateData')
self.fragments = []
self.currentFragment = 0
self.lastFragmentTime = datetime.now()
self.currentGroup = 0
for i in range(0, len(data), self.frag_size):
self.fragments.append(data[i : i + self.frag_size])
def sendNextGroup(self):
# Expected to be defined by child class
pass