Skip to content

Instantly share code, notes, and snippets.

@arnaudmorin
Created April 10, 2025 21:46
Show Gist options
  • Save arnaudmorin/7d47d9b9a4412745ecb3afaaf35aea12 to your computer and use it in GitHub Desktop.
Save arnaudmorin/7d47d9b9a4412745ecb3afaaf35aea12 to your computer and use it in GitHub Desktop.
rh plugin auto freqs
import json
import logging
from eventmanager import Evt
#
# @author Arnaud Morin <[email protected]>
#
class GFPVAutoFreqs():
"""This class handles update of RH nodes freqs"""
version = "0.1.0"
def __init__(self, rhapi):
self.logger = logging.getLogger(__name__)
self.racecontext = rhapi._racecontext
def callback(self, args):
# TODO build freqs with real args
# Fake payload for debug now
payload = {
"b": ['R', 'R', 'R', 'R', 'D', 'D', 'D', 'D'],
"c": [1, 3, 7, 8, 1, 3, 6, 7],
"f": [5658, 5732, 5880, 5917, 5660, 5735, 5880, 5914]
}
self.set_all_frequencies(payload)
def set_all_frequencies(self, freqs):
''' Set frequencies for all nodes '''
# Set in DB first
profile = self.racecontext.race.profile
profile_freqs = json.loads(profile.frequencies)
self.logger.info("Sending frequency values to nodes: " + str(freqs["f"]))
for idx in range(self.racecontext.race.num_nodes):
profile_freqs["b"][idx] = freqs["b"][idx]
profile_freqs["c"][idx] = freqs["c"][idx]
profile_freqs["f"][idx] = freqs["f"][idx]
self.racecontext.interface.set_frequency(idx, freqs["f"][idx])
self.racecontext.race.clear_results()
self.logger.info('Frequency set: Node {0} B:{1} Ch:{2} Freq:{3}'.format(idx+1, freqs["b"][idx], freqs["c"][idx], freqs["f"][idx]))
profile = self.racecontext.rhdata.alter_profile({
'profile_id': profile.id,
'frequencies': profile_freqs
})
self.racecontext.race.profile = profile
def initialize(rhapi):
gfpvautofreqs = GFPVAutoFreqs(rhapi)
rhapi.events.on(Evt.HEAT_ALTER, gfpvautofreqs.callback, priority=500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment