-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdxing.py
More file actions
84 lines (67 loc) · 2.83 KB
/
dxing.py
File metadata and controls
84 lines (67 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import wx
import ctypes
import numpy as np
import logging
from configparser import ConfigParser
from wx import FileDialog
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Load configuration and Rust library
config = ConfigParser()
config.read('config.ini')
lib_path = config.get('DEFAULT', 'RustLibPath', fallback='dxing_lib.so')
try:
rust_lib = ctypes.CDLL(lib_path)
except OSError as e:
logger.error(f"Failed to load Rust library: {e}")
raise
# Define the interface to the Rust function
process_data = rust_lib.process_data
process_data.argtypes = [np.ctypeslib.ndpointer(ctypes.c_double, flags="C_CONTIGUOUS"), ctypes.c_size_t]
process_data.restype = ctypes.c_bool
class MainFrame(wx.Frame):
def __init__(self):
super().__init__(None, title="Signal and Sensor Analysis", size=(600, 400))
panel = wx.Panel(self)
self.load_button = wx.Button(panel, label="Load Signal")
self.process_button = wx.Button(panel, label="Process Signal")
self.result_text = wx.TextCtrl(panel, style=wx.TE_MULTILINE | wx.HSCROLL)
self.load_button.Bind(wx.EVT_BUTTON, self.on_load_signal)
self.process_button.Bind(wx.EVT_BUTTON, self.on_process_signal)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.load_button, 0, wx.ALL | wx.EXPAND, 5)
sizer.Add(self.process_button, 0, wx.ALL | wx.EXPAND, 5)
sizer.Add(self.result_text, 1, wx.ALL | wx.EXPAND, 5)
panel.SetSizer(sizer)
self.input_signal = None
def on_load_signal(self, event):
with FileDialog(self, "Open Signal Data File", wildcard="Data files (*.dat)|*.dat",
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return # User cancelled the action
# Proceed to load the file
path = fileDialog.GetPath()
try:
# Assuming the file contains an array in text format
self.input_signal = np.loadtxt(path)
logger.info("Signal loaded successfully.")
except Exception as e:
logger.error(f"Failed to load file: {e}")
def on_process_signal(self, event):
if self.input_signal is None:
logger.error("No signal loaded")
return
if not isinstance(self.input_signal, np.ndarray):
logger.error("Loaded signal is not a numpy array")
return
success = process_data(self.input_signal, len(self.input_signal))
if success:
self.result_text.SetValue(f"Processed Signal:\n{np.array_str(self.input_signal)}")
else:
logger.error("Signal processing failed")
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
frame.Show()
app.MainLoop()