Interrupt Zaehler: Unterschied zwischen den Versionen
Kiwi (Diskussion | Beiträge) K |
Kiwi (Diskussion | Beiträge) K |
||
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
Zeile 47: | Zeile 47: | ||
for (;;) { | for (;;) { | ||
// syslog format, initial <Priority Facility> | // syslog format, initial <Priority Facility> | ||
− | TCP_SEND("<27>%s %02d %02d:%02d:%02d %s interrupt: InterruptCall=%d", &YearMonth[CLOCK_MONTH()], CLOCK_DAY(), CLOCK_HOUR(), CLOCK_MIN(), CLOCK_SEC(), CONF_HOSTNAME, InterruptCall); | + | TCP_SEND("<27>%s %02d %02d:%02d:%02d %s interrupt: InterruptCall=%d\n", &YearMonth[CLOCK_MONTH()], CLOCK_DAY(), CLOCK_HOUR(), CLOCK_MIN(), CLOCK_SEC(), CONF_HOSTNAME, InterruptCall); |
WAIT(60); | WAIT(60); | ||
} | } | ||
Zeile 58: | Zeile 58: | ||
</source> | </source> | ||
<br> | <br> | ||
+ | <br> | ||
+ | <br> | ||
+ | <br> | ||
+ | <source lang="text"> | ||
+ | // ################################################################################ | ||
+ | // # # | ||
+ | // # Interrupt Counter # | ||
+ | // # Copyright (C) 2010 - Michael Schultz <ethersex@keyb.de> # | ||
+ | // # Mit viel unterstuetzung/Geduld von: stesie, veyron und DanielW # | ||
+ | // # # | ||
+ | // # This program is free software; you can redistribute it and/or modify it # | ||
+ | // # under the terms of the GNU General Public License (either version 2 or # | ||
+ | // # version 3) as published by the Free Software Foundation. # | ||
+ | // # # | ||
+ | // # 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, write to the Free Software # | ||
+ | // # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # | ||
+ | // # # | ||
+ | // # For more information on the GPL, please go to: # | ||
+ | // # http://www.gnu.org/copyleft/gpl.html # | ||
+ | // # # | ||
+ | // # Anwendung z.b. Auslesen/Übertragen von Strom/Gas/Wasser Zähler Impulsen # | ||
+ | // # Läuft nur auf Prozessoren mit Pin Change Interrupt !! # | ||
+ | // # z.b. ATMega644 / ATMega644p # | ||
+ | // # # | ||
+ | // # Daten übermittlung alle 60 Sekunden, TCP, Syslog format # | ||
+ | // ################################################################################ | ||
+ | // Logging Destination Host: 10.0.0.77 on Port 95 | ||
+ | |||
+ | char YearMonth[13][4] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | ||
+ | |||
+ | uint16_t count = 0 ; // loop Count | ||
+ | uint16_t InterruptCall = 0 ; // Interrupt counter | ||
+ | |||
+ | CONTROL_START | ||
+ | ON STARTUP DO | ||
+ | // aktiviere den Pin Change Interrupt für PA7 / ADC7 | ||
+ | PCMSK0 |= (1 << PCINT7); // PCMSK0(PCINT7) = 1 Pin Change Enable Mask | ||
+ | PCICR |= (1 << PCIE0); // PCICR(PCIE0) = 1 Pin Change Interrupt Enable 0 | ||
+ | |||
+ | // aktiviere Pullup wiederstand für PA7 / ADC7 | ||
+ | DDRA &= ~(1 << PA7); // DDRA(PA7) = 0 | ||
+ | PORTA |= (1 << PA7); // PORTA(PA7) = 1 | ||
+ | MCUCR &= ~(1 << PUD); // MCUCR(PUD) = 0 Pull-up Disable = 0 | ||
+ | |||
+ | TCP_CONNECT(10.0.0.77, 95, message_handler); | ||
+ | END | ||
+ | TCP_HANDLER_PERSIST(message_handler) | ||
+ | for (;;) { | ||
+ | // syslog sending | ||
+ | count ++; | ||
+ | TCP_SEND("<27>%s %02d %02d:%02d:%02d %s interrupt: InterruptCall=%d count=%d\n", &YearMonth[CLOCK_MONTH()], CLOCK_DAY(), CLOCK_HOUR(), CLOCK_MIN(), CLOCK_SEC(), CONF_HOSTNAME, InterruptCall, count); | ||
+ | WAIT(60); | ||
+ | } | ||
+ | TCP_HANDLER_END(); | ||
+ | CONTROL_END | ||
+ | |||
+ | // ############################################################################################################################### | ||
+ | ISR(PCINT0_vect) { | ||
+ | InterruptCall ++; | ||
+ | PCIFR &= ~(1 << PCIF0); // PCIFR(PCIF0) = 0 | ||
+ | } | ||
+ | </source> | ||
<br> | <br> | ||
<br> | <br> |
Aktuelle Version vom 14. August 2010, 21:15 Uhr
// ################################################################################
// # #
// # Interrupt Counter #
// # Copyright (C) 2010 - Michael Schultz <ethersex@keyb.de> #
// # Mit viel unterstuetzung/Geduld von: stesie, veyron und DanielW #
// # #
// # This program is free software; you can redistribute it and/or modify it #
// # under the terms of the GNU General Public License (either version 2 or #
// # version 3) as published by the Free Software Foundation. #
// # #
// # 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, write to the Free Software #
// # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
// # #
// # For more information on the GPL, please go to: #
// # http://www.gnu.org/copyleft/gpl.html #
// # #
// # Anwendung z.b. Auslesen/Übertragen von Strom/Gas/Wasser Zähler Impulsen #
// # Getestet auf ATMega644 und ATMega32 #
// # #
// # Daten übermittlung alle 60 Sekunden, TCP, Syslog format #
// ################################################################################
// Logging Destination Host: 10.0.0.77 on Port 95
char YearMonth[13][4] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
uint16_t InterruptCall = 0 ; // Interrupt0 aufrufs counter
CONTROL_START
ON STARTUP DO
_EIMSK |= _BV(INT0); // EIMSK(INT0) = 1 Interrupt, Input Data on INT0 / PD2
_EICRA &= ~_BV(ISC01); // EICRA(ISC01) = 0 interrupt on any edge, asyncronously
_EICRA |= _BV(ISC00); // EICRA(ISC00) = 1 interrupt on any edge, asyncronously
TCP_CONNECT(10.0.0.77, 95, message_handler);
END
TCP_HANDLER_PERSIST(message_handler)
for (;;) {
// syslog format, initial <Priority Facility>
TCP_SEND("<27>%s %02d %02d:%02d:%02d %s interrupt: InterruptCall=%d\n", &YearMonth[CLOCK_MONTH()], CLOCK_DAY(), CLOCK_HOUR(), CLOCK_MIN(), CLOCK_SEC(), CONF_HOSTNAME, InterruptCall);
WAIT(60);
}
TCP_HANDLER_END();
CONTROL_END
// ###############################################################################################################################
ISR(INT0_vect) {
InterruptCall ++;
}
// ################################################################################
// # #
// # Interrupt Counter #
// # Copyright (C) 2010 - Michael Schultz <ethersex@keyb.de> #
// # Mit viel unterstuetzung/Geduld von: stesie, veyron und DanielW #
// # #
// # This program is free software; you can redistribute it and/or modify it #
// # under the terms of the GNU General Public License (either version 2 or #
// # version 3) as published by the Free Software Foundation. #
// # #
// # 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, write to the Free Software #
// # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
// # #
// # For more information on the GPL, please go to: #
// # http://www.gnu.org/copyleft/gpl.html #
// # #
// # Anwendung z.b. Auslesen/Übertragen von Strom/Gas/Wasser Zähler Impulsen #
// # Läuft nur auf Prozessoren mit Pin Change Interrupt !! #
// # z.b. ATMega644 / ATMega644p #
// # #
// # Daten übermittlung alle 60 Sekunden, TCP, Syslog format #
// ################################################################################
// Logging Destination Host: 10.0.0.77 on Port 95
char YearMonth[13][4] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
uint16_t count = 0 ; // loop Count
uint16_t InterruptCall = 0 ; // Interrupt counter
CONTROL_START
ON STARTUP DO
// aktiviere den Pin Change Interrupt für PA7 / ADC7
PCMSK0 |= (1 << PCINT7); // PCMSK0(PCINT7) = 1 Pin Change Enable Mask
PCICR |= (1 << PCIE0); // PCICR(PCIE0) = 1 Pin Change Interrupt Enable 0
// aktiviere Pullup wiederstand für PA7 / ADC7
DDRA &= ~(1 << PA7); // DDRA(PA7) = 0
PORTA |= (1 << PA7); // PORTA(PA7) = 1
MCUCR &= ~(1 << PUD); // MCUCR(PUD) = 0 Pull-up Disable = 0
TCP_CONNECT(10.0.0.77, 95, message_handler);
END
TCP_HANDLER_PERSIST(message_handler)
for (;;) {
// syslog sending
count ++;
TCP_SEND("<27>%s %02d %02d:%02d:%02d %s interrupt: InterruptCall=%d count=%d\n", &YearMonth[CLOCK_MONTH()], CLOCK_DAY(), CLOCK_HOUR(), CLOCK_MIN(), CLOCK_SEC(), CONF_HOSTNAME, InterruptCall, count);
WAIT(60);
}
TCP_HANDLER_END();
CONTROL_END
// ###############################################################################################################################
ISR(PCINT0_vect) {
InterruptCall ++;
PCIFR &= ~(1 << PCIF0); // PCIFR(PCIF0) = 0
}
Emfangen der Daten Mittels Syslog-NG
Sample "/etc/syslog-ng/syslog-ng.conf" File
################################################################################
# Speicherung der "Wetter" Daten (Temp und Feuchte)
################################################################################
source src_net_t95 { tcp( ip(10.0.0.77) port(95) max_connections(1000) ); };
destination dst_file_t95 { file("/mnt/log/current/$YEAR/$MONTH/$DAY/$HOUR/$HOST/$PROGRAM/$FACILITY.$PRIORITY.log"); };
log { source(src_net_t95); destination(dst_file_t95); };
################################################################################
So sehen die daten dann gespeichert aus:
(/mnt/log/current/2010/05/02/06/wichtel/ethersex/daemon.err.log
May 2 06:25:00 wichtel interrupt: InterruptCall=0
May 2 06:26:01 wichtel interrupt: InterruptCall=588