diff --git a/libhive/action.cpp b/libhive/action.cpp index 0ef98c0b..f8f95c81 100644 --- a/libhive/action.cpp +++ b/libhive/action.cpp @@ -31,12 +31,12 @@ void Action::setName(const QString &name) m_name = name; } -QVariantList Action::params() const +QVariantMap Action::params() const { return m_params; } -void Action::setParams(const QVariantList ¶ms) +void Action::setParams(const QVariantMap ¶ms) { m_params = params; } diff --git a/libhive/action.h b/libhive/action.h index 2e4741c1..7edbc210 100644 --- a/libhive/action.h +++ b/libhive/action.h @@ -17,14 +17,14 @@ public: QString name() const; void setName(const QString &name); - QVariantList params() const; - void setParams(const QVariantList ¶ms); + QVariantMap params() const; + void setParams(const QVariantMap ¶ms); private: QUuid m_id; QUuid m_deviceId; QString m_name; - QVariantList m_params; + QVariantMap m_params; }; #endif // ACTION_H diff --git a/libhive/radio433.cpp b/libhive/radio433.cpp index 8c6e8697..423851cd 100644 --- a/libhive/radio433.cpp +++ b/libhive/radio433.cpp @@ -14,7 +14,7 @@ Radio433::Radio433(QObject *parent) : // Set up transmitter m_transmitter = new Gpio(this,22); m_transmitter->setDirection(OUTPUT); - m_transmitter->setValue(LOW); + m_transmitter->setValue(HIGH); connect(m_receiver,SIGNAL(pinInterrupt()),this,SLOT(handleInterrupt())); @@ -30,22 +30,25 @@ Radio433::~Radio433() void Radio433::sendData(QList rawData) { - qDebug() << "send 433"; //first we have to disable our receiver, to prevent reading this signal - //m_receiver->stop(); + m_receiver->stop(); m_transmitter->setValue(LOW); - delayMicroseconds(500); - int flag=1; - foreach (int delay, rawData) { - // 1 = High, 0 = Low - m_transmitter->setValue(flag++ %2); - delayMicroseconds(delay); + + for(int i = 0; i <= 8; i++){ + foreach (int delay, rawData) { + // 1 = High, 0 = Low + m_transmitter->setValue(flag %2); + flag++; + //qDebug() << "flag" << flag %2; + delayMicros(delay); + } } + //qDebug() << "signal sent." << rawData; // re-enable it - //m_receiver->start(); + m_receiver->start(); } @@ -60,29 +63,50 @@ int Radio433::micros() 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){ - return; - }else { - if(pulseLength < 100){ - struct timeval tNow, tLong, tEnd ; + sleeper.tv_sec = (time_t)(milliSeconds / 1000) ; + sleeper.tv_nsec = (long)(milliSeconds % 1000) * 1000000; - gettimeofday (&tNow, NULL) ; - tLong.tv_sec = pulseLength / 1000000 ; - tLong.tv_usec = pulseLength % 1000000 ; - timeradd (&tNow, &tLong, &tEnd) ; + nanosleep (&sleeper, &dummy) ; +} - while (timercmp (&tNow, &tEnd, <)){ - gettimeofday (&tNow, NULL) ; - } - } - sleeper.tv_sec = 0 ; - sleeper.tv_nsec = (long)(pulseLength * 1000) ; - nanosleep (&sleeper, NULL) ; - } +//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); + + nanosleep (&sleeper, NULL) ; } @@ -107,11 +131,11 @@ void Radio433::handleInterrupt() rawData.append(m_timings[i]); m_timings[i] = 0; } -// qDebug() << "-----------------------------------------------------------"; -// qDebug() << "| GENERIC signal |"; -// qDebug() << "-----------------------------------------------------------"; -// qDebug() << "delay :" << rawData.first() /31; -// qDebug() << rawData; + // qDebug() << "-----------------------------------------------------------"; + // qDebug() << "| GENERIC signal |"; + // qDebug() << "-----------------------------------------------------------"; + // qDebug() << "delay :" << rawData.first() /31; + // qDebug() << rawData; emit dataReceived(rawData); } diff --git a/libhive/radio433.h b/libhive/radio433.h index e607fb89..11de9a0c 100644 --- a/libhive/radio433.h +++ b/libhive/radio433.h @@ -31,6 +31,8 @@ private: int micros(); void delayMicroseconds(int pulseLength); + void delayMicros(int microSeconds); + void delayMilli(int milliSeconds); private slots: void handleInterrupt(); diff --git a/plugins/deviceplugins/devicepluginelro/devicepluginelro.cpp b/plugins/deviceplugins/devicepluginelro/devicepluginelro.cpp index 57f6a042..d70ef6d7 100644 --- a/plugins/deviceplugins/devicepluginelro/devicepluginelro.cpp +++ b/plugins/deviceplugins/devicepluginelro/devicepluginelro.cpp @@ -158,7 +158,6 @@ void DevicePluginElro::executeAction(Device *device, const Action &action) QList rawData; QByteArray binCode; - qDebug() << "rawData" << rawData; // ======================================= // create the bincode // channels @@ -215,12 +214,12 @@ void DevicePluginElro::executeAction(Device *device, const Action &action) binCode.append("01"); } // Power - if(action.params().first().toBool()){ + if(action.params().value("power").toBool()){ binCode.append("0001"); }else{ binCode.append("0100"); } - + qDebug() << "bin code:" << binCode; // ======================================= //create rawData timings list int delay = 350; @@ -359,6 +358,7 @@ void DevicePluginElro::receiveData(QList rawData) DeviceClass deviceClass = supportedDevices().first(); foreach (const TriggerType &triggerType, deviceClass.triggers()) { if (triggerType.name() == button) { + qDebug() << "emit trigger " << group << triggerType.name() << power; Trigger trigger = Trigger(triggerType.id(), device->id(), params); emit emitTrigger(trigger); return; diff --git a/plugins/deviceplugins/devicepluginintertechno/devicepluginintertechno.cpp b/plugins/deviceplugins/devicepluginintertechno/devicepluginintertechno.cpp index 9238e800..8fa4b821 100644 --- a/plugins/deviceplugins/devicepluginintertechno/devicepluginintertechno.cpp +++ b/plugins/deviceplugins/devicepluginintertechno/devicepluginintertechno.cpp @@ -409,7 +409,7 @@ void DevicePluginIntertechno::receiveData(QList rawData) DeviceClass deviceClass = supportedDevices().first(); foreach (const TriggerType &triggerType, deviceClass.triggers()) { if (triggerType.name() == buttonCode) { - //qDebug() << "emit trigger " << triggerType.name(); + qDebug() << "emit trigger " << familyCode << triggerType.name() << power; Trigger trigger = Trigger(triggerType.id(), device->id(), params); emit emitTrigger(trigger); return; diff --git a/server/jsonrpcserver.cpp b/server/jsonrpcserver.cpp index cf5b1d5a..84d200e5 100644 --- a/server/jsonrpcserver.cpp +++ b/server/jsonrpcserver.cpp @@ -120,7 +120,7 @@ void JsonRPCServer::handleRulesMessage(int clientId, int commandId, const QStrin Action action(params.value("deviceId").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)) { case RuleEngine::RuleErrorNoError: @@ -141,11 +141,14 @@ void JsonRPCServer::handleActionMessage(int clientId, int commandId, const QStri if (method == "ExecuteAction") { QVariantMap actionMap = params.value("action").toMap(); QUuid deviceId = actionMap.value("deviceId").toUuid(); - QVariantList actionParams = actionMap.value("params").toList(); + QVariantMap actionParams = actionMap.value("params").toMap(); Action action(deviceId); action.setParams(actionParams); + qDebug() << "actions params in json" << action.params(); + + DeviceManager::DeviceError error = HiveCore::instance()->deviceManager()->executeAction(action); switch (error) { case DeviceManager::DeviceErrorNoError: diff --git a/server/ruleengine.cpp b/server/ruleengine.cpp index 55f97a62..ac818bb0 100644 --- a/server/ruleengine.cpp +++ b/server/ruleengine.cpp @@ -28,7 +28,7 @@ RuleEngine::RuleEngine(QObject *parent) : settings.beginGroup("action"); Action action = Action(settings.value("deviceId").toUuid(), settings.value("id").toUuid()); action.setName(settings.value("name").toString()); - action.setParams(settings.value("params").toList()); + action.setParams(settings.value("params").toMap()); settings.endGroup(); settings.endGroup(); diff --git a/tests/addrule.sh b/tests/addrule.sh index 50ed14df..1edce044 100755 --- a/tests/addrule.sh +++ b/tests/addrule.sh @@ -3,5 +3,6 @@ if test -z $3; then echo "usage: $1 host triggerId actionId" 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