bool CTellstick::WriteToHardware(const char *pdata, const unsigned char length) { _tGeneralSwitch *pSwitch = (_tGeneralSwitch*)pdata; //tRBUF *pCmd=(tRBUF*) pdata; _log.Log(LOG_NORM, "Tellstick: WriteToHardware %d id: %d cmd: %d", pSwitch->type, pSwitch->id, pSwitch->cmnd); if (pSwitch->type != pTypeGeneralSwitch) return false; //only allowed to control switches if (pSwitch->cmnd == gswitch_sOn) { _log.Log(LOG_NORM, "Tellstick: Switch ON"); tdTurnOn(pSwitch->id); } else if(pSwitch->cmnd == gswitch_sOff) { _log.Log(LOG_NORM, "Tellstick: Switch OFF"); tdTurnOff(pSwitch->id); } else if(pSwitch->cmnd == gswitch_sSetLevel) { _log.Log(LOG_NORM, "Tellstick: Dim level %d %d", pSwitch->level, pSwitch->level * 255 / 99); tdDim(pSwitch->id, pSwitch->level * 255 / 99); } return true; }
void lightingCommandHandler(xPL_ServicePtr theService, xPL_MessagePtr theMessage, xPL_ObjectPtr userValue) { Bool found = FALSE; int deviceCount = 0, deviceId = 0, i, level = 0; if (!xPL_doesMessageNamedValueExist(theMessage, "command")) { return; } else if (xPL_strcmpIgnoreCase(xPL_getMessageNamedValue(theMessage, "command"), "goto") != 0) { return; } if (!xPL_doesMessageNamedValueExist(theMessage, "network")) { return; } else if (xPL_strcmpIgnoreCase(xPL_getMessageNamedValue(theMessage, "network"), "1") != 0) { return; } if (!xPL_doesMessageNamedValueExist(theMessage, "device")) { return; } else { /* Loop the devices to see it realy exists */ deviceCount = tdGetNumberOfDevices(); xPL_strToInt(xPL_getMessageNamedValue(theMessage, "device"), &deviceId); for( i = 0; i < deviceCount; ++i ) { if (tdGetDeviceId(i) == deviceId) { found = TRUE; break; } } if (found == FALSE) { return; } } if (!xPL_doesMessageNamedValueExist(theMessage, "level")) { return; } else { xPL_strToInt(xPL_getMessageNamedValue(theMessage, "level"), &level); if (level < 0 || level > 100) { return; } level = (float)level * 255.0 / 100.0; } if (level > 0 && level < 255) { /* See if the device supports dim */ if (!(tdMethods(deviceId, TELLSTICK_DIM) & TELLSTICK_DIM)) { /* Non dimmable device was dimmed */ return; } tdDim(deviceId, (unsigned char)level); } else if (level == 255) { /* See if the device supports dim */ if (!(tdMethods(deviceId, TELLSTICK_TURNON) & TELLSTICK_TURNON)) { /* Non dimmable device was dimmed */ return; } tdTurnOn(deviceId); } else if (level == 0) { /* See if the device supports dim */ if (!(tdMethods(deviceId, TELLSTICK_TURNOFF) & TELLSTICK_TURNOFF)) { /* Non dimmable device was dimmed */ return; } tdTurnOff(deviceId); } }