sync during ir_recv dev
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
This commit is contained in:
1
firmware/apps/_samples/ir_recv_sim/.gitignore
vendored
Normal file
1
firmware/apps/_samples/ir_recv_sim/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build*/
|
||||
10
firmware/apps/_samples/ir_recv_sim/CMakeLists.txt
Normal file
10
firmware/apps/_samples/ir_recv_sim/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
# Tell Zephyr to look into our libs folder for extra modules
|
||||
list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
project(_mcumgr)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
||||
@@ -0,0 +1,44 @@
|
||||
// To get started, press Ctrl+Space (or Option+Esc) to bring up the completion menu and view the available nodes.
|
||||
|
||||
// You can also use the buttons in the sidebar to perform actions on nodes.
|
||||
// Actions currently available include:
|
||||
|
||||
// * Enabling / disabling the node
|
||||
// * Adding the bus to a bus
|
||||
// * Removing the node
|
||||
// * Connecting ADC channels
|
||||
|
||||
// For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html
|
||||
// You can also visit the nRF DeviceTree extension documentation at https://docs.nordicsemi.com/bundle/nrf-connect-vscode/page/guides/ncs_configure_app.html#devicetree-support-in-the-extension
|
||||
|
||||
/ {
|
||||
chosen {
|
||||
nordic,pm-ext-flash = &mx25r64;
|
||||
};
|
||||
};
|
||||
|
||||
&pinctrl {
|
||||
i2s0_default: i2s0_default {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(I2S_SCK_M, 0, 31)>, /* SCK Pin */
|
||||
<NRF_PSEL(I2S_LRCK_M, 0, 30)>, /* WS/LRCK Pin */
|
||||
<NRF_PSEL(I2S_SDOUT, 0, 29)>; /* SD Pin (DIN am MAX) */
|
||||
};
|
||||
};
|
||||
|
||||
i2s0_sleep: i2s0_sleep {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(I2S_SCK_M, 0, 31)>,
|
||||
<NRF_PSEL(I2S_LRCK_M, 0, 30)>,
|
||||
<NRF_PSEL(I2S_SDOUT, 0, 29)>;
|
||||
low-power-enable;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&i2s0 {
|
||||
status = "okay";
|
||||
pinctrl-0 = <&i2s0_default>;
|
||||
pinctrl-1 = <&i2s0_sleep>;
|
||||
pinctrl-names = "default", "sleep";
|
||||
};
|
||||
4
firmware/apps/_samples/ir_recv_sim/pm_static.yml
Normal file
4
firmware/apps/_samples/ir_recv_sim/pm_static.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
littlefs_storage:
|
||||
address: 0x0
|
||||
size: 0x800000
|
||||
region: external_flash
|
||||
16
firmware/apps/_samples/ir_recv_sim/prj.conf
Normal file
16
firmware/apps/_samples/ir_recv_sim/prj.conf
Normal file
@@ -0,0 +1,16 @@
|
||||
CONFIG_LOG=y
|
||||
|
||||
# UART-Grundlagen
|
||||
CONFIG_SERIAL=y
|
||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||
|
||||
# Shell-Konfiguration
|
||||
CONFIG_SHELL=y
|
||||
CONFIG_SHELL_BACKEND_SERIAL=y
|
||||
|
||||
# Lasertag-spezifische Konfiguration
|
||||
CONFIG_LASERTAG_UTILS=y
|
||||
CONFIG_IR_RECV=y
|
||||
CONFIG_IR_RECV_LOG_LEVEL_DBG=y
|
||||
CONFIG_IR_RECV_SIMULATOR=y
|
||||
|
||||
36
firmware/apps/_samples/ir_recv_sim/src/main.c
Normal file
36
firmware/apps/_samples/ir_recv_sim/src/main.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <lasertag_utils.h>
|
||||
#include <ir_recv.h>
|
||||
|
||||
LOG_MODULE_REGISTER(ir_recv_sim, LOG_LEVEL_INF);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
LOG_INF("Starting IR receive simulator application...");
|
||||
lasertag_utils_init();
|
||||
ir_recv_init();
|
||||
|
||||
ir_packet_t test_packet = {0};
|
||||
|
||||
LOG_INF("Sending perfect packet...");
|
||||
test_packet.data.fields.type = 1;
|
||||
test_packet.data.fields.id = 42;
|
||||
test_packet.data.fields.value = 15;
|
||||
ir_recv_sim_send_packet(&test_packet, NULL);
|
||||
|
||||
k_msleep(100);
|
||||
|
||||
LOG_INF("Sending noisy packet with high jitter...");
|
||||
test_packet.data.fields.id = 255;
|
||||
|
||||
ir_sim_error_t ext_error = {
|
||||
.noise_flips_per_8 = 1, /* 2 von 8 Samples pro Block sind falsch */
|
||||
.jitter_mark = 1, /* Mark schwankt zwischen 6 und 10 Samples */
|
||||
.jitter_space_0 = 1, /* Space0 schwankt zwischen 4 und 12 Samples */
|
||||
.jitter_space_1 = 1 /* Space1 schwankt zwischen 14 und 18 Samples */
|
||||
};
|
||||
ir_recv_sim_send_packet(&test_packet, &ext_error);
|
||||
|
||||
return 0;
|
||||
}
|
||||
2
firmware/apps/_samples/ir_recv_sim/tool/requirements.txt
Normal file
2
firmware/apps/_samples/ir_recv_sim/tool/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
pyserial
|
||||
cbor2
|
||||
120
firmware/apps/_samples/ir_recv_sim/tool/tool.py
Normal file
120
firmware/apps/_samples/ir_recv_sim/tool/tool.py
Normal file
@@ -0,0 +1,120 @@
|
||||
import serial
|
||||
import base64
|
||||
import cbor2
|
||||
import struct
|
||||
import time
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
# Icons (NerdFont / Emoji)
|
||||
ICON_DIR = "📁"
|
||||
ICON_FILE = "📄"
|
||||
|
||||
class nRF_FS_Client:
|
||||
def __init__(self, port, baud):
|
||||
try:
|
||||
self.ser = serial.Serial(port, baud, timeout=0.2)
|
||||
self.seq = 0
|
||||
self.ser.reset_input_buffer()
|
||||
except serial.SerialException as e:
|
||||
print(f"Fehler: Konnte {port} nicht öffnen ({e})")
|
||||
sys.exit(1)
|
||||
|
||||
def crc16(self, data):
|
||||
crc = 0x0000
|
||||
for byte in data:
|
||||
crc ^= (byte << 8)
|
||||
for _ in range(8):
|
||||
if crc & 0x8000:
|
||||
crc = (crc << 1) ^ 0x1021
|
||||
else:
|
||||
crc = crc << 1
|
||||
crc &= 0xFFFF
|
||||
return crc
|
||||
|
||||
def build_packet(self, group, cmd, payload):
|
||||
self.seq = (self.seq + 1) % 256
|
||||
cbor_payload = cbor2.dumps(payload)
|
||||
header = struct.pack(">BBHHBB", 0x00, 0x08, len(cbor_payload), group, self.seq, cmd)
|
||||
full_body = header + cbor_payload
|
||||
checksum = self.crc16(full_body)
|
||||
full_msg = full_body + struct.pack(">H", checksum)
|
||||
return struct.pack(">H", len(full_msg)) + full_msg
|
||||
|
||||
def request(self, group, cmd, payload):
|
||||
packet = self.build_packet(group, cmd, payload)
|
||||
b64_data = base64.b64encode(packet).decode()
|
||||
self.ser.write(f"\x06\t{b64_data}\n".encode())
|
||||
|
||||
full_response_b64 = ""
|
||||
expected_len = -1
|
||||
start_time = time.time()
|
||||
|
||||
while (time.time() - start_time) < 3.0:
|
||||
line = self.ser.readline().strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
is_smp = line.startswith(b'\x06\t') or line.startswith(b'\x06\n')
|
||||
is_cont_special = line.startswith(b'\x04\x14') and expected_len > 0
|
||||
|
||||
if is_smp or is_cont_special:
|
||||
full_response_b64 += line[2:].decode()
|
||||
try:
|
||||
raw_data = base64.b64decode(full_response_b64)
|
||||
if expected_len == -1 and len(raw_data) >= 2:
|
||||
expected_len = struct.unpack(">H", raw_data[:2])[0]
|
||||
|
||||
if expected_len != -1 and len(raw_data) >= expected_len + 2:
|
||||
if raw_data[8] == self.seq:
|
||||
return cbor2.loads(raw_data[10:-2])
|
||||
except:
|
||||
continue
|
||||
return None
|
||||
|
||||
def list_recursive(self, path="/", prefix=""):
|
||||
res = self.request(64, 0, {"path": path})
|
||||
if res is None or 'files' not in res:
|
||||
return
|
||||
|
||||
# Sortierung: Verzeichnisse zuerst, dann Namen
|
||||
entries = sorted(res['files'], key=lambda x: (x.get('t', 'f') != 'd', x['n']))
|
||||
count = len(entries)
|
||||
|
||||
for i, entry in enumerate(entries):
|
||||
is_last = (i == count - 1)
|
||||
name = entry['n']
|
||||
is_dir = entry.get('t', 'f').startswith('d')
|
||||
|
||||
# Line-Art Auswahl
|
||||
# connector = "└── " if is_last else "├── "
|
||||
connector = "└─ " if is_last else "├─ "
|
||||
|
||||
|
||||
print(f"{prefix}{connector}{ICON_DIR if is_dir else ICON_FILE} {name}")
|
||||
|
||||
if is_dir:
|
||||
# Prefix für die nächste Ebene erweitern
|
||||
extension = " " if is_last else "│ "
|
||||
sub_path = f"{path}/{name}".replace("//", "/")
|
||||
self.list_recursive(sub_path, prefix + extension)
|
||||
|
||||
def close(self):
|
||||
if hasattr(self, 'ser') and self.ser.is_open:
|
||||
self.ser.close()
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="nRF52840 LittleFS Tree Tool")
|
||||
parser.add_argument("port", help="Serieller Port (z.B. /dev/cu.usbmodem...)")
|
||||
args = parser.parse_args()
|
||||
|
||||
client = nRF_FS_Client(args.port, 115200)
|
||||
print(f"--- Dateistruktur auf nRF ({args.port}) ---")
|
||||
try:
|
||||
# Initialer Aufruf
|
||||
client.list_recursive("/")
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user