Skip to content

Commit d9c4300

Browse files
committed
Merge remote-tracking branch 'origin/2.9'
* origin/2.9: wj200: only complain once about "failed to get status" wj200: whitespace cleanup, no behavior change
2 parents 56b906c + 3085057 commit d9c4300

1 file changed

Lines changed: 31 additions & 21 deletions

File tree

src/hal/user_comps/wj200_vfd/wj200_vfd.comp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ bool wj200_getStatus(modbus_t* ctx, wj200_status* status)
146146

147147
void print_modbus_error(struct __comp_state *__comp_inst, const char* msg)
148148
{
149-
fprintf(stderr,
149+
fprintf(stderr,
150150
"Error: wj200_vfd slave(%d): %s - Modbus error (%d) - %s\n",
151151
mbslaveaddr,
152152
msg,
@@ -175,7 +175,7 @@ void userinit(int argc, char **argv)
175175
{"stopbits", required_argument, 0, 0 },
176176
{"device", required_argument, 0, 0 },
177177
{0, 0, 0, 0}
178-
};
178+
};
179179

180180
while(1) {
181181
c = getopt_long(argc, argv, "", options, &opt_index);
@@ -189,8 +189,8 @@ void userinit(int argc, char **argv)
189189

190190
if(baud == 0)
191191
{
192-
fprintf(stderr,
193-
"Invalid argument: baud must be a number. Given '%s'\n",
192+
fprintf(stderr,
193+
"Invalid argument: buad must be a number. Given '%s'\n",
194194
optarg);
195195
exit(1);
196196
}
@@ -213,20 +213,20 @@ void userinit(int argc, char **argv)
213213

214214
if(data_bits == 0)
215215
{
216-
fprintf(stderr,
217-
"Invalid argument: databits must be a number. Given '%s'\n",
216+
fprintf(stderr,
217+
"Invalid argument: databits must be a number. Given '%s'\n",
218218
optarg);
219219
exit(1);
220220
}
221221
break;
222222

223223
case 3:
224224
stop_bits = atoi(optarg);
225-
225+
226226
if(stop_bits == 0)
227227
{
228-
fprintf(stderr,
229-
"Invalid argument: stopbits must be a number. Given '%s'\n",
228+
fprintf(stderr,
229+
"Invalid argument: stopbits must be a number. Given '%s'\n",
230230
optarg);
231231
exit(1);
232232
}
@@ -253,16 +253,16 @@ void userinit(int argc, char **argv)
253253
ctx = modbus_new_rtu(device, baud, parity, data_bits, stop_bits);
254254

255255
if (ctx == NULL) {
256-
fprintf(stderr,
257-
"ERROR: wj200_vfd unable to create libmodbus context. - %s\n",
256+
fprintf(stderr,
257+
"ERROR: wj200_vfd unable to create libmodbus context. - %s\n",
258258
modbus_strerror(errno));
259259
fprintf(stderr, "Check your commandline!\n");
260-
exit(1);
260+
exit(1);
261261
}
262-
262+
263263
if (modbus_connect(ctx)) {
264-
fprintf(stderr,
265-
"ERROR: wj200_vfd unable to create libmodbus connection. - %s\n",
264+
fprintf(stderr,
265+
"ERROR: wj200_vfd unable to create libmodbus connection. - %s\n",
266266
modbus_strerror(errno));
267267
exit(1);
268268
}
@@ -271,6 +271,7 @@ void userinit(int argc, char **argv)
271271
void user_mainloop(void) {
272272
wj200_status status;
273273
uint16_t calculated_frequency;
274+
bool last_enable_state = FALSE;
274275

275276
while(1) {
276277
FOR_ALL_INSTS() {
@@ -283,7 +284,7 @@ void user_mainloop(void) {
283284
*/
284285
if(mbslaveaddr == 0) {
285286
sleep(1);
286-
continue;
287+
continue;
287288
}
288289

289290
modbus_set_slave(ctx, mbslaveaddr);
@@ -297,10 +298,19 @@ void user_mainloop(void) {
297298
pin won't change until we make it all the way through
298299
the loop.
299300
*/
300-
if(!wj200_getStatus(ctx, &status)) {
301-
print_modbus_error(__comp_inst, "failed to get status");
302-
continue;
303-
}
301+
302+
if(!wj200_getStatus(ctx, &status)) {
303+
/*
304+
Only want to list 'failed to get status' once
305+
any time enable changes - don't spam the output.
306+
A wink is as good as a nod.
307+
*/
308+
if (last_enable_state != enable) {
309+
print_modbus_error(__comp_inst, "failed to get status");
310+
}
311+
last_enable_state = enable;
312+
continue;
313+
}
304314

305315
is_running = status.running;
306316
is_at_speed = status.at_speed;
@@ -318,7 +328,7 @@ void user_mainloop(void) {
318328
else {
319329
calculated_frequency = (uint16_t)(fabs(commanded_frequency) * 100);
320330

321-
if(calculated_frequency != status.frequency
331+
if(calculated_frequency != status.frequency
322332
&& !wj200_setFrequency(ctx, calculated_frequency)) {
323333
print_modbus_error(__comp_inst, "failed to set frequency");
324334
continue;

0 commit comments

Comments
 (0)