Class to communicate with ELV(R) MAX! wireless devices with RFM22B-Modules. Based on Library RF22. Initial version unable to send! Only receive! See http://mbed.org/users/charly/notebook/reading-a-max-wireless-window-sensor-with-rfm22-an/

Dependents:   RF22_MAX_test_Send

Files at this revision

API Documentation at this revision

Comitter:
charly
Date:
Tue Oct 22 19:41:52 2013 +0000
Parent:
1:6321e6784ada
Commit message:
Changes for Sending Messages

Changed in this revision

RF22Max.cpp Show annotated file Show diff for this revision Revisions of this file
RF22Max.h Show annotated file Show diff for this revision Revisions of this file
--- a/RF22Max.cpp	Wed Sep 18 20:03:26 2013 +0000
+++ b/RF22Max.cpp	Tue Oct 22 19:41:52 2013 +0000
@@ -1,3 +1,6 @@
+//show debug output on Serial pc
+#define DEBUG
+
 #include "mbed.h"
 #include <RF22Max.h>
 
@@ -8,9 +11,9 @@
 }
 
 static const RF22::ModemConfig max_config = { // for MAX! protocol
-    .reg_1c = 0x01,
-    .reg_1f = 0x03,
-    .reg_20 = 0x90,
+    .reg_1c = 0x01, //POR-Value : 75KHzBW?
+    .reg_1f = 0x03, //POR-Value: 
+    .reg_20 = 0x90, //?? Oversampling Rate
     .reg_21 = 0x20,
     .reg_22 = 0x51,
     .reg_23 = 0xea,
@@ -22,10 +25,12 @@
     .reg_2e = 0x00,
     .reg_58 = 0x80, // Copied from RF22 defaults
     .reg_69 = 0x60, // Copied from RF22 defaults
-    .reg_6e = 0x08,
-    .reg_6f = 0x31,
-    .reg_70 = 0x24,
-    .reg_71 = RF22_DTMOD_FIFO | RF22_MODTYP_FSK,
+    //.reg_6e = 0x08, // TX Data Rate 1
+    //.reg_6f = 0x31, // TX Data Rate 0
+    .reg_6e = 0x51, // TX Data Rate 1
+    .reg_6f = 0xDC, // TX Data Rate 0
+    .reg_70 = 0x20, //<30kps,no manchaster, no dewithening
+    .reg_71 = RF22_DTMOD_FIFO | RF22_MODTYP_FSK, //=0x22
     .reg_72 = 0x1e,
 };
 
@@ -169,7 +174,7 @@
     if (ret) {
         //Max! specific settings
         this->RF22::setModemRegisters(&max_config);
-        this->RF22::setFrequency(868.3, 0.035);
+        this->RF22::setFrequency(868.299866, 0.035);
         /* Disable TX packet control, since the RF22 doesn't do proper
          * whitening so can't read the length header or CRC. We need RX packet
          * control so the RF22 actually sends pkvalid interrupts when the
@@ -181,8 +186,8 @@
         this->RF22::setSyncWords(max_sync_words, lengthof(max_sync_words));
         /* Detect preamble after 4 nibbles */
         this->RF22::spiWrite(RF22_REG_35_PREAMBLE_DETECTION_CONTROL1, (0x4 << 3));
-        /* Send 8 bytes of preamble */
-        this->RF22::setPreambleLength(8); // in nibbles
+        /* Send 4 nibbles of preamble */
+        this->RF22::setPreambleLength(4); // in nibbles
         this->RF22::spiWrite(RF22_REG_3E_PACKET_LENGTH, 30); // maximum length of a MAX!-packet
     }
     return ret;
@@ -310,6 +315,52 @@
             }
 
         }
+#if 0
+        if (message->type == 0x00 && len >= 11) { //PairPing
+            char    serial[20]="";
+            uint8_t sbuf[RF22_MAX_MESSAGE_LEN];
+            uint8_t slen =0;
+            
+            strncpy(serial,(char*)buf+14,10); //10 Characters for Seial Number
+            serial[11] = '\0';
+#ifdef DEBUG                    
+            pc.printf("Serial:        %s\n\r",serial);
+#endif            
+
+            // try to send PairPong
+            // wait some time
+            wait_ms(20);         // seen at moritz-code
+            sbuf[0] = 11; // MsgLen
+            sbuf[1] = buf[1]+1 &0xFF; // MsgCount ??
+            sbuf[2] = 0x00; // Flag
+            sbuf[3] = 0x01; // Type = Cmd = PairPong
+            sbuf[4] = 0x11; // From Fake Address
+            sbuf[5] = 0x11; // From
+            sbuf[6] = 0x11; // From
+            sbuf[7] = buf[4] ; // To Address = From address of Windowcontact
+            sbuf[8] = buf[5] ;
+            sbuf[9] = buf[6] ;
+            sbuf[10] = 0x00; // GroupId
+            sbuf[11] = 0x00;  //Payload is 0x00 for pairpong?
+            slen = 12+2; //+2Byte CRC????
+            /* Calculate CRC */
+            uint16_t scrc = calc_crc(sbuf, slen - 2);
+            sbuf[12] = crc >> 8;
+            sbuf[13] = crc & 0xff;
+
+
+            if (RF22::send(sbuf,slen)) {
+#ifdef DEBUG        
+                pc.printf("Send PairPong OK\n\r");
+#endif                
+            } else {
+#ifdef DEBUG                    
+                pc.printf("Send PairPong NOT OK\n\r");
+#endif                
+            }
+
+        }
+#endif
         return true;
     } else
         return false;
--- a/RF22Max.h	Wed Sep 18 20:03:26 2013 +0000
+++ b/RF22Max.h	Tue Oct 22 19:41:52 2013 +0000
@@ -113,15 +113,19 @@
     boolean init();
 
     /// start receiver and see if a valid MAX!-message is available and return it undecoded to the caller
+    ///
     /// nonblocking
-    /// check crc and do dewithening
+    ///
+    /// do NOT check crc and DO dewithening
     /// \param[in] buf Location to copy the received message
     /// \param[in,out] len Pointer to available space in buf(copies maximum len bytes!). Set to the actual number of octets copied.
     /// \return true if a valid message was copied to buf
     boolean recv(uint8_t* buf, uint8_t* len);
 
     /// start receiver and see if a valid MAX!-message is available and return the decoded message to the caller
+    ///
     /// nonblocking
+    ///
     /// check crc and do dewithening and do decoding of fields
     /// \param[in] message A pointer to a RF22Max::max_message
     /// \return true if a valid message was copied to buf
@@ -134,10 +138,14 @@
     void printHex(uint8_t *buf, size_t len, bool nl);
 #endif
 
+
     /// calc_crc_setup setup crc-calculation
     uint16_t calc_crc_step(uint8_t crcData, uint16_t crcReg);
-
-    /// calc_crc calculate crc for the data in buf
+    
+public:
+    /// calculate crc for the data in buf with len
+    /// \param[in] buf message to calculate crc for
+    /// \param[in,out] len of message
     uint16_t calc_crc(uint8_t *buf, size_t len);