mirror of https://github.com/nymea/nymea.git
send elro code works now
parent
29dc1b63b3
commit
04df5cc685
|
|
@ -31,12 +31,12 @@ void Action::setName(const QString &name)
|
||||||
m_name = name;
|
m_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList Action::params() const
|
QVariantMap Action::params() const
|
||||||
{
|
{
|
||||||
return m_params;
|
return m_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Action::setParams(const QVariantList ¶ms)
|
void Action::setParams(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
m_params = params;
|
m_params = params;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,14 @@ public:
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|
||||||
QVariantList params() const;
|
QVariantMap params() const;
|
||||||
void setParams(const QVariantList ¶ms);
|
void setParams(const QVariantMap ¶ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_id;
|
QUuid m_id;
|
||||||
QUuid m_deviceId;
|
QUuid m_deviceId;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QVariantList m_params;
|
QVariantMap m_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ACTION_H
|
#endif // ACTION_H
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ Radio433::Radio433(QObject *parent) :
|
||||||
// Set up transmitter
|
// Set up transmitter
|
||||||
m_transmitter = new Gpio(this,22);
|
m_transmitter = new Gpio(this,22);
|
||||||
m_transmitter->setDirection(OUTPUT);
|
m_transmitter->setDirection(OUTPUT);
|
||||||
m_transmitter->setValue(LOW);
|
m_transmitter->setValue(HIGH);
|
||||||
|
|
||||||
connect(m_receiver,SIGNAL(pinInterrupt()),this,SLOT(handleInterrupt()));
|
connect(m_receiver,SIGNAL(pinInterrupt()),this,SLOT(handleInterrupt()));
|
||||||
|
|
||||||
|
|
@ -30,22 +30,25 @@ Radio433::~Radio433()
|
||||||
void Radio433::sendData(QList<int> rawData)
|
void Radio433::sendData(QList<int> rawData)
|
||||||
{
|
{
|
||||||
|
|
||||||
qDebug() << "send 433";
|
|
||||||
//first we have to disable our receiver, to prevent reading this signal
|
//first we have to disable our receiver, to prevent reading this signal
|
||||||
//m_receiver->stop();
|
m_receiver->stop();
|
||||||
|
|
||||||
m_transmitter->setValue(LOW);
|
m_transmitter->setValue(LOW);
|
||||||
delayMicroseconds(500);
|
|
||||||
|
|
||||||
int flag=1;
|
int flag=1;
|
||||||
|
|
||||||
|
for(int i = 0; i <= 8; i++){
|
||||||
foreach (int delay, rawData) {
|
foreach (int delay, rawData) {
|
||||||
// 1 = High, 0 = Low
|
// 1 = High, 0 = Low
|
||||||
m_transmitter->setValue(flag++ %2);
|
m_transmitter->setValue(flag %2);
|
||||||
delayMicroseconds(delay);
|
flag++;
|
||||||
|
//qDebug() << "flag" << flag %2;
|
||||||
|
delayMicros(delay);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//qDebug() << "signal sent." << rawData;
|
||||||
|
|
||||||
// re-enable it
|
// re-enable it
|
||||||
//m_receiver->start();
|
m_receiver->start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,29 +63,50 @@ int Radio433::micros()
|
||||||
return (int)(now - m_epochMicro) ;
|
return (int)(now - m_epochMicro) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Radio433::delayMicroseconds(int pulseLength)
|
void Radio433::delayMilli(int milliSeconds)
|
||||||
{
|
{
|
||||||
struct timespec sleeper ;
|
struct timespec sleeper, dummy ;
|
||||||
|
|
||||||
if(pulseLength <= 0){
|
sleeper.tv_sec = (time_t)(milliSeconds / 1000) ;
|
||||||
return;
|
sleeper.tv_nsec = (long)(milliSeconds % 1000) * 1000000;
|
||||||
}else {
|
|
||||||
if(pulseLength < 100){
|
|
||||||
struct timeval tNow, tLong, tEnd ;
|
|
||||||
|
|
||||||
gettimeofday (&tNow, NULL) ;
|
nanosleep (&sleeper, &dummy) ;
|
||||||
tLong.tv_sec = pulseLength / 1000000 ;
|
}
|
||||||
tLong.tv_usec = pulseLength % 1000000 ;
|
|
||||||
timeradd (&tNow, &tLong, &tEnd) ;
|
//void Radio433::delayMicroseconds(int pulseLength)
|
||||||
|
//{
|
||||||
|
// struct timespec sleeper ;
|
||||||
|
|
||||||
|
// if(pulseLength <= 0){
|
||||||
|
// return;
|
||||||
|
// }else {
|
||||||
|
// if(pulseLength < 100){
|
||||||
|
// struct timeval tNow, tLong, tEnd ;
|
||||||
|
|
||||||
|
// gettimeofday (&tNow, NULL) ;
|
||||||
|
// tLong.tv_sec = pulseLength / 1000000 ;
|
||||||
|
// tLong.tv_usec = pulseLength % 1000000 ;
|
||||||
|
// timeradd (&tNow, &tLong, &tEnd) ;
|
||||||
|
|
||||||
|
// while (timercmp (&tNow, &tEnd, <)){
|
||||||
|
// gettimeofday (&tNow, NULL) ;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// sleeper.tv_sec = 0 ;
|
||||||
|
// sleeper.tv_nsec = (long)(pulseLength * 1000) ;
|
||||||
|
// nanosleep (&sleeper, NULL);
|
||||||
|
// //qDebug() << "time " << sleeper.tv_nsec;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
void Radio433::delayMicros(int microSeconds)
|
||||||
|
{
|
||||||
|
struct timespec sleeper;
|
||||||
|
|
||||||
|
sleeper.tv_sec = 0;
|
||||||
|
sleeper.tv_nsec = (long)(microSeconds * 1000);
|
||||||
|
|
||||||
while (timercmp (&tNow, &tEnd, <)){
|
|
||||||
gettimeofday (&tNow, NULL) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sleeper.tv_sec = 0 ;
|
|
||||||
sleeper.tv_nsec = (long)(pulseLength * 1000) ;
|
|
||||||
nanosleep (&sleeper, NULL) ;
|
nanosleep (&sleeper, NULL) ;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -107,11 +131,11 @@ void Radio433::handleInterrupt()
|
||||||
rawData.append(m_timings[i]);
|
rawData.append(m_timings[i]);
|
||||||
m_timings[i] = 0;
|
m_timings[i] = 0;
|
||||||
}
|
}
|
||||||
// qDebug() << "-----------------------------------------------------------";
|
// qDebug() << "-----------------------------------------------------------";
|
||||||
// qDebug() << "| GENERIC signal |";
|
// qDebug() << "| GENERIC signal |";
|
||||||
// qDebug() << "-----------------------------------------------------------";
|
// qDebug() << "-----------------------------------------------------------";
|
||||||
// qDebug() << "delay :" << rawData.first() /31;
|
// qDebug() << "delay :" << rawData.first() /31;
|
||||||
// qDebug() << rawData;
|
// qDebug() << rawData;
|
||||||
|
|
||||||
emit dataReceived(rawData);
|
emit dataReceived(rawData);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ private:
|
||||||
|
|
||||||
int micros();
|
int micros();
|
||||||
void delayMicroseconds(int pulseLength);
|
void delayMicroseconds(int pulseLength);
|
||||||
|
void delayMicros(int microSeconds);
|
||||||
|
void delayMilli(int milliSeconds);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleInterrupt();
|
void handleInterrupt();
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,6 @@ void DevicePluginElro::executeAction(Device *device, const Action &action)
|
||||||
QList<int> rawData;
|
QList<int> rawData;
|
||||||
QByteArray binCode;
|
QByteArray binCode;
|
||||||
|
|
||||||
qDebug() << "rawData" << rawData;
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// create the bincode
|
// create the bincode
|
||||||
// channels
|
// channels
|
||||||
|
|
@ -215,12 +214,12 @@ void DevicePluginElro::executeAction(Device *device, const Action &action)
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
// Power
|
// Power
|
||||||
if(action.params().first().toBool()){
|
if(action.params().value("power").toBool()){
|
||||||
binCode.append("0001");
|
binCode.append("0001");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("0100");
|
binCode.append("0100");
|
||||||
}
|
}
|
||||||
|
qDebug() << "bin code:" << binCode;
|
||||||
// =======================================
|
// =======================================
|
||||||
//create rawData timings list
|
//create rawData timings list
|
||||||
int delay = 350;
|
int delay = 350;
|
||||||
|
|
@ -359,6 +358,7 @@ void DevicePluginElro::receiveData(QList<int> rawData)
|
||||||
DeviceClass deviceClass = supportedDevices().first();
|
DeviceClass deviceClass = supportedDevices().first();
|
||||||
foreach (const TriggerType &triggerType, deviceClass.triggers()) {
|
foreach (const TriggerType &triggerType, deviceClass.triggers()) {
|
||||||
if (triggerType.name() == button) {
|
if (triggerType.name() == button) {
|
||||||
|
qDebug() << "emit trigger " << group << triggerType.name() << power;
|
||||||
Trigger trigger = Trigger(triggerType.id(), device->id(), params);
|
Trigger trigger = Trigger(triggerType.id(), device->id(), params);
|
||||||
emit emitTrigger(trigger);
|
emit emitTrigger(trigger);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -409,7 +409,7 @@ void DevicePluginIntertechno::receiveData(QList<int> rawData)
|
||||||
DeviceClass deviceClass = supportedDevices().first();
|
DeviceClass deviceClass = supportedDevices().first();
|
||||||
foreach (const TriggerType &triggerType, deviceClass.triggers()) {
|
foreach (const TriggerType &triggerType, deviceClass.triggers()) {
|
||||||
if (triggerType.name() == buttonCode) {
|
if (triggerType.name() == buttonCode) {
|
||||||
//qDebug() << "emit trigger " << triggerType.name();
|
qDebug() << "emit trigger " << familyCode << triggerType.name() << power;
|
||||||
Trigger trigger = Trigger(triggerType.id(), device->id(), params);
|
Trigger trigger = Trigger(triggerType.id(), device->id(), params);
|
||||||
emit emitTrigger(trigger);
|
emit emitTrigger(trigger);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ void JsonRPCServer::handleRulesMessage(int clientId, int commandId, const QStrin
|
||||||
|
|
||||||
Action action(params.value("deviceId").toString());
|
Action action(params.value("deviceId").toString());
|
||||||
action.setName(params.value("name").toString());
|
action.setName(params.value("name").toString());
|
||||||
action.setParams(params.value("params").toList());
|
action.setParams(params.value("params").toMap());
|
||||||
|
|
||||||
switch(HiveCore::instance()->ruleEngine()->addRule(trigger, action)) {
|
switch(HiveCore::instance()->ruleEngine()->addRule(trigger, action)) {
|
||||||
case RuleEngine::RuleErrorNoError:
|
case RuleEngine::RuleErrorNoError:
|
||||||
|
|
@ -141,11 +141,14 @@ void JsonRPCServer::handleActionMessage(int clientId, int commandId, const QStri
|
||||||
if (method == "ExecuteAction") {
|
if (method == "ExecuteAction") {
|
||||||
QVariantMap actionMap = params.value("action").toMap();
|
QVariantMap actionMap = params.value("action").toMap();
|
||||||
QUuid deviceId = actionMap.value("deviceId").toUuid();
|
QUuid deviceId = actionMap.value("deviceId").toUuid();
|
||||||
QVariantList actionParams = actionMap.value("params").toList();
|
QVariantMap actionParams = actionMap.value("params").toMap();
|
||||||
|
|
||||||
Action action(deviceId);
|
Action action(deviceId);
|
||||||
action.setParams(actionParams);
|
action.setParams(actionParams);
|
||||||
|
|
||||||
|
qDebug() << "actions params in json" << action.params();
|
||||||
|
|
||||||
|
|
||||||
DeviceManager::DeviceError error = HiveCore::instance()->deviceManager()->executeAction(action);
|
DeviceManager::DeviceError error = HiveCore::instance()->deviceManager()->executeAction(action);
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case DeviceManager::DeviceErrorNoError:
|
case DeviceManager::DeviceErrorNoError:
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ RuleEngine::RuleEngine(QObject *parent) :
|
||||||
settings.beginGroup("action");
|
settings.beginGroup("action");
|
||||||
Action action = Action(settings.value("deviceId").toUuid(), settings.value("id").toUuid());
|
Action action = Action(settings.value("deviceId").toUuid(), settings.value("id").toUuid());
|
||||||
action.setName(settings.value("name").toString());
|
action.setName(settings.value("name").toString());
|
||||||
action.setParams(settings.value("params").toList());
|
action.setParams(settings.value("params").toMap());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,6 @@
|
||||||
if test -z $3; then
|
if test -z $3; then
|
||||||
echo "usage: $1 host triggerId actionId"
|
echo "usage: $1 host triggerId actionId"
|
||||||
else
|
else
|
||||||
(echo '{"id":1, "method":"Rules.AddRule", "params":{"triggerTypeId": "'$2'", "action":{ "deviceId":"'$3'", "name":"rule 1", "actionParams":{"power":"on"}}}}'; sleep 1) | nc $1 1234
|
(echo '{"id":1, "method":"Rules.AddRule", "params":{"triggerTypeId": "'$2'", "action":{ "deviceId":"'$3'", "name":"rule 1", "actionParams":{"power":"true"}}}}'; sleep 1) | nc $1 1234
|
||||||
|
(echo '{"id":2, "method":"Rules.AddRule", "params":{"triggerTypeId": "'$2'", "action":{ "deviceId":"'$3'", "name":"rule 2", "actionParams":{"power":"false"}}}}'; sleep 1) | nc $1 1234
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue