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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<int> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ private:
|
|||
|
||||
int micros();
|
||||
void delayMicroseconds(int pulseLength);
|
||||
void delayMicros(int microSeconds);
|
||||
void delayMilli(int milliSeconds);
|
||||
|
||||
private slots:
|
||||
void handleInterrupt();
|
||||
|
|
|
|||
|
|
@ -158,7 +158,6 @@ void DevicePluginElro::executeAction(Device *device, const Action &action)
|
|||
QList<int> 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<int> 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;
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ void DevicePluginIntertechno::receiveData(QList<int> 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;
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue