forked from thestealth131205/vfdmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-config.cpp
201 lines (172 loc) · 6.98 KB
/
make-config.cpp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <stdio.h>
#include <QString>
#include <QVector>
#include <QFile>
#include "default-values.h"
#include "structures.h"
void make_blank_config()
{
QFile ini(":/configs/blank-config.ini");
if (!ini.exists())
return;
if (!ini.open(QIODevice::ReadOnly | QIODevice::Text))
return;
while (!ini.atEnd()) {
QString line = ini.readLine();
printf(qPrintable(line));
}
ini.close();
}
void make_postgui_config(const main_config_t &mconfig, const QVector<user_config_t> &uconfig)
{
printf("# Spindle output speed\n"
"net spindle-rpm-out %s.%s.%s => %s.%s\n",
qPrintable(mconfig.common.componentName),
HAL_GROUP_SPINDLE,
HAL_PIN_RPM_OUT,
PYVCP,
HAL_PIN_RPM_OUT);
printf("net spindle-at-speed <= %s.%s\n",
PYVCP,
HAL_PIN_AT_SPEED);
printf("\n"
"# Communication\n"
"net %s-%s %s.%s.%s => %s.%s\n",
PYVCP,
HAL_PIN_IS_CONNECTED,
qPrintable(mconfig.common.componentName),
HAL_GROUP_RS485,
HAL_PIN_IS_CONNECTED,
PYVCP,
HAL_PIN_IS_CONNECTED);
printf("net %s-%s %s.%s.%s => %s.%s\n",
PYVCP,
HAL_PIN_ERROR_COUNT,
qPrintable(mconfig.common.componentName),
HAL_GROUP_RS485,
HAL_PIN_ERROR_COUNT,
PYVCP,
HAL_PIN_ERROR_COUNT);
printf("net %s-%s %s.%s.%s => %s.%s\n",
PYVCP,
HAL_PIN_LAST_ERROR,
qPrintable(mconfig.common.componentName),
HAL_GROUP_RS485,
HAL_PIN_LAST_ERROR,
PYVCP,
HAL_PIN_LAST_ERROR);
if ((((mconfig.control.functionCode == MODBUS_FUNC_WRITE_SINGLE_HOLDING_REGISTER)
|| (mconfig.control.functionCode == MODBUS_FUNC_WRITE_MULTIPLE_HOLDING_REGISTERS))
&& (mconfig.control.faultResetValue != INACTIVE_FLAG))
|| (((mconfig.control.functionCode == MODBUS_FUNC_WRITE_SINGLE_COIL)
|| (mconfig.control.functionCode == MODBUS_FUNC_WRITE_MULTIPLE_COILS))
&& (mconfig.control.faultResetCoil != INACTIVE_FLAG))) {
printf("\n"
"# Fault reset!\n"
"# Because of ordinary button click is too short, it's necessary\n"
"# to prolong fault reset output in active state for a while.\n"
"loadrt oneshot names=fault-reset-delay\n"
"addf fault-reset-delay servo-thread\n"
"# Two seconds delay should be enough.\n"
"setp fault-reset-delay.width 2\n");
printf("net %s-%s-short %s.%s => fault-reset-delay.in\n",
PYVCP,
HAL_PIN_FAULT_RESET,
PYVCP,
HAL_PIN_FAULT_RESET);
printf("net %s-%s-long fault-reset-delay.out => %s.%s.%s\n",
PYVCP,
HAL_PIN_FAULT_RESET,
qPrintable(mconfig.common.componentName),
HAL_GROUP_CONTROL,
HAL_PIN_FAULT_RESET);
}
printf("\n"
"# User parameters\n");
for (int i = 0; i < uconfig.size(); i++) {
printf("net %s-%s %s.%s.%s => %s.%s\n",
PYVCP,
qPrintable(uconfig.at(i).pinName),
qPrintable(mconfig.common.componentName),
HAL_GROUP_USER_PARAMETERS,
qPrintable(uconfig.at(i).pinName),
PYVCP,
qPrintable(uconfig.at(i).pinName));
}
}
void make_pyvcp_config(const QString &inifile, const main_config_t &mconfig, const QVector<user_config_t> &uconfig)
{
printf("<pyvcp>\n"
"<labelframe text=\"%s\">\n"
"\n", qPrintable(inifile));
printf(" <label text=\"Output RPM:\"/>\n"
" <bar halpin=\"%s\" max_=\"%d\"/>\n"
"\n", HAL_PIN_RPM_OUT, mconfig.common.maxSpeedRpm);
printf(" <table flexible_rows=\"[1]\" flexible_columns=\"[2]\">\n"
" <tablerow/>\n"
" <label text=\"Spindle at speed\"/>\n"
" <led halpin=\"%s\" size=\"12\" on_color=\"green\" off_color=\"red\"/>\n"
" <tablerow/>\n", HAL_PIN_AT_SPEED);
printf(" <label text=\"'\\nParameters:'\"/>\n"
"\n"
" <!-- User parameters start here -->\n");
for (int i = 0; i < uconfig.size(); i++) {
printf(" <tablerow/>\n"
" <label text=\"%s\"/>\n", qPrintable(uconfig.at(i).groupName));
if ((uconfig.at(i).functionCode == MODBUS_FUNC_READ_MULTIPLE_COILS)
|| (uconfig.at(i).pinType == HAL_BIT)) {
printf(" <led halpin=\"%s\" size=\"12\" on_color=\"yellow\" off_color=\"blue\"/>\n",
qPrintable(uconfig.at(i).pinName));
} else
switch (uconfig.at(i).pinType) {
case HAL_FLOAT:
printf(" <number halpin=\"%s\" format=\".1f\"/>\n", qPrintable(uconfig.at(i).pinName));
break;
case HAL_S32:
printf(" <s32 halpin=\"%s\"/>\n", qPrintable(uconfig.at(i).pinName));
break;
case HAL_U32:
printf(" <u32 halpin=\"%s\"/>\n", qPrintable(uconfig.at(i).pinName));
break;
// This makes compiler happy!
default:
break;
}
}
printf(" <!-- User parameters end -->\n"
"\n"
" <tablerow/>\n"
" <label text=\"'\\nRS485:'\"/>\n");
printf(" <tablerow/>\n"
" <label text=\"Is connected\"/>\n"
" <led halpin=\"%s\" size=\"12\" on_color=\"green\" off_color=\"red\"/>\n",
HAL_PIN_IS_CONNECTED);
printf(" <tablerow/>\n"
" <label text=\"Error count\"/>\n"
" <s32 halpin=\"%s\"/>\n",
HAL_PIN_ERROR_COUNT);
printf(" <tablerow/>\n"
" <label text=\"Last error\"/>\n"
" <s32 halpin=\"%s\"/>\n",
HAL_PIN_LAST_ERROR);
printf(" </table>\n"
"\n");
/* FAULT RESET BUTTON */
// If function code is (0x06 or 0x10) and fault reset value is active...
// ... OR ...
// If function code is (0x05 or 0x0F) and fault reset coil is active...
if ((((mconfig.control.functionCode == MODBUS_FUNC_WRITE_SINGLE_HOLDING_REGISTER)
|| (mconfig.control.functionCode == MODBUS_FUNC_WRITE_MULTIPLE_HOLDING_REGISTERS))
&& (mconfig.control.faultResetValue != INACTIVE_FLAG))
|| (((mconfig.control.functionCode == MODBUS_FUNC_WRITE_SINGLE_COIL)
|| (mconfig.control.functionCode == MODBUS_FUNC_WRITE_MULTIPLE_COILS))
&& (mconfig.control.faultResetCoil != INACTIVE_FLAG)))
printf(" <button>\n"
" <halpin>\"%s\"</halpin>\n"
" <text>\"FAULT RESET\"</text>\n"
" </button>\n"
"\n",
HAL_PIN_FAULT_RESET);
printf("</labelframe>\n"
"</pyvcp>\n");
}