Skip to content

Commit

Permalink
v1.2.46
Browse files Browse the repository at this point in the history
- `x10-transceiver` firmware: fix receiver initialization;
- `x10-transceiver` firmware: added support for X10 security RF codes.
  • Loading branch information
genemars committed Jan 10, 2025
1 parent c5fcb9d commit abca6c5
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 63 deletions.
4 changes: 2 additions & 2 deletions examples/rf-transceiver/configuration.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define CONFIG_RCSwitchReceiverPin 5
#define CONFIG_RCSwitchTransmitterPin 6
#define CONFIG_RCSwitchReceiverPin 7
#define CONFIG_RCSwitchTransmitterPin 5
#define CONFIG_RCSwitchRF_MODULE_ADDRESS "RF"
74 changes: 55 additions & 19 deletions examples/x10-transceiver/api/X10Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ namespace Service { namespace API {
}

void X10Handler::init() {
if (transmitter != nullptr) {
transmitter->begin();
}
}


Expand All @@ -101,9 +104,13 @@ namespace Service { namespace API {
uint8_t data[commandString.length() / 2];
Utility::getBytes(commandString, data);

// only 0x20 standard type message are actually supported
receiver->disableMs(500);
transmitter->sendCommand(&data[1], sizeof(data)-1, sendRepeat);
// only 0x20 standard type message are currently supported
if (receiver != nullptr) {
receiver->disableMs(500);
}
if (transmitter != nullptr) {
transmitter->sendCommand(&data[1], sizeof(data) - 1, sendRepeat);
}
responseCallback->writeAll(ApiHandlerResponseStatus::OK);

return true;
Expand Down Expand Up @@ -138,11 +145,11 @@ namespace Service { namespace API {
float prevLevel = levelProperty->value.toFloat();
sendRepeat = abs((level - prevLevel) / X10_DIM_BRIGHT_STEP);
if (level > prevLevel) {
x10Message.command = X10::Command::CMD_BRIGHT;
x10Message.command = X10::Command::CMD_LIGHTS_BRIGHT;
levelProperty->value = String(prevLevel + (sendRepeat * X10_DIM_BRIGHT_STEP));
if (levelProperty->value.toFloat() > 1) levelProperty->value = "1";
} else if (level < prevLevel) {
x10Message.command = X10::Command::CMD_DIM;
x10Message.command = X10::Command::CMD_LIGHTS_DIM;
levelProperty->value = String(prevLevel - (sendRepeat * X10_DIM_BRIGHT_STEP));
if (levelProperty->value.toFloat() < 0) levelProperty->value = "0";
}
Expand All @@ -167,8 +174,12 @@ namespace Service { namespace API {

if (!ignoreCommand) {
X10::X10Message::encodeCommand(&x10Message, data);
receiver->disableMs(500);
transmitter->sendCommand(&data[1], sizeof(data)-1, sendRepeat);
if (receiver != nullptr) {
receiver->disableMs(500);
}
if (transmitter != nullptr) {
transmitter->sendCommand(&data[1], sizeof(data) - 1, sendRepeat);
}
}
responseCallback->writeAll(ApiHandlerResponseStatus::OK);

Expand Down Expand Up @@ -220,21 +231,46 @@ namespace Service { namespace API {
HomeGenie::getInstance()->getEventRouter().signalEvent(QueuedMessage(domain, CONFIG_X10RF_MODULE_ADDRESS, IOEventPaths::Receiver_RawData, rawDataString,
nullptr, IOEventDataType::Undefined));

if (type == 0x20) { // 0x20 = standard, 0x29 = security
// 0x20 = standard, 0x29 = security
switch (type) {

case 0x20: {

// Convert enums to string
String houseCode(house_code_to_char(decodedMessage->houseCode));
String unitCode(unit_code_to_int(decodedMessage->unitCode));
if (unitCode == "0") unitCode = "";
const char* command = cmd_code_to_str(decodedMessage->command);
String commandString = (houseCode + unitCode + " " + command);

Logger::trace(":%s %s", HOMEGENIEMINI_NS_PREFIX, commandString.c_str());

receiverCommand->setValue(commandString.c_str());
HomeGenie::getInstance()->getEventRouter().signalEvent(
QueuedMessage(domain, CONFIG_X10RF_MODULE_ADDRESS, IOEventPaths::Receiver_Command,
commandString,
nullptr, IOEventDataType::Undefined));

} break;

case 0x29: {

int commandCode = (b2 << 8) + b3;
const char* command = cmd_code_to_str((Command)commandCode);
String commandString = (command);
String subtype = Utility::byteToHex((b0)) + Utility::byteToHex((b1));
subtype.toUpperCase();

Logger::trace(":%s S-%s %s", HOMEGENIEMINI_NS_PREFIX, subtype.c_str(), commandString.c_str());

// Convert enums to string
String houseCode(house_code_to_char(decodedMessage->houseCode));
String unitCode(unit_code_to_int(decodedMessage->unitCode));
const char* command = cmd_code_to_str(decodedMessage->command);
String commandString = (houseCode + unitCode + " " + command);
receiverCommand->setValue(commandString.c_str());
HomeGenie::getInstance()->getEventRouter().signalEvent(
QueuedMessage(domain, CONFIG_X10RF_MODULE_ADDRESS, IOEventPaths::Receiver_Command,
commandString,
nullptr, IOEventDataType::Undefined));

Logger::trace(":%s %s", HOMEGENIEMINI_NS_PREFIX, commandString.c_str());
} break;

receiverCommand->setValue(commandString.c_str());
HomeGenie::getInstance()->getEventRouter().signalEvent(
QueuedMessage(domain, CONFIG_X10RF_MODULE_ADDRESS, IOEventPaths::Receiver_Command,
commandString,
nullptr, IOEventDataType::Undefined));
}
/*
QueuedMessage m = QueuedMessage(domain, houseCode + unitCode, (IOEventPaths::Status_Level), "");
Expand Down
4 changes: 2 additions & 2 deletions examples/x10-transceiver/api/X10Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ namespace Service { namespace API {
Module* rfModule;
ModuleParameter* receiverRawData;
ModuleParameter* receiverCommand;
RFTransmitter* transmitter{};
RFReceiver* receiver{};
RFTransmitter* transmitter = nullptr;
RFReceiver* receiver = nullptr;
public:
X10Handler();
void setReceiver(RFReceiver* receiver);
Expand Down
4 changes: 2 additions & 2 deletions examples/x10-transceiver/configuration.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define CONFIG_X10RFReceiverPin 5
#define CONFIG_X10RFTransmitterPin 6
#define CONFIG_X10RFReceiverPin 7
#define CONFIG_X10RFTransmitterPin 5
#define CONFIG_X10RF_MODULE_ADDRESS "RF"
8 changes: 4 additions & 4 deletions examples/x10-transceiver/io/RFReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ namespace IO { namespace X10 {
// 32-bit RF message decoding
volatile uint8_t messageType = 0x00;
volatile uint8_t byteBuffer[4];
volatile uint32_t riseUs;
volatile int8_t receivedCount;
volatile uint32_t receiveBuffer;
volatile uint32_t riseUs = 0;
volatile int8_t receivedCount = 0;
volatile uint32_t receiveBuffer = 0;
// event data
uint8_t eventData[5];
bool eventReady = false;
uint32_t disabledToMs;
uint32_t disabledToMs = 0;
};

}} // ns
Expand Down
2 changes: 1 addition & 1 deletion examples/x10-transceiver/io/RFReceiverConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace IO { namespace X10 {
}
RFReceiverConfig::RFReceiverConfig(uint8_t pin) : RFReceiverConfig()
{
this->pin = pin;
this->pin = this->interrupt = pin;
}
RFReceiverConfig::RFReceiverConfig(
uint8_t interrupt, uint8_t pin
Expand Down
20 changes: 18 additions & 2 deletions examples/x10-transceiver/io/X10Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,25 @@ namespace IO {
decodedMessage->houseCode = (enum HouseCode) encodedMessage[3];
decodedMessage->unitCode = UNIT_1;
} else {
decodedMessage->unitCode = (enum UnitCode) (((encodedMessage[1] & 0xF) << 8) | (encodedMessage[3] & ~CMD_OFF));
decodedMessage->unitCode = UnitCode::UNIT_NONE;
decodedMessage->houseCode = (enum HouseCode) (encodedMessage[1] & 0xF0);
decodedMessage->command = (enum Command) (encodedMessage[3] & CMD_OFF);
switch (encodedMessage[3]) {
case CMD_LIGHTS_ALL_OFF:
decodedMessage->command = CMD_LIGHTS_ALL_OFF;
break;
case CMD_LIGHTS_ALL_ON:
decodedMessage->command = CMD_LIGHTS_ALL_ON;
break;
case CMD_LIGHTS_DIM:
decodedMessage->command = CMD_LIGHTS_DIM;
break;
case CMD_LIGHTS_BRIGHT:
decodedMessage->command = CMD_LIGHTS_BRIGHT;
break;
default:
decodedMessage->unitCode = (enum UnitCode) (((encodedMessage[1] & 0xF) << 8) | (encodedMessage[3] & ~CMD_OFF));
decodedMessage->command = (enum Command) (encodedMessage[3] & CMD_OFF);
}
}

return 0;
Expand Down
Loading

0 comments on commit abca6c5

Please sign in to comment.