Patch for rfcmd to support EVERFLOURISH devices

Moderator: Telldus

Post Reply
egil
Posts: 3
Joined: Fri Mar 17, 2023 9:45 am

Patch for rfcmd to support EVERFLOURISH devices

Post by egil »

based on the excellent magic by Snakehand, this integrates his discoveries into the rfcmd. It is against version 2.0.1:

Code: Select all

--- rfcmd.c.orig	2009-10-22 16:31:13.000000000 +0200
+++ rfcmd.c	2010-03-15 21:34:58.000000000 +0100
@@ -56,6 +56,19 @@
  *    Arg 5: Level (0=off, 1 = on)
  ******************************************************************************/
 
+/*******************************************************************************
+ * Modifications from rfcmd.c ver 2.1.0 based on marvelous work by Snakehand
+ * See http://telldus.se/forum/viewtopic.php?t=97&start=63
+ *  Added support for EVERFLOURISH
+ * Note:
+ * 1. Command line syntax:
+ *    /usr/local/bin/rfcmd  /dev/ttyUSB0  EVERFLOURISH 1 15
+ *    Arg 1: device
+ *    Arg 2: protocol
+ *    Arg 3: device number (0..65535)
+ *    Arg 4: Level (0=off, 15=on, 10=learn)
+ ******************************************************************************/
+
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -79,6 +92,8 @@
                      char * pStrReturn);
 int createRisingSunString(const char * pCodeStr, const char* pUnitStr, const char * pOn_offStr,
                         char * pTxStr);
+int createEverFlourishString(const char* pUnitStr, const char * pLevelStr,
+                        char * pTxStr);
 
 void printUsage(void);
 void printVersion(void);
@@ -128,6 +143,13 @@
 			exit(1);
 			}
 			/* else - a send cmd string was created */
+        } else if ( (argc == 5) && (strcmp(*(argv+2),"EVERFLOURISH")==0) ) {
+        //                      Unit,          Level
+                if ( createEverFlourishString(*(argv+3), *(argv+4), txStr) == 0 ) {
+			printUsage();
+			exit(1);
+			}
+			/* else - a send cmd string was created */
 	} else if ( (argc >= 2) && (strcmp(*(argv+1),"--version")==0) ) {
 		printVersion();
 		exit(1);
@@ -501,6 +523,81 @@
 }
 
 
+unsigned int everflourish_find_code(unsigned int x)
+{
+    unsigned int bits[16] = { 0xf ,0xa ,0x7 ,0xe,
+                              0xf ,0xd ,0x9 ,0x1,
+                              0x1 ,0x2 ,0x4 ,0x8,
+                              0x3 ,0x6 ,0xc ,0xb };
+    unsigned int bit = 1;
+    unsigned int res = 0x5;
+    int i;
+    unsigned int lo,hi;
+
+    if ((x&0x3)==3) {
+        lo = x & 0x00ff;
+        hi = x & 0xff00;
+        lo += 4;
+        if (lo>0x100) lo = 0x12;
+        x = lo | hi;
+    }
+
+    for(i=0;i<16;i++) {
+        if (x&bit) {
+            res = res ^ bits[i];
+        }
+        bit = bit << 1;
+    }
+
+    return res;
+}
+
+
+int createEverFlourishString(const char * pUnitStr, const char * pLevelStr,
+                        char * pTxStr)
+{
+        int len = 0;
+	int level;
+	int unit;
+        unsigned int check;
+	int i;
+
+        unit = atoi(pUnitStr);
+	level = atoi(pLevelStr);                /* ON=15, OFF=0, LEARN=10 */
+        check = everflourish_find_code(unit);
+
+#ifdef RFCMD_DEBUG
+	printf("unit: %d, level: %d\n", unit, level);
+#endif
+
+	/* check converted parameters for validity */
+        if((unit < 0) || (unit > 0xffff) ||
+           (level < 0) || (level > 15)) {
+	} else {
+            const char ssss = 85;
+            const char sssl = 84; // 0
+            const char slss = 69; // 1
+
+            const char bits[2] = {sssl,slss};
+            int i;
+
+            char preamble[] = {'R', 5, 'T', 114,60,1,1,105,ssss,ssss};
+	    memcpy(pTxStr, preamble, sizeof(preamble));
+            len += sizeof(preamble);
+
+	    for(i=15;i>=0;i--) pTxStr[len++]=bits[(unit>>i)&0x01];
+	    for(i=3;i>=0;i--) pTxStr[len++]=bits[(check>>i)&0x01];
+	    for(i=3;i>=0;i--) pTxStr[len++]=bits[(level>>i)&0x01];
+
+	    pTxStr[len++] = ssss;
+	    pTxStr[len++] = '+';
+	}
+
+        pTxStr[len] = '\0';
+	return strlen(pTxStr);
+}
+
+
 void printUsage(void)
 {
 	printf("Usage: rfcmd DEVICE PROTOCOL [PROTOCOL_ARGUMENTS] \n");
@@ -510,7 +607,7 @@
 #else
 	printf("\t DEVICE: /dev/ttyUSB[0..n]\n" );
 #endif
-	printf("\t PROTOCOLS: NEXA, SARTANO, WAVEMAN, IKEA, RISINGSUN\n" );
+	printf("\t PROTOCOLS: NEXA, SARTANO, WAVEMAN, IKEA, RISINGSUN, EVERFLOURISH\n" );
 	printf("\n");
 	printf("\t PROTOCOL ARGUMENTS - NEXA, WAVEMAN:\n");
 	printf("\t\tHOUSE_CODE: A..P\n\t\tCHANNEL: 1..16\n\t\tOFF_ON: 0..1\n" );
@@ -526,6 +623,10 @@
 	printf("\t\tCODE: 1..4\n\t\tDEVICE: 1..4\n");
 	printf("\t\tOFF_ON: 0..1\n" );
 	printf("\n");
+        printf("\t PROTOCOL ARGUMENTS - EVERFLOURISH:\n");
+        printf("\t\tDEVICE: 0..65535\n");
+        printf("\t\tLEVEL: 0=off, 10=learn, 15=on\n" );
+	printf("\n");
 	printf("Report bugs to <info.tech@telldus.se>\n");
 }
 
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Patch for rfcmd to support EVERFLOURISH devices

Post by micke.prag »

Thank you, it seems to have slipped through my fingers. Will be included soon.

http://developer.telldus.com/ticket/141
Micke Prag
Software
Telldus Technologies
PHermansson
Posts: 27
Joined: Fri Mar 17, 2023 9:45 am
Contact:

Re: Patch for rfcmd to support EVERFLOURISH devices

Post by PHermansson »

This patch gives the following arguments:

Code: Select all

	 PROTOCOL ARGUMENTS - EVERFLOURISH:
		DEVICE: 0..65535
		LEVEL: 0=off, 10=learn, 15=on
The Everflourish device I bought recently is a EMW200RA. It's not self learning, you set the code the same way as with old-school Nexa's, ie a knob with letters A-D and numbers 1-3.
I added the patch manually to rfcmd 2.1.3 and it builds and seems to work. I tried some settings to control the Everflourish , but no success. Is this patch only for self-learning devices?
Post Reply