Changeset bdb766
- Timestamp:
- 01/16/12 16:30:41 (4 months ago)
- Branches:
- ('master', 'deebf2045e7119c339412580f37a1e653f7d5715')('controller-upgrade', '00f95d22e12d96ef089e0902ef62ae8ce841dc6f')
- Children:
- 9afb2cbbacbc788de8372e6c0a2dd60585f0e947
- Parents:
- 1e650c7142f7844537be880bdfa4b4229880b6add326331538b646bc02f6b87b9391500238901a94
- git-author:
- Micke Prag <micke.prag@telldus.se>2012-01-16 16:30:10+01:00
- git-committer:
- Micke Prag <micke.prag@telldus.se>2012-01-16 16:30:41+01:00
- Files:
-
- 27 added
- 15 deleted
- 54 edited
- 24 moved
-
.gitignore (modified) (1 diff)
-
3rdparty/tellstick.net/Properties/AssemblyInfo.cs (moved) (moved from tellstick.net/Properties/AssemblyInfo.cs)
-
3rdparty/tellstick.net/TellStick.NET.csproj (moved) (moved from tellstick.net/TellStick.NET.csproj)
-
3rdparty/tellstick.net/TellStick.cs (moved) (moved from tellstick.net/TellStick.cs)
-
3rdparty/tellstickcontroller/License (moved) (moved from tellstickcontroller/License)
-
3rdparty/tellstickcontroller/Readme (moved) (moved from tellstickcontroller/Readme)
-
3rdparty/tellstickcontroller/examples/power_off_all_lights (moved) (moved from tellstickcontroller/examples/power_off_all_lights)
-
3rdparty/tellstickcontroller/examples/power_off_bedroom_mythtv (moved) (moved from tellstickcontroller/examples/power_off_bedroom_mythtv)
-
3rdparty/tellstickcontroller/examples/power_on_all_lights (moved) (moved from tellstickcontroller/examples/power_on_all_lights)
-
3rdparty/tellstickcontroller/examples/power_on_bedroom_mythtv (moved) (moved from tellstickcontroller/examples/power_on_bedroom_mythtv)
-
3rdparty/tellstickcontroller/examples/swap_livingroom_tv_mode (moved) (moved from tellstickcontroller/examples/swap_livingroom_tv_mode)
-
3rdparty/tellstickcontroller/examples/tellstickController.conf (moved) (moved from tellstickcontroller/examples/tellstickController.conf)
-
3rdparty/tellstickcontroller/tellstick.conf (moved) (moved from tellstickcontroller/tellstick.conf)
-
3rdparty/tellstickcontroller/tellstickController (moved) (moved from tellstickcontroller/tellstickController)
-
3rdparty/tellstickcontroller/tellstickController.conf (moved) (moved from tellstickcontroller/tellstickController.conf)
-
3rdparty/tellstickcontroller/tellstickControllerRfcmd (moved) (moved from tellstickcontroller/tellstickControllerRfcmd)
-
3rdparty/tellstickcontroller/tellstickControllerRfcmd.conf (moved) (moved from tellstickcontroller/tellstickControllerRfcmd.conf)
-
3rdparty/tellstickcontroller/tellstickControllerTdtool (moved) (moved from tellstickcontroller/tellstickControllerTdtool)
-
3rdparty/tellstickcontroller/tellstickControllerTdtool.conf (moved) (moved from tellstickcontroller/tellstickControllerTdtool.conf)
-
3rdparty/tellstickd/LICENSE (moved) (moved from tellstickd/LICENSE)
-
3rdparty/tellstickd/README (moved) (moved from tellstickd/README)
-
3rdparty/tellstickd/init_script/tellstickd (moved) (moved from tellstickd/init_script/tellstickd)
-
3rdparty/tellstickd/init_script/tellstickd.debian (moved) (moved from tellstickd/init_script/tellstickd.debian)
-
3rdparty/tellstickd/tellstickd (moved) (moved from tellstickd/tellstickd)
-
3rdparty/tellstickd/tellstickd.conf (moved) (moved from tellstickd/tellstickd.conf)
-
docs/telldus-core.dox (modified) (6 diffs)
-
examples/php/live/authentication/common.php (added)
-
examples/php/live/authentication/getAccessToken.php (added)
-
examples/php/live/authentication/getRequestToken.php (added)
-
examples/php/live/authentication/index.php (added)
-
rfcmd/CMakeLists.txt (added)
-
rfcmd/COPYING (added)
-
rfcmd/Makefile (added)
-
rfcmd/build.sh (added)
-
rfcmd/find_telldus.c (added)
-
rfcmd/ftdi.c (added)
-
rfcmd/rfcmd.c (added)
-
systray/src/SysTray_sv.ts (deleted)
-
systray/src/icon.cpp (deleted)
-
systray/src/icon.h (deleted)
-
systray/src/images/bell.png (deleted)
-
systray/src/images/lamp-off.png (deleted)
-
systray/src/images/lamp-on.png (deleted)
-
systray/src/images/preferences-system.png (deleted)
-
systray/src/images/system-log-out.png (deleted)
-
systray/src/images/systray.icns (deleted)
-
systray/src/images/systray.ico (deleted)
-
systray/src/main.cpp (deleted)
-
systray/src/resource.qrc (deleted)
-
systray/src/src.pro (deleted)
-
systray/src/systray.rc (deleted)
-
systray/systray.pro (deleted)
-
telldus-core/client/CallbackDispatcher.cpp (modified) (2 diffs)
-
telldus-core/client/Client.cpp (modified) (3 diffs)
-
telldus-core/client/telldus-core.cpp (modified) (8 diffs)
-
telldus-core/client/telldus-core.h (modified) (1 diff)
-
telldus-core/common/Message.cpp (modified) (2 diffs)
-
telldus-core/common/Message.h (modified) (1 diff)
-
telldus-core/common/Socket_unix.cpp (modified) (4 diffs)
-
telldus-core/common/Socket_win.cpp (modified) (3 diffs)
-
telldus-core/common/Strings.cpp (modified) (3 diffs)
-
telldus-core/common/Strings.h (modified) (2 diffs)
-
telldus-core/service/CMakeLists.txt (modified) (6 diffs)
-
telldus-core/service/ClientCommunicationHandler.cpp (modified) (2 diffs)
-
telldus-core/service/ConnectionListener_win.cpp (modified) (1 diff)
-
telldus-core/service/Controller.h (modified) (1 diff)
-
telldus-core/service/ControllerManager.cpp (modified) (2 diffs)
-
telldus-core/service/ControllerManager.h (modified) (1 diff)
-
telldus-core/service/DeviceManager.cpp (modified) (4 diffs)
-
telldus-core/service/EventHandler_win.cpp (modified) (1 diff)
-
telldus-core/service/EventUpdateManager.cpp (modified) (1 diff)
-
telldus-core/service/Log.cpp (added)
-
telldus-core/service/Log.h (added)
-
telldus-core/service/Messages.mc (added)
-
telldus-core/service/Protocol.cpp (modified) (5 diffs)
-
telldus-core/service/ProtocolFineoffset.cpp (added)
-
telldus-core/service/ProtocolFineoffset.h (added)
-
telldus-core/service/ProtocolMandolyn.cpp (added)
-
telldus-core/service/ProtocolMandolyn.h (added)
-
telldus-core/service/ProtocolNexa.cpp (modified) (1 diff)
-
telldus-core/service/ProtocolOregon.cpp (added)
-
telldus-core/service/ProtocolOregon.h (added)
-
telldus-core/service/SettingsConfuse.cpp (modified) (1 diff)
-
telldus-core/service/SettingsWinRegistry.cpp (modified) (8 diffs)
-
telldus-core/service/TellStick.h (modified) (1 diff)
-
telldus-core/service/TellStick_ftd2xx.cpp (modified) (9 diffs)
-
telldus-core/service/TellStick_libftdi.cpp (modified) (8 diffs)
-
telldus-core/service/TelldusMain.cpp (modified) (3 diffs)
-
telldus-core/service/TelldusWinService_win.cpp (modified) (3 diffs)
-
telldus-core/service/Timer.cpp (added)
-
telldus-core/service/Timer.h (added)
-
telldus-core/service/main_mac.cpp (modified) (2 diffs)
-
telldus-core/service/main_unix.cpp (modified) (9 diffs)
-
telldus-core/service/tellstick.conf (modified) (1 diff)
-
telldus-core/tdadmin/05-tellstick.rules (modified) (1 diff)
-
telldus-core/tdtool/main.cpp (modified) (15 diffs)
-
telldus-gui/Plugins/Live/LiveMessageToken.cpp (modified) (3 diffs)
-
telldus-gui/Plugins/Live/LiveMessageToken.h (modified) (3 diffs)
-
telldus-gui/Plugins/Live/LiveObject.cpp (modified) (13 diffs)
-
telldus-gui/Plugins/Live/LiveObject.h (modified) (1 diff)
-
telldus-gui/Plugins/Live/__init__.js (modified) (4 diffs)
-
telldus-gui/Plugins/Live/configuration.ui (modified) (1 diff)
-
telldus-gui/TelldusCenter/CMakeLists.txt (modified) (1 diff)
-
telldus-gui/TelldusGui/devicesetting.cpp (modified) (1 diff)
-
telldus-gui/TelldusGui/devicesetting.h (modified) (1 diff)
-
telldus-gui/TelldusGui/editdevicedialog.cpp (modified) (1 diff)
-
telldus-gui/TelldusGui/filtereddeviceproxymodel.cpp (modified) (1 diff)
-
telldus-gui/TelldusGui/filtereddeviceproxymodel.h (modified) (1 diff)
-
.gitmodules (added)
-
telldus-gui/3rdparty/qt-components-desktop (added)
-
telldus-gui/3rdparty/qt-components-desktop.cmake (added)
-
telldus-gui/Plugins/QML/CMakeLists.txt (modified) (1 diff)
-
telldus-gui/Plugins/QML/qmlview.cpp (modified) (2 diffs)
-
telldus-gui/Plugins/Sensors/CMakeLists.txt (modified) (2 diffs)
-
telldus-gui/Plugins/Sensors/SensorList.qml (added)
-
telldus-gui/Plugins/Sensors/SensorView.qml (added)
-
telldus-gui/Plugins/Sensors/main.qml (modified) (2 diffs)
-
telldus-gui/Plugins/Sensors/qmldir (modified) (1 diff)
-
telldus-gui/Plugins/Sensors/sensor.cpp (modified) (1 diff)
-
telldus-gui/Plugins/TelldusCenterPlugin.cmake (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
.gitignore
r47998b r01855c 1 1 build/ 2 qtcreator-build/ 3 Doxyfile 4 html/ 5 latex/ 6 CMakeLists.txt.user -
docs/telldus-core.dox
r72575f r290a80 188 188 * \endcode 189 189 * 190 * \subsection sec_bu_sensors Sensors 191 * 192 * Retrieving sensor values can be done in two ways. Either by a polling 193 * interface or by callbacks. The client application can implement one or both 194 * of these interfaces. For callbacks, read more under \ref sec_events. 195 * 196 * Each of the sensors can have one or several value types. Currently only 197 * temperature and humidity are implemented. 198 * 199 * There is no API to add, remove or edit sensors. Each sensor that 200 * TellStick Duo has got any data from is added to an internal list. It is up to 201 * the client application to filter and only show the sensors your are 202 * interested in. 203 * 204 * To iterate over the list of sensors, call tdSensor() repeatedly as long as it 205 * returns \c TELLSTICK_SUCCESS. The parameters \c protocol, \c model, 206 * \c sensorId, and \c dataTypes are sent by reference and will be filled with 207 * the values. 208 * 209 * Example: 210 * \code 211 * char protocol[DATA_LENGTH], model[DATA_LENGTH]; 212 * int sensorId = 0, dataTypes = 0; 213 * while(tdSensor(protocol, DATA_LENGTH, model, DATA_LENGTH, &sensorId, &dataTypes) == TELLSTICK_SUCCESS) { 214 * //Print the sensor 215 * printf("%s,\t%s,\t%i\n", protocol, model, sensorId); 216 * } 217 * \endcode 218 * 219 * The type of sensor values the sensor supports are stored as flags in the 220 * parameter \c sensorId. Call tdSensorValue() for each type. 221 * 222 * Example: 223 * \code 224 * char value[DATA_LENGTH]; 225 * char timeBuf[80]; 226 * time_t timestamp = 0; 227 * if (dataTypes & TELLSTICK_TEMPERATURE) { 228 * tdSensorValue(protocol, model, sensorId, TELLSTICK_TEMPERATURE, value, DATA_LENGTH, (int *)×tamp); 229 * strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S", localtime(×tamp)); 230 * printf("Temperature:\t%sº\t(%s)\n", value, timeBuf); 231 * } 232 * \endcode 233 * 190 234 * \section sec_events Events 191 235 * 192 * To get events from either a TellStick Duo or ifanother software changes the193 * status of a device you have to register for a callback.236 * To get events from either a TellStick Duo, another software changes the 237 * status of a device, or new sensors values you have to register for a callback. 194 238 * 195 239 * \subsection sec_events_registering Registering for callbacks … … 199 243 * \li tdRegisterDeviceChangeEvent() 200 244 * \li tdRegisterRawDeviceEvent() 245 * \li tdRegisterSensorEvent() 201 246 * 202 247 * These all work in the same way. The first parameter is a function-pointer to … … 213 258 * Many devices (for example motion detectors) resends their messages many times 214 259 * to ensure that they are received correctly. If a deviceeventcallback or 215 * rawdeviceeventcallback in turn is calling a controlling function, for example tdTurnOn, 216 * it may be neccessary to implement some solution to wait for the device to finish its 217 * resending, before executing the controlling function. See how this can be done in the python example. 260 * rawdeviceeventcallback in turn is calling a controlling function, for example 261 * tdTurnOn, it may be neccessary to implement some solution to wait for the 262 * device to finish its resending, before executing the controlling function. 263 * See how this can be done in the python example. 218 264 * 219 265 * \subsection sec_events_callbacks Callbacks 220 266 * 221 * telldus-core currently implements threedifferent callback function for267 * telldus-core currently implements four different callback function for 222 268 * different purposes. 223 269 * … … 235 281 * this hold the current value. 236 282 * - int callbackId - id of callback 237 * - void *context - see "Registering for callbacks"for description283 * - void *context - see \ref sec_events_registering for description 238 284 * 239 285 * \subsubsection sec_events_callbacks_devicechangeevent DeviceChangeEvent 286 * 240 287 * This event is fired when the data around a device is changed. It can only be 241 288 * triggered by another software. Use this callback to keep your list of devices … … 257 304 * - TELLSTICK_CHANGE_MODEL - Use tdGetModel() to read the new value. 258 305 * - int callbackId - id of callback 259 * - void *context - see "Registering for callbacks"for description306 * - void *context - see \ref sec_events_registering for description 260 307 * 261 308 * \subsubsection sec_events_callbacks_rawdeviceevent RawDeviceEvent 262 309 * 263 * Use this callback with caution. It outputs everything from the Duo without264 * any preprocessing. This can be used to get events from devices not already265 * configured.310 * Use this callback with caution. It outputs everything from a TellStick Duo 311 * without any preprocessing. This can be used to get events from devices not 312 * already configured. 266 313 * 267 314 * Parameters: … … 269 316 * - int controllerId - id of receiving controller, can identify the TellStick if several exists in the system 270 317 * - int callbackId - id of callback 271 * - void *context - see "Registering for callbacks" for description 318 * - void *context - see \ref sec_events_registering for description 319 * 320 * \subsubsection sec_events_callbacks_sensorevent SensorEvent 321 * 322 * This event is fired when a new sensor value is retrieved. 323 * 324 * Parameters: 325 * - const char *protocol - The sensors protocol 326 * - const char *model - The model of the sensor 327 * - int id - The unique id for the sensor. 328 * - int dataType - Flags for which types of data the sensor supports 329 * - const char *value - A human readable string of the data 330 * - int timestamp - The timestamp when the latest value was received 331 * - int callbackId - id of callback 332 * - void *context - See \ref sec_events_registering for description 272 333 * 273 334 * \subsection sec_events_example Example -
telldus-core/client/CallbackDispatcher.cpp
r9535ec r245864 9 9 10 10 #include "CallbackDispatcher.h" 11 #include "common.h" 11 12 12 13 using namespace TelldusCore; … … 29 30 30 31 void TDDeviceEventDispatcher::run() { 32 char *str = wrapStdString(strData); 31 33 d->event(deviceId, method, strData.c_str(), d->id, d->context); 34 32 35 doneRunning = true; 33 36 } -
telldus-core/client/Client.cpp
r9535ec r46d70a 115 115 int Client::getIntegerFromService(const Message &msg) { 116 116 std::wstring response = sendToService(msg); 117 if (response.compare(L"") == 0) { 118 return TELLSTICK_ERROR_COMMUNICATING_SERVICE; 119 } 117 120 return Message::takeInt(&response); 118 121 } … … 182 185 } 183 186 184 std::wstring clientMessage = d->eventSocket.read(5000); //testing 5 second timeout 187 std::wstring clientMessage = d->eventSocket.read(1000); //testing 5 second timeout 188 185 189 while(clientMessage != L""){ 186 190 //a message arrived … … 283 287 284 288 std::wstring Client::sendToService(const Message &msg) { 285 Socket s; 286 s.connect(L"TelldusClient"); 287 if (!s.isConnected()) { //Connection failed 288 TelldusCore::Message msg; 289 msg.addArgument(TELLSTICK_ERROR_CONNECTING_SERVICE); 290 return msg; 291 } 292 s.write(msg.data()); 293 294 return s.read(5000); 289 290 int tries = 0; 291 std::wstring readData; 292 while(tries < 20){ 293 tries++; 294 if(tries == 20){ 295 TelldusCore::Message msg; 296 msg.addArgument(TELLSTICK_ERROR_CONNECTING_SERVICE); 297 return msg; 298 } 299 Socket s; 300 s.connect(L"TelldusClient"); 301 if (!s.isConnected()) { //Connection failed 302 printf("Connection failed\n\r"); 303 msleep(500); 304 continue; //retry 305 } 306 s.write(msg.data()); 307 if (!s.isConnected()) { //Connection failed sometime during operation... (better check here, instead of 5 seconds timeout later) 308 printf("Connection failed after write\n\r"); 309 msleep(500); 310 continue; //retry 311 } 312 readData = s.read(8000); //TODO changed to 10000 from 5000, how much does this do...? 313 if(readData == L""){ 314 printf("Readdata nothing\n\r"); 315 msleep(500); 316 continue; //TODO can we be really sure it SHOULD be anything? 317 //TODO perhaps break here instead? 318 } 319 320 if (!s.isConnected()) { //Connection failed sometime during operation... 321 printf("Connection failed in the end\n\r"); 322 msleep(500); 323 continue; //retry 324 } 325 break; 326 } 327 328 return readData; 295 329 } 296 330 -
telldus-core/client/telldus-core.cpp
r8eaaf6 r46d70a 58 58 * Error code. Returned when the command succeeded. 59 59 * 60 * @def TELLSTICK_ERROR_BROKEN_PIPE 61 * Error code. Pipe broken during communication. 62 * 60 63 * @def TELLSTICK_ERROR_NOT_FOUND 61 64 * Error code. Returned if a TellStick was not found on the system. … … 82 85 * Error code. The client library received a response from the service 83 86 * it did not understand. 87 * 88 * @def TELLSTICK_ERROR_SYNTAX 89 * Error code. Input/command could not be parsed or didn't follow 90 * input rules. 91 * 92 * @def TELLSTICK_ERROR_COMMUNICATING_SERVICE 93 * Error code. Timeout waiting for response from the Telldus Service. 84 94 * 85 95 * @def TELLSTICK_ERROR_UNKNOWN … … 480 490 * @sa TELLSTICK_ERROR_DEVICE_NOT_FOUND 481 491 * @sa TELLSTICK_ERROR_METHOD_NOT_SUPPORTED 492 * @sa TELLSTICK_ERROR_COMMUNICATION 493 * @sa TELLSTICK_ERROR_CONNECTING_SERVICE 494 * @sa TELLSTICK_ERROR_UNKNOWN_RESPONSE 495 * @sa TELLSTICK_ERROR_SYNTAX 496 * @sa TELLSTICK_ERROR_BROKEN_PIPE 497 * @sa TELLSTICK_ERROR_COMMUNICATING_SERVICE 482 498 * @sa TELLSTICK_ERROR_UNKNOWN 483 499 */ 484 500 char * WINAPI tdGetErrorString(int intErrorNo) { 485 const int numResponses = 8;501 const int numResponses = 10; 486 502 const char *responses[numResponses] = { 487 503 "Success", … … 492 508 "An error occurred while communicating with TellStick", 493 509 "Could not connect to the Telldus Service", 494 "Received an unknown response" 510 "Received an unknown response", 511 "Syntax error", 512 "Broken pipe" 513 "An error occured while communicating with the Telldus Service" 495 514 }; 496 515 std::string strReturn; … … 512 531 */ 513 532 int WINAPI tdSendRawCommand(const char *command, int reserved) { 533 std::wstring wcommand; 534 for(int i = 0; i < strlen(command);++i) { 535 wcommand.append(1, (unsigned char)command[i]); 536 } 514 537 Message msg(L"tdSendRawCommand"); 515 msg.addArgument( command);538 msg.addArgument(wcommand); 516 539 msg.addArgument(reserved); 517 540 return Client::getIntegerFromService(msg); … … 535 558 } 536 559 560 /** 561 * Use this function to iterate over all sensors. Iterate until 562 * TELLSTICK_SUCCESS is not returned 563 * @param protocol A byref string where the protocol of the sensor will be placed 564 * @param protocolLen The length of the \c protocol parameter 565 * @param model A byref string where the model of the sensor will be placed 566 * @param modelLen The length of the \c model parameter 567 * @param id A byref int where the id of the sensor will be placed 568 * @param dataTypes A byref int with flags for the supported sensor values 569 * @returns TELLSTICK_SUCCESS if there is more sensors to be fetched 570 */ 537 571 int WINAPI tdSensor(char *protocol, int protocolLen, char *model, int modelLen, int *id, int *dataTypes) { 538 572 Client *client = Client::getInstance(); … … 540 574 } 541 575 576 /** 577 * Get one of the supported sensor values from a sensor. Make sure it support 578 * the value type first by calling tdSensor(). The triplet \c protocol, 579 * \c model, and \c id together identifies a sensor. 580 * @param protocol The protocol for the sensor 581 * @param model The model for the sensor 582 * @param id The id of the sensor 583 * @param dataType One of the datatype to retrieve 584 * @param value A byref string where the value will be places 585 * @param len The length of the \c value parameter 586 * @param timestamp A byref int where the timestamp of the value will be placed 587 * @returns TELLSTICK_SUCCESS if the value could be fetched or one of the 588 * errorcodes on failure 589 */ 542 590 int WINAPI tdSensorValue(const char *protocol, const char *model, int id, int dataType, char *value, int len, int *timestamp) { 543 591 Message msg(L"tdSensorValue"); … … 563 611 564 612 565 /* \@}*/613 /* @} */ -
telldus-core/client/telldus-core.h
r8eaaf6 r46d70a 116 116 #define TELLSTICK_ERROR_CONNECTING_SERVICE -6 117 117 #define TELLSTICK_ERROR_UNKNOWN_RESPONSE -7 118 #define TELLSTICK_ERROR_SYNTAX -8 119 #define TELLSTICK_ERROR_BROKEN_PIPE -9 120 #define TELLSTICK_ERROR_COMMUNICATING_SERVICE -10 118 121 #define TELLSTICK_ERROR_UNKNOWN -99 119 122 -
telldus-core/common/Message.cpp
rfe7f8f r245864 24 24 25 25 void Message::addArgument(const std::wstring &value) { 26 std::wstringstream st;27 st << (int)value.size();28 this->append( st.str());26 //std::wstringstream st; 27 //st << (int)value.size(); 28 this->append(TelldusCore::intToWstring(value.size())); //st.str()); 29 29 this->append(L":"); 30 30 this->append(value); … … 32 32 33 33 void Message::addArgument(int value) { 34 std::wstringstream st;35 st << (int)value;34 //std::wstringstream st; 35 //st << (int)value; 36 36 this->append(L"i"); 37 this->append( st.str());37 this->append(TelldusCore::intToWstring(value)); // st.str()); 38 38 this->append(L"s"); 39 39 } 40 41 /* 42 void Message::addSpecialArgument(const std::wstring &value){ 43 int i = 0; 44 while(i<1000000){ 45 i++; 46 47 char numstr[21]; // enough to hold all numbers up to 64-bits 48 //sprintf(numstr, "%d", value.size()); 49 //this->append(TelldusCore::charToWstring(numstr)); //.str()); 50 51 itoa(value.size(), numstr, 10); 52 std::string test(numstr); 53 std::wstring temp(test.length(), L' '); 54 std::copy(test.begin(), test.end(), temp.begin()); 55 56 this->append(temp); 57 this->append(L":"); 58 this->append(value); 59 60 /* 61 std::wstringstream st; 62 st << (int)value.size(); 63 this->append(st.str()); 64 this->append(L":"); 65 this->append(value); 66 67 } 68 } 69 70 void Message::addSpecialArgument(int value){ 71 int i = 0; 72 while(i<1000000){ 73 i++; 74 /* 75 //std::wstringstream st; 76 //st << (int)value; 77 this->append(L"i"); 78 //this->append(st.str()); 79 this->append(L"s"); 80 81 } 82 } 83 */ 84 /* 85 void Message::addSpecialArgument(const char *value){ 86 this->addSpecialArgument(TelldusCore::charToWstring(value)); 87 } 88 */ 40 89 41 90 void Message::addArgument(const char *value) { -
telldus-core/common/Message.h
rfe7f8f r245864 12 12 13 13 void addArgument(const std::wstring &); 14 //void addSpecialArgument(const std::wstring &); 15 //void addSpecialArgument(int); 16 //void addSpecialArgument(const char *); 14 17 void addArgument(int); 15 18 void addArgument(const char *); -
telldus-core/common/Socket_unix.cpp
rb25802 r673daf 79 79 struct timeval tv; 80 80 char inbuf[BUFSIZE]; 81 memset(inbuf, '\0', sizeof(inbuf));82 81 83 82 FD_SET(d->socket, &d->infds); 83 std::string msg; 84 84 while(isConnected()) { 85 85 tv.tv_sec = floor(timeout / 1000.0); … … 94 94 } 95 95 96 int received = recv(d->socket, inbuf, BUFSIZE - 1, 0); 97 if (received <= 0) { 96 int received = BUFSIZE; 97 while(received >= (BUFSIZE - 1)){ 98 memset(inbuf, '\0', sizeof(inbuf)); 99 received = recv(d->socket, inbuf, BUFSIZE - 1, 0); 100 if(received > 0){ 101 msg.append(std::string(inbuf)); 102 } 103 } 104 if (received < 0) { 98 105 TelldusCore::MutexLocker locker(&d->mutex); 99 106 d->connected = false; … … 102 109 } 103 110 104 std::string msg(inbuf);105 111 return TelldusCore::charToWstring(msg.c_str()); 106 112 } … … 109 115 TelldusCore::MutexLocker locker(&d->mutex); 110 116 d->connected = false; 117 //TODO somehow signal the socket here? 111 118 } 112 119 -
telldus-core/common/Socket_win.cpp
rffeb0b red502d 38 38 if (d->hPipe != INVALID_HANDLE_VALUE) { 39 39 CloseHandle(d->hPipe); 40 d->hPipe = 0; 40 41 } 41 42 delete d; … … 90 91 memset(&oOverlap, 0, sizeof(OVERLAPPED)); 91 92 92 d->readEvent = CreateEvent(NULL, TRUE, TRUE, NULL);93 d->readEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 93 94 oOverlap.hEvent = d->readEvent; 94 95 BOOL fSuccess = false; 96 std::wstring returnString; 97 bool moreData = true; 95 98 96 memset(&buf, 0, BUFSIZE); 99 while(moreData){ 100 moreData = false; 101 memset(&buf, 0, sizeof(buf)); 97 102 98 ReadFile( d->hPipe, &buf, sizeof(wchar_t)*BUFSIZE, &cbBytesRead, &oOverlap); 103 ReadFile( d->hPipe, &buf, sizeof(buf)-sizeof(wchar_t), &cbBytesRead, &oOverlap); 104 105 result = WaitForSingleObject(oOverlap.hEvent, timeout); 106 107 if(!d->running){ 108 CancelIo(d->hPipe); 109 WaitForSingleObject(oOverlap.hEvent, INFINITE); 110 d->readEvent = 0; 111 CloseHandle(oOverlap.hEvent); 112 return L""; 113 } 99 114 100 result = WaitForSingleObject(oOverlap.hEvent, timeout); 115 if (result == WAIT_TIMEOUT) { 116 CancelIo(d->hPipe); 117 // Cancel, we still need to cleanup 118 } 119 fSuccess = GetOverlappedResult(d->hPipe, &oOverlap, &cbBytesRead, true); 101 120 102 if(!d->running){ 103 CancelIo(d->hPipe); 104 CloseHandle(d->readEvent); 105 return L""; 121 if (!fSuccess) { 122 DWORD err = GetLastError(); 123 124 if(err == ERROR_MORE_DATA){ 125 moreData = true; 126 } 127 else{ 128 buf[0] = 0; 129 } 130 if (err == ERROR_BROKEN_PIPE) { 131 d->connected = false; 132 } 133 } 134 returnString.append(buf); 106 135 } 107 108 if (result == WAIT_TIMEOUT) { 109 CancelIo(d->hPipe); 110 CloseHandle(d->readEvent); 111 return L""; 112 } 113 fSuccess = GetOverlappedResult(d->hPipe, &oOverlap, &cbBytesRead, false); 114 if (!fSuccess) { 115 DWORD err = GetLastError(); 116 if (err == ERROR_BROKEN_PIPE) { 117 d->connected = false; 118 } 119 buf[0] = 0; 120 } 121 122 CancelIo(d->hPipe); 123 CloseHandle(d->readEvent); 124 return buf; 136 d->readEvent = 0; 137 CloseHandle(oOverlap.hEvent); 138 return returnString; 125 139 } 126 140 … … 130 144 DWORD bytesWritten = 0; 131 145 int result; 132 BOOL fSuccess ;146 BOOL fSuccess = false; 133 147 134 148 memset(&oOverlap, 0, sizeof(OVERLAPPED)); 135 149 136 HANDLE writeEvent = CreateEvent(NULL, TRUE, TRUE, NULL);150 HANDLE writeEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 137 151 oOverlap.hEvent = writeEvent; 138 152 139 WriteFile(d->hPipe, msg.data(), (DWORD)msg.length()*sizeof(wchar_t), &bytesWritten, &oOverlap); 153 BOOL writeSuccess = WriteFile(d->hPipe, msg.data(), (DWORD)msg.length()*sizeof(wchar_t), &bytesWritten, &oOverlap); 154 result = GetLastError(); 155 if (writeSuccess || result == ERROR_IO_PENDING) { 156 result = WaitForSingleObject(writeEvent, 500); 157 if (result == WAIT_TIMEOUT) { 158 CancelIo(d->hPipe); 159 WaitForSingleObject(oOverlap.hEvent, INFINITE); 160 CloseHandle(writeEvent); 161 CloseHandle(d->hPipe); 162 d->hPipe = 0; 163 d->connected = false; 164 return; 165 } 166 fSuccess = GetOverlappedResult(d->hPipe, &oOverlap, &bytesWritten, TRUE); 167 } 140 168 141 result = WaitForSingleObject(writeEvent, 500);142 if (result == WAIT_TIMEOUT) {143 CancelIo(d->hPipe);144 CloseHandle(writeEvent);145 d->connected = false;146 return;147 }148 fSuccess = GetOverlappedResult(d->hPipe, &oOverlap, &bytesWritten, TRUE);149 169 CloseHandle(writeEvent); 150 170 if (!fSuccess) { 151 CancelIo(d->hPipe); 171 CloseHandle(d->hPipe); 172 d->hPipe = 0; 152 173 d->connected = false; 153 174 return; -
telldus-core/common/Strings.cpp
r11dd17 r2ec2da 5 5 #include <string> 6 6 #include <string.h> 7 #include <stdio.h> 7 8 8 9 #ifdef _WINDOWS … … 92 93 93 94 std::wstring TelldusCore::intToWstring(int value) { 95 #ifdef _WINDOWS 96 //no stream used 97 //TODO! Make effective and safe... 98 wchar_t numstr[21]; // enough to hold all numbers up to 64-bits 99 _itow_s(value, numstr, sizeof(numstr), 10); 100 std::wstring newstring(numstr); 101 return newstring; 102 //return TelldusCore::charToWstring(stdstring.c_str()); 103 //std::wstring temp = TelldusCore::charToWstring(stdstring.c_str()); 104 //std::wstring temp(stdstring.length(), L' '); 105 //std::copy(stdstring.begin(), stdstring.end(), temp.begin()); 106 //return temp; 107 #else 94 108 std::wstringstream st; 95 109 st << value; 96 110 return st.str(); 111 #endif 97 112 } 98 113 99 114 std::string TelldusCore::intToString(int value) { 115 //Not sure if this is neecssary (for ordinary stringstream that is) 116 #ifdef _WINDOWS 117 char numstr[21]; // enough to hold all numbers up to 64-bits 118 _itoa_s(value, numstr, sizeof(numstr), 10); 119 std::string stdstring(numstr); 120 return stdstring; 121 #else 100 122 std::stringstream st; 101 123 st << value; 102 124 return st.str(); 103 } 125 #endif 126 } 127 128 /* 129 std::wstring TelldusCore::intToWStringSafe(int value){ 130 #ifdef _WINDOWS 131 //no stream used 132 //TODO! Make effective and safe... 133 char numstr[21]; // enough to hold all numbers up to 64-bits 134 itoa(value, numstr, 10); 135 std::string stdstring(numstr); 136 return TelldusCore::charToWstring(stdstring.c_str()); 137 //std::wstring temp = TelldusCore::charToWstring(stdstring.c_str()); 138 //std::wstring temp(stdstring.length(), L' '); 139 //std::copy(stdstring.begin(), stdstring.end(), temp.begin()); 140 //return temp; 141 #else 142 return TelldusCore::intToWString(value); 143 #endif 144 } 145 */ 104 146 105 147 int TelldusCore::wideToInteger(const std::wstring &input){ … … 159 201 #endif 160 202 } 203 204 std::string TelldusCore::formatf(const char *format, ...) { 205 va_list ap; 206 va_start(ap, format); 207 std::string retval = sformatf(format, ap); 208 va_end(ap); 209 return retval; 210 } 211 212 std::string TelldusCore::sformatf(const char *format, va_list ap) { 213 //This code is based on code from the Linux man-pages project (man vsprintf) 214 int n; 215 int size = 100; /* Guess we need no more than 100 bytes. */ 216 char *p, *np; 217 218 if ((p = (char*)malloc(size)) == NULL) { 219 return ""; 220 } 221 222 while (1) { 223 /* Try to print in the allocated space. */ 224 n = vsnprintf(p, size, format, ap); 225 226 /* If that worked, return the string. */ 227 if (n > -1 && n < size) { 228 std::string retval(p); 229 free(p); 230 return retval; 231 } 232 233 /* Else try again with more space. */ 234 235 if (n > -1) { /* glibc 2.1 */ 236 size = n+1; /* precisely what is needed */ 237 } else { /* glibc 2.0 */ 238 size *= 2; /* twice the old size */ 239 } 240 if ((np = (char *)realloc (p, size)) == NULL) { 241 free(p); 242 return ""; 243 } else { 244 p = np; 245 } 246 } 247 } -
telldus-core/common/Strings.h
r11dd17 r716deb 3 3 4 4 #include <string> 5 #include <stdarg.h> 5 6 6 7 namespace TelldusCore { … … 11 12 bool comparei(std::wstring stringA, std::wstring stringB); 12 13 std::wstring intToWstring(int value); 14 //std::wstring intToWStringSafe(int value); 13 15 std::string intToString(int value); 14 16 std::string wideToString(const std::wstring &input); 15 17 16 18 int wideToInteger(const std::wstring &input); 19 20 std::string formatf(const char *format, ...); 21 std::string sformatf(const char *format, va_list ap); 17 22 } 18 23 -
telldus-core/service/CMakeLists.txt
reb073d r988b44 20 20 DeviceManager.cpp 21 21 Event.cpp 22 Log.cpp 22 23 Sensor.cpp 23 24 Settings.cpp 24 25 TelldusMain.cpp 25 26 TellStick.cpp 27 Timer.cpp 26 28 EventUpdateManager.cpp 27 29 ) … … 35 37 ProtocolEverflourish.h 36 38 ProtocolEverflourish.cpp 39 ProtocolFineoffset.h 40 ProtocolFineoffset.cpp 37 41 ProtocolFuhaote.h 38 42 ProtocolFuhaote.cpp … … 43 47 ProtocolIkea.h 44 48 ProtocolIkea.cpp 49 ProtocolMandolyn.h 50 ProtocolMandolyn.cpp 45 51 ProtocolNexa.h 46 52 ProtocolNexa.cpp 53 ProtocolOregon.h 54 ProtocolOregon.cpp 47 55 ProtocolRisingSun.h 48 56 ProtocolRisingSun.cpp … … 73 81 Event.h 74 82 EventHandler.h 83 EventUpdateManager.h 84 Log.h 75 85 Sensor.h 76 86 Settings.h 77 87 TelldusMain.h 78 88 TellStick.h 79 EventUpdateManager.h89 Timer.h 80 90 ) 81 91 FIND_PACKAGE(Threads REQUIRED) … … 130 140 SettingsWinRegistry.cpp 131 141 TelldusWinService_win.cpp 142 Messages.mc 143 ${CMAKE_CURRENT_BINARY_DIR}/Messages.rc 144 ${CMAKE_CURRENT_BINARY_DIR}/Messages.h 132 145 ) 133 146 LIST(APPEND telldus-service_HDRS 134 147 TelldusWinService_win.h 135 148 ) 149 ADD_CUSTOM_COMMAND( 150 OUTPUT Messages.rc Messages.h 151 COMMAND mc.exe -u -r ${CMAKE_CURRENT_BINARY_DIR} -h ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/Messages.mc 152 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Messages.mc 153 DEPENDS Messages.rc 154 COMMENT "Compiling Messages Resource" 155 ) 156 INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ) 136 157 137 158 ELSE (APPLE) #### Linux #### … … 139 160 FIND_LIBRARY(CONFUSE_LIBRARY confuse) 140 161 ADD_DEFINITIONS( -D_CONFUSE ) 162 ADD_DEFINITIONS( -D_LINUX ) 141 163 142 164 SET( telldus-service_TARGET telldusd ) -
telldus-core/service/ClientCommunicationHandler.cpp
rad1b18 rb84e8b 77 77 int deviceId = TelldusCore::Message::takeInt(&msg); 78 78 (*intReturn) = d->deviceManager->doAction(deviceId, TELLSTICK_TURNON, 0); 79 79 80 } else if (function == L"tdTurnOff") { 80 81 int deviceId = TelldusCore::Message::takeInt(&msg); … … 207 208 int reserved = TelldusCore::Message::takeInt(&msg); 208 209 (*intReturn) = d->deviceManager->sendRawCommand(command, reserved); 209 EventUpdateData *eventData = new EventUpdateData();210 eventData->messageType = L"TDRawDeviceEvent";211 eventData->controllerId = -1;212 eventData->eventValue = command;213 d->deviceUpdateEvent->signal(eventData);214 210 215 211 } else if (function == L"tdConnectTellStickController") { -
telldus-core/service/ConnectionListener_win.cpp
r184d2e r65ef52 92 92 d->hEvent = CreateEvent(NULL, true, false, NULL); 93 93 oOverlap.hEvent = d->hEvent; 94 bool recreate = true; 94 95 95 96 while (1) { 96 hPipe = CreateNamedPipe( 97 (const wchar_t *)d->pipename.c_str(), // pipe name 98 PIPE_ACCESS_DUPLEX | // read/write access 99 FILE_FLAG_OVERLAPPED, //Overlapped mode 100 PIPE_TYPE_MESSAGE | // message type pipe 101 PIPE_READMODE_MESSAGE | // message-read mode 102 PIPE_WAIT, // blocking mode 103 PIPE_UNLIMITED_INSTANCES, // max. instances 104 BUFSIZE, // output buffer size 105 BUFSIZE, // input buffer size 106 0, // client time-out 107 &d->sa); // default security attribute 97 BOOL alreadyConnected = false; 98 if (recreate) { 99 hPipe = CreateNamedPipe( 100 (const wchar_t *)d->pipename.c_str(), // pipe name 101 PIPE_ACCESS_DUPLEX | // read/write access 102 FILE_FLAG_OVERLAPPED, //Overlapped mode 103 PIPE_TYPE_MESSAGE | // message type pipe 104 PIPE_READMODE_MESSAGE | // message-read mode 105 PIPE_WAIT, // blocking mode 106 PIPE_UNLIMITED_INSTANCES, // max. instances 107 BUFSIZE, // output buffer size 108 BUFSIZE, // input buffer size 109 0, // client time-out 110 &d->sa); // default security attribute 108 111 109 if (hPipe == INVALID_HANDLE_VALUE) { 110 //TelldusCore::logMessage("Could not create named pipe"); 111 return; 112 if (hPipe == INVALID_HANDLE_VALUE) { 113 return; 114 } 115 116 ConnectNamedPipe(hPipe, &oOverlap); 117 alreadyConnected = GetLastError() == ERROR_PIPE_CONNECTED; 118 recreate = false; 112 119 } 120 if(!alreadyConnected){ 121 DWORD result = WaitForSingleObject(oOverlap.hEvent, 1000); 122 if (!d->running) { 123 CancelIo(hPipe); 124 WaitForSingleObject(oOverlap.hEvent, INFINITE); 125 break; 126 } 127 128 if(result == WAIT_TIMEOUT){ 129 //CloseHandle(hPipe); 130 continue; 131 } 132 BOOL connected = GetOverlappedResult(hPipe, &oOverlap, &cbBytesRead, false); 113 133 114 ConnectNamedPipe(hPipe, &oOverlap); 115 116 DWORD result = WaitForSingleObject(oOverlap.hEvent, 1000); 117 118 if (!d->running) { 119 break; 120 } 121 if(result == WAIT_TIMEOUT){ 122 CloseHandle(hPipe); 123 continue; 124 } 125 BOOL connected = GetOverlappedResult(hPipe, &oOverlap, &cbBytesRead, false); 126 127 if (!connected) { 128 CloseHandle(hPipe); 129 return; 134 if (!connected) { 135 CloseHandle(hPipe); 136 return; 137 } 130 138 } 131 139 ConnectionListenerEventData *data = new ConnectionListenerEventData(); 140 ResetEvent(oOverlap.hEvent); 132 141 data->socket = new TelldusCore::Socket(hPipe); 133 142 d->waitEvent->signal(data); 143 144 recreate = true; 134 145 } 135 146 -
telldus-core/service/Controller.h
r99f0b1 r06ac02 17 17 virtual int firmwareVersion() = 0; 18 18 virtual int send( const std::string &message ) = 0; 19 virtual int reset() = 0; 19 20 20 21 protected: -
telldus-core/service/ControllerManager.cpp
rbf4589 rb84e8b 3 3 #include "Mutex.h" 4 4 #include "TellStick.h" 5 #include "Log.h" 6 #include "../client/telldus-core.h" 5 7 6 8 #include <map> … … 120 122 } 121 123 } 124 125 void ControllerManager::queryControllerStatus(){ 126 127 std::list<TellStick *> tellStickControllers; 128 129 { 130 TelldusCore::MutexLocker locker(&d->mutex); 131 for(ControllerMap::iterator it = d->controllers.begin(); it != d->controllers.end(); ++it) { 132 TellStick *tellstick = reinterpret_cast<TellStick*>(it->second); 133 if (tellstick) { 134 tellStickControllers.push_back(tellstick); 135 } 136 } 137 } 138 139 bool reloadControllers = false; 140 std::string noop = "N+"; 141 for(std::list<TellStick *>::iterator it = tellStickControllers.begin(); it != tellStickControllers.end(); ++it) { 142 int success = (*it)->send(noop); 143 if(success == TELLSTICK_ERROR_BROKEN_PIPE){ 144 Log::warning("TellStick query: Error in communication with TellStick, resetting USB"); 145 resetController(*it); 146 } 147 if(success == TELLSTICK_ERROR_BROKEN_PIPE || success == TELLSTICK_ERROR_NOT_FOUND){ 148 reloadControllers = true; 149 } 150 } 151 152 if(!tellStickControllers.size() || reloadControllers){ 153 //no tellstick at all found, or controller was reset 154 Log::debug("TellStick query: Rescanning USB ports"); //only log as debug, since this will happen all the time if no TellStick is connected 155 loadControllers(); 156 } 157 } 158 159 int ControllerManager::resetController(Controller *controller) { 160 TellStick *tellstick = reinterpret_cast<TellStick*>(controller); 161 if (!tellstick) { 162 return true; //not tellstick, nothing to reset at the moment, just return true 163 } 164 int success = tellstick->reset(); 165 deviceInsertedOrRemoved(tellstick->vid(), tellstick->pid(), tellstick->serial(), false); //remove from list and delete 166 return success; 167 } -
telldus-core/service/ControllerManager.h
rcccaf8 r673daf 15 15 16 16 Controller *getBestControllerById(int id); 17 18 protected:19 17 void loadControllers(); 18 void queryControllerStatus(); 19 int resetController(Controller *controller); 20 20 21 21 private: -
telldus-core/service/DeviceManager.cpp
r1646eb rb84e8b 6 6 #include "Strings.h" 7 7 #include "Message.h" 8 #include " common.h"8 #include "Log.h" 9 9 10 10 #include <map> … … 433 433 else{ 434 434 Controller *controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId()); 435 if(!controller){ 436 Log::warning("Trying to execute action, but no controller found. Rescanning USB ports"); 437 //no controller found, scan for one, and retry once 438 d->controllerManager->loadControllers(); 439 controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId()); 440 } 441 435 442 if(controller){ 436 443 retval = device->doAction(action, data, controller); 444 if(retval == TELLSTICK_ERROR_BROKEN_PIPE){ 445 Log::warning("Error in communication with TellStick when executing action. Resetting USB"); 446 d->controllerManager->resetController(controller); 447 } 448 if(retval == TELLSTICK_ERROR_BROKEN_PIPE || retval == TELLSTICK_ERROR_NOT_FOUND){ 449 Log::warning("Rescanning USB ports"); 450 d->controllerManager->loadControllers(); 451 controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId()); 452 if(!controller){ 453 Log::error("No contoller (TellStick) found, even after reset. Giving up."); 454 return TELLSTICK_ERROR_NOT_FOUND; 455 } 456 retval = device->doAction(action, data, controller); //retry one more time 457 } 437 458 } else { 459 Log::error("No contoller (TellStick) found after one retry. Giving up."); 438 460 return TELLSTICK_ERROR_NOT_FOUND; 439 461 } … … 480 502 } 481 503 else if(childType == TELLSTICK_TYPE_SCENE){ 482 deviceReturnValue = doGroupAction(DeviceManager::getDeviceParameter(deviceId, L"devices", L""), action, data, childType, deviceId, duplicateDeviceIds); //TODO make scenes (and test)infinite loops-safe504 deviceReturnValue = doGroupAction(DeviceManager::getDeviceParameter(deviceId, L"devices", L""), action, data, childType, deviceId, duplicateDeviceIds); //TODO make scenes infinite loops-safe 483 505 } 484 506 else{ … … 720 742 721 743 Controller *controller = d->controllerManager->getBestControllerById(-1); 744 745 if(!controller){ 746 //no controller found, scan for one, and retry once 747 d->controllerManager->loadControllers(); 748 controller = d->controllerManager->getBestControllerById(-1); 749 } 750 751 int retval = TELLSTICK_ERROR_UNKNOWN; 722 752 if(controller){ 723 return controller->send(TelldusCore::wideToString(command)); 724 } 725 else{ 753 retval = controller->send(TelldusCore::wideToString(command)); 754 if(retval == TELLSTICK_ERROR_BROKEN_PIPE){ 755 d->controllerManager->resetController(controller); 756 } 757 if(retval == TELLSTICK_ERROR_BROKEN_PIPE || retval == TELLSTICK_ERROR_NOT_FOUND){ 758 d->controllerManager->loadControllers(); 759 controller = d->controllerManager->getBestControllerById(-1); 760 if(!controller){ 761 return TELLSTICK_ERROR_NOT_FOUND; 762 } 763 retval = controller->send(TelldusCore::wideToString(command)); //retry one more time 764 } 765 return retval; 766 } else { 726 767 return TELLSTICK_ERROR_NOT_FOUND; 727 768 } -
telldus-core/service/EventHandler_win.cpp
r485b1e r65ef52 52 52 53 53 bool EventHandler::waitForAny() { 54 int result = WaitForMultipleObjects(d->eventCount, d->eventArray, FALSE, INFINITE); 55 56 TelldusCore::MutexLocker locker(&d->mutex); 57 if (result == WAIT_TIMEOUT) { 58 return false; 54 55 while(1){ 56 int result = WaitForMultipleObjects(d->eventCount, d->eventArray, FALSE, 1000); 57 if (result == WAIT_TIMEOUT) { 58 continue; 59 } 60 TelldusCore::MutexLocker locker(&d->mutex); 61 int eventIndex = result - WAIT_OBJECT_0; 62 if (eventIndex >= d->eventCount) { 63 return false; 64 } 65 return true; 59 66 } 60 int eventIndex = result - WAIT_OBJECT_0;61 if (eventIndex >= d->eventCount) {62 return false;63 }64 return true;65 67 } -
telldus-core/service/EventUpdateManager.cpp
rf25ca4 r86554b 74 74 void EventUpdateManager::sendMessageToClients(EventUpdateData *data){ 75 75 76 int connected = 0; 76 77 for(SocketList::iterator it = d->clients.begin(); it != d->clients.end();){ 77 78 78 if((*it)->isConnected()){ 79 79 connected++; 80 80 TelldusCore::Message msg; 81 81 -
telldus-core/service/Protocol.cpp
rb92e19 r16a9b8 6 6 #include "ProtocolComen.h" 7 7 #include "ProtocolEverflourish.h" 8 #include "ProtocolFineoffset.h" 8 9 #include "ProtocolFuhaote.h" 9 10 #include "ProtocolGroup.h" 10 11 #include "ProtocolHasta.h" 11 12 #include "ProtocolIkea.h" 13 #include "ProtocolMandolyn.h" 12 14 #include "ProtocolNexa.h" 15 #include "ProtocolOregon.h" 13 16 #include "ProtocolRisingSun.h" 14 17 #include "ProtocolSartano.h" … … 196 199 } else if (TelldusCore::comparei(protocolName, L"yidong")) { 197 200 parameters.push_back("unit"); 198 201 199 202 } else if (TelldusCore::comparei(protocolName, L"group")) { 200 203 parameters.push_back("devices"); 201 204 202 205 } else if (TelldusCore::comparei(protocolName, L"scene")) { 203 206 parameters.push_back("devices"); … … 210 213 std::list<std::string> retval; 211 214 std::string decoded = ""; 212 215 213 216 ControllerMessage dataMsg(fullData); 214 217 if( TelldusCore::comparei(dataMsg.protocol(), L"arctech") ) { … … 232 235 } 233 236 } 237 else if(TelldusCore::comparei(dataMsg.protocol(), L"fineoffset") ) { 238 decoded = ProtocolFineoffset::decodeData(dataMsg); 239 if (decoded != "") { 240 retval.push_back(decoded); 241 } 242 } 243 else if(TelldusCore::comparei(dataMsg.protocol(), L"mandolyn") ) { 244 decoded = ProtocolMandolyn::decodeData(dataMsg); 245 if (decoded != "") { 246 retval.push_back(decoded); 247 } 248 } 249 else if(TelldusCore::comparei(dataMsg.protocol(), L"oregon") ) { 250 decoded = ProtocolOregon::decodeData(dataMsg); 251 if (decoded != "") { 252 retval.push_back(decoded); 253 } 254 } 234 255 else if(TelldusCore::comparei(dataMsg.protocol(), L"x10") ) { 235 256 decoded = ProtocolX10::decodeData(dataMsg); … … 238 259 } 239 260 } 240 261 241 262 return retval; 242 263 } -
telldus-core/service/ProtocolNexa.cpp
ree627e r245864 4 4 #include "TellStick.h" 5 5 #include "Strings.h" 6 #include "common.h"7 6 8 7 int ProtocolNexa::lastArctecCodeSwitchWasTurnOff=0; //TODO, always removing first turnon now, make more flexible (waveman too) -
telldus-core/service/SettingsConfuse.cpp
rc4ef48 rd7cce5 376 376 CFG_STR(const_cast<char *>("group"), const_cast<char *>("plugdev"), CFGF_NONE), 377 377 CFG_STR(const_cast<char *>("deviceNode"), const_cast<char *>("/dev/tellstick"), CFGF_NONE), 378 CFG_STR(const_cast<char *>("ignoreControllerConfirmation"), const_cast<char *>("false"), CFGF_NONE), 378 379 CFG_SEC(const_cast<char *>("device"), device_opts, CFGF_MULTI), 379 380 CFG_END() -
telldus-core/service/SettingsWinRegistry.cpp
rc36430 r406874 1 1 #include "Settings.h" 2 #include "Strings.h" 2 3 #include <Windows.h> 3 4 #include <sstream> … … 6 7 #include <iostream> 7 8 #include <fstream> 9 #include "common.h" 8 10 9 11 #include "../client/telldus-core.h" … … 94 96 intDeviceId = getNextDeviceId(); 95 97 96 std::wostringstream ssRegPath; 97 ssRegPath << d->strRegPathDevice << intDeviceId; 98 std::wstring strCompleteRegPath = ssRegPath.str(); 98 std::wstring strCompleteRegPath = d->strRegPathDevice; 99 strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 99 100 100 101 if (RegCreateKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hk, &dwDisp)) { … … 123 124 DWORD nResult(0); 124 125 125 long lngStatus = RegQueryValueEx(hk, L"LastUsedId", NULL, NULL, reinterpret_cast<LPBYTE>(&nResult), &dwLength); //(LPBYTE)Buff, &dwLength);126 long lngStatus = RegQueryValueEx(hk, L"LastUsedId", NULL, NULL, reinterpret_cast<LPBYTE>(&nResult), &dwLength); 126 127 127 128 if(lngStatus == ERROR_SUCCESS){ … … 144 145 TelldusCore::MutexLocker locker(&mutex); 145 146 146 std::wostringstream ssRegPath; 147 ssRegPath << d->strRegPathDevice << intDeviceId; 148 std::wstring strCompleteRegPath = ssRegPath.str(); 147 std::wstring strCompleteRegPath = d->strRegPathDevice; 148 strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 149 149 150 150 long lngSuccess = RegDeleteKey(d->rootKey, strCompleteRegPath.c_str()); … … 158 158 } 159 159 160 std::wstring Settings::getSetting(const std::wstring &strName) const{ 161 std::wstring strReturn; 162 HKEY hk; 163 164 std::wstring strCompleteRegPath = d->strRegPath; 165 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); 166 167 if(lnExists == ERROR_SUCCESS){ 168 wchar_t* Buff = new wchar_t[intMaxRegValueLength]; 169 DWORD dwLength = sizeof(wchar_t)*intMaxRegValueLength; 170 long lngStatus = RegQueryValueEx(hk, strName.c_str(), NULL, NULL, (LPBYTE)Buff, &dwLength); 171 172 if(lngStatus == ERROR_MORE_DATA){ 173 //The buffer is to small, recreate it 174 delete Buff; 175 Buff = new wchar_t[dwLength]; 176 lngStatus = RegQueryValueEx(hk, strName.c_str(), NULL, NULL, (LPBYTE)Buff, &dwLength); 177 } 178 if (lngStatus == ERROR_SUCCESS) { 179 strReturn = Buff; 180 } 181 delete Buff; 182 } 183 RegCloseKey(hk); 184 return strReturn; 185 } 186 160 187 std::wstring Settings::getStringSetting(int intDeviceId, const std::wstring &name, bool parameter) const { 161 188 std::wstring strReturn; 162 189 HKEY hk; 163 190 164 std::wostringstream ssRegPath; 165 ssRegPath << d->strRegPathDevice << intDeviceId; 166 std::wstring strCompleteRegPath = ssRegPath.str(); 191 std::wstring strCompleteRegPath = d->strRegPathDevice; 192 strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 167 193 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); 168 194 … … 192 218 int ret = TELLSTICK_SUCCESS; 193 219 194 std::w ostringstream ssRegPath;195 s sRegPath << d->strRegPathDevice << intDeviceId;196 st d::wstring strCompleteRegPath = ssRegPath.str();220 std::wstring bla = TelldusCore::intToWstring(intDeviceId); 221 std::wstring strCompleteRegPath = d->strRegPathDevice; 222 strCompleteRegPath.append(bla); 197 223 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 198 224 … … 224 250 HKEY hk; 225 251 226 std::wostringstream ssRegPath; 227 ssRegPath << d->strRegPathDevice << intDeviceId; 228 std::wstring strCompleteRegPath = ssRegPath.str(); 252 std::wstring strCompleteRegPath = d->strRegPathDevice; 253 strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 229 254 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 230 255 if (lnExists == ERROR_SUCCESS) { -
telldus-core/service/TellStick.h
r05a816 r06ac02 30 30 virtual int firmwareVersion(); 31 31 virtual int pid() const; 32 virtual int vid() const; 33 virtual std::string serial() const; 34 32 35 bool isOpen() const; 33 36 bool isSameAsDescriptor(const TellStickDescriptor &d) const; 37 virtual int reset(); 34 38 virtual int send( const std::string &message ); 35 39 bool stillConnected() const; -
telldus-core/service/TellStick_ftd2xx.cpp
r777256 r915d47 11 11 // 12 12 #include "TellStick.h" 13 #include "common.h" 13 14 #include "Mutex.h" 15 #include "Settings.h" 14 16 #include "Strings.h" 17 #include "Log.h" 15 18 #include "../client/telldus-core.h" 16 19 #include <string.h> … … 21 24 class TellStick::PrivateData { 22 25 public: 23 bool open, running ;26 bool open, running, ignoreControllerConfirmation; 24 27 int vid, pid, fwVersion; 25 28 std::string serial, message; … … 54 57 d->fwVersion = 0; 55 58 d->serial = td.serial; 59 Settings set; 60 d->ignoreControllerConfirmation = set.getSetting(L"ignoreControllerConfirmation")==L"true"; 56 61 57 62 char *tempSerial = new char[td.serial.size()+1]; … … 62 67 FT_SetVIDPID(td.vid, td.pid); 63 68 #endif 69 Log::notice("Connecting to TellStick (%X/%X) with serial %s", d->vid, d->pid, d->serial.c_str()); 64 70 FT_STATUS ftStatus = FT_OpenEx(tempSerial, FT_OPEN_BY_SERIAL_NUMBER, &d->ftHandle); 65 71 delete tempSerial; … … 77 83 } 78 84 this->start(); 85 } else { 86 Log::warning("Failed to open TellStick"); 79 87 } 80 88 } 81 89 82 90 TellStick::~TellStick() { 91 Log::warning("Disconnected TellStick (%X/%X) with serial %s", d->vid, d->pid, d->serial.c_str()); 83 92 if (d->running) { 84 93 TelldusCore::MutexLocker locker(&d->mutex); … … 107 116 int TellStick::pid() const { 108 117 return d->pid; 118 } 119 120 int TellStick::vid() const { 121 return d->vid; 122 } 123 124 std::string TellStick::serial() const { 125 return d->serial; 109 126 } 110 127 … … 145 162 } 146 163 164 int TellStick::reset(){ 165 #ifndef _WINDOWS 166 return TELLSTICK_SUCCESS; //nothing to be done on other platforms 167 #else 168 int success = FT_CyclePort( d->ftHandle ); 169 if(success == FT_OK){ 170 return TELLSTICK_SUCCESS; 171 } 172 return TELLSTICK_ERROR_UNKNOWN; 173 #endif 174 } 175 147 176 void TellStick::run() { 148 177 d->running = true; … … 187 216 return TELLSTICK_ERROR_NOT_FOUND; 188 217 } 189 bool c = true; 190 218 191 219 //This lock does two things 192 220 // 1 Prevents two calls from different threads to this function … … 206 234 ftStatus = FT_Write(d->ftHandle, tempMessage, (DWORD)strMessage.length(), &bytesWritten); 207 235 free(tempMessage); 208 209 while(c) { 236 237 if(ftStatus != FT_OK){ 238 Log::debug("Broken pipe on send"); 239 return TELLSTICK_ERROR_BROKEN_PIPE; 240 } 241 242 if(strMessage.compare("N+") == 0 && ((pid() == 0x0C31 && firmwareVersion() < 5) || (pid() == 0x0C30 && firmwareVersion() < 6))){ 243 //these firmware versions doesn't implement ack to noop, just check that the noop can be sent correctly 244 return TELLSTICK_SUCCESS; 245 } 246 if(d->ignoreControllerConfirmation){ 247 //wait for TellStick to finish its air-sending 248 msleep(1000); 249 return TELLSTICK_SUCCESS; 250 } 251 252 while(1) { 210 253 ftStatus = FT_Read(d->ftHandle,&in,1,&bytesRead); 211 254 if (ftStatus == FT_OK) { 212 255 if (bytesRead == 1) { 213 256 if (in == '\n') { 214 break; 257 return TELLSTICK_SUCCESS; 258 } else { 259 continue; 215 260 } 216 261 } else { //Timeout 217 c = false;262 return TELLSTICK_ERROR_COMMUNICATION; 218 263 } 219 264 } else { //Error 220 c = false; 221 } 222 } 223 224 if (!c) { 225 return TELLSTICK_ERROR_COMMUNICATION; 226 } 227 return TELLSTICK_SUCCESS; 265 Log::debug("Broken pipe on read"); 266 return TELLSTICK_ERROR_BROKEN_PIPE; 267 } 268 } 228 269 } 229 270 -
telldus-core/service/TellStick_libftdi.cpp
r894997 rd32633 19 19 #include "Thread.h" 20 20 #include "Mutex.h" 21 #include "Log.h" 22 #include "Settings.h" 21 23 #include "Strings.h" 22 24 #include "common.h" … … 32 34 class TellStick::PrivateData { 33 35 public: 34 bool open ;36 bool open, ignoreControllerConfirmation; 35 37 int vid, pid, fwVersion; 36 38 std::string serial, message; … … 52 54 d->running = false; 53 55 56 Settings set; 57 d->ignoreControllerConfirmation = set.getSetting(L"ignoreControllerConfirmation")==L"true"; 58 54 59 ftdi_init(&d->ftHandle); 55 60 ftdi_set_interface(&d->ftHandle, INTERFACE_ANY); 56 61 62 Log::notice("Connecting to TellStick (%X/%X) with serial %s", d->vid, d->pid, d->serial.c_str()); 57 63 int ret = ftdi_usb_open_desc(&d->ftHandle, td.vid, td.pid, NULL, td.serial.c_str()); 58 64 if (ret < 0) { … … 63 69 ftdi_usb_reset( &d->ftHandle ); 64 70 ftdi_disable_bitbang( &d->ftHandle ); 71 ftdi_set_latency_timer(&d->ftHandle, 16); 65 72 66 73 if (d->open) { … … 72 79 } 73 80 this->start(); 81 } else { 82 Log::warning("Failed to open TellStick"); 74 83 } 75 84 } 76 85 77 86 TellStick::~TellStick() { 87 Log::warning("Disconnected TellStick (%X/%X) with serial %s", d->vid, d->pid, d->serial.c_str()); 78 88 if (d->running) { 79 89 stop(); … … 93 103 int TellStick::pid() const { 94 104 return d->pid; 105 } 106 107 int TellStick::vid() const { 108 return d->vid; 109 } 110 111 std::string TellStick::serial() const { 112 return d->serial; 95 113 } 96 114 … … 131 149 } 132 150 151 int TellStick::reset(){ 152 int success = ftdi_usb_reset( &d->ftHandle ); 153 if(success < 0){ 154 return TELLSTICK_ERROR_UNKNOWN; //-1 = FTDI reset failed, -2 = USB device unavailable 155 } 156 return TELLSTICK_SUCCESS; 157 } 158 133 159 void TellStick::run() { 134 160 int dwBytesRead = 0; … … 187 213 c = false; 188 214 } else if(ret != strMessage.length()) { 189 fprintf(stderr, "weird send length? retval %i instead of %d\n", 190 ret, (int)strMessage.length()); 215 Log::debug("Weird send length? retval %i instead of %d\n", ret, (int)strMessage.length()); 191 216 } 192 217 193 218 delete[] tempMessage; 194 219 195 int retrycnt = 200; 220 if(!c){ 221 Log::debug("Broken pipe on send"); 222 return TELLSTICK_ERROR_BROKEN_PIPE; 223 } 224 225 if(strMessage.compare("N+") == 0 && ((pid() == 0x0C31 && firmwareVersion() < 5) || (pid() == 0x0C30 && firmwareVersion() < 6))){ 226 //these firmware versions doesn't implement ack to noop, just check that the noop can be sent correctly 227 return TELLSTICK_SUCCESS; 228 } 229 230 if(d->ignoreControllerConfirmation){ 231 //allow TellStick to finish its air-sending 232 msleep(1000); 233 return TELLSTICK_SUCCESS; 234 } 235 236 int retrycnt = 250; 196 237 unsigned char in; 197 while( c &&--retrycnt) {238 while(--retrycnt) { 198 239 ret = ftdi_read_data( &d->ftHandle, &in, 1); 199 240 if (ret > 0) { 200 241 if (in == '\n') { 201 break;242 return TELLSTICK_SUCCESS; 202 243 } 203 244 } else if(ret == 0) { // No data available 204 245 usleep(100); 205 246 } else { //Error 206 c = false; 207 } 208 } 209 if (!retrycnt) { 210 c = false; 211 } 212 if (!c) { 213 return TELLSTICK_ERROR_COMMUNICATION; 214 } 215 return TELLSTICK_SUCCESS; 247 Log::debug("Broken pipe on read"); 248 return TELLSTICK_ERROR_BROKEN_PIPE; 249 } 250 } 251 252 return TELLSTICK_ERROR_COMMUNICATION; 216 253 } 217 254 -
telldus-core/service/TelldusMain.cpp
rcccaf8 re2e9ba 7 7 #include "ControllerListener.h" 8 8 #include "EventUpdateManager.h" 9 #include "Timer.h" 10 #include "Log.h" 9 11 10 12 #include <stdio.h> … … 40 42 EventRef clientEvent = d->eventHandler.addEvent(); 41 43 EventRef dataEvent = d->eventHandler.addEvent(); 44 EventRef janitor = d->eventHandler.addEvent(); //Used for regular cleanups 45 Timer supervisor(janitor); //Tells the janitor to go back to work 46 supervisor.setInterval(60); //Once every minute 47 supervisor.start(); 42 48 43 49 ControllerManager controllerManager(dataEvent.get()); … … 102 108 } 103 109 } 110 if (janitor->isSignaled()) { 111 //Clear all of them if there is more than one 112 while(janitor->isSignaled()) { 113 janitor->popSignal(); 114 } 115 controllerManager.queryControllerStatus(); 116 } 104 117 } 118 119 supervisor.stop(); 105 120 } 106 121 -
telldus-core/service/TelldusWinService_win.cpp
r2697fd r986240 1 1 #include "TelldusWinService_win.h" 2 2 #include "TelldusMain.h" 3 #include "Log.h" 3 4 4 5 #include <Dbt.h> … … 112 113 TelldusWinService instance; 113 114 115 //Enable debug if we hade this supplied 116 for(unsigned int i = 1; i < argc; ++i) { 117 if (wcscmp(argv[i], L"--debug") == 0) { 118 Log::setDebug(); 119 } 120 } 121 114 122 // initialise service status 115 123 instance.serviceStatus.dwServiceType = SERVICE_WIN32; … … 141 149 HDEVNOTIFY deviceNotificationHandle = RegisterDeviceNotificationW(instance.serviceStatusHandle, &devInterface, DEVICE_NOTIFY_SERVICE_HANDLE); 142 150 151 Log::notice("TelldusService started"); 152 143 153 //Start our main-loop 144 154 instance.tm->start(); 155 156 Log::notice("TelldusService stopping"); 157 Log::destroy(); 145 158 146 159 // service was stopped -
telldus-core/service/main_mac.cpp
r83aa0d r727287 1 1 #include "TelldusMain.h" 2 #include "Log.h" 2 3 #include <signal.h> 3 #include <stdio.h>4 4 5 5 TelldusMain tm; 6 6 7 7 void shutdownHandler(int onSignal) { 8 printf("Shutting down\n");8 Log::notice("Shutting down"); 9 9 tm.stop(); 10 10 } 11 11 12 12 void sigpipeHandler(int onSignal) { 13 printf("SIGPIPE received\n");13 Log::notice("SIGPIPE received"); 14 14 } 15 15 … … 20 20 signal(SIGPIPE, sigpipeHandler); 21 21 22 Log::notice("telldusd started"); 22 23 tm.start(); 23 printf("telldusd stopped gracefully\n"); 24 Log::notice("telldusd stopped gracefully"); 25 26 Log::destroy(); 24 27 return 0; 25 28 } -
telldus-core/service/main_unix.cpp
r55f49a r83fb47 5 5 #include <stdlib.h> 6 6 #include <unistd.h> 7 #include <syslog.h>8 7 #include <sys/stat.h> 9 8 #include <errno.h> … … 13 12 #include "Settings.h" 14 13 #include "Strings.h" 14 #include "Log.h" 15 15 16 16 #define DAEMON_NAME "telldusd" … … 22 22 switch(sig) { 23 23 case SIGHUP: 24 syslog(LOG_WARNING,"Received SIGHUP signal.");24 Log::warning("Received SIGHUP signal."); 25 25 break; 26 26 case SIGTERM: 27 27 case SIGINT: 28 syslog(LOG_WARNING,"Received SIGTERM or SIGINT signal.");29 syslog(LOG_WARNING,"Shutting down");28 Log::warning("Received SIGTERM or SIGINT signal."); 29 Log::warning("Shutting down"); 30 30 tm.stop(); 31 31 break; 32 32 case SIGPIPE: 33 syslog(LOG_WARNING,"Received SIGPIPE signal.");33 Log::warning("Received SIGPIPE signal."); 34 34 break; 35 35 default: 36 syslog(LOG_WARNING,"Unhandled signal (%d) %s", sig, strsignal(sig));36 Log::warning("Unhandled signal (%d) %s", sig, strsignal(sig)); 37 37 break; 38 38 } … … 47 47 if (strcmp(argv[i], "--nodaemon") == 0) { 48 48 deamonize = false; 49 }50 if (strcmp(argv[i], "--help") == 0) {49 Log::setLogOutput(Log::StdOut); 50 } else if (strcmp(argv[i], "--help") == 0) { 51 51 printf("Telldus TellStick background service\n\nStart with --nodaemon to not run as daemon\n\n"); 52 52 printf("Report bugs to <info.tech@telldus.com>\n"); 53 53 exit(EXIT_SUCCESS); 54 } 55 if (strcmp(argv[i], "--version") == 0) { 54 } else if (strcmp(argv[i], "--version") == 0) { 56 55 printf("telldusd " VERSION "\n\n"); 57 56 printf("Copyright (C) 2011 Telldus Technologies AB\n\n"); 58 57 printf("Written by Micke Prag <micke.prag@telldus.se>\n"); 59 58 exit(EXIT_SUCCESS); 59 } else { 60 printf("Unknown option %s\n", argv[i]); 61 exit(EXIT_FAILURE); 60 62 } 61 63 } … … 77 79 fclose(fd); 78 80 } else { 79 syslog(LOG_ERR,"Could not open pid file %s: %s", PID_FILE, strerror(errno));81 Log::error("Could not open pid file %s: %s", PID_FILE, strerror(errno)); 80 82 exit(EXIT_FAILURE); 81 83 } … … 84 86 } 85 87 86 setlogmask(LOG_UPTO(LOG_INFO)); 87 openlog(DAEMON_NAME, LOG_CONS, LOG_USER); 88 89 syslog(LOG_NOTICE, "%s daemon starting up", DAEMON_NAME); 88 Log::notice("%s daemon starting up", DAEMON_NAME); 90 89 91 90 if (deamonize) { … … 116 115 setgid(grp->gr_gid); 117 116 } else { 118 syslog(LOG_WARNING,"Group %s could not be found", group.c_str());117 Log::warning("Group %s could not be found", group.c_str()); 119 118 exit(EXIT_FAILURE); 120 119 } … … 123 122 setuid( pw->pw_uid ); 124 123 } else { 125 syslog(LOG_WARNING,"User %s could not be found", user.c_str());124 Log::warning("User %s could not be found", user.c_str()); 126 125 exit(EXIT_FAILURE); 127 126 } … … 140 139 tm.start(); 141 140 142 syslog(LOG_NOTICE,"%s daemon exited", DAEMON_NAME);141 Log::notice("%s daemon exited", DAEMON_NAME); 143 142 exit(EXIT_SUCCESS); 144 143 } -
telldus-core/service/tellstick.conf
rbea7b7 rd7cce5 1 1 user = "nobody" 2 2 group = "plugdev" 3 ignoreControllerConfirmation = "false" 3 4 device { 4 5 id = 1 -
telldus-core/tdadmin/05-tellstick.rules
r80dfac rcd6e59 1 ID_VENDOR_ID=="1781", SUBSYSTEM=="usb", ACTION=="add", MODE="664", GROUP="plugdev" RUN+="${CMAKE_INSTALL_PREFIX}/share/telldus-core/helpers/udev.sh"2 ID_VENDOR_ID=="1781", SUBSYSTEM=="usb", ACTION=="remove" RUN+="${CMAKE_INSTALL_PREFIX}/share/telldus-core/helpers/udev.sh"1 ATTRS{idVendor}=="1781", SUBSYSTEM=="usb", ACTION=="add", MODE="664", GROUP="plugdev" RUN+="${CMAKE_INSTALL_PREFIX}/share/telldus-core/helpers/udev.sh" 2 ENV{ID_VENDOR_ID}=="1781", SUBSYSTEM=="usb", ACTION=="remove" RUN+="${CMAKE_INSTALL_PREFIX}/share/telldus-core/helpers/udev.sh" 3 3 -
telldus-core/tdtool/main.cpp
raf6cc7 r5190c4 3 3 #include <stdlib.h> 4 4 #include <string.h> 5 #include <ctime> 5 6 #include "../client/telldus-core.h" 6 7 … … 22 23 printf("\n"); 23 24 printf(" --list (-l short option)\n"); 24 printf(" List currently configured devices .\n");25 printf(" List currently configured devices and all discovered sensors.\n"); 25 26 printf("\n"); 26 27 printf(" --help (-h short option)\n"); … … 78 79 79 80 void print_device( int index ) { 81 tdInit(); 80 82 int intId = tdGetDeviceId(index); 81 83 char *name = tdGetName(intId); … … 102 104 } 103 105 104 void list_devices() { 106 int list_devices() { 107 tdInit(); 105 108 int intNum = tdGetNumberOfDevices(); 106 109 if (intNum < 0) { … … 108 111 fprintf(stderr, "Error fetching devices: %s\n", errorString); 109 112 tdReleaseString(errorString); 110 return ;113 return intNum; 111 114 } 112 115 printf("Number of devices: %i\n", intNum); … … 116 119 i++; 117 120 } 121 122 int DATA_LENGTH = 20; 123 char protocol[DATA_LENGTH], model[DATA_LENGTH]; 124 int sensorId = 0, dataTypes = 0; 125 126 int sensorStatus = tdSensor(protocol, DATA_LENGTH, model, DATA_LENGTH, &sensorId, &dataTypes); 127 if(sensorStatus == 0){ 128 printf("\nSENSORS:\n%-20s\t%-20s\t%-5s\t%-5s\t%-8s\t%-20s\n", "PROTOCOL", "MODEL", "ID", "TEMP", "HUMIDITY", "LAST UPDATED"); 129 } 130 while(sensorStatus == 0){ 131 sensorStatus = tdSensor(protocol, DATA_LENGTH, model, DATA_LENGTH, &sensorId, &dataTypes); 132 133 char tempvalue[DATA_LENGTH]; 134 tempvalue[0] = 0; 135 char humidityvalue[DATA_LENGTH]; 136 humidityvalue[0] = 0; 137 char timeBuf[80]; 138 time_t timestamp = 0; 139 140 if (dataTypes & TELLSTICK_TEMPERATURE) { 141 tdSensorValue(protocol, model, sensorId, TELLSTICK_TEMPERATURE, tempvalue, DATA_LENGTH, (int *)×tamp); 142 strcat(tempvalue, "°"); 143 strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S", localtime(×tamp)); 144 } 145 146 if (dataTypes & TELLSTICK_HUMIDITY) { 147 tdSensorValue(protocol, model, sensorId, TELLSTICK_HUMIDITY, humidityvalue, DATA_LENGTH, (int *)×tamp); 148 strcat(humidityvalue, "%"); 149 strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S", localtime(×tamp)); 150 } 151 printf("%-20s\t%-20s\t%-5i\t%-5s\t%-8s\t%-20s\n", protocol, model, sensorId, tempvalue, humidityvalue, timeBuf); 152 153 printf("\n"); 154 } 155 if(sensorStatus != TELLSTICK_ERROR_DEVICE_NOT_FOUND){ 156 char *errorString = tdGetErrorString(sensorStatus); 157 fprintf(stderr, "Error fetching sensors: %s\n", errorString); 158 tdReleaseString(errorString); 159 return sensorStatus; 160 } 161 return TELLSTICK_SUCCESS; 118 162 } 119 163 120 164 int find_device( char *device ) { 165 tdInit(); 121 166 int deviceId = atoi(device); 122 167 if (deviceId == 0) { //Try to find the id from the name … … 138 183 } 139 184 140 void switch_device( bool turnOn, char *device ) { 185 int switch_device( bool turnOn, char *device ) { 186 tdInit(); 141 187 int deviceId = find_device( device ); 142 188 if (deviceId == 0) { 143 189 printf("Device '%s', not found!\n", device); 144 return ;190 return TELLSTICK_ERROR_DEVICE_NOT_FOUND; 145 191 } 146 192 … … 159 205 printf(" - %s\n", errorString); 160 206 tdReleaseString(errorString); 161 } 162 163 void dim_device( char *device, int level ) { 207 return retval; 208 } 209 210 int dim_device( char *device, int level ) { 211 tdInit(); 164 212 int deviceId = find_device( device ); 165 213 if (deviceId == 0) { 166 214 printf("Device '%s', not found!\n", device); 167 return ;215 return TELLSTICK_ERROR_DEVICE_NOT_FOUND; 168 216 } 169 217 if (level < 0 || level > 255) { 170 218 printf("Level %i out of range!\n", level); 171 return ;219 return TELLSTICK_ERROR_SYNTAX; 172 220 } 173 221 … … 178 226 tdReleaseString(name); 179 227 tdReleaseString(errorString); 180 } 181 182 void bell_device( char *device ) { 228 return retval; 229 } 230 231 int bell_device( char *device ) { 232 tdInit(); 183 233 int deviceId = find_device( device ); 184 234 if (deviceId == 0) { 185 235 printf("Device '%s', not found!\n", device); 186 return ;236 return TELLSTICK_ERROR_DEVICE_NOT_FOUND; 187 237 } 188 238 … … 193 243 tdReleaseString(name); 194 244 tdReleaseString(errorString); 195 } 196 197 void learn_device( char *device ) { 245 return retval; 246 } 247 248 int learn_device( char *device ) { 249 tdInit(); 198 250 int deviceId = find_device( device ); 199 251 if (deviceId == 0) { 200 252 printf("Device '%s', not found!\n", device); 201 return ;253 return TELLSTICK_ERROR_DEVICE_NOT_FOUND; 202 254 } 203 255 … … 208 260 tdReleaseString(name); 209 261 tdReleaseString(errorString); 210 } 211 212 void send_raw_command( char *command ) { 262 return retval; 263 } 264 265 int send_raw_command( char *command ) { 266 tdInit(); 213 267 const int MAX_LENGTH = 100; 214 268 char msg[MAX_LENGTH]; … … 222 276 if (fd == NULL) { 223 277 printf("Error opening file %s\n", command); 224 return ;278 return TELLSTICK_ERROR_UNKNOWN; 225 279 } 226 280 fgets(msg, MAX_LENGTH, fd); … … 231 285 printf("Sending raw command: %s\n", errorString); 232 286 tdReleaseString(errorString); 287 return retval; 233 288 } 234 289 … … 254 309 if (argc < 2) { 255 310 print_usage( argv[0] ); 256 return -1; 257 } 258 259 while ( (optch = getopt_long(argc,argv,optstring,long_opts,&longindex)) != -1 ) 311 return -TELLSTICK_ERROR_SYNTAX; 312 } 313 314 int returnSuccess = 0; 315 while ( (optch = getopt_long(argc,argv,optstring,long_opts,&longindex)) != -1 ){ 316 int success = 0; 260 317 switch (optch) { 261 318 case 'b' : 262 bell_device( &optarg[0] );319 success = bell_device( &optarg[0] ); 263 320 break; 264 321 case 'd' : 265 322 if (level >= 0) { 266 dim_device( &optarg[0], level ); 323 success = dim_device( &optarg[0], level ); 324 break; 267 325 } 326 printf("Dim level missing or incorrect value.\n"); 327 success = TELLSTICK_ERROR_SYNTAX; 268 328 break; 269 329 case 'f' : 270 s witch_device(false, &optarg[0]);330 success = switch_device(false, &optarg[0]); 271 331 break; 272 332 case 'h' : 273 333 print_usage( argv[0] ); 274 break;334 success = TELLSTICK_SUCCESS; 275 335 case 'i' : 276 336 print_version( ); 277 break;337 success = TELLSTICK_SUCCESS; 278 338 case 'l' : 279 list_devices();339 success = list_devices(); 280 340 break; 281 341 case 'n' : 282 s witch_device(true, &optarg[0]);342 success = switch_device(true, &optarg[0]); 283 343 break; 284 344 case 'e' : 285 learn_device(&optarg[0]);345 success = learn_device(&optarg[0]); 286 346 break; 287 347 case 'r' : 288 s end_raw_command(&optarg[0]);348 success = send_raw_command(&optarg[0]); 289 349 break; 290 350 case 'v' : … … 293 353 default : 294 354 print_usage( argv[0] ); 295 return -1; 296 } 297 355 success = TELLSTICK_ERROR_SYNTAX; 356 } 357 if(success != TELLSTICK_SUCCESS){ 358 returnSuccess = success; //return last error message 359 } 360 } 298 361 tdClose(); //Cleaning up 299 return 0;300 } 362 return -returnSuccess; 363 } -
telldus-gui/Plugins/Live/LiveMessageToken.cpp
raf2ae0 r06bf1a 10 10 valueType = String; 11 11 stringVal = value; 12 } 13 14 LiveMessageToken::LiveMessageToken(int value) { 15 valueType = Int; 16 intVal = value; 12 17 } 13 18 … … 123 128 } 124 129 125 int LiveMessageTokenScriptWrapper::getInt(const QString &key, int defaultValue) {130 int LiveMessageTokenScriptWrapper::getInt(const QString &key, int defaultValue) const { 126 131 if (p_token.valueType != LiveMessageToken::Dictionary) { 127 132 return defaultValue; … … 131 136 } 132 137 return p_token.dictVal[key].intVal; 138 } 139 140 QString LiveMessageTokenScriptWrapper::getString(const QString &key, const QString &defaultValue) const { 141 if (p_token.valueType != LiveMessageToken::Dictionary) { 142 return defaultValue; 143 } 144 if (!p_token.dictVal.contains(key)) { 145 return defaultValue; 146 } 147 return p_token.dictVal[key].stringVal; 133 148 } 134 149 -
telldus-gui/Plugins/Live/LiveMessageToken.h
rb2212c r06bf1a 13 13 LiveMessageToken(); 14 14 LiveMessageToken(const QString &value); 15 LiveMessageToken(int value); 15 16 QByteArray toByteArray() const; 16 17 static LiveMessageToken parseToken(const QByteArray &string, int* start); … … 35 36 void add(LiveMessageTokenScriptWrapper *token); 36 37 37 int getInt(const QString &key, int defaultValue = 0); 38 int getInt(const QString &key, int defaultValue = 0) const; 39 QString getString(const QString &key, const QString &defaultValue = "") const; 38 40 39 41 int intVal() const; … … 41 43 void set(const QString &key, int value); 42 44 void set(const QString &key, const QString &value); 43 45 44 46 private: 45 47 LiveMessageToken p_token; -
telldus-gui/Plugins/Live/LiveObject.cpp
r35d694 r5bb60a 14 14 15 15 QSslSocket *socket; 16 QTimer timer;16 QTimer pingTimer, pongTimer; 17 17 bool registered; 18 18 QUrl registerUrl; … … 47 47 connect(d->socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &))); 48 48 49 d->timer.setInterval(60000); //Once a minute 50 connect(&d->timer, SIGNAL(timeout()), this, SLOT(pingServer())); 49 d->pingTimer.setInterval(120000); //Two minutes 50 d->pongTimer.setInterval(360000); //Six minutes 51 d->pongTimer.setSingleShot(true); 52 connect(&d->pingTimer, SIGNAL(timeout()), this, SLOT(pingServer())); 53 connect(&d->pongTimer, SIGNAL(timeout()), this, SLOT(pongTimeout())); 51 54 52 55 d->manager = new QNetworkAccessManager(this); … … 103 106 return; 104 107 } 108 d->pongTimer.stop(); 109 d->pongTimer.start(); 105 110 106 111 if (msg->name() == "") { … … 123 128 emit notRegistered(); 124 129 emit errorChanged("Not registered"); 130 } else if (msg->name() == "command") { 131 if (msg->arg(0).valueType == LiveMessageToken::Dictionary && msg->arg(0).dictVal.contains("ACK")) { 132 int ack = msg->arg(0).dictVal["ACK"].intVal; 133 LiveMessage msg("ACK"); 134 msg.append(ack); 135 this->sendMessage(msg); 136 } 137 emit messageReceived(msg.data()); 125 138 } else { 126 139 emit messageReceived(msg.data()); … … 133 146 d->serverList.clear(); 134 147 QUrl url(TELLDUS_LIVE_URI); 135 QPair<QString, QString> version("protocolVersion", " 1");148 QPair<QString, QString> version("protocolVersion", "2"); 136 149 QList<QPair<QString, QString> > query; 137 150 query.append(version); … … 157 170 d->socket->write(msg.toByteArray()); 158 171 d->socket->flush(); 172 d->pingTimer.stop(); 173 d->pingTimer.start(); 159 174 } 160 175 … … 171 186 d->uuid = settings.value("Live/UUID", "").toString(); 172 187 173 d->timer.start(); //For pings 188 d->pingTimer.start(); //For pings 189 d->pongTimer.start(); //For pongs 174 190 LiveMessage msg("Register"); 175 191 … … 189 205 190 206 void LiveObject::p_disconnected() { 191 d->timer.stop(); 207 d->pingTimer.stop(); 208 d->pongTimer.stop(); 209 if (d->registered) { 210 //Clear the registered status 211 emit errorChanged("Disconnected from server"); 212 } 192 213 d->registered = false; 193 214 } … … 199 220 void LiveObject::stateChanged( QAbstractSocket::SocketState socketState ) { 200 221 if (socketState == QAbstractSocket::UnconnectedState) { 201 int timeout = rand() % 20 + 10; //Random timeout from 10-30s to avoid flooding the servers222 int timeout = rand() % 40 + 10; //Random timeout from 10-50s to avoid flooding the servers 202 223 QTimer::singleShot(timeout*1000, this, SLOT(connectToServer())); 203 224 emit statusChanged("Reconnecting in " + QString::number(timeout) + " seconds..."); 204 225 } else if (socketState == QAbstractSocket::ConnectingState) { 205 226 emit statusChanged("Connecting..."); 227 emit errorChanged(""); 206 228 } 207 229 } … … 229 251 r->deleteLater(); 230 252 if (r->error() != QNetworkReply::NoError) { 253 int timeout = rand() % 300 + 60; //Random timeout from 60s-6min to avoid flooding the servers 231 254 emit errorChanged(r->errorString()); 232 emit statusChanged("Error retrieving server list"); 255 emit statusChanged("Retrying in " + QString::number(timeout) + " seconds..."); 256 QTimer::singleShot(timeout * 1000, this, SLOT(connectToServer())); 233 257 return; 234 258 } … … 254 278 QTimer::singleShot(0, this, SLOT(connectToServer())); 255 279 } else { 256 int timeout = rand() % 20 + 10; //Random timeout from 10-30sto avoid flooding the servers280 int timeout = rand() % 300 + 60; //Random timeout from 60-6min to avoid flooding the servers 257 281 emit errorChanged("No servers found"); 258 282 emit statusChanged("Retrying in " + QString::number(timeout) + " seconds..."); … … 271 295 LiveMessageToken token; 272 296 token.valueType = LiveMessageToken::Dictionary; 273 token.dictVal["protocol"] = LiveMessageToken( "1");297 token.dictVal["protocol"] = LiveMessageToken(2); 274 298 token.dictVal["version"] = LiveMessageToken(TELLDUS_CENTER_VERSION); 275 299 #if defined(Q_WS_WIN) … … 315 339 return token; 316 340 } 341 342 void LiveObject::pongTimeout() { 343 this->disconnect(); 344 } -
telldus-gui/Plugins/Live/LiveObject.h
r0ec9cc r2feeb8 40 40 void p_disconnected(); 41 41 void readyRead(); 42 void pongTimeout(); 42 43 void error( QAbstractSocket::SocketError socketError ); 43 44 void stateChanged( QAbstractSocket::SocketState socketState ); -
telldus-gui/Plugins/Live/__init__.js
r40c330 rd3227e 20 20 com.telldus.core.deviceEvent.connect(deviceEvent); 21 21 com.telldus.core.deviceChange.connect(sendDevicesReport); 22 configUI.findChild('registrationLink').clicked.connect(socket.activate); 23 configUI.findChild('registrationLink').visible = false; 22 24 } 23 25 … … 29 31 com.telldus.systray.menuItem(menuId).triggered.connect(socket.activate); 30 32 } 33 registrationLinkVisible(true); 31 34 } 32 35 … … 43 46 44 47 function messageReceived(msg) { 45 if (msg.name() == "turnon") { 46 com.telldus.core.turnOn( msg.argument(0).intVal() ); 47 } else if (msg.name() == "turnoff") { 48 com.telldus.core.turnOff( msg.argument(0).intVal() ); 49 } else if (msg.name() == "dim") { 50 com.telldus.core.dim( msg.argument(0).intVal(), msg.argument(1).intVal() ); 51 } else if (msg.name() == "bell") { 52 com.telldus.core.bell( msg.argument(0).intVal() ); 48 if (msg.name() == "command") { 49 handleCommand(msg.argument(0)); 53 50 } 54 print("Received: " + msg.name()); 51 } 52 53 function handleCommand(msg) { 54 var action = msg.getString('action'); 55 if (action == "turnon") { 56 com.telldus.core.turnOn( msg.getInt('id') ); 57 } else if (action == "turnoff") { 58 com.telldus.core.turnOff( msg.getInt('id') ); 59 } else if (action == "dim") { 60 com.telldus.core.dim( msg.getInt('id'), msg.getInt('value') ); 61 } else if (action == "bell") { 62 com.telldus.core.bell( msg.getInt('id') ); 63 } else if (action == "up") { 64 com.telldus.core.up( msg.getInt('id') ); 65 } else if (action == "down") { 66 com.telldus.core.down( msg.getInt('id') ); 67 } else if (action == "stop") { 68 com.telldus.core.stop( msg.getInt('id') ); 69 } 55 70 } 56 71 … … 62 77 separatorId = 0; 63 78 } 64 supportedMethods = msg.getInt('supportedMethods'); 79 //Mask to lowest common denominator 80 supportedMethods = 81 com.telldus.core.TELLSTICK_TURNON | 82 com.telldus.core.TELLSTICK_TURNOFF | 83 com.telldus.core.TELLSTICK_DIM | 84 com.telldus.core.TELLSTICK_BELL | 85 com.telldus.core.TELLSTICK_UP | 86 com.telldus.core.TELLSTICK_DOWN | 87 com.telldus.core.TELLSTICK_STOP; 88 supportedMethods = supportedMethods & msg.getInt('supportedMethods'); 65 89 isRegistered = true; 90 registrationLinkVisible(false); 66 91 sendDevicesReport(); 92 } 93 94 function registrationLinkVisible(visibleParam){ 95 configUI.findChild('registrationLink').visible = visibleParam; 67 96 } 68 97 -
telldus-gui/Plugins/Live/configuration.ui
r0ec9cc r319e50 8 8 <y>0</y> 9 9 <width>323</width> 10 <height>2 63</height>10 <height>251</height> 11 11 </rect> 12 </property> 13 <property name="sizePolicy"> 14 <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> 15 <horstretch>0</horstretch> 16 <verstretch>0</verstretch> 17 </sizepolicy> 12 18 </property> 13 19 <property name="windowTitle"> 14 20 <string>Form</string> 15 21 </property> 16 <layout class="QFormLayout" name="formLayout"> 17 <item row="0" column="0"> 18 <widget class="QLabel" name="label"> 19 <property name="text"> 20 <string>Status:</string> 21 </property> 22 </widget> 23 </item> 24 <item row="0" column="1"> 25 <widget class="QLabel" name="statusLabel"> 26 <property name="text"> 27 <string>unknown</string> 28 </property> 29 </widget> 30 </item> 31 <item row="1" column="1"> 32 <widget class="QLabel" name="errorLabel"> 33 <property name="text"> 34 <string/> 35 </property> 36 <property name="wordWrap"> 37 <bool>true</bool> 38 </property> 39 </widget> 40 </item> 41 </layout> 22 <widget class="QWidget" name=""> 23 <property name="geometry"> 24 <rect> 25 <x>0</x> 26 <y>0</y> 27 <width>331</width> 28 <height>251</height> 29 </rect> 30 </property> 31 <layout class="QHBoxLayout" name="horizontalLayout_2"> 32 <item> 33 <layout class="QGridLayout" name="gridLayout_3"> 34 <item row="0" column="0"> 35 <widget class="QLabel" name="label"> 36 <property name="text"> 37 <string>Status:</string> 38 </property> 39 </widget> 40 </item> 41 <item row="0" column="1"> 42 <widget class="QLabel" name="statusLabel"> 43 <property name="text"> 44 <string>unknown</string> 45 </property> 46 <property name="wordWrap"> 47 <bool>true</bool> 48 </property> 49 </widget> 50 </item> 51 <item row="2" column="1"> 52 <widget class="QLabel" name="errorLabel"> 53 <property name="text"> 54 <string/> 55 </property> 56 <property name="wordWrap"> 57 <bool>true</bool> 58 </property> 59 </widget> 60 </item> 61 <item row="5" column="0" colspan="2"> 62 <widget class="QPushButton" name="registrationLink"> 63 <property name="text"> 64 <string>Activate Telldus Live!</string> 65 </property> 66 </widget> 67 </item> 68 <item row="3" column="1"> 69 <spacer name="verticalSpacer_2"> 70 <property name="orientation"> 71 <enum>Qt::Vertical</enum> 72 </property> 73 <property name="sizeHint" stdset="0"> 74 <size> 75 <width>20</width> 76 <height>40</height> 77 </size> 78 </property> 79 </spacer> 80 </item> 81 <item row="3" column="0"> 82 <spacer name="verticalSpacer"> 83 <property name="orientation"> 84 <enum>Qt::Vertical</enum> 85 </property> 86 <property name="sizeHint" stdset="0"> 87 <size> 88 <width>20</width> 89 <height>40</height> 90 </size> 91 </property> 92 </spacer> 93 </item> 94 <item row="6" column="0"> 95 <spacer name="verticalSpacer_3"> 96 <property name="orientation"> 97 <enum>Qt::Vertical</enum> 98 </property> 99 <property name="sizeHint" stdset="0"> 100 <size> 101 <width>20</width> 102 <height>40</height> 103 </size> 104 </property> 105 </spacer> 106 </item> 107 </layout> 108 </item> 109 <item> 110 <spacer name="horizontalSpacer"> 111 <property name="orientation"> 112 <enum>Qt::Horizontal</enum> 113 </property> 114 <property name="sizeHint" stdset="0"> 115 <size> 116 <width>40</width> 117 <height>20</height> 118 </size> 119 </property> 120 </spacer> 121 </item> 122 </layout> 123 </widget> 42 124 </widget> 43 125 <resources/> -
telldus-gui/TelldusCenter/CMakeLists.txt
rf834ad r084930 66 66 67 67 IF (APPLE) #### Mac OS X #### 68 LIST(APPEND telldus-center_LIBRARIES69 /usr/lib/libQtUiTools.a70 )71 68 INCLUDE_DIRECTORIES( 72 69 /usr/include/QtUiTools -
telldus-gui/TelldusGui/devicesetting.cpp
rfea831 r2d1756 22 22 { 23 23 } 24 25 void DeviceSetting::addProtocolMatch( const QString &protocol, const QString &model ){ 26 QString protocolmodel; //concat to one string 27 protocolmodel.append(protocol).append(model); 28 acceptedProtocolModel << protocolmodel; 29 } 30 31 void DeviceSetting::setProtocolValue( const QString &name, const QString &value, const QString &protocol, const QString &model ){ 32 QString protocolmodel; //concat to one string 33 protocolmodel.append(protocol).append(model); 34 if(acceptedProtocolModel.contains(protocolmodel)){ //protocol not set yet, or equal 35 this->setValue(name, value); 36 } 37 } -
telldus-gui/TelldusGui/devicesetting.h
r6af64f r2d1756 30 30 public slots: 31 31 virtual void saveParameters() = 0; 32 void addProtocolMatch( const QString &protocol, const QString &model ); 33 34 private slots: 35 void setProtocolValue( const QString &name, const QString &value, const QString &protocol, const QString &model ); 32 36 virtual void setValue( const QString &name, const QString &value ) = 0; 33 37 34 38 protected: 35 39 Device *p_device; 40 41 private: 42 QList<QString> acceptedProtocolModel; 43 36 44 }; 37 45 -
telldus-gui/TelldusGui/editdevicedialog.cpp
r7bdbd4 r2d1756 174 174 175 175 foreach( DeviceSetting *s, d->deviceSettings ) { 176 connect(d->filteredModel, SIGNAL(setParameter(const QString&, const QString& )), s, SLOT(setValue(const QString&, const QString&)));176 connect(d->filteredModel, SIGNAL(setParameter(const QString&, const QString&, const QString&, const QString&)), s, SLOT(setProtocolValue(const QString&, const QString&, const QString&, const QString&))); 177 177 d->settingsLayout->addWidget( s ); 178 } 179 180 for (int i=0; i<d->model->rowCount(QModelIndex()); ++i){ 181 QModelIndex index = d->model->index(i, 0, QModelIndex()); 182 VendorDeviceTreeItem *typeitem = d->model->item(index); 183 184 for(int j=0; j<typeitem->childCount(); ++j){ 185 VendorDeviceTreeItem *branditem = typeitem->child(j); //d->model->item(index); 186 187 for(int k=0; k<branditem->childCount(); ++k){ 188 VendorDeviceTreeItem *deviceitem = branditem->child(k); //d->model->item(index); 189 190 int widget = deviceitem->widget(); 191 QString strModel = deviceitem->deviceModel().section(':', 0, 0); 192 if (strModel.startsWith("selflearning-")) { 193 strModel = "selflearning"; 194 } 195 d->deviceSettings[widget]->addProtocolMatch(deviceitem->deviceProtocol(), strModel); 196 } 197 } 178 198 } 179 199 -
telldus-gui/TelldusGui/filtereddeviceproxymodel.cpp
r217c63 r2d1756 55 55 } 56 56 else { 57 emit setParameter(name, value );57 emit setParameter(name, value, protocol, model); 58 58 } 59 59 } -
telldus-gui/TelldusGui/filtereddeviceproxymodel.h
r0a9f46 r2d1756 18 18 19 19 signals: 20 void setParameter(const QString &name, const QString &value );20 void setParameter(const QString &name, const QString &value, const QString &protocol, const QString &model); 21 21 22 22 protected: -
telldus-gui/Plugins/QML/CMakeLists.txt
r3738b3 r1e650c 24 24 25 25 INCLUDE( ../TelldusCenterPlugin.cmake NO_POLICY_SCOPE ) 26 27 IF (WIN32) 28 SET(QT_COMPONENTS_OUTPUT_DIR "${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/Plugins/declarative") 29 ELSE() 30 SET(QT_COMPONENTS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/TelldusCenter/Plugins/declarative") 31 ENDIF() 32 INCLUDE( ${CMAKE_SOURCE_DIR}/3rdparty/qt-components-desktop.cmake NO_POLICY_SCOPE ) -
telldus-gui/Plugins/QML/qmlview.cpp
r61331e r5531d6 3 3 #include <QDeclarativeContext> 4 4 #include <QScriptValueIterator> 5 #include <QDeclarativeEngine> 5 6 #include <QVariant> 7 #include <QApplication> 6 8 7 9 class QMLView::PrivateData { … … 16 18 setAttribute(Qt::WA_TranslucentBackground); 17 19 setStyleSheet("background:transparent;"); 20 21 QDeclarativeEngine *eng = this->engine(); 22 QStringList paths(eng->importPathList()); 23 QDir pluginsDir = QDir(qApp->applicationDirPath()); 24 25 #if defined(Q_OS_MAC) 26 if (pluginsDir.dirName() == "MacOS") { 27 pluginsDir.cdUp(); 28 } 29 #endif 30 31 if (pluginsDir.cd("Plugins/declarative")) { 32 paths << pluginsDir.absolutePath(); 33 } 34 35 eng->setImportPathList(paths); 18 36 19 37 d = new PrivateData; -
telldus-gui/Plugins/Sensors/CMakeLists.txt
re7ec37 r394270 4 4 SET(QT_USE_QTDECLARATIVE TRUE) 5 5 6 SET( Plugin_NAME " sensors" )6 SET( Plugin_NAME "Sensors" ) 7 7 8 8 … … 34 34 qmldir 35 35 SensorValue.qml 36 SensorView.qml 37 SensorList.qml 36 38 ) 37 39 -
telldus-gui/Plugins/Sensors/main.qml
r8e377a rc90a4c 1 1 import Qt 4.7 2 import QtDesktop 0.1 2 3 3 4 Item { … … 5 6 state: "VIEW" 6 7 7 Component { 8 id: sensorView 9 Item{ 10 id: sensorViewItem 11 visible: main.state == "EDIT" || modelData.showInList 12 height: childrenRect.height 13 width: parent.width 8 ScrollArea { 9 id: scrollArea 10 anchors.fill: parent 11 frame: false 14 12 15 BorderImage { 16 source: "row_bg.png" 17 border.left: 5; border.top: 5 18 border.right: 5; border.bottom: 5 19 height: sensorInfo.height 20 width: parent.width 13 contentHeight: sensorList.height 14 contentWidth: sensorList.width 21 15 22 Text { 23 visible: main.state == "VIEW" 24 anchors.left: parent.left 25 anchors.leftMargin: 15 26 height: 40 27 verticalAlignment: Text.AlignVCenter 28 text: modelData.name; 29 color: "#004275" 30 } 31 Rectangle{ 32 color: "white" 33 visible: main.state == "EDIT" 34 anchors.left: parent.left 35 anchors.leftMargin: 15 36 width: nameEdit.width + 4 37 height: 22 38 TextInput{ 39 id: nameEdit 40 anchors.centerIn: parent 41 text: modelData.name; 42 color: "#004275" 43 44 onActiveFocusChanged: { 45 if(!activeFocus){ 46 //todo other way? 47 modelData.setName(nameEdit.text); 48 } 49 } 50 onAccepted: { 51 modelData.setName(nameEdit.text); 52 } 53 } 54 } 55 Text{ 56 anchors.right: model.left 57 visible: main.state == "EDIT" 58 height: 40 59 verticalAlignment: Text.AlignVCenter 60 text: modelData.id 61 color: "#004275" 62 width: 50 63 } 64 Text{ 65 id: model 66 anchors.right: visibleinlistcheckbox.left 67 visible: main.state == "EDIT" 68 height: 40 69 verticalAlignment: Text.AlignVCenter 70 text: modelData.model 71 color: "#004275" 72 width: 100 73 } 74 Item{ 75 id: visibleinlistcheckbox 76 anchors.right: sensorInfo.left 77 visible: main.state == "EDIT" 78 height: 40 79 Rectangle{ 80 anchors.centerIn: parent 81 height: 10 82 width: 10 83 color: "white" 84 Text{ 85 anchors.centerIn: parent 86 color: "#004275" 87 text: modelData.showInList ? "X" : "" 88 } 89 MouseArea{ 90 anchors.fill: parent 91 onClicked: { 92 modelData.setShowInList(!modelData.showInList); 93 } 94 } 95 } 96 width: 100 97 } 98 99 Column { 100 id: sensorInfo 101 anchors.right: parent.right 102 width: 250 103 SensorValue { 104 visible: modelData.hasTemperature 105 text: visible ? modelData.sensorValue(1).value + '°C' : '' 106 icon: "icon_temp.png" 107 lastUpdated: visible ? modelData.sensorValue(1).lastUpdated : new Date() 108 } 109 SensorValue { 110 visible: modelData.hasHumidity 111 text: visible ? modelData.sensorValue(2).value + '%' : '' 112 icon: "icon_humidity.png" 113 lastUpdated: visible ? modelData.sensorValue(2).lastUpdated : new Date() 114 } 115 } 116 } 16 SensorList { 17 id: sensorList 18 width: main.width-scrollArea.verticalScrollBar.width 117 19 } 118 20 } 119 120 Column {121 spacing: 1122 BorderImage {123 id: header124 source: "header_bg.png"125 width: parent.width; height: 40126 border.left: 5; border.top: 5127 border.right: 5; border.bottom: 5128 129 HeaderTitle {130 text: "Name"131 anchors.left: parent.left132 anchors.leftMargin: 15133 }134 HeaderTitle {135 text: "ID"136 anchors.right: modelTitle.left137 visible: main.state == "EDIT"138 width: 50139 }140 HeaderTitle {141 id: modelTitle142 text: "Model"143 anchors.right: visibleinlistTitle.left144 visible: main.state == "EDIT"145 width: 100146 }147 HeaderTitle {148 id: visibleinlistTitle149 text: "Visible in list"150 anchors.right: sensorinformationTitle.left151 visible: main.state == "EDIT"152 width: 100153 }154 HeaderTitle {155 id: sensorinformationTitle156 text: "Sensor information"157 width: 150158 anchors.right: timestampTitle.left159 }160 HeaderTitle {161 id: timestampTitle162 text: "Last updated"163 width: 100164 anchors.right: parent.right165 //horizontalAlignment: Text.AlignRight166 }167 }168 Repeater {169 model: sensorModel170 delegate: sensorView171 }172 Row{173 spacing: 20174 Rectangle {175 width: 50176 height: 20177 Text{178 anchors.centerIn: parent179 text: main.state == "VIEW" ? "Edit" : "View"180 }181 MouseArea{182 anchors.fill: parent183 onClicked: {184 if(main.state == "VIEW"){185 main.state = "EDIT"186 }187 else{188 main.state ="VIEW"189 }190 }191 }192 }193 /*194 Rectangle {195 //TODO should this button exist at all, or always save?196 width: 50197 height: 20198 visible: main.state == "EDIT"199 Text{200 anchors.centerIn: parent201 text: "Cancel"202 }203 MouseArea{204 anchors.fill: parent205 onClicked: {206 main.state ="VIEW"207 }208 }209 }210 */211 }212 anchors.fill: parent213 }214 21 } -
telldus-gui/Plugins/Sensors/qmldir
r1bebae r394270 1 1 HeaderTitle 1.0 HeaderTitle.qml 2 2 SensorValue 1.0 SensorValue.qml 3 SensorView 1.0 SensorView.qml 4 SensorList 1.0 SensorList.qml -
telldus-gui/Plugins/Sensors/sensor.cpp
r8e377a r99c2b0 47 47 48 48 QString Sensor::name() const { 49 //return QString("%1 %2").arg(this->protocol()).arg(this->id()); //TODO: Remove when name is fully implemented50 if(d->name == ""){51 return "<unnamed>";52 }53 49 return d->name; 54 50 } -
telldus-gui/Plugins/TelldusCenterPlugin.cmake
rf834ad r69b16f 64 64 ENDIF (UPDATE_TRANSLATIONS) 65 65 66 IF(Plugin_PATH) 67 FOREACH(_FILE ${Plugin_FILES}) 68 GET_FILENAME_COMPONENT(_FILENAME ${_FILE} NAME) 69 ADD_CUSTOM_COMMAND( OUTPUT ${Plugin_PATH}/${_FILENAME} 70 COMMAND ${CMAKE_COMMAND} -E copy ${_FILE} ${Plugin_PATH}/${_FILENAME} 71 DEPENDS ${_FILE} 72 COMMENT "Copy ${_FILENAME} for plugin ${Plugin_NAME}" 73 ) 74 LIST(APPEND Plugin_TARGET_FILES "${Plugin_PATH}/${_FILENAME}") 75 IF (NOT APPLE) 76 INSTALL(FILES ${_FILE} DESTINATION "${PLUGIN_LIB_FULL_PATH}/script/${Plugin_PATH_relative}") 77 ENDIF () 78 ENDFOREACH(_FILE) 79 ENDIF(Plugin_PATH) 80 66 81 IF(Plugin_SRCS) 67 82 ADD_LIBRARY(${Plugin_NAME} SHARED … … 75 90 ${Plugin_TS} 76 91 ${Plugin_QM} 92 ${Plugin_TARGET_FILES} 77 93 ) 78 94 TARGET_LINK_LIBRARIES( ${Plugin_NAME} ${Plugin_LIBRARIES} ) … … 88 104 GET_BUNDLE_AND_EXECUTABLE(\"\${app}\" bundle exe valid) 89 105 SET(plugin \"\${bundle}/Contents/Plugins/script/${Plugin_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}\") 90 106 91 107 GET_ITEM_KEY(\"\${plugin}\" pkey) 92 108 SET(prereqs \"\") … … 94 110 FOREACH(pr \${prereqs}) 95 111 GET_ITEM_KEY(\"\${pr}\" rkey) 96 112 97 113 #Don't change the path to TelldusCore 98 114 IF (NOT \"\${rkey}\" STREQUAL \"TelldusCore\") … … 118 134 ) 119 135 INSTALL(TARGETS ${Plugin_NAME} 120 LIBRARY DESTINATION "${PLUGIN_LIB_FULL_PATH}/script" 136 LIBRARY DESTINATION "${PLUGIN_LIB_FULL_PATH}/script" 121 137 ) 122 138 ENDIF (APPLE) … … 124 140 ELSE(Plugin_SRCS) 125 141 ADD_CUSTOM_TARGET(${Plugin_NAME} ALL 126 SOURCES ${Plugin_FILES} 142 SOURCES ${Plugin_FILES} ${Plugin_TARGET_FILES} 127 143 ) 128 144 ENDIF(Plugin_SRCS) 129 130 IF(Plugin_PATH)131 ADD_CUSTOM_COMMAND( TARGET ${Plugin_NAME}132 POST_BUILD133 COMMAND ${CMAKE_COMMAND} -E make_directory ${Plugin_PATH}134 COMMENT "Creating plugin directory ${Plugin_NAME}"135 )136 FOREACH(_FILE ${Plugin_FILES})137 GET_FILENAME_COMPONENT(_FILENAME ${_FILE} NAME)138 ADD_CUSTOM_COMMAND( TARGET ${Plugin_NAME}139 POST_BUILD140 COMMAND ${CMAKE_COMMAND} -E copy ${_FILE} ${Plugin_PATH}141 COMMENT "Copy ${_FILENAME} for plugin ${Plugin_NAME}"142 )143 IF (NOT APPLE)144 INSTALL(FILES ${_FILE} DESTINATION "${PLUGIN_LIB_FULL_PATH}/script/${Plugin_PATH_relative}")145 ENDIF ()146 ENDFOREACH(_FILE)147 ENDIF(Plugin_PATH)148 149
Note: See TracChangeset
for help on using the changeset viewer.
