forked from sfeakes/AqualinkD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial_logger.c
651 lines (565 loc) · 19.1 KB
/
serial_logger.c
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/*
* Copyright (c) 2017 Shaun Feakes - All rights reserved
*
* You may use redistribute and/or modify this code under the terms of
* the GNU General Public License version 2 as published by the
* Free Software Foundation. For the terms of this license,
* see <http://www.gnu.org/licenses/>.
*
* You are free to use this software under the terms of the GNU General
* Public License, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* https://github.com/sfeakes/aqualinkd
*/
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include "aq_serial.h"
#include "utils.h"
#include "packetLogger.h"
#include "rs_msg_utils.h"
#define SLOG_MAX 80
#define PACKET_MAX 600
#define VERSION "serial_logger V1.4"
/*
typedef enum used {
yes,
no,
unknown
} used;
*/
// Bogus config to keep aq_serial.c happy
struct aqconfig
{
bool readahead_b4_write;
};
struct aqconfig _aqconfig_;
char _panelType[AQ_MSGLEN];
char _panelRev[AQ_MSGLEN];
typedef struct serial_id_log {
unsigned char ID;
bool inuse;
} serial_id_log;
bool _keepRunning = true;
unsigned char _goodID[] = {0x0a, 0x0b, 0x08, 0x09};
unsigned char _goodPDAID[] = {0x60, 0x61, 0x62, 0x63}; // PDA Panel only supports one PDA.
unsigned char _goodONETID[] = {0x40, 0x41, 0x42, 0x43};
unsigned char _goodIAQTID[] = {0x30, 0x31, 0x32, 0x33};
//unsigned char _goodRSSAID[] = {0x48, 0x49, 0x4a, 0x4b};
unsigned char _goodRSSAID[] = {0x48, 0x49}; // Know there are only 2 good RS SA id's, guess 0x49 is the second.
unsigned char _filter[10];
int _filters=0;
bool _rawlog=false;
bool _playback_file = false;
int timespec_subtract (struct timespec *result, const struct timespec *x, const struct timespec *y);
void intHandler(int dummy) {
_keepRunning = false;
LOG(RSSD_LOG, LOG_NOTICE, "Stopping!\n");
if (_playback_file) // If we are reading file, loop is irevelent
exit(0);
}
#define MASTER " <-- Master control panel"
#define SWG " <-- Salt Water Generator (Aquarite mode)"
#define KEYPAD " <-- RS Keypad"
#define SPA_R " <-- Spa remote"
#define AQUA " <-- Aqualink (iAqualink / Touch)"
#define HEATER " <-- LX Heater"
#define ONE_T " <-- Onetouch device"
#define RS_SERL " <-- RS Serial Adapter"
#define PC_DOCK " <-- PC Interface (RS485 to RS232)"
#define PDA " <-- PDA Remote"
#define EPUMP " <-- Jandy VSP ePump"
#define CHEM " <-- Chemlink"
#define UNKNOWN " <-- Unknown Device"
#define P_VSP " <-- Pentair VSP"
#define P_MASTER " <-- Pentair Master (Probably Jandy RS Control Panel)"
#define P_SWG " <-- Salt Water Generator (Jandy mode)"
#define P_BCAST " <-- Broadcast address"
#define P_RCTL " <-- Remote wired controller"
#define P_RWCTL " <-- Remote wireless controller (Screen Logic)"
#define P_CTL " <-- Pool controller (EasyTouch)"
const char *getDevice(unsigned char ID) {
if (ID >= 0x00 && ID <= 0x03)
return MASTER;
if (ID >= 0x08 && ID <= 0x0B)
return KEYPAD;
if (ID >= 0x50 && ID <= 0x53)
return SWG;
if (ID >= 0x20 && ID <= 0x23)
return SPA_R;
if (ID >= 0x30 && ID <= 0x33)
return AQUA;
if (ID >= 0x38 && ID <= 0x3B)
return HEATER;
if (ID >= 0x40 && ID <= 0x43)
return ONE_T;
if (ID >= 0x48 && ID <= 0x4B)
return RS_SERL;
if (ID >= 0x58 && ID <= 0x5B)
return PC_DOCK;
if (ID >= 0x60 && ID <= 0x63)
return PDA;
//if (ID >= 0x70 && ID <= 0x73)
if (ID >= 0x78 && ID <= 0x7B)
return EPUMP;
if (ID >= 0x80 && ID <= 0x83)
return CHEM;
//if (ID == 0x08)
// return KEYPAD;
return UNKNOWN;
}
const char *getPentairDevice(unsigned char ID) {
if (ID >= 0x60 && ID <= 0x6F)
return P_VSP;
if (ID == 0x02)
return P_SWG;
if (ID == 0x10)
return P_MASTER;
if (ID == 0x0F)
return P_BCAST;
if (ID == 0x10)
return P_CTL;
if (ID == 0x20)
return P_RCTL;
if (ID == 0x22)
return P_RWCTL;
return UNKNOWN;
}
void advance_cursor() {
static int pos=0;
char cursor[4]={'/','-','\\','|'};
printf("%c\b", cursor[pos]);
fflush(stdout);
pos = (pos+1) % 4;
}
bool canUse(unsigned char ID) {
int i;
for (i = 0; i < 4; i++) {
if (ID == _goodID[i])
return true;
}
for (i = 0; i < 4; i++) {
if (ID == _goodPDAID[i])
return true;
}
for (i = 0; i < 4; i++) {
if (ID == _goodONETID[i])
return true;
}
for (i = 0; i < 4; i++) {
if (ID == _goodIAQTID[i])
return true;
}
for (i = 0; i < 2; i++) {
if (ID == _goodRSSAID[i])
return true;
}
return false;
}
char* canUseExtended(unsigned char ID) {
int i;
for (i = 0; i < 4; i++) {
if (ID == _goodID[i])
return " <-- can use for Aqualinkd";
}
for (i = 0; i < 4; i++) {
if (ID == _goodPDAID[i])
return " <-- can use for Aqualinkd (PDA mode only)";
}
for (i = 0; i < 4; i++) {
if (ID == _goodONETID[i])
return " <-- can use for Aqualinkd (Extended Device ID)";
}
for (i = 0; i < 4; i++) {
if (ID == _goodIAQTID[i])
return " <-- can use for Aqualinkd (Prefered Extended Device ID)";
}
for (i = 0; i < 2; i++) {
if (ID == _goodRSSAID[i])
return " <-- can use for Aqualinkd (RSSA ID)";
}
return "";
}
void printHex(char *pk, int length)
{
int i=0;
for (i=0;i<length;i++)
{
printf("0x%02hhx|",pk[i]);
}
}
void printPacket(unsigned char ID, unsigned char *packet_buffer, int packet_length)
{
int i;
//if (_filter != 0x00 && ID != _filter && packet_buffer[PKT_DEST] != _filter )
// return;
if (_rawlog) {
printHex((char *)packet_buffer, packet_length);
printf("\n");
return;
}
if (_filters != 0)
{
//int i;
bool dest_match = false;
bool src_match = false;
for (i=0; i < _filters; i++) {
if ( packet_buffer[PKT_DEST] == _filter[i])
dest_match = true;
if ( ID == _filter[i] && packet_buffer[PKT_DEST] == 0x00 )
src_match = true;
}
if(dest_match == false && src_match == false)
return;
}
/*
if (_filter != 0x00) {
if ( packet_buffer[PKT_DEST]==0x00 && ID != _filter )
return;
if ( packet_buffer[PKT_DEST]!=0x00 && packet_buffer[PKT_DEST] != _filter )
return;
}
*/
if (getProtocolType(packet_buffer)==JANDY) {
if (packet_buffer[PKT_DEST] != 0x00)
printf("\n");
printf("Jandy %4.4s 0x%02hhx of type %16.16s", (packet_buffer[PKT_DEST]==0x00?"From":"To"), (packet_buffer[PKT_DEST]==0x00?ID:packet_buffer[PKT_DEST]), get_packet_type(packet_buffer, packet_length));
} else {
printf("Pentair From 0x%02hhx To 0x%02hhx ",packet_buffer[PEN_PKT_FROM],packet_buffer[PEN_PKT_DEST] );
}
printf(" | HEX: ");
printHex((char *)packet_buffer, packet_length);
if (packet_buffer[PKT_CMD] == CMD_MSG || packet_buffer[PKT_CMD] == CMD_MSG_LONG) {
printf(" Message : ");
//fwrite(packet_buffer + 4, 1, AQ_MSGLEN+1, stdout);
//fwrite(packet_buffer + 4, 1, packet_length-7, stdout);
for(i=4; i < packet_length-3; i++) {
if (packet_buffer[i] >= 32 && packet_buffer[i] <= 126)
printf("%c",packet_buffer[i]);
}
}
//if (packet_buffer[PKT_DEST]==0x00)
// printf("\n\n");
//else
printf("\n");
}
void getPanelInfo(int rs_fd, unsigned char *packet_buffer, int packet_length)
{
static unsigned char getPanelRev[] = {0x00,0x14,0x01};
static unsigned char getPanelType[] = {0x00,0x14,0x02};
static int msgcnt=0;
//int i;
if (packet_buffer[PKT_CMD] == CMD_PROBE) {
if (msgcnt == 0)
send_ack(rs_fd, 0x00);
else if (msgcnt == 1)
send_jandy_command(rs_fd, getPanelRev, 3);
else if (msgcnt == 2)
send_jandy_command(rs_fd, getPanelType, 3);
msgcnt++;
} else if (packet_buffer[PKT_CMD] == CMD_MSG) {
send_ack(rs_fd, 0x00);
if (msgcnt == 2)
rsm_strncpy(_panelRev, packet_buffer+4, AQ_MSGLEN, packet_length-5);
else if (msgcnt == 3)
rsm_strncpy(_panelType, packet_buffer+4, AQ_MSGLEN, packet_length-5);
/*
for(i=4; i < packet_length-3; i++) {
if (packet_buffer[i] == 0x00)
break;
else if (packet_buffer[i] >= 32 && packet_buffer[i] <= 126)
printf("%c",packet_buffer[i]);
}
printf("\n");
*/
}
}
int main(int argc, char *argv[]) {
int rs_fd;
int packet_length;
int last_packet_length = 0;
unsigned char packet_buffer[AQ_MAXPKTLEN];
unsigned char last_packet_buffer[AQ_MAXPKTLEN];
unsigned char lastID = 0x00;
int i = 0;
bool found;
serial_id_log slog[SLOG_MAX];
serial_id_log pent_slog[SLOG_MAX];
int sindex = 0;
int pent_sindex = 0;
int received_packets = 0;
int logPackets = PACKET_MAX;
int logLevel = LOG_NOTICE;
bool rsRawDebug = false;
bool panleProbe = true;
bool rsSerialSpeedTest = false;
bool serialBlocking = true;
bool errorMonitor = false;
struct timespec start_time;
struct timespec end_time;
struct timespec elapsed;
int blankReads = 0;
//bool playback_file = false;
//int logLevel;
//char buffer[256];
//bool idMode = true;
// Keep bogus crap happy for aq_serial.c
_aqconfig_.readahead_b4_write = false;
printf("AqualinkD %s\n",VERSION);
if (getuid() != 0) {
fprintf(stderr, "ERROR %s Can only be run as root\n", argv[0]);
return EXIT_FAILURE;
}
if (argc < 2 || access( argv[1], F_OK ) == -1 ) {
fprintf(stderr, "ERROR, first param must be valid serial port, ie:-\n\t%s /dev/ttyUSB0\n\n", argv[0]);
//fprintf(stderr, "Optional parameters are -d (debug) & -p <number> (log # packets) & -i <ID> & -r (raw) ie:=\n\t%s /dev/ttyUSB0 -d -p 1000 -i 0x08\n\n", argv[0]);
fprintf(stderr, "Optional parameters are :-\n");
fprintf(stderr, "\t-n (Do not probe panel for type/rev info)\n");
fprintf(stderr, "\t-d (debug)\n");
fprintf(stderr, "\t-p <number> (# packets to log, default=%d)\n",PACKET_MAX);
fprintf(stderr, "\t-i <ID> (just log these ID's, can use multiple -i)\n");
fprintf(stderr, "\t-r (raw)\n");
fprintf(stderr, "\t-s (Serial Speed Test / OS caching issues)\n");
fprintf(stderr, "\t-rsrd (log raw RS bytes to %s)\n",RS485BYTELOGFILE);
fprintf(stderr, "\t-e (monitor errors)\n");
fprintf(stderr, "\nie:\t%s /dev/ttyUSB0 -d -p 1000 -i 0x08 -i 0x0a\n\n", argv[0]);
return 1;
}
for (i = 2; i < argc; i++) {
if (strcmp(argv[i], "-d") == 0) {
logLevel = LOG_DEBUG;
} else if (strcmp(argv[i], "-p") == 0 && i+1 < argc) {
logPackets = atoi(argv[i+1]);
} else if (strcmp(argv[i], "-i") == 0 && i+1 < argc) {
unsigned int n;
sscanf(argv[i+1], "0x%2x", &n);
_filter[_filters] = n;
_filters++;
printf("Add filter %i 0x%02hhx\n",_filters, _filter[_filters-1]);
logLevel = LOG_DEBUG; // no point in filtering on ID if we're not going to print it.
} else if (strcmp(argv[i], "-r") == 0) {
_rawlog = true;
logLevel = LOG_DEBUG;
} else if (strcmp(argv[i], "-f") == 0) {
_playback_file = true;
} else if (strcmp(argv[i], "-rsrd") == 0) {
rsRawDebug = true;
} else if (strcmp(argv[i], "-n") == 0) {
panleProbe = false;
} else if (strcmp(argv[i], "-s") == 0) {
rsSerialSpeedTest = true;
serialBlocking = false;
} else if (strcmp(argv[i], "-e") == 0) {
errorMonitor = true;
}
}
setLoggingPrms(logLevel, false, false, NULL);
if (_playback_file) {
rs_fd = open(argv[1], O_RDONLY | O_NOCTTY | O_NONBLOCK | O_NDELAY);
if (rs_fd < 0) {
LOG(RSSD_LOG, LOG_ERR, "Unable to open file: %s\n", argv[1]);
displayLastSystemError(argv[1]);
return -1;
}
} else {
if (!serialBlocking)
rs_fd = init_serial_port(argv[1]);
else
rs_fd = init_blocking_serial_port(argv[1]);
}
signal(SIGINT, intHandler);
signal(SIGTERM, intHandler);
if (!errorMonitor) {
LOG(RSSD_LOG, LOG_NOTICE, "Logging serial information!\n");
} else {
LOG(RSSD_LOG, LOG_NOTICE, "Logging serial errors!\n");
}
if (logLevel < LOG_DEBUG && errorMonitor==false )
printf("Please wait.");
clock_gettime(CLOCK_REALTIME, &start_time);
while (_keepRunning == true) {
if (rs_fd < 0) {
LOG(RSSD_LOG, LOG_ERR, "ERROR, serial port disconnect\n");
}
//packet_length = get_packet(rs_fd, packet_buffer);
if (rsRawDebug)
packet_length = get_packet_lograw(rs_fd, packet_buffer);
else
packet_length = get_packet(rs_fd, packet_buffer);
if (packet_length == AQSERR_READ) {
// Unrecoverable read error. Force an attempt to reconnect.
LOG(RSSD_LOG, LOG_ERR, "ERROR, on serial port! Please check %s\n",argv[1]);
_keepRunning = false;
} else if (packet_length == AQSERR_TIMEOUT) {
// Unrecoverable read error. Force an attempt to reconnect.
LOG(RSSD_LOG, LOG_ERR, "ERROR, Timeout on serial port, nothing read! Please check %s\n",argv[1]);
_keepRunning = false;
} else if (packet_length < 0) {
// Error condition
if (errorMonitor && last_packet_length > 0) { // Error packet wwould have already been printed.
char buff[900];
beautifyPacket(buff, last_packet_buffer, last_packet_length);
LOG(RSSD_LOG, LOG_NOTICE, "Previous packet (before error)\n");
LOG(RSSD_LOG, LOG_NOTICE, "%s------------------------------\n",buff);
//LOG(RSSD_LOG, LOG_NOTICE, "\n");
}
} else if (packet_length == 0) {
// Nothing read
if (++blankReads > (rsSerialSpeedTest?100000000:1000) ) {
LOG(RSSD_LOG, LOG_ERR, "ERROR, too many blank reads! Please check %s\n",argv[1]);
_keepRunning = false;
}
//if (!rsSerialSpeedTest)
delay(1);
} else if (packet_length > 0) {
blankReads = 0;
//LOG(RSSD_LOG, LOG_DEBUG_SERIAL, "Received Packet for ID 0x%02hhx of type %s\n", packet_buffer[PKT_DEST], get_packet_type(packet_buffer, packet_length));
if (logLevel > LOG_NOTICE)
printPacket(lastID, packet_buffer, packet_length);
if (getProtocolType(packet_buffer) == PENTAIR) {
found = false;
for (i = 0; i <= pent_sindex; i++) {
if (pent_slog[i].ID == packet_buffer[PEN_PKT_FROM]) {
found = true;
break;
}
}
if (found == false) {
pent_slog[pent_sindex].ID = packet_buffer[PEN_PKT_FROM];
pent_slog[pent_sindex].inuse = true;
pent_sindex++;
}
} else {
if (packet_buffer[PKT_DEST] != DEV_MASTER) {
found = false;
for (i = 0; i <= sindex; i++) {
if (slog[i].ID == packet_buffer[PKT_DEST]) {
found = true;
break;
}
}
if (found != true && sindex < SLOG_MAX) {
slog[sindex].ID = packet_buffer[PKT_DEST];
slog[sindex].inuse = false;
sindex++;
}
}
if (packet_buffer[PKT_DEST] == DEV_MASTER /*&& packet_buffer[PKT_CMD] == CMD_ACK*/) {
//LOG(RSSD_LOG, LOG_NOTICE, "ID is in use 0x%02hhx %x\n", lastID, lastID);
for (i = 0; i <= sindex; i++) {
if (slog[i].ID == lastID) {
slog[i].inuse = true;
break;
}
}
}
if (panleProbe && packet_buffer[PKT_DEST] == 0x58 ) {
getPanelInfo(rs_fd, packet_buffer, packet_length);
}
lastID = packet_buffer[PKT_DEST];
}
received_packets++;
// NSF TESTING
/*
if (packet_buffer[PKT_DEST] == 0x40) {
static int hex = 0;
//printf("Sent ack\n");
//printf("Sent ack hex 0x%02hhx\n",(unsigned char)hex);
//send_extended_ack (rs_fd, 0x8b, (unsigned char)hex);
send_extended_ack (rs_fd, 0x8b, 0x00);
hex++;
}*/
// NSF
// Test Serial speed & caching
if (rsSerialSpeedTest) {
if (rsRawDebug)
packet_length = get_packet_lograw(rs_fd, packet_buffer);
else
packet_length = get_packet(rs_fd, packet_buffer);
if (packet_length > 0 && packet_buffer[PKT_DEST] != 0x00) {
// Only test for packets from panel, when you test to panel you are timing reply.
LOG(RSSD_LOG, LOG_ERR, "SERIOUS RS485 ERROR, Slow serial port read detected, (check RS485 adapteer / os performance / USB serial speed\n");
}
}
}
if (logPackets != 0 && received_packets >= logPackets) {
_keepRunning = false;
}
if (errorMonitor) {
if (packet_length > 0) {
memcpy(last_packet_buffer, packet_buffer, packet_length);
last_packet_length = packet_length;
received_packets = 0;
}
} else if (logLevel < LOG_DEBUG) {
advance_cursor();
}
//sleep(1);
}
clock_gettime(CLOCK_REALTIME, &end_time);
if (errorMonitor) {
return 0;
}
timespec_subtract(&elapsed, &end_time, &start_time);
LOG(RSSD_LOG, LOG_DEBUG, "\n\n");
if (logLevel < LOG_DEBUG)
printf("\n\n");
if (sindex >= SLOG_MAX)
LOG(RSSD_LOG, LOG_ERR, "Ran out of storage, some ID's were not captured, please increase SLOG_MAX and recompile\n");
if (elapsed.tv_sec > 0) {
LOG(RSSD_LOG, LOG_NOTICE, "RS485 interface received %d packets in %d seconds (~%.2f Msg/Sec)\n", received_packets, elapsed.tv_sec, (received_packets / (float)elapsed.tv_sec) );
}
LOG(RSSD_LOG, LOG_NOTICE, "Jandy Control Panel Model : %s\n", _panelType);
LOG(RSSD_LOG, LOG_NOTICE, "Jandy Control Panel Version : %s\n", _panelRev);
LOG(RSSD_LOG, LOG_NOTICE, "Jandy ID's found\n");
for (i = 0; i < sindex; i++) {
//LOG(RSSD_LOG, LOG_NOTICE, "ID 0x%02hhx is %s %s\n", slog[i].ID, (slog[i].inuse == true) ? "in use" : "not used",
// (slog[i].inuse == false && canUse(slog[i].ID) == true)? " <-- can use for Aqualinkd" : "");
if (logLevel >= LOG_DEBUG || slog[i].inuse == true || canUse(slog[i].ID) == true) {
LOG(RSSD_LOG, LOG_NOTICE, "ID 0x%02hhx is %s %s\n", slog[i].ID, (slog[i].inuse == true) ? "in use" : "not used",
(slog[i].inuse == false)?canUseExtended(slog[i].ID):getDevice(slog[i].ID));
}
}
if (pent_sindex > 0) {
LOG(RSSD_LOG, LOG_NOTICE, "\n\n");
LOG(RSSD_LOG, LOG_NOTICE, "Pentair ID's found\n");
}
for (i=0; i < pent_sindex; i++) {
LOG(RSSD_LOG, LOG_NOTICE, "ID 0x%02hhx is %s %s\n", pent_slog[i].ID, (pent_slog[i].inuse == true) ? "in use" : "not used",
(pent_slog[i].inuse == false)?canUseExtended(pent_slog[i].ID):getPentairDevice(pent_slog[i].ID));
}
LOG(RSSD_LOG, LOG_NOTICE, "\n\n");
return 0;
}
int timespec_subtract (struct timespec *result, const struct timespec *x, const struct timespec *y)
{
struct timespec tmp;
memcpy (&tmp, y, sizeof(struct timespec));
/* Perform the carry for the later subtraction by updating y. */
if (x->tv_nsec < tmp.tv_nsec)
{
int nsec = (tmp.tv_nsec - x->tv_nsec) / 1000000000 + 1;
tmp.tv_nsec -= 1000000000 * nsec;
tmp.tv_sec += nsec;
}
if (x->tv_nsec - tmp.tv_nsec > 1000000000)
{
int nsec = (x->tv_nsec - tmp.tv_nsec) / 1000000000;
tmp.tv_nsec += 1000000000 * nsec;
tmp.tv_sec -= nsec;
}
/* Compute the time remaining to wait.
tv_nsec is certainly positive. */
result->tv_sec = x->tv_sec - tmp.tv_sec;
result->tv_nsec = x->tv_nsec - tmp.tv_nsec;
/* Return 1 if result is negative. */
return x->tv_sec < tmp.tv_sec;
}