Skip to content

Commit ef34cc7

Browse files
committed
add interactive and not fully working way to communicate with forth scpi engine, note: it breaks target build
1 parent c6cc920 commit ef34cc7

17 files changed

Lines changed: 395 additions & 266 deletions

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Software/TargetFirmware/Drivers linguist-vendored
22
Software/NUCLEO-F091RC/Drivers linguist-vendored
3-
Software/Common/Libraries linguist-vendored
3+
Software/Common/Libraries linguist-vendored
11.9 KB
Loading

Simulation/FirmwarePCSimulator/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ This project consists of two parts:
55
- firmware that is built to sharable object (.so)
66
- python script that loads this sharable object, and acts as a mockup of hardware
77

8+
![Simulator Picture](https://raw.githubusercontent.com/RobertGawron/DDSFunctionGenerator/master/Documentation/Pictures/PCSimulation_20_10_2020.png)
89

9-
Note that in order to load .so object into an application, both of them needs to be 32bits, or 64bits. In case of errors during loading .so object, check your version on Python and gcc (both should be either 32bits or 64bits).
1010

1111
## Requirements
12+
1213
- Intsall PyQt5
1314

1415
```pip install PyQt5```
16+
1517
- Install gcc an makefile
1618

19+
Note that in order to load .so object into an application, both of them needs to be 32bits, or 64bits. In case of errors during loading .so object, check your version on Python and gcc (both should be either 32bits or 64bits).
20+
1721
## Usage
18-
- Build firmware, in Software/NUCLEO-F091RC directory execute:
22+
23+
- Build firmware, in Software/Common/BusinessLogic directory execute:
1924

2025
```make```
2126

Simulation/FirmwarePCSimulator/device_under_test.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,23 @@ def __init__(self):
99
"..\\..\\Software" + os.path.sep + "Common" + os.path.sep + "BusinessLogic" + os.path.sep + dll_name
1010

1111
self.dut = ctypes.CDLL(dllabspath)
12-
self.dut.Lib_Simulation_Init()
12+
13+
self.dut.Lib_Simulation_SendSCPIRequest.argtypes = [POINTER(c_char)]
14+
self.dut.Lib_Simulation_Init("../../Software/Common/BusinessLogic/".encode()) # TODO
1315

14-
15-
def getLoggedData(self):
16-
self.dut.Lib_GMLoggerSIM_GetLoggedData.argtypes = [POINTER(POINTER(c_uint8)), POINTER(c_uint8)]
17-
data = POINTER(c_uint8)()
18-
size = c_uint8()
1916

20-
self.dut.Lib_Simulation_GetLoggedData(byref(data), byref(size))
2117

22-
"""logged_data = ""
23-
for i in range(size.value):
24-
logged_data += chr(data[i])
18+
def sendSCPI(self, command):
19+
self.dut.Lib_Simulation_SendSCPIRequest.argtypes = [POINTER(c_char)]
20+
data = POINTER(c_uint8)()
21+
size = c_uint8()
22+
return self.dut.Lib_Simulation_SendSCPIRequest(command.encode())
2523

26-
# it is expected that log end with new line,
27-
# this should be stripped application
28-
return logged_data[:-3]"""
2924

30-
return "xxxx"
25+
def receiveSCPI(self):
26+
self.dut.Lib_Simulation_ReceiveSCPIResponse.restype = c_char_p
27+
print ( self.dut.Lib_Simulation_ReceiveSCPIResponse() )
28+
return self.dut.Lib_Simulation_ReceiveSCPIResponse()
3129

3230

3331
def pressKey(self):

Simulation/FirmwarePCSimulator/gui.ui

Lines changed: 107 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>709</width>
10-
<height>251</height>
9+
<width>800</width>
10+
<height>400</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
14-
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
14+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
1515
<horstretch>0</horstretch>
1616
<verstretch>0</verstretch>
1717
</sizepolicy>
@@ -28,27 +28,32 @@
2828
<widget class="QWidget" name="centralwidget">
2929
<layout class="QHBoxLayout" name="horizontalLayout_2">
3030
<item>
31-
<layout class="QHBoxLayout" name="horizontalLayout"/>
32-
</item>
33-
<item>
34-
<widget class="QTabWidget" name="tabWidget">
35-
<property name="currentIndex">
31+
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0">
32+
<property name="spacing">
3633
<number>0</number>
3734
</property>
38-
<widget class="QWidget" name="tab">
39-
<attribute name="title">
40-
<string>Actions</string>
41-
</attribute>
42-
<layout class="QVBoxLayout" name="verticalLayout_4">
35+
<property name="sizeConstraint">
36+
<enum>QLayout::SetMinimumSize</enum>
37+
</property>
38+
<property name="leftMargin">
39+
<number>0</number>
40+
</property>
41+
<property name="topMargin">
42+
<number>0</number>
43+
</property>
44+
<property name="rightMargin">
45+
<number>0</number>
46+
</property>
47+
<property name="bottomMargin">
48+
<number>0</number>
49+
</property>
50+
<item>
51+
<layout class="QVBoxLayout" name="verticalLayout_5">
4352
<item>
44-
<layout class="QVBoxLayout" name="verticalLayout_2">
45-
<item>
46-
<widget class="QPushButton" name="WidgetGenerateGMPulse">
47-
<property name="text">
48-
<string>Generate GM Pulse</string>
49-
</property>
50-
</widget>
51-
</item>
53+
<layout class="QVBoxLayout" name="verticalLayout_8">
54+
<property name="sizeConstraint">
55+
<enum>QLayout::SetMinimumSize</enum>
56+
</property>
5257
<item>
5358
<widget class="QPushButton" name="WidgetPushHWKey">
5459
<property name="text">
@@ -57,114 +62,103 @@
5762
</widget>
5863
</item>
5964
<item>
60-
<widget class="QPushButton" name="pushButton_3">
65+
<widget class="QPushButton" name="pushButton">
6166
<property name="text">
6267
<string>Reload DUT</string>
6368
</property>
6469
</widget>
6570
</item>
6671
<item>
67-
<widget class="QPushButton" name="pushButton_2">
68-
<property name="text">
69-
<string>Load Test Data</string>
70-
</property>
71-
</widget>
72+
<widget class="QDial" name="dial"/>
7273
</item>
73-
</layout>
74-
</item>
75-
</layout>
76-
</widget>
77-
<widget class="QWidget" name="tab_2">
78-
<attribute name="title">
79-
<string>Config</string>
80-
</attribute>
81-
<layout class="QVBoxLayout" name="verticalLayout_6">
82-
<item>
83-
<layout class="QVBoxLayout" name="verticalLayout_3">
8474
<item>
85-
<layout class="QFormLayout" name="formLayout">
86-
<item row="1" column="0">
87-
<widget class="QRadioButton" name="radioButton_2">
88-
<property name="text">
89-
<string>x1</string>
90-
</property>
91-
</widget>
92-
</item>
93-
<item row="0" column="0">
94-
<widget class="QLabel" name="label_2">
95-
<property name="text">
96-
<string>Simulation Speed</string>
97-
</property>
98-
</widget>
99-
</item>
100-
<item row="2" column="0">
101-
<widget class="QRadioButton" name="radioButton">
102-
<property name="text">
103-
<string>x2</string>
104-
</property>
105-
</widget>
106-
</item>
107-
<item row="3" column="0">
108-
<widget class="QRadioButton" name="radioButton_3">
109-
<property name="text">
110-
<string>x10</string>
111-
</property>
112-
</widget>
113-
</item>
114-
</layout>
75+
<spacer name="verticalSpacer_2">
76+
<property name="orientation">
77+
<enum>Qt::Vertical</enum>
78+
</property>
79+
<property name="sizeHint" stdset="0">
80+
<size>
81+
<width>20</width>
82+
<height>40</height>
83+
</size>
84+
</property>
85+
</spacer>
11586
</item>
11687
</layout>
11788
</item>
11889
</layout>
119-
</widget>
120-
</widget>
121-
</item>
122-
<item>
123-
<layout class="QVBoxLayout" name="verticalLayout"/>
124-
</item>
125-
<item>
126-
<layout class="QVBoxLayout" name="verticalLayout_5"/>
90+
</item>
91+
</layout>
12792
</item>
12893
<item>
129-
<widget class="QLabel" name="WidgetHWDisplay">
130-
<property name="minimumSize">
131-
<size>
132-
<width>128</width>
133-
<height>64</height>
134-
</size>
135-
</property>
136-
<property name="maximumSize">
137-
<size>
138-
<width>300</width>
139-
<height>300</height>
140-
</size>
141-
</property>
142-
<property name="text">
143-
<string/>
144-
</property>
145-
</widget>
94+
<layout class="QVBoxLayout" name="verticalLayout_6">
95+
<item>
96+
<layout class="QVBoxLayout" name="verticalLayout_4">
97+
<item>
98+
<widget class="QLabel" name="WidgetHWDisplay">
99+
<property name="sizePolicy">
100+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
101+
<horstretch>0</horstretch>
102+
<verstretch>0</verstretch>
103+
</sizepolicy>
104+
</property>
105+
<property name="minimumSize">
106+
<size>
107+
<width>128</width>
108+
<height>64</height>
109+
</size>
110+
</property>
111+
<property name="maximumSize">
112+
<size>
113+
<width>128</width>
114+
<height>64</height>
115+
</size>
116+
</property>
117+
<property name="text">
118+
<string>TextLabel</string>
119+
</property>
120+
</widget>
121+
</item>
122+
<item>
123+
<spacer name="verticalSpacer">
124+
<property name="orientation">
125+
<enum>Qt::Vertical</enum>
126+
</property>
127+
<property name="sizeHint" stdset="0">
128+
<size>
129+
<width>20</width>
130+
<height>40</height>
131+
</size>
132+
</property>
133+
</spacer>
134+
</item>
135+
</layout>
136+
</item>
137+
</layout>
146138
</item>
147139
<item>
148-
<widget class="QTextBrowser" name="WidgetLogger">
149-
<property name="sizePolicy">
150-
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
151-
<horstretch>0</horstretch>
152-
<verstretch>0</verstretch>
153-
</sizepolicy>
140+
<layout class="QHBoxLayout" name="horizontalLayout_5">
141+
<property name="sizeConstraint">
142+
<enum>QLayout::SetFixedSize</enum>
154143
</property>
155-
<property name="minimumSize">
156-
<size>
157-
<width>400</width>
158-
<height>0</height>
159-
</size>
160-
</property>
161-
<property name="maximumSize">
162-
<size>
163-
<width>400</width>
164-
<height>600</height>
165-
</size>
166-
</property>
167-
</widget>
144+
<item>
145+
<layout class="QVBoxLayout" name="verticalLayout_3">
146+
<item>
147+
<widget class="QTextBrowser" name="WidgetLogger"/>
148+
</item>
149+
<item>
150+
<widget class="QLineEdit" name="WidgetSCPIToSend"/>
151+
</item>
152+
<item>
153+
<widget class="QPushButton" name="WidgetSendSCPI">
154+
<property name="text">
155+
<string>Send SCPI command</string>
156+
</property>
157+
</widget>
158+
</item>
159+
</layout>
160+
</item>
161+
</layout>
168162
</item>
169163
</layout>
170164
</widget>
@@ -173,7 +167,7 @@
173167
<rect>
174168
<x>0</x>
175169
<y>0</y>
176-
<width>709</width>
170+
<width>800</width>
177171
<height>21</height>
178172
</rect>
179173
</property>
@@ -198,9 +192,6 @@
198192
</property>
199193
</action>
200194
</widget>
201-
<tabstops>
202-
<tabstop>tabWidget</tabstop>
203-
</tabstops>
204195
<resources/>
205196
<connections/>
206197
</ui>

Simulation/FirmwarePCSimulator/main.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class MainWindow(QMainWindow):
99
def __init__(self):
1010
QMainWindow.__init__(self)
11-
11+
1212
self.dut = DeviceUnderTest()
1313
self.setupWidgets()
1414
self.onHWDisplayUpdate()
@@ -20,13 +20,26 @@ def setupWidgets(self):
2020
self.WidgetGenerateGMPulse = self.findChild(QPushButton, "WidgetGenerateGMPulse")
2121
self.WidgetLogger = self.findChild(QTextBrowser, "WidgetLogger")
2222
self.WidgetHWDisplay= self.findChild(QLabel, "WidgetHWDisplay")
23-
23+
self.WidgetSendSCPI= self.findChild(QPushButton, "WidgetSendSCPI")
24+
self.WidgetSCPIToSend= self.findChild(QLineEdit, "WidgetSCPIToSend")
25+
2426
self.WidgetPushHWKey.clicked.connect(self.onPressHWKey)
27+
self.WidgetSendSCPI.clicked.connect(self.onSendSCPI)
28+
29+
#self.WidgetSCPIToSend.text = "12 1 + . ;"
30+
#self.onSendSCPI()
31+
32+
def onSendSCPI(self):
33+
self.dut.sendSCPI(self.WidgetSCPIToSend.text())
2534

35+
# todo
36+
import time
37+
time.sleep(1)
2638

39+
self.onReceiveSCPI()
2740

28-
def onNewLoggedData(self):
29-
logged_data = self.dut.getLoggedData()
41+
def onReceiveSCPI(self):
42+
logged_data = self.dut.receiveSCPI()
3043
local_timestamp = datetime.now()
3144
data_with_timestamp = "{}: {}".format(local_timestamp, logged_data)
3245
self.WidgetLogger.append (data_with_timestamp)

0 commit comments

Comments
 (0)