Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new remotes #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Master/Itho/CC1101Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <stdio.h>
#ifdef ESP8266
#include <arduino.h>
#include <Arduino.h>
#endif

#define CC1101_BUFFER_LEN 64
Expand All @@ -22,4 +22,4 @@ class CC1101Packet
};


#endif /* CC1101PACKET_H_ */
#endif /* CC1101PACKET_H_ */
83 changes: 83 additions & 0 deletions Master/Itho/DemandItho.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "stdlib.h"
#include "DemandItho.h"

// void DemandItho::decodeLastCommand()
// {
// printf("decodeLastCommand\n");
// CC1101Packet p;
// CC1101Packet received = getLastMessagePacket();
// uint8_t errorCnt = decode(received, p);
// printf("\terr = %d\n", errorCnt);
// }

uint8_t DemandItho::decode(CC1101Packet& in, CC1101Packet& decoded)
{
uint8_t errorCount = 0;
for (int i = 0; i < 8; i++) {
printf("skip %08x\n", in.data[i]);
}

// init response
const int numberOfLeadByte = 8;
int numberOfNibble = ((in.length - 8)*8) / (2*(8+2));

printf("nn = %d\n", numberOfNibble);

decoded.length = (numberOfNibble - (numberOfLeadByte *2))/2;
for (int i = 0; i < decoded.length; i++) {
decoded.data[i] = 0;
}

// skip preamble and first 2 bits
int bitIndex = (numberOfLeadByte*8) + 2;
for (int nibbleIndex = 16; nibbleIndex < numberOfNibble; nibbleIndex++) {
for (int idxInNibble = 0; idxInNibble < 4; idxInNibble++) {
bool value = getBit(in, bitIndex);
setBit(decoded, 8*(nibbleIndex / 2) + 4*(1 - (nibbleIndex%2)), value);
bitIndex++;
if (value == getBit(in, bitIndex)) errorCount++;
bitIndex++; // skip a bit
}
// at the end of a nibble, there should be a 0
if (getBit(in, bitIndex) != false) errorCount++;
}

//Serial.println(Packet2str(decoded));
return errorCount;

}

bool DemandItho::getBit(CC1101Packet& p, int idx)
{
int byteIdx = idx / 8;
int bitInByte = 7 - (idx % 8);
return ((p.data[byteIdx] >> bitInByte) & 1);
}

void DemandItho::setBit(CC1101Packet& p, int idx, bool value)
{
int byteIdx = idx / 8;
int bitInByte = 7 - (idx % 8);
if (value) {
p.data[byteIdx] = p.data[byteIdx] | (1 << bitInByte);
} else {
p.data[byteIdx] = p.data[byteIdx] & (0xff ^ (1 << bitInByte));
}
}

// String DemandItho::Packet2str(CC1101Packet& p , bool ashex) {
// String str;
// for (uint8_t i=0; i<p.length;i++) {
// if (ashex) {
// if (p.data[i] == 0) {
// str += "0";
// }
// str += String(p.data[i], HEX);
// }
// else {
// str += String(p.data[i]);
// }
// if (i<p.length-1) str += ":";
// }
// return str;
// }
29 changes: 29 additions & 0 deletions Master/Itho/DemandItho.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//#include "IthoCC1101.h"
#include "CC1101Packet.h"

class DemandIthoCommand {
public:
uint8_t length;
uint8_t data[72];
};

const DemandIthoCommand commandList[] = {
{3, {1,2,3}},
{3, {1,2,3}},
{3, {1,2,3}}
};

class DemandItho //: public IthoCC1101
{
public:
void decodeLastCommand();

public:
static uint8_t decode(CC1101Packet& packetIn, CC1101Packet& decoded);

// return bit idx, start countin from byte 0, assume single string of bits
static bool getBit(CC1101Packet& p, int idx);
static void setBit(CC1101Packet& p, int idx, bool value);

//String Packet2str(CC1101Packet& p , bool ashex = true);
};
29 changes: 25 additions & 4 deletions Master/Itho/IthoCC1101.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ void IthoCC1101::parseMessageCommand()
bool isTimer3Command = true;
bool isJoinCommand = true;
bool isLeaveCommand = true;
bool isH1Command = true;
bool isH2Command = true;
bool isCookCommand = true;
bool isTimerCommand = true;


//device id
memcpy(inIthoPacket.deviceId2, &inMessage2.data[8], sizeof inIthoPacket.deviceId2);
Expand All @@ -414,6 +419,11 @@ void IthoCC1101::parseMessageCommand()
if (inMessage2.data[i+18] != ithoMessage2Timer3CommandBytes[i]) isTimer3Command = false;
if (inMessage2.data[i+18] != ithoMessage2JoinCommandBytes[i]) isJoinCommand = false;
if (inMessage2.data[i+18] != ithoMessage2LeaveCommandBytes[i]) isLeaveCommand = false;
if (inMessage2.data[i+18] != ithoMessage2_5360146_EcoCommandBytes[i]) isH1Command = false;
if (inMessage2.data[i+18] != ithoMessage2_5360146_ComfortCommandBytes[i]) isH2Command = false;
if (inMessage2.data[i+18] != ithoMessage2_5360146_Cook1CommandBytes[i]) isCookCommand = false;
if (inMessage2.data[i+18] != ithoMessage2_5360146_Timer1CommandBytes[i]) isTimerCommand = false;

}

//determine command
Expand All @@ -428,6 +438,10 @@ void IthoCC1101::parseMessageCommand()
if (isTimer3Command) inIthoPacket.command = IthoTimer3;
if (isJoinCommand) inIthoPacket.command = IthoJoin;
if (isLeaveCommand) inIthoPacket.command = IthoLeave;
if (isH1Command) inIthoPacket.command = IthoHome1;
if (isH2Command) inIthoPacket.command = IthoHome2;
if (isCookCommand) inIthoPacket.command = IthoCook;
if (isTimerCommand) inIthoPacket.command = IthoTimer;
}

void IthoCC1101::sendCommand(IthoCommand command)
Expand Down Expand Up @@ -995,9 +1009,16 @@ String IthoCC1101::getLastIDstr(bool ashex) {
String IthoCC1101::getLastMessage2str(bool ashex) {
String str = "Length="+ String(inMessage2.length) + ".";
for (uint8_t i=0; i<inMessage2.length;i++) {
if (ashex) str += String(inMessage2.data[i], HEX);
else str += String(inMessage2.data[i]);
if (i<inMessage2.length-1) str += ":";
if (ashex) {
if (inMessage2.data[i] == 0) {
str += "0";
}
str += String(inMessage2.data[i], HEX);
}
else {
str += String(inMessage2.data[i]);
}
if (i<inMessage2.length-1) str += ":";
}
return str;
}
}
25 changes: 24 additions & 1 deletion Master/Itho/IthoCC1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ const uint8_t ithoMessage2Timer3CommandBytes[] = {6,89,150,170,169,101,90,150,85
const uint8_t ithoMessage2JoinCommandBytes[] = {9,90,170,90,165,165,89,106,85,149,102,89,150,170,165};
const uint8_t ithoMessage2LeaveCommandBytes[] = {9,90,170,90,165,165,89,166,85,149,105,90,170,90,165};

// message 2 commands 536-0146 remote
const uint8_t ithoMessage2_5360146_EcoCommandBytes[] = {38,89,150,170,149,165,90,150,85,149,101,90,86,85,153};
const uint8_t ithoMessage2_5360146_ComfortCommandBytes[] = {166,89,150,170,149,165,90,150,85,149,101,89,150,85,153};
const uint8_t ithoMessage2_5360146_Cook1CommandBytes[] = {102,89,150,170,169,101,90,102,85,149,101,89,150,149,154};
const uint8_t ithoMessage2_5360146_Cook2CommandBytes[] = {102,89,150,170,169,101,90,102,85,149,101,89,150,165,150};
const uint8_t ithoMessage2_5360146_Timer1CommandBytes[] = {102,89,150,170,169,101,90,102,85,149,101,153,150,85,169};
const uint8_t ithoMessage2_5360146_Timer2CommandBytes[]= {102,89,150,170,169,101,90,102,85,149,101,153,150,85,154};
const uint8_t ithoMessage2_5360146_Timer3CommandBytes[]= {166,89,150,170,169,101,90,102,85,149,101,153,150,85,165};
const uint8_t ithoMessage2_5360146_JoinCommandBytes[] = {169, 90,170, 90,165,165, 89,106, 85,149,102, 89,150,170,149};
const uint8_t ithoMessage2_5360146_LeavCommandBytes[] = {105, 90,170, 90,165,165, 89,106, 85,149,102, 89,150,170,149};

// message 2 command 536-0150 remote
const uint8_t ithoMessage2_5360150_LowCommandBytes[] = {102,89,150,170,165,101,90,150,105,169,101,89,150,85,150};
const uint8_t ithoMessage2_5360150_HighCommandBytes[] = {102,89,150,170,165,101,90,150,105,169,101,89,102,85,150};
const uint8_t ithoMessage2_5360150_AutoCommandBytes[] = {102,89,150,170,165,101,90,150,105,169,101,90,150,85,150};
const uint8_t ithoMessage2_5360150_Auto2CommandBytes[] = {102,89,150,170,149,165,90,150,105,169,101,89,150,85,169};
const uint8_t ithoMessage2_5360150_Timer1CommandBytes[] = {166,89,150,170,169,101,90,150,105,169,101,105,86,85,165};
const uint8_t ithoMessage2_5360150_Timer2CommandBytes[] = {102,89,150,170,169,101,90,150,105,169,101,105,86,85,153};
const uint8_t ithoMessage2_5360150_Timer3CommandBytes[] = {102,89,150,170,169,101,90,150,105,169,101,105,86,85,169};
const uint8_t ithoMessage2_5360150_JoinCommandBytes[] = {105,90,170,90,165,165,89,106,105,169,102,89,150,170,149};
const uint8_t ithoMessage2_5360150_LeaveCommandBytes[] = {169,90,170,90,165,165,89,166,105,169,105,90,170,90,165};

//message 2, counter
const uint8_t counterBytes24a[] = {1,2};
const uint8_t counterBytes24b[] = {84,148,100,164,88,152,104,168};
Expand All @@ -59,7 +81,7 @@ const uint8_t counterBytes66[] = {170,106};


//state machine
typedef enum IthoReceiveStates
enum IthoReceiveStates
{
ExpectMessageStart,
ExpectNormalCommand,
Expand Down Expand Up @@ -108,6 +130,7 @@ class IthoCC1101 : protected CC1101
String getLastIDstr(bool ashex=true);
String getLastMessage2str(bool ashex=true);

CC1101Packet& getLastMessagePacket() { return inMessage2; }

//send
void sendCommand(IthoCommand command);
Expand Down
11 changes: 9 additions & 2 deletions Master/Itho/IthoPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ITHOPACKET_H_


typedef enum IthoMessageType
enum IthoMessageType
{
ithomsg_unknown = 0,
ithomsg_control = 1,
Expand All @@ -32,6 +32,13 @@ enum IthoCommand
IthoTimer2 = 51,
IthoTimer3 = 61,

// preliminary values
IthoHome1 = 200,
IthoHome2 = 201,
IthoCook = 202,
IthoTimer = 203,


//duco c system remote
DucoStandby = 251,
DucoLow = 252,
Expand All @@ -53,4 +60,4 @@ class IthoPacket
};


#endif /* ITHOPACKET_H_ */
#endif /* ITHOPACKET_H_ */
Loading