/* * modbuslog * * Copyright (C) 2011 Jonathan McCrohan * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * 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. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ // gcc modbuslog.c -o modbuslog `pkg-config --libs --cflags libmodbus libconfig` #ifndef VERSION_STRING #define VERSION_STRING "[undefined version]" #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // handle SIGALRM by resetting it void minute_check(int signum) { alarm(60); } // get mac address of primary interface eth0 char *mac_address() { int s; struct ifreq ifr; s = socket(PF_INET, SOCK_DGRAM, 0); memset(&ifr, 0x00, sizeof(ifr)); strcpy(ifr.ifr_name, "eth0"); ioctl(s, SIOCGIFHWADDR, &ifr); close(s); static char mac_address[12]; sprintf(mac_address, "%.2X%.2X%.2X%.2X%.2X%.2X", (unsigned char) ifr.ifr_hwaddr.sa_data[0], (unsigned char) ifr.ifr_hwaddr.sa_data[1], (unsigned char) ifr.ifr_hwaddr.sa_data[2], (unsigned char) ifr.ifr_hwaddr.sa_data[3], (unsigned char) ifr.ifr_hwaddr.sa_data[4], (unsigned char) ifr.ifr_hwaddr.sa_data[5]); return mac_address; } int main(int argc, char *argv[]) { int DEBUG = 0; int SYSLOG_CONSOLE_OUTPUT = 0; int k; // check the argv array for strings matching -d for (k = 1; k < argc; k++) { if (strcmp(argv[k], "-d") == 0) { DEBUG = 1; SYSLOG_CONSOLE_OUTPUT = LOG_PERROR; } } openlog("modbuslog", SYSLOG_CONSOLE_OUTPUT | LOG_PID | LOG_CONS, LOG_USER); syslog(LOG_INFO, ""); syslog(LOG_INFO, "modbuslog [%s] starting", VERSION_STRING); syslog(LOG_INFO, ""); const char *configfile = "/etc/modbuslog.cfg"; config_t cfg; //config_setting_t *setting; const char *modbus_device_address; int modbus_baud_rate; int modbus_data_bits; const char *modbus_parity; int modbus_stop_bits; int modbus_retry; config_init(&cfg); // attempt to read config // loads entire file to memory and destroys file descriptor if (!config_read_file(&cfg, configfile)) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); syslog(LOG_ERR, "Unable to find configfile"); return -1; } else { syslog(LOG_INFO, "configfile found successfu
# Digitenne (Randstad, The Netherlands)
# T freq bw fec_hi fec_lo mod transmission-mode guard-interval hierarchy
T 474000000 8MHz 1/2 NONE QAM64 8k 1/4 NONE
T 490000000 8MHz 1/2 NONE QAM64 8k 1/4 NONE
T 578000000 8MHz 1/2 NONE QAM64 8k 1/4 NONE
T 762000000 8MHz 1/2 NONE QAM64 8k 1/4 NONE
T 818000000 8MHz 1/2 NONE QAM64 8k 1/4 NONE
stervalue = ((byte[0]) << 8) + byte[1]; break; } struct tm utc = *gmtime(&unixtime_min); struct tm lc = *localtime(&unixtime_min); int intervalid; char interval_filename[50]; sprintf(interval_filename, "/var/modbuslog/interval/interval.txt"); syslog(LOG_DEBUG, "opening interval file: [%s]", interval_filename); FILE *intervalfile = fopen(interval_filename, "r+"); if (intervalfile) { fclose(intervalfile); } else { // file doesn't exist. create it. syslog(LOG_NOTICE, "interval file does not exist"); syslog(LOG_INFO, "attempting to create file: [%s]", interval_filename); intervalfile = fopen(interval_filename, "w"); fprintf(intervalfile, "0\n"); fclose(intervalfile); } // file now exists, try opening again intervalfile = fopen(interval_filename, "r+"); fscanf(intervalfile, "%d", &intervalid); //handle 32bit signed overflow if (intervalid == 2147483647) { intervalid = 0; } else { intervalid++; } rewind(intervalfile); fprintf(intervalfile, "%d", intervalid); fclose(intervalfile); fprintf( filehandle, "%i|%04i%02i%02i|%02i%02i%02i|%04i%02i%02i|%02i%02i%02i|%i|%i|%i\n", intervalid, utc.tm_year + 1900, utc.tm_mon + 1, utc.tm_mday, utc.tm_hour, utc.tm_min, utc.tm_sec, lc.tm_year + 1900, lc.tm_mon + 1, lc.tm_mday, lc.tm_hour, lc.tm_min, lc.tm_sec, slaveid, startaddress, registervalue); fclose(filehandle); syslog( LOG_DEBUG, "[%i|%04i%02i%02i|%02i%02i%02i|%04i%02i%02i|%02i%02i%02i|%i|%i|%i]\n", intervalid, utc.tm_year + 1900, utc.tm_mon + 1, utc.tm_mday, utc.tm_hour, utc.tm_min, utc.tm_sec, lc.tm_year + 1900, lc.tm_mon + 1, lc.tm_mday, lc.tm_hour, lc.tm_min, lc.tm_sec, slaveid, startaddress, registervalue); modbus_close(ctx); modbus_free(ctx); sleep(1); //return 0; } //printf("%d ", slaveid); } // revert to normal timing firstrun = 0; //printf("%d\n", unixtime_min); } }