Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Tysonpower authored Sep 11, 2024
2 parents e548bab + ecde3b1 commit 43e795a
Show file tree
Hide file tree
Showing 16 changed files with 441 additions and 273 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ repos:
hooks:
- id: isort
- repo: https://github.com/ambv/black
rev: 24.1.1
rev: 24.4.2
hooks:
- id: black
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.0
hooks:
- id: flake8
additional_dependencies:
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Please [consult the Wiki on the kraken_docs repo](https://github.com/krakenrf/kr

**Download Latest Images From :** https://mega.nz/folder/8T1jiIzR#_1Ujs4Eoy0wdRib9eHCVSg

**Alternative Download:** https://drive.google.com/drive/folders/14NuCOGM1Fh1QypDNMngXEepKYRBsG--B?usp=sharing

In these image the code will automatically run on boot. Note that it may take 2-3 minutes for the boot process to complete.

To run this code flash the image file to an SD Card using Etcher. The SD Card needs to be at least 8GB and we recommend using a class 10 card or faster. For advanced users the login/password details for SSH and terminal are "krakenrf"/"krakensdr"
Expand Down Expand Up @@ -62,7 +64,15 @@ Manual install is only required if you are not using the premade images, and are

``` bash
sudo apt -y update
sudo apt -y install nodejs jq rustc cargo
sudo apt -y install nodejs jq rustc cargo php-cli
cargo install miniserve
```

(**OPTIONAL** - rustc, cargo and miniserver are not needed for 99% of users, and we don't recommend installing unless you know what you're doing)

(NOTE: If installing miniserve you might need to get the latest rustc directly from Rust depending on your OS - see Issue https://github.com/krakenrf/krakensdr_doa/issues/131)
```bash
sudo apt -y install rustc cargo
cargo install miniserve
```

Expand Down Expand Up @@ -94,7 +104,7 @@ conda install dash==1.20.0
conda install werkzeug==2.0.2
```

4. (OPTIONAL) Install GPSD if you want to run a USB GPS on the Pi 4.
4. (**OPTIONAL**) Install GPSD if you want to run a USB GPS on the Pi 4.

```
sudo apt install gpsd
Expand Down
5 changes: 3 additions & 2 deletions _sdr/_receiver/iq_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class IQHeader:
FRAME_TYPE_RAMP = 2
FRAME_TYPE_CAL = 3
FRAME_TYPE_TRIGW = 4
FRAME_TYPE_EMPTY = 5

SYNC_WORD = 0x2BF7B95A

Expand All @@ -34,8 +35,8 @@ def __init__(self):
self.header_size = 1024 # size in bytes
self.reserved_bytes = 192

self.sync_word = self.SYNC_WORD # uint32_t
self.frame_type = 0 # uint32_t
self.sync_word = 0 # uint32_t
self.frame_type = self.FRAME_TYPE_EMPTY # uint32_t
self.hardware_id = "" # char [16]
self.unit_id = 0 # uint32_t
self.active_ant_chs = 0 # uint32_t
Expand Down
12 changes: 11 additions & 1 deletion _sdr/_receiver/kraken_sdr_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
from shmemIface import inShmemIface
from variables import AUTO_GAIN_VALUE

IN_SHMEM_IFACE_READ_TIMEOUT = 5.0 # sec


class ReceiverRTLSDR:
def __init__(self, data_que, data_interface="eth", logging_level=10):
Expand Down Expand Up @@ -92,7 +94,9 @@ def __init__(self, data_que, data_interface="eth", logging_level=10):
def init_data_iface(self):
if self.data_interface == "shmem":
# Open shared memory interface to capture the DAQ firmware output
self.in_shmem_iface = inShmemIface("delay_sync_iq", self.daq_shmem_control_path)
self.in_shmem_iface = inShmemIface(
"delay_sync_iq", self.daq_shmem_control_path, read_timeout=IN_SHMEM_IFACE_READ_TIMEOUT
)
if not self.in_shmem_iface.init_ok:
self.logger.critical("Shared memory initialization failed")
self.in_shmem_iface.destory_sm_buffer()
Expand Down Expand Up @@ -182,6 +186,9 @@ def get_iq_online(self):
if not self.receiver_connection_status:
fail = self.eth_connect()
if fail:
# If we cannot get the new IQ frame then we zero the stored IQ header
self.iq_header = IQHeader()
self.iq_samples = np.empty(0)
return -1

if self.data_interface == "eth":
Expand All @@ -192,6 +199,9 @@ def get_iq_online(self):
active_buff_index = self.in_shmem_iface.wait_buff_free()
if active_buff_index < 0 or active_buff_index > 1:
self.logger.info("Terminating.., signal: {:d}".format(active_buff_index))
# If we cannot get the new IQ frame then we zero the stored IQ header
self.iq_header = IQHeader()
self.iq_samples = np.empty(0)
return -1

buffer = self.in_shmem_iface.buffers[active_buff_index]
Expand Down
33 changes: 25 additions & 8 deletions _sdr/_receiver/shmemIface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import logging
import os
import time
from multiprocessing import shared_memory
from struct import pack, unpack

Expand All @@ -30,6 +31,7 @@
B_BUFF_READY = 2
INIT_READY = 10
TERMINATE = 255
SLEEP_TIME_BETWEEN_READ_ATTEMPTS = 0.01 # seconds


class outShmemIface:
Expand Down Expand Up @@ -136,18 +138,19 @@ def wait_buff_free(self):


class inShmemIface:
def __init__(self, shmem_name, ctr_fifo_path="_data_control/"):
def __init__(self, shmem_name, ctr_fifo_path="_data_control/", read_timeout=None):
self.init_ok = True
logging.basicConfig(level=logging.INFO)
self.logger = logging.getLogger(__name__)
self.drop_mode = False

self.num_read_attempts = int(read_timeout / SLEEP_TIME_BETWEEN_READ_ATTEMPTS) if read_timeout else 1
self.shmem_name = shmem_name

self.memories = []
self.buffers = []
fw_fifo_flags = os.O_RDONLY | os.O_NONBLOCK if read_timeout else os.O_RDONLY

try:
self.fw_ctr_fifo = os.open(ctr_fifo_path + "fw_" + shmem_name, os.O_RDONLY)
self.fw_ctr_fifo = os.open(ctr_fifo_path + "fw_" + shmem_name, fw_fifo_flags)
self.bw_ctr_fifo = os.open(ctr_fifo_path + "bw_" + shmem_name, os.O_WRONLY)
except OSError as err:
self.logger.critical("OS error: {0}".format(err))
Expand All @@ -157,7 +160,8 @@ def __init__(self, shmem_name, ctr_fifo_path="_data_control/"):
self.init_ok = False

if self.fw_ctr_fifo is not None:
if unpack("B", os.read(self.fw_ctr_fifo, 1))[0] == INIT_READY:
signal = self.read_fw_ctr_fifo()
if signal and signal == INIT_READY:
self.memories.append(shared_memory.SharedMemory(name=shmem_name + "_A"))
self.memories.append(shared_memory.SharedMemory(name=shmem_name + "_B"))
self.buffers.append(
Expand Down Expand Up @@ -194,11 +198,24 @@ def destory_sm_buffer(self):
os.close(self.bw_ctr_fifo)

def wait_buff_free(self):
signal = unpack("B", os.read(self.fw_ctr_fifo, 1))[0]
if signal == A_BUFF_READY:
signal = self.read_fw_ctr_fifo()
if not signal:
return -1
elif signal == A_BUFF_READY:
return 0
elif signal == B_BUFF_READY:
return 1
elif signal == TERMINATE:
return TERMINATE
return -1
else:
return -1

def read_fw_ctr_fifo(self):
for _ in range(self.num_read_attempts):
try:
signal = unpack("B", os.read(self.fw_ctr_fifo, 1))[0]
except BlockingIOError:
time.sleep(SLEEP_TIME_BETWEEN_READ_ATTEMPTS)
else:
return signal
return None
Loading

0 comments on commit 43e795a

Please sign in to comment.