< fdZddlZddlZddlZddlZddlZddlZddlmZej e Z gdZ Gddej ZGddZdS) zm Author: Vertigo Designs, Ryan Summers Description: Provides an API for controlling Booster NGFW over MQTT. N) MqttError)ZeroOneTwoThreeFourFiveSixSevenceZdZdZdZdZdS)Actionz8Represents an action that can be taken on channel state.z read-biassaveN)__name__ __module__ __qualname____doc__ReadBiasCurrentSaveOC:\Users\rsummers\Documents\repositories\quartiq\booster\py\booster\__init__.pyr r sBB!O DDDrr c.eZdZdZdZdedefdZdZdS)BoosterzMAn asynchronous API for controlling booster using the MQTT control interface.cH||_tj|||_dS)zConsructor. Args: client: A connected MQTT5 client. prefix: The prefix of the booster to control. N)prefixminiconfMiniconf)selfclientrs r__init__zBooster.__init__)s#  )&&99 ractionchannelcKtjdt|i}|j|jd|j|d{V}tj|dS)zSend a command to a booster control topic. Args: action: The action to take channel: The channel on which to perform the action. Returns: The received response to the action. r"z /command/)payloadNr)jsondumpsCHANNELr_dorvalueloads)rr!r"messageresponses rperform_actionzBooster.perform_action3s*77+    **{ 3 3V\ 3 3W+        z(1+&&&rcKjdddd{Vtjdd{Vfd}d}d}d }d } ||krt d ||d{V\}} | |krt d | |dz krt d| }| |krn|dz }e|dz } |dz}| |kst d ||d{V\}} | |krt d | |krnK|| fS)a Set a booster RF bias current. Args: channel: The channel index to configure. current: The bias current. Returns: (Vgs, Ids) where Vgs is the actual bias voltage and Ids is the measured RF amplifier drain current. /channel/z/statePoweredNg?c0Kjdd|d{Vtjdd{Vt jd{V}|d|d}}td|dd|d zd d ||fS) Nr/z /bias_voltage皙?vgsidszVgs = z.3fz V, Ids = iz.2fz mA)rsetasynciosleepr-r rprint)voltager,r3r4r"rs rset_biasz#Booster.tune_bias..set_biasWs-##$F$F$F$FPP P P P P P P P-$$ $ $ $ $ $ $ $!001GQQQQQQQQHC A3AAAcDjAAAA B B B8Orgg333333ӿr2gTzVoltage out of boundszIds out of rangeg{Gz?FoldbackgQ?gMbP?)rr5r6r7 ValueError) rr"currentr:r9vgs_maxids_maxlast_idsr3r4 lower_limits `` r tune_biaszBooster.tune_biasHsm ;G ; ; ;YGGGGGGGGGmC                   !9:::%Xg........HCW}} !4555X_$$ ---HW}} tOG  n   u G')) !9:::%Xg........HCW}} !4555g~~ CxrN) rrrrr r strr-rBrrrrr&sZWW:::'6'C''''*:::::rr)rr6timer%enumloggingraiomqttr getLoggerrLOGGERr'Enumr rrrrrKs    8 $ $   TY\\\\\\\\\\r