#include #include #include #include #include "ow-functions.h" #include "dev-functions.h" #define ADAPTER_SETTINGS_FILE "DS2490-settings.dat" extern int sleepSeconds (int sec); static volatile sig_atomic_t interrupted = 0; void handler (int signal) { interrupted = 1; return; } int main() { owDevice devList[MAX_DEVICES]; long numDevices, n; if (signal (SIGINT, &handler) == SIG_ERR) { fprintf (stderr, "ERROR: Signal handler could not be initialized\n"); return EXIT_FAILURE; } // Read adapter settings from file readAdapterSettings (ADAPTER_SETTINGS_FILE); // Acquire adapter if ( acquireAdapter() < 0 ) { return EXIT_FAILURE; } // Reset adapter if ( resetAdapter() < 0 ) { releaseAdapter(); return EXIT_FAILURE; } // Find Devices numDevices = makeDeviceList (devList); if (numDevices <= 0) { releaseAdapter(); return EXIT_FAILURE; } while (!interrupted) { // Set up devices if needed for (n = 0; n < numDevices; n++) { if (devList[n].configError | devList[n].alarmError) { setupDevice (&devList[n]); } } // Initiate conversions for (n = 0; n < numDevices; n++) { if ( !(devList[n].configError) ) { doConversion (&devList[n]); } } // Sleep 1 second if (sleepSeconds(1) < 0) { if (interrupted) { break; } fprintf (stderr, "ERROR: Sleep failed\n"); errPrintDet (NULL); fprintf (stderr, "\n"); for (n = 0; n < numDevices; n++) { devList[n].convertError = 1; } } for (n = 0; n < numDevices; n++) { if (devList[n].channels != 0) { devList[n].tries++; } } // Read devices for (n = 0; n < numDevices; n++) { if ( !(devList[n].configError | devList[n].convertError) ) { float data[MAX_CHANNELS]; if ( readDevice(&devList[n], data) < 0 ) { fprintf (stderr, "\n"); } else { int i; printf ("%lu ", (unsigned long) devList[n].convertTime); for (i = 7; i >= 0; i--) { printf ("%02X", devList[n].SN[i]); } for (i = 0; i < devList[n].channels; i++) { printf (" %8.4f", data[i]); } printf ("\n"); } } } // Search for alarming devices alarmSearch (devList, numDevices); } printSuccessRate (devList, numDevices); releaseAdapter(); return 0; }