use a generic unpickler
This commit is contained in:
parent
1d2ee127e0
commit
1c937e147e
@ -15,13 +15,10 @@ from owrx.config import Config
|
|||||||
from owrx.waterfall import WaterfallOptions
|
from owrx.waterfall import WaterfallOptions
|
||||||
from owrx.websocket import Handler
|
from owrx.websocket import Handler
|
||||||
from queue import Queue, Full, Empty
|
from queue import Queue, Full, Empty
|
||||||
from js8py import Js8Frame
|
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
from io import BytesIO
|
|
||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
import struct
|
import struct
|
||||||
import pickle
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -379,12 +376,8 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
|
|||||||
self.send(bytes([0x04]) + data)
|
self.send(bytes([0x04]) + data)
|
||||||
|
|
||||||
def write_s_meter_level(self, level):
|
def write_s_meter_level(self, level):
|
||||||
if isinstance(level, memoryview):
|
# may contain more than one sample, so only take the last 4 bytes = 1 float
|
||||||
# may contain more than one sample, so only take the last 4 bytes = 1 float
|
level, = struct.unpack('f', level[-4:])
|
||||||
level, = struct.unpack('f', level[-4:])
|
|
||||||
if not isinstance(level, float):
|
|
||||||
logger.warning("s-meter value has unexpected type")
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
self.send({"type": "smeter", "value": level})
|
self.send({"type": "smeter", "value": level})
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -400,12 +393,7 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
|
|||||||
self.send(bytes([0x03]) + data)
|
self.send(bytes([0x03]) + data)
|
||||||
|
|
||||||
def write_secondary_demod(self, message):
|
def write_secondary_demod(self, message):
|
||||||
io = BytesIO(message.tobytes())
|
self.send({"type": "secondary_demod", "value": message})
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
self.send({"type": "secondary_demod", "value": pickle.load(io)})
|
|
||||||
except EOFError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def write_secondary_dsp_config(self, cfg):
|
def write_secondary_dsp_config(self, cfg):
|
||||||
self.send({"type": "secondary_config", "value": cfg})
|
self.send({"type": "secondary_config", "value": cfg})
|
||||||
@ -420,12 +408,7 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
|
|||||||
self.send({"type": "features", "value": features})
|
self.send({"type": "features", "value": features})
|
||||||
|
|
||||||
def write_metadata(self, metadata):
|
def write_metadata(self, metadata):
|
||||||
io = BytesIO(metadata.tobytes())
|
self.send({"type": "metadata", "value": metadata})
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
self.send({"type": "metadata", "value": pickle.load(io)})
|
|
||||||
except EOFError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def write_dial_frequencies(self, frequencies):
|
def write_dial_frequencies(self, frequencies):
|
||||||
self.send({"type": "dial_frequencies", "value": frequencies})
|
self.send({"type": "dial_frequencies", "value": frequencies})
|
||||||
|
17
owrx/dsp.py
17
owrx/dsp.py
@ -18,8 +18,10 @@ from csdr.chain.digimodes import AudioChopperDemodulator, PacketDemodulator, Poc
|
|||||||
from pycsdr.modules import Buffer, Writer
|
from pycsdr.modules import Buffer, Writer
|
||||||
from pycsdr.types import Format
|
from pycsdr.types import Format
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
from io import BytesIO
|
||||||
import threading
|
import threading
|
||||||
import re
|
import re
|
||||||
|
import pickle
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -525,8 +527,8 @@ class DspManager(Output, SdrSourceEventClient):
|
|||||||
"hd_audio": self.handler.write_hd_audio,
|
"hd_audio": self.handler.write_hd_audio,
|
||||||
"smeter": self.handler.write_s_meter_level,
|
"smeter": self.handler.write_s_meter_level,
|
||||||
"secondary_fft": self.handler.write_secondary_fft,
|
"secondary_fft": self.handler.write_secondary_fft,
|
||||||
"secondary_demod": self.handler.write_secondary_demod,
|
"secondary_demod": self._unpickle(self.handler.write_secondary_demod),
|
||||||
"meta": self.handler.write_metadata,
|
"meta": self._unpickle(self.handler.write_metadata),
|
||||||
}
|
}
|
||||||
|
|
||||||
write = writers[t]
|
write = writers[t]
|
||||||
@ -537,6 +539,17 @@ class DspManager(Output, SdrSourceEventClient):
|
|||||||
self.readers[t] = reader
|
self.readers[t] = reader
|
||||||
threading.Thread(target=self.pump(reader.read, write), name="dsp_pump_{}".format(t)).start()
|
threading.Thread(target=self.pump(reader.read, write), name="dsp_pump_{}".format(t)).start()
|
||||||
|
|
||||||
|
def _unpickle(self, callback):
|
||||||
|
def unpickler(data):
|
||||||
|
io = BytesIO(data.tobytes())
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
callback(pickle.load(io))
|
||||||
|
except EOFError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return unpickler
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.chain.stop()
|
self.chain.stop()
|
||||||
self.chain = None
|
self.chain = None
|
||||||
|
Loading…
Reference in New Issue
Block a user