Changeset dfae48
- Timestamp:
- 01/10/12 10:01:55 (4 months ago)
- Branches:
- ('master', 'deebf2045e7119c339412580f37a1e653f7d5715')('controller-upgrade', '00f95d22e12d96ef089e0902ef62ae8ce841dc6f')
- Children:
- 673daf471de0a8094bad2a567b78527158a5f15d
- Parents:
- 06ac023b4a4081c2c409979fb0da45b8123ba9d1fb8e978accbe51e1a0923cb57edfd03c8ca531ca
- git-author:
- Stefan Persson <stefan.persson@telldus.se>2012-01-10 10:01:55+01:00
- git-committer:
- Stefan Persson <stefan.persson@telldus.se>2012-01-10 10:01:55+01:00
- Files:
-
- 6 added
- 25 edited
-
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/rfcmd.c (modified) (6 diffs)
-
telldus-core/client/CallbackDispatcher.cpp (modified) (2 diffs)
-
telldus-core/client/Client.cpp (modified) (2 diffs)
-
telldus-core/client/telldus-core.cpp (modified) (1 diff)
-
telldus-core/common/Message.cpp (modified) (2 diffs)
-
telldus-core/common/Message.h (modified) (1 diff)
-
telldus-core/common/Socket_win.cpp (modified) (3 diffs)
-
telldus-core/common/Strings.cpp (modified) (2 diffs)
-
telldus-core/common/Strings.h (modified) (1 diff)
-
telldus-core/service/CMakeLists.txt (modified) (3 diffs)
-
telldus-core/service/ClientCommunicationHandler.cpp (modified) (2 diffs)
-
telldus-core/service/ConnectionListener_win.cpp (modified) (1 diff)
-
telldus-core/service/DeviceManager.cpp (modified) (2 diffs)
-
telldus-core/service/EventHandler_win.cpp (modified) (1 diff)
-
telldus-core/service/EventUpdateManager.cpp (modified) (1 diff)
-
telldus-core/service/ProtocolNexa.cpp (modified) (1 diff)
-
telldus-core/service/ProtocolOregon.cpp (modified) (2 diffs)
-
telldus-core/service/SettingsWinRegistry.cpp (modified) (8 diffs)
-
telldus-core/service/TelldusMain.cpp (modified) (3 diffs)
-
telldus-core/service/Timer.cpp (added)
-
telldus-core/service/Timer.h (added)
-
telldus-gui/Plugins/Live/__init__.js (modified) (2 diffs)
-
telldus-core/service/Controller.h (modified) (1 diff)
-
telldus-core/service/ControllerManager.cpp (modified) (5 diffs)
-
telldus-core/service/ControllerManager.h (modified) (1 diff)
-
telldus-core/service/TellStick.h (modified) (1 diff)
-
telldus-core/service/TellStick_libftdi.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rfcmd/rfcmd.c
r1bee70 rdd3504 58 58 59 59 /******************************************************************************* 60 * Modifications from rfcmd.c ver 2.1.0 based on marvelous work by Snakehand 61 * See http://www.telldus.com/forum/viewtopic.php?t=97&start=63 62 * Added support for EVERFLOURISH 63 * Note: 64 * 1. Command line syntax: 65 * /usr/local/bin/rfcmd /dev/ttyUSB0 EVERFLOURISH 1 15 66 * Arg 1: device 67 * Arg 2: protocol 68 * Arg 3: device number (0..65535) 69 * Arg 4: Level (0=off, 15=on, 10=learn) 70 ******************************************************************************/ 71 72 /******************************************************************************* 60 73 * Modifications from rfcmd ver 2.1.1 done by Johan Ström 61 74 * Default disabled semaphores for FreeBSD. … … 99 112 int createRisingSunString(const char * pCodeStr, const char* pUnitStr, const char * pOn_offStr, 100 113 char * pTxStr); 101 114 int createEverFlourishString(const char* pUnitStr, const char * pLevelStr, 115 char * pTxStr); 102 116 void printUsage(void); 103 117 void printVersion(void); … … 149 163 exit(1); 150 164 } 151 /* else - a send cmd string was created */ 165 /* else - a send cmd string was created */ 166 } else if ( (argc == 5) && (strcmp(*(argv+2),"EVERFLOURISH")==0) ) { 167 // Unit, Level 168 if ( createEverFlourishString(*(argv+3), *(argv+4), txStr) == 0 ) { 169 printUsage(); 170 exit(1); 171 } 172 /* else - a send cmd string was created */ 152 173 } else if ( (argc >= 2) && (strcmp(*(argv+1),"--version")==0) ) { 153 174 printVersion(); … … 526 547 } 527 548 549 unsigned int everflourish_find_code(unsigned int x) { 550 unsigned int bits[16] = { 0xf ,0xa ,0x7 ,0xe, 551 0xf ,0xd ,0x9 ,0x1, 552 0x1 ,0x2 ,0x4 ,0x8, 553 0x3 ,0x6 ,0xc ,0xb }; 554 unsigned int bit = 1; 555 unsigned int res = 0x5; 556 int i; 557 unsigned int lo,hi; 558 559 if ((x&0x3)==3) { 560 lo = x & 0x00ff; 561 hi = x & 0xff00; 562 lo += 4; 563 if (lo>0x100) lo = 0x12; 564 x = lo | hi; 565 } 566 567 for(i=0;i<16;i++) { 568 if (x&bit) { 569 res = res ^ bits[i]; 570 } 571 bit = bit << 1; 572 } 573 574 return res; 575 } 576 577 578 int createEverFlourishString(const char * pUnitStr, const char * pLevelStr, 579 char * pTxStr) 580 { 581 int len = 0; 582 int level; 583 int unit; 584 unsigned int check; 585 int i; 586 587 unit = atoi(pUnitStr); 588 level = atoi(pLevelStr); /* ON=15, OFF=0, LEARN=10 */ 589 check = everflourish_find_code(unit); 590 591 #ifdef RFCMD_DEBUG 592 printf("unit: %d, level: %d\n", unit, level); 593 #endif 594 595 /* check converted parameters for validity */ 596 if((unit < 0) || (unit > 0xffff) || 597 (level < 0) || (level > 15)) { 598 } else { 599 const char ssss = 85; 600 const char sssl = 84; // 0 601 const char slss = 69; // 1 602 603 const char bits[2] = {sssl,slss}; 604 int i; 605 606 char preamble[] = {'R', 5, 'T', 114,60,1,1,105,ssss,ssss}; 607 memcpy(pTxStr, preamble, sizeof(preamble)); 608 len += sizeof(preamble); 609 610 for(i=15;i>=0;i--) pTxStr[len++]=bits[(unit>>i)&0x01]; 611 for(i=3;i>=0;i--) pTxStr[len++]=bits[(check>>i)&0x01]; 612 for(i=3;i>=0;i--) pTxStr[len++]=bits[(level>>i)&0x01]; 613 614 pTxStr[len++] = ssss; 615 pTxStr[len++] = '+'; 616 } 617 618 pTxStr[len] = '\0'; 619 return strlen(pTxStr); 620 } 528 621 529 622 void printUsage(void) … … 536 629 printf("\t DEVICE: /dev/ttyUSB[0..n]\n" ); 537 630 #endif 538 printf("\t PROTOCOLS: NEXA, SARTANO, WAVEMAN, IKEA, RISINGSUN \n" );631 printf("\t PROTOCOLS: NEXA, SARTANO, WAVEMAN, IKEA, RISINGSUN, EVERFLOURISH\n" ); 539 632 printf("\n"); 540 633 printf("\t PROTOCOL ARGUMENTS - NEXA, WAVEMAN:\n"); … … 552 645 printf("\t\tOFF_ON: 0..1\n" ); 553 646 printf("\n"); 647 printf("\t PROTOCOL ARGUMENTS - EVERFLOURISH:\n"); 648 printf("\t\tDEVICE: 0..65535\n"); 649 printf("\t\tLEVEL: 0=off, 10=learn, 15=on\n" ); 650 printf("\n"); 554 651 printf("Report bugs to <info.tech@telldus.se>\n"); 555 652 } -
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 r86554b 183 183 184 184 std::wstring clientMessage = d->eventSocket.read(5000); //testing 5 second timeout 185 185 186 while(clientMessage != L""){ 186 187 //a message arrived … … 283 284 284 285 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); 286 287 int tries = 0; 288 std::wstring readData; 289 while(tries < 20){ 290 tries++; 291 if(tries == 20){ 292 TelldusCore::Message msg; 293 msg.addArgument(TELLSTICK_ERROR_CONNECTING_SERVICE); 294 return msg; 295 } 296 Socket s; 297 s.connect(L"TelldusClient"); 298 if (!s.isConnected()) { //Connection failed 299 msleep(500); 300 continue; //retry 301 } 302 s.write(msg.data()); 303 if (!s.isConnected()) { //Connection failed sometime during operation... (better check here, instead of 5 seconds timeout later) 304 msleep(500); 305 continue; //retry 306 } 307 readData = s.read(5000); 308 if(readData == L""){ 309 msleep(500); 310 continue; //TODO can we be really sure it SHOULD be anything? 311 } 312 313 if (!s.isConnected()) { //Connection failed sometime during operation... 314 msleep(500); 315 continue; //retry 316 } 317 break; 318 } 319 320 return readData; 295 321 } 296 322 -
telldus-core/client/telldus-core.cpp
r44e5b8 r265daf 521 521 */ 522 522 int WINAPI tdSendRawCommand(const char *command, int reserved) { 523 std::wstring wcommand; 524 for(int i = 0; i < strlen(command);++i) { 525 wcommand.append(1, (unsigned char)command[i]); 526 } 523 527 Message msg(L"tdSendRawCommand"); 524 msg.addArgument( command);528 msg.addArgument(wcommand); 525 529 msg.addArgument(reserved); 526 530 return Client::getIntegerFromService(msg); -
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_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
r8c4c62 r2ec2da 93 93 94 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 95 108 std::wstringstream st; 96 109 st << value; 97 110 return st.str(); 111 #endif 98 112 } 99 113 100 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 101 122 std::stringstream st; 102 123 st << value; 103 124 return st.str(); 104 } 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 */ 105 146 106 147 int TelldusCore::wideToInteger(const std::wstring &input){ … … 199 240 if ((np = (char *)realloc (p, size)) == NULL) { 200 241 free(p); 201 return "";242 return ""; 202 243 } else { 203 244 p = np; -
telldus-core/common/Strings.h
r8c4c62 r716deb 12 12 bool comparei(std::wstring stringA, std::wstring stringB); 13 13 std::wstring intToWstring(int value); 14 //std::wstring intToWStringSafe(int value); 14 15 std::string intToString(int value); 15 16 std::string wideToString(const std::wstring &input); -
telldus-core/service/CMakeLists.txt
r50e69a r988b44 25 25 TelldusMain.cpp 26 26 TellStick.cpp 27 Timer.cpp 27 28 EventUpdateManager.cpp 28 29 ) … … 80 81 Event.h 81 82 EventHandler.h 83 EventUpdateManager.h 82 84 Log.h 83 85 Sensor.h … … 85 87 TelldusMain.h 86 88 TellStick.h 87 EventUpdateManager.h89 Timer.h 88 90 ) 89 91 FIND_PACKAGE(Threads REQUIRED) -
telldus-core/service/ClientCommunicationHandler.cpp
rad1b18 r36bfa0 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/DeviceManager.cpp
r06ac02 rdfae48 6 6 #include "Strings.h" 7 7 #include "Message.h" 8 #include "common.h" 9 #include "Log.h" 8 9 #include "common.h" //TODO remove? 10 #include "Log.h" //TODO remove? 10 11 11 12 #include <map> … … 511 512 } 512 513 else if(childType == TELLSTICK_TYPE_SCENE){ 513 deviceReturnValue = doGroupAction(DeviceManager::getDeviceParameter(deviceId, L"devices", L""), action, data, childType, deviceId, duplicateDeviceIds); //TODO make scenes (and test)infinite loops-safe514 deviceReturnValue = doGroupAction(DeviceManager::getDeviceParameter(deviceId, L"devices", L""), action, data, childType, deviceId, duplicateDeviceIds); //TODO make scenes infinite loops-safe 514 515 } 515 516 else{ -
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/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/ProtocolOregon.cpp
rc03018 rf58793 17 17 if (model.compare(L"0xEA4C") == 0) { 18 18 return decodeEA4C(data); 19 } else if (model.compare(L"0x1A2D") ) {19 } else if (model.compare(L"0x1A2D") == 0) { 20 20 return decode1A2D(data); 21 21 } … … 70 70 71 71 std::string ProtocolOregon::decode1A2D(const std::string &data) { 72 //TODO 73 return ""; 72 uint64_t value = strtol(data.c_str(), NULL, 16); 73 uint8_t checksum2 = value & 0xFF; 74 value >>= 8; 75 uint8_t checksum1 = value & 0xFF; 76 value >>= 8; 77 78 uint8_t checksum = ((value >> 4) & 0xF) + (value & 0xF); 79 uint8_t hum1 = value & 0xF; 80 value >>= 8; 81 82 checksum += ((value >> 4) & 0xF) + (value & 0xF); 83 uint8_t neg = value & (1 << 3); 84 uint8_t hum2 = (value >> 4) & 0xF; 85 value >>= 8; 86 87 checksum += ((value >> 4) & 0xF) + (value & 0xF); 88 uint8_t temp2 = value & 0xF; 89 uint8_t temp1 = (value >> 4) & 0xF; 90 value >>= 8; 91 92 checksum += ((value >> 4) & 0xF) + (value & 0xF); 93 uint8_t temp3 = (value >> 4) & 0xF; 94 value >>= 8; 95 96 checksum += ((value >> 4) & 0xF) + (value & 0xF); 97 uint8_t address = value & 0xFF; 98 value >>= 8; 99 100 checksum += ((value >> 4) & 0xF) + (value & 0xF); 101 uint8_t channel = (value >> 4) & 0x7; 102 103 checksum += 0x1 + 0xA + 0x2 + 0xD - 0xA; 104 105 //TODO: Find out how checksum2 works 106 if (checksum != checksum1) { 107 return ""; 108 } 109 110 double temperature = ((temp1 * 100) + (temp2 * 10) + temp3)/10.0; 111 if (neg) { 112 temperature = -temperature; 113 } 114 115 std::stringstream retString; 116 retString << "class:sensor;protocol:oregon;model:1A2D;id:" << (int)address 117 << ";temp:" << std::fixed << std::setprecision(1) << temperature << ";"; 118 119 return retString.str(); 74 120 } -
telldus-core/service/SettingsWinRegistry.cpp
rc36430 r86554b 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()); … … 162 162 HKEY hk; 163 163 164 std::wostringstream ssRegPath; 165 ssRegPath << d->strRegPathDevice << intDeviceId; 166 std::wstring strCompleteRegPath = ssRegPath.str(); 164 std::wstring strCompleteRegPath = d->strRegPathDevice; 165 strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 167 166 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); 168 167 … … 192 191 int ret = TELLSTICK_SUCCESS; 193 192 194 std::w ostringstream ssRegPath;195 s sRegPath << d->strRegPathDevice << intDeviceId;196 st d::wstring strCompleteRegPath = ssRegPath.str();193 std::wstring bla = TelldusCore::intToWstring(intDeviceId); 194 std::wstring strCompleteRegPath = d->strRegPathDevice; 195 strCompleteRegPath.append(bla); 197 196 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 198 197 … … 224 223 HKEY hk; 225 224 226 std::wostringstream ssRegPath; 227 ssRegPath << d->strRegPathDevice << intDeviceId; 228 std::wstring strCompleteRegPath = ssRegPath.str(); 225 std::wstring strCompleteRegPath = d->strRegPathDevice; 226 strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 229 227 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 230 228 if (lnExists == ERROR_SUCCESS) { -
telldus-core/service/TelldusMain.cpp
rcccaf8 r542d17a 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*5); //Every 5 minutes 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 Log::debug("Do Janitor cleanup"); 116 } 104 117 } 118 119 supervisor.stop(); 105 120 } 106 121 -
telldus-gui/Plugins/Live/__init__.js
r5bb60a rd3227e 61 61 } else if (action == "bell") { 62 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') ); 63 69 } 64 70 } … … 71 77 separatorId = 0; 72 78 } 73 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'); 74 89 isRegistered = true; 75 90 registrationLinkVisible(false); -
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 r06ac02 3 3 #include "Mutex.h" 4 4 #include "TellStick.h" 5 #include "Log.h" 5 6 6 7 #include <map> … … 91 92 92 93 std::list<TellStickDescriptor>::iterator it = list.begin(); 94 Log::notice("Before for-loop"); 93 95 for(; it != list.end(); ++it) { 96 Log::notice("Something in the loop"); 94 97 //Most backend only report non-opened devices. 95 98 //If they don't make sure we don't open them twice … … 97 100 ControllerMap::const_iterator cit = d->controllers.begin(); 98 101 for(; cit != d->controllers.end(); ++cit) { 102 Log::notice("Something in second the loop"); 99 103 TellStick *tellstick = reinterpret_cast<TellStick*>(cit->second); 100 104 if (!tellstick) { 105 Log::notice("No tellstick"); 101 106 continue; 102 107 } 103 108 if (tellstick->isSameAsDescriptor(*it)) { 104 109 found = true; 110 Log::notice("FOUND"); 105 111 break; 106 112 } … … 112 118 int controllerId = d->lastControllerId-1; 113 119 TellStick *controller = new TellStick(controllerId, d->event, *it); 120 Log::notice("Is it open?"); 114 121 if (!controller->isOpen()) { 122 Log::notice("Yes it was"); 115 123 delete controller; 116 124 continue; … … 120 128 } 121 129 } 130 131 int ControllerManager::resetController(Controller *controller) { 132 TellStick *tellstick = reinterpret_cast<TellStick*>(controller); 133 if (!tellstick) { 134 return true; //not tellstick, nothing to reset at the moment, just return true 135 } 136 Log::notice("resettingController"); 137 int success = controller->reset(); //ehh, här är väl controllern borttagen förresten? 138 Log::notice("Remove device"); 139 deviceInsertedOrRemoved(tellstick->vid(), tellstick->pid(), tellstick->serial(), false); //remove from list and delete 140 Log::notice("Device removed"); 141 return success; 142 } -
telldus-core/service/ControllerManager.h
rcccaf8 r06ac02 15 15 16 16 Controller *getBestControllerById(int id); 17 18 protected:19 17 void loadControllers(); 18 int resetController(Controller *controller); 20 19 21 20 private: -
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_libftdi.cpp
re019f4 r06ac02 22 22 #include "Strings.h" 23 23 #include "common.h" 24 #include "Log.h" 24 25 25 26 #include <unistd.h> … … 98 99 int TellStick::pid() const { 99 100 return d->pid; 101 } 102 103 int TellStick::vid() const { 104 return d->vid; 105 } 106 107 std::string TellStick::serial() const { 108 return d->serial; 100 109 } 101 110 … … 136 145 } 137 146 147 int TellStick::reset(){ 148 Log::notice("Resetting one"); 149 int success = ftdi_usb_reset( &d->ftHandle ); 150 Log::notice("Has reset one"); 151 if(success < 0){ 152 return TELLSTICK_ERROR_UNKNOWN; //-1 = FTDI reset failed, -2 = USB device unavailable 153 } 154 return success; 155 } 156 138 157 void TellStick::run() { 139 158 int dwBytesRead = 0; … … 274 293 ftdi_init(&ftdic); 275 294 295 Log::notice("Trying to find Duo"); 276 296 int ret = ftdi_usb_find_all(&ftdic, &devlist, vid, pid); 277 297 if (ret > 0) { 298 Log::notice("Curdev > 0"); 278 299 for (curdev = devlist; curdev != NULL; curdev = curdev->next) { 300 Log::notice("Something in the loop"); 279 301 ret = ftdi_usb_get_strings(&ftdic, curdev->dev, NULL, 0, NULL, 0, serialBuffer, 10); 302 Log::notice("Ret: %d",ret); 303 //blir -9 efter felen, "get serial number failed", även lsusb -v ger annat svar än innan...? 280 304 if (ret != 0) { 281 305 continue;
Note: See TracChangeset
for help on using the changeset viewer.
