• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


[Fully Supported] Impuls/SelectRemote
#1
When I try to use my remote with pilight-debug it never gives output. So I attempted to just write the code for it. However pilight-daemon seems to crash as soon as I use pilight-receive or pilight-send. Nothing is given as output and nothing in the log.

Here is the code:
impuls.c:
Code:
/*
    Copyright (C) 2013 CurlyMo & Bram1337

    This file is part of pilight.

    pilight 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.

    pilight 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 pilight. If not, see    <http://www.gnu.org/licenses/>
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "settings.h"
#include "log.h"
#include "protocol.h"
#include "binary.h"
#include "impuls.h"

void impulsCreateMessage(int id, int unit, int state) {
    impuls.message = json_mkobject();
    json_append_member(impuls.message, "id", json_mknumber(id));
    json_append_member(impuls.message, "unit", json_mknumber(unit));
    if(state == 1)
        json_append_member(impuls.message, "state", json_mkstring("on"));
    else
        json_append_member(impuls.message, "state", json_mkstring("off"));
}

void impulsParseBinary(void) {
    int unit = binToDec(impuls.binary, 0, 4);
    int check = impuls.binary[10];
    int state = impuls.binary[11];
    int id = binToDec(impuls.binary, 5, 9);
    if(check != state)
        impulsCreateMessage(id, unit, state);
}

void impulsCreateLow(int s, int e) {
    int i;

    for(i=s;i<=e;i+=4) {
        impuls.raw[i]=(PULSE_LENGTH);
        impuls.raw[i+1]=(impuls.pulse*PULSE_LENGTH);
        impuls.raw[i+2]=(impuls.pulse*PULSE_LENGTH);
        impuls.raw[i+3]=(PULSE_LENGTH);
        }
}

void impulsCreateMed(int s, int e) {
    int i;

    for(i=s;i<=e;i+=4) {
        impuls.raw[i]=(impuls.pulse*PULSE_LENGTH);
        impuls.raw[i+1]=(PULSE_LENGTH);
        impuls.raw[i+2]=(impuls.pulse*PULSE_LENGTH);
        impuls.raw[i+3]=(PULSE_LENGTH);
    }
}

void impulsCreateHigh(int s, int e) {
    int i;

    for(i=s;i<=e;i+=4) {
        impuls.raw[i]=(PULSE_LENGTH);
        impuls.raw[i+1]=(impuls.pulse*PULSE_LENGTH);
        impuls.raw[i+2]=(PULSE_LENGTH);
        impuls.raw[i+3]=(impuls.pulse*PULSE_LENGTH);
        }
}

void impulsClearCode(void) {
    impulsCreateLow(0,47);
}

void impulsCreateUnit(int unit) {
    int binary[255];
    int length = 0;
    int i=0, x=0;

    length = decToBinRev(unit, binary);
    for(i=0;i<=length;i++) {
        if(binary[i]==1) {
            x=i*4;
            impulsCreateMed(x, x+3);
        }
    }
}

void impulsCreateId(int id) {
    int binary[255];
    int length = 0;
    int i=0, x=0;

    length = decToBinRev(id, binary);
    for(i=0;i<=length;i++) {
        if(binary[i]==1) {
            x=i*4;
            impulsCreateHigh(20+x, 20+x+3);
        }
    }
}

void impulsCreateState(int state) {
    if(state == 0) {
        impulsCreateHigh(40, 43);
    } else {
        impulsCreateHigh(44, 47);
    }
}

void impulsCreateFooter(void) {
    impuls.raw[48]=(PULSE_LENGTH);
    impuls.raw[49]=(impuls.footer*PULSE_LENGTH);
}

int impulsCreateCode(JsonNode *code) {
    int id = -1;
    int unit = -1;
    int state = -1;
    char *tmp;

    if(json_find_string(code, "id", &tmp) == 0)
        id=atoi(tmp);
    if(json_find_string(code, "off", &tmp) == 0)
        state=0;
    else if(json_find_string(code, "on", &tmp) == 0)
        state=1;
    if(json_find_string(code, "unit", &tmp) == 0)
        unit = atoi(tmp);

    if(id == -1 || unit == -1 || state == -1) {
        logprintf(LOG_ERR, "impuls: insufficient number of arguments");
        return EXIT_FAILURE;
    } else if(id > 31 || id < 0) {
        logprintf(LOG_ERR, "impuls: invalid id range");
        return EXIT_FAILURE;
    } else if(unit > 31 || unit < 0) {
        logprintf(LOG_ERR, "impuls: invalid unit range");
        return EXIT_FAILURE;
    } else {
        impulsCreateMessage(id, unit, state);
        impulsClearCode();
        impulsCreateUnit(unit);
        impulsCreateId(id);
        impulsCreateState(state);
    impulsCreateFooter();
    }
    return EXIT_SUCCESS;
}

void impulsPrintHelp(void) {
    printf("\t -t --on\t\t\tsend an on signal\n");
    printf("\t -f --off\t\t\tsend an off signal\n");
    printf("\t -u --unit=unit\t\t\tcontrol a device with this unit code\n");
    printf("\t -i --id=id\t\t\tcontrol a device with this id\n");
}

void impulsInit(void) {

    strcpy(impuls.id, "impuls");
    protocol_add_device(&impuls, "impuls", "Impuls Switches");
    protocol_add_device(&impuls, "selectremote", "SelectRemote Switches");
    protocol_add_conflict(&impuls, "sartano");
    impuls.type = SWITCH;
    impuls.pulse = 3;
    impuls.footer = 31;
    impuls.length = 50;
    impuls.message = malloc(sizeof(JsonNode));

    impuls.bit = 0;
    impuls.recording = 0;

    options_add(&impuls.options, 't', "on", no_value, config_state, NULL);
    options_add(&impuls.options, 'f', "off", no_value, config_state, NULL);
    options_add(&impuls.options, 'u', "unit", has_value, config_id, "^(3[12]?|[012][0-9]|[0-9]{1})$");
    options_add(&impuls.options, 'i', "id", has_value, config_id, "^(3[12]?|[012][0-9]|[0-9]{1})$");

    impuls.parseBinary=&impulsParseBinary;
    impuls.createCode=&impulsCreateCode;
    impuls.printHelp=&impulsPrintHelp;

    protocol_register(&impuls);
}

impuls.h:
Code:
/*
    Copyright (C) 2013 CurlyMo & Bram1337

    This file is part of pilight.

    pilight 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.

    pilight 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 pilight. If not, see    <http://www.gnu.org/licenses/>
*/

#ifndef _PROTOCOL_IMPULS_H_
#define _PROTOCOL_IMPULS_H_

protocol_t impuls;

void impulsInit(void);
void impulsCreateMessage(int id, int unit, int state);
void impulsParseBinary(void);
int impulsCreateCode(JsonNode *code);
void impulsCreateLow(int s, int e);
void impulsCreateMed(int s, int e);
void impulsCreateHigh(int s, int e);
void impulsClearCode(void);
void impulsCreateUnit(int unit);
void impulsCreateId(int id);
void impulsCreateState(int state);
void impulsCreateFooter(void);
void impulsPrintHelp(void);

#endif

hardware.c:
Code:
#include "protocols/sartano.h"
#include "protocols/impuls.h"

    sartanoInit();
    impulsInit();

Any clues to why it is crashing and why pilight-debug doesn't give output ? I suspect it might be because there are 3 different pulse sets (Low, Med and High) but I could be wrong.
 
Reply
#2
Increased the amount of protocols by 2 in protocol.h (oddly enough had to also do it for sartano just now).
Code:
typedef struct {
        int nr;
        protocol_t *listeners[8]; // Change this to the number of available protocols
} protocols_t;

That fixed it. The whole protocol is now working and complete.

The only thing that could be improved is the pilight-debug for similar protocols but I have no idea how to recognize 3 different pulse sets.
 
Reply
#3
So you tested sending and receiving for these protocols? If so, can you do a pull request for all changes / additions you made?

Just one minor thing. You're still using the faulty regex for the unit code and id. This was already fixed on github.
 
Reply
#4
That's odd I thought I was using the latest GitHub code.

I tested receiving as far as sending out a pilight-send and then getting output on pilight-receive. I have been unable to receive anything from my remote with either pilight-debug or pilight-receive.

Sending I tested and works.

Should I proceed with a pull request?
 
Reply
#5
I will check things through once you did the pull request.
 
Reply
#6
Can you post an impuls raw code and how to translate it?
 
Reply
#7
No, but I have an idea of how to send it.

0-4 Unit works with Low and Med bits.
5-9 ID works with Low and High bits.
10-11 works is always al Low and High or High and Low bit

Low is 0110 (Short Long Long Short)
Med is 1010 (Long Short Long Short)
High is 0101 (Short Long Short Long)
Note that minimal LSB required to notice difference between any is both bit[1] and bit[2].

Example raw code:
[0] Unit 31: Med Med Med Med Med
[20] ID : 1: High Low Low Low Low
[40] On: Low High
Footer: [48] PULSE_LENGTH [49] PULSE_LENGTH*33

Unfortunately I had no luck with mode2 to find anything useful nor with pilight-debug or pilight-learn.

Hope that helps.
 
Reply
#8
If you can send raw codes, you can also generate them Wink Just add a printf here or here and start the daemon in debug mode.
 
Reply
#9
Input:
Code:
pilight-send -p impuls -i 31 -u 1 -t
Output:
Code:
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 0
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 1
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 2
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 3
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 4
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 5
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 6
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 7
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 8
885 295 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 885 295 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 295 885 885 295 295 885 295 885 295 9735 was repeat 9

Need more?

For reference, I used this:
Code:
                for(i=0;i<send_repeat;i++) {
                    for(x=0;x<protocol->rawLength;x++) {
                        longCode[x+(protocol->rawLength*i)]=protocol->raw[x];
                        printf("%d ", protocol->raw[x]);
                    }
                    printf("was repeat %d \n", i);
                }
 
Reply
#10
Another thing that came to mind and you might not have know is that you aren't forced to use the parseBinary to decode the codes. You can hop in from three different stages. When you check the output of the learner (in the readme on bit) you will see how the code is parses (by default) in each stage.

parseRaw: This function will be called when the header, footer, and number of raw bits matches (and if the function is present).
parseCode: This function will be called when the header, footer, and number of raw bits matches (and if the function is present). The difference with parseRaw is that parseCode can work with the normalized raw codes. Meaning the raw codes have been transformed into zero's and one's depending on the pulse lengths.
parseBinary: The function will be called when the header, footer, and number of binary bits matches (and if the function is present). The daemon will try to determine the high and low values and create a binary string according to them.

In case of impuls (and previously in case of alecto) the parseBinary logic of the daemon isn't sufficient for creating the binary code. So, instead of using the parseBinary step, you can use the parseCode step and implement your own logic to figure out the codes. Check the alecto protocol on how this is done in defining the protocol.

The case of impuls is just a matter of interpretation:

2 LSB's but interpreting LSB 3 is high = 1
Code:
885 295 885 295 1
295 885 885 295 1
295 885 885 295 1
295 885 885 295 1
295 885 885 295 1
295 885 295 885 0
295 885 295 885 0
295 885 295 885 0
295 885 295 885 0
295 885 295 885 0
295 885 885 295 1
295 885 295 885 0
295 9735

1 LSB but interpreting LSB 2 is high = 1
Code:
885 295
885 295 295 885  0
885 295 295 885  0
885 295 295 885  0
885 295 295 885  0
885 295 295 885  0
295 885 295 885  1
295 885 295 885  1
295 885 295 885  1
295 885 295 885  1
295 885 295 885  1
885 295 295 885  0
295 885 295 9735 1

It seems like you can easily decode them with just using 1 LSB.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  [Partially Supported] TFA / Conrad Weather Yves 184 9,294 03-31-2019, 05:22 PM
Last Post: curlymo
  [Fully Supported] DHT22 IcedEarth 86 30,480 11-18-2018, 09:33 AM
Last Post: curlymo
  [Fully Supported] Arctech Old Martin 111 34,173 03-27-2018, 04:43 PM
Last Post: genfersee
  [Fully Supported] Clarus Switches Marcin 69 23,466 01-30-2018, 07:10 PM
Last Post: Niek
  [Fully Supported] Remote Control Socket (RC101-U/RC201) Sean 18 10,332 01-04-2018, 06:18 AM
Last Post: ettman8
  [Fully Supported] LM75 and LM76 temperature sensor horst_dieter 64 24,411 11-19-2017, 08:54 PM
Last Post: edepi
  [Fully Supported] No-brand temp/humidity sensor (alecto_ws1700) meloen 57 34,232 12-25-2016, 09:53 PM
Last Post: creamers
Lightbulb [Fully Supported] Kaku Door sensor (AMST-606) geerttttt 50 23,386 11-29-2016, 06:52 AM
Last Post: curlymo
  [Fully Supported] KAKU ABST-604 (dusk/dawn sensor) Netopyr 15 7,471 03-04-2016, 05:43 PM
Last Post: Niek
  [Fully Supported] Arctech Dimmer (KaKu) fhp 107 39,291 01-02-2016, 05:26 PM
Last Post: kniazio

Forum Jump:


Browsing: 2 Guest(s)