Skip to content

Commit

Permalink
Umstrukturierung
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirk Melchers committed Apr 10, 2011
1 parent 0c4b319 commit d99d189
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 87 deletions.
69 changes: 11 additions & 58 deletions HausMessung/Strom_Transmitter/Strom_Transmitter.pde
Expand Up @@ -9,10 +9,8 @@

#include <Ports.h>
#include <RF12.h>
#include <util/crc16.h>
#include <util/parity.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>

#include "hausmessung.h"

#define SCHWELLWERT_IN 300
#define SCHWELLWERT_OUT 250
Expand All @@ -21,50 +19,6 @@
#define REFLEX_DEBUG 1


// Utility class to fill a buffer with string data
class PacketBuffer : public Print {
public:
PacketBuffer () : fill (0) {
}

const byte* buffer() {
return buf;
}

byte length() {
return fill;
}

void reset() {
fill = 0;
}

const char* print() {
buf[fill]=0;
return (char *)buf;
}

virtual void write(uint8_t ch)
{
if (fill < sizeof buf) buf[fill++] = ch;
}

private:
byte fill, buf[RF12_MAXDATA];
};


// no-cost stream operator as described at
// http://sundial.org/arduino/?page_id=119
template<class T>
inline Print &operator <<(Print &obj, T arg)
{
obj.print(arg);
return obj;
}



unsigned long watt = 0;
unsigned long counter=0;

Expand All @@ -77,8 +31,6 @@ unsigned long tx_counter=0;

Port strom (1);
byte myId;
PacketBuffer payload; // temp buffer to send out

int insend=0;


Expand All @@ -92,6 +44,7 @@ void setup()
strom.mode(OUTPUT);
}

struct payload_data payload;

void loop()
{
Expand Down Expand Up @@ -177,16 +130,16 @@ void loop()

tx_counter++;

payload.reset();
payload << "Strom" << ";"<< 1 << ";" << watt << ";" << counter << ";" << time << ";" << tx_counter;
payload.typ = 2;
payload.id = 1;
payload.data.strom.watt = watt;
payload.data.strom.count = counter;
payload.data.strom.tx_count = tx_counter;

#if REFLEX_DEBUG > 0
Serial << "Transmit: " << payload.print() << "\n";
#endif
Serial << "Strom: " << payload.data.strom.watt << ";" << payload.data.strom.count << ";"<< payload.data.strom.tx_count << "\n";

byte header = RF12_HDR_ACK;
header |= RF12_HDR_DST | 1;
rf12_sendStart(header, payload.buffer() , payload.length());
byte header = RF12_HDR_ACK | RF12_HDR_DST | 1;
rf12_sendStart(header, &payload, sizeof payload);
rf12_sendWait(0);

last_transmit = millis();
Expand Down
1 change: 1 addition & 0 deletions HausMessung/Strom_Transmitter/hausmessung.h
33 changes: 4 additions & 29 deletions HausMessung/Temp_Transmitter/Temp_Transmitter.pde
Expand Up @@ -4,6 +4,7 @@
#include <Ports.h>
#include <RF12.h>

#include "hausmessung.h"

// Data wire is plugged into port 3 on the Arduino
#define ONE_WIRE_BUS 3
Expand All @@ -12,33 +13,6 @@
#define TRANSMIT_RATE 1000


struct {
byte typ;
byte id; // temp sensor: 0..255
union {
struct {
int temp; // temperature * 100
char name[20];
} temperatur;
struct {
int watt;
unsigned long count;
unsigned long transmittcount;
} strom;
} data;
} payload;


// no-cost stream operator as described at
// http://sundial.org/arduino/?page_id=119
template<class T>
inline Print &operator <<(Print &obj, T arg)
{
obj.print(arg);
return obj;
}


// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

Expand Down Expand Up @@ -99,6 +73,8 @@ byte myId;
unsigned long last_transmit = 0;
unsigned long tx_counter=0;

struct payload_data payload;


void init_temp(void) {
// Start up the library
Expand Down Expand Up @@ -178,8 +154,7 @@ void loop(void)
payload.id = i;
payload.typ = 1;
strncpy((char*)payload.data.temperatur.name, device_names[i], 19);
float tempC = sensors.getTempC(device_ids[i]);
payload.data.temperatur.temp = (int)(tempC*100);
payload.data.temperatur.temp = sensors.getTempC(device_ids[i]);
Serial << "Temp" << ";"<< i << ";" << payload.data.temperatur.temp << ";" << payload.data.temperatur.name << "\n";

byte header = RF12_HDR_ACK | RF12_HDR_DST | 1;
Expand Down
1 change: 1 addition & 0 deletions HausMessung/Temp_Transmitter/hausmessung.h
25 changes: 25 additions & 0 deletions HausMessung/hausmessung.h
@@ -0,0 +1,25 @@
struct payload_data {
byte typ; // typ = 1: temp, 2: strom
byte id; // sensor id: 0..255
union {
struct {
float temp; // temperature * 100
char name[20];
} temperatur;
struct {
int watt;
unsigned long count;
unsigned long tx_count;
} strom;
} data;
};


// no-cost stream operator as described at
// http://sundial.org/arduino/?page_id=119
template<class T>
inline Print &operator <<(Print &obj, T arg)
{
obj.print(arg);
return obj;
}
2 changes: 2 additions & 0 deletions Hausmessung.kpf
Expand Up @@ -5,6 +5,8 @@
</file>
<file id="24b049e2-d177-a040-a1e3-8daf06e20450" idref="9b120cb2-1cb4-5147-9456-7b21aef52236" name="Temp_Transmitter.pde" url="HausMessung/Temp_Transmitter/Temp_Transmitter.pde">
</file>
<file id="4908fa9c-75b2-db4e-a1f9-d6434324f074" idref="9b120cb2-1cb4-5147-9456-7b21aef52236" name="hausmessung.h" url="HausMessung/hausmessung.h">
</file>
<file id="5331b0ef-db83-ae44-b5fb-93d5672472aa" idref="9b120cb2-1cb4-5147-9456-7b21aef52236" name="Strom_Transmitter.pde" url="HausMessung/Strom_Transmitter/Strom_Transmitter.pde">
</file>
<file id="67da3387-bb0a-ad48-9168-baeba45901f7" idref="9b120cb2-1cb4-5147-9456-7b21aef52236" name="read_serial_rf12_data.pl" url="HausMessung/read_serial_rf12_data/read_serial_rf12_data.pl">
Expand Down

0 comments on commit d99d189

Please sign in to comment.