Changeset dfae48


Ignore:
Timestamp:
01/10/12 10:01:55 (4 months ago)
Author:
Stefan Persson <stefan.persson@…>
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
Message:

Merge remote-tracking branch 'origin/t132' into ticket132

Conflicts:

telldus-core/service/DeviceManager.cpp

Files:
6 added
25 edited

Legend:

Unmodified
Added
Removed
  • rfcmd/rfcmd.c

    r1bee70 rdd3504  
    5858 
    5959/******************************************************************************* 
     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/******************************************************************************* 
    6073 * Modifications from rfcmd ver 2.1.1 done by Johan Ström 
    6174 *  Default disabled semaphores for FreeBSD. 
     
    99112int createRisingSunString(const char * pCodeStr, const char* pUnitStr, const char * pOn_offStr, 
    100113                        char * pTxStr); 
    101  
     114int createEverFlourishString(const char* pUnitStr, const char * pLevelStr, 
     115                        char * pTxStr); 
    102116void printUsage(void); 
    103117void printVersion(void); 
     
    149163                        exit(1); 
    150164                        } 
    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 */ 
    152173        } else if ( (argc >= 2) && (strcmp(*(argv+1),"--version")==0) ) { 
    153174                printVersion(); 
     
    526547} 
    527548 
     549unsigned 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 
     578int 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} 
    528621 
    529622void printUsage(void) 
     
    536629        printf("\t DEVICE: /dev/ttyUSB[0..n]\n" ); 
    537630#endif 
    538         printf("\t PROTOCOLS: NEXA, SARTANO, WAVEMAN, IKEA, RISINGSUN\n" ); 
     631        printf("\t PROTOCOLS: NEXA, SARTANO, WAVEMAN, IKEA, RISINGSUN, EVERFLOURISH\n" ); 
    539632        printf("\n"); 
    540633        printf("\t PROTOCOL ARGUMENTS - NEXA, WAVEMAN:\n"); 
     
    552645        printf("\t\tOFF_ON: 0..1\n" ); 
    553646        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"); 
    554651        printf("Report bugs to <info.tech@telldus.se>\n"); 
    555652} 
  • telldus-core/client/CallbackDispatcher.cpp

    r9535ec r245864  
    99 
    1010#include "CallbackDispatcher.h" 
     11#include "common.h" 
    1112 
    1213using namespace TelldusCore; 
     
    2930 
    3031void TDDeviceEventDispatcher::run() { 
     32        char *str = wrapStdString(strData); 
    3133        d->event(deviceId, method, strData.c_str(), d->id, d->context); 
     34 
    3235        doneRunning = true; 
    3336} 
  • telldus-core/client/Client.cpp

    r9535ec r86554b  
    183183 
    184184                std::wstring clientMessage = d->eventSocket.read(5000); //testing 5 second timeout 
     185 
    185186                while(clientMessage != L""){ 
    186187                        //a message arrived 
     
    283284 
    284285std::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; 
    295321} 
    296322 
  • telldus-core/client/telldus-core.cpp

    r44e5b8 r265daf  
    521521 */ 
    522522int 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        } 
    523527        Message msg(L"tdSendRawCommand"); 
    524         msg.addArgument(command); 
     528        msg.addArgument(wcommand); 
    525529        msg.addArgument(reserved); 
    526530        return Client::getIntegerFromService(msg); 
  • telldus-core/common/Message.cpp

    rfe7f8f r245864  
    2424 
    2525void 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()); 
    2929        this->append(L":"); 
    3030        this->append(value); 
     
    3232 
    3333void Message::addArgument(int value) { 
    34         std::wstringstream st; 
    35         st << (int)value; 
     34        //std::wstringstream st; 
     35        //st << (int)value; 
    3636        this->append(L"i"); 
    37         this->append(st.str()); 
     37        this->append(TelldusCore::intToWstring(value)); // st.str()); 
    3838        this->append(L"s"); 
    3939} 
     40 
     41/* 
     42void 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 
     70void 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/* 
     85void Message::addSpecialArgument(const char *value){ 
     86        this->addSpecialArgument(TelldusCore::charToWstring(value)); 
     87} 
     88*/ 
    4089 
    4190void Message::addArgument(const char *value) { 
  • telldus-core/common/Message.h

    rfe7f8f r245864  
    1212 
    1313                void addArgument(const std::wstring &); 
     14                //void addSpecialArgument(const std::wstring &); 
     15                //void addSpecialArgument(int); 
     16                //void addSpecialArgument(const char *); 
    1417                void addArgument(int); 
    1518                void addArgument(const char *); 
  • telldus-core/common/Socket_win.cpp

    rffeb0b red502d  
    3838        if (d->hPipe != INVALID_HANDLE_VALUE) { 
    3939                CloseHandle(d->hPipe); 
     40                d->hPipe = 0; 
    4041        } 
    4142        delete d; 
     
    9091        memset(&oOverlap, 0, sizeof(OVERLAPPED)); 
    9192 
    92         d->readEvent = CreateEvent(NULL, TRUE, TRUE, NULL); 
     93        d->readEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 
    9394        oOverlap.hEvent = d->readEvent; 
    9495        BOOL fSuccess = false; 
     96        std::wstring returnString; 
     97        bool moreData = true; 
    9598 
    96         memset(&buf, 0, BUFSIZE); 
     99        while(moreData){ 
     100                moreData = false; 
     101                memset(&buf, 0, sizeof(buf)); 
    97102 
    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                } 
    99114 
    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); 
    101120         
    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); 
    106135        } 
    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; 
    125139} 
    126140 
     
    130144        DWORD bytesWritten = 0; 
    131145        int result; 
    132         BOOL fSuccess; 
     146        BOOL fSuccess = false; 
    133147 
    134148        memset(&oOverlap, 0, sizeof(OVERLAPPED)); 
    135149 
    136         HANDLE writeEvent = CreateEvent(NULL, TRUE, TRUE, NULL); 
     150        HANDLE writeEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 
    137151        oOverlap.hEvent = writeEvent; 
    138152         
    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        } 
    140168 
    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); 
    149169        CloseHandle(writeEvent); 
    150170        if (!fSuccess) { 
    151                 CancelIo(d->hPipe); 
     171                CloseHandle(d->hPipe); 
     172                d->hPipe = 0; 
    152173                d->connected = false; 
    153174                return;  
  • telldus-core/common/Strings.cpp

    r8c4c62 r2ec2da  
    9393 
    9494std::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 
    95108        std::wstringstream st; 
    96109        st << value; 
    97110        return st.str(); 
     111#endif 
    98112} 
    99113 
    100114std::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 
    101122        std::stringstream st; 
    102123        st << value; 
    103124        return st.str(); 
    104 } 
     125#endif 
     126} 
     127 
     128/* 
     129std::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*/ 
    105146 
    106147int TelldusCore::wideToInteger(const std::wstring &input){ 
     
    199240                if ((np = (char *)realloc (p, size)) == NULL) { 
    200241                        free(p); 
    201             return ""; 
     242                        return ""; 
    202243                } else { 
    203244                        p = np; 
  • telldus-core/common/Strings.h

    r8c4c62 r716deb  
    1212        bool comparei(std::wstring stringA, std::wstring stringB); 
    1313        std::wstring intToWstring(int value); 
     14        //std::wstring intToWStringSafe(int value); 
    1415        std::string intToString(int value); 
    1516        std::string wideToString(const std::wstring &input); 
  • telldus-core/service/CMakeLists.txt

    r50e69a r988b44  
    2525        TelldusMain.cpp 
    2626        TellStick.cpp 
     27        Timer.cpp 
    2728        EventUpdateManager.cpp 
    2829) 
     
    8081        Event.h 
    8182        EventHandler.h 
     83        EventUpdateManager.h 
    8284        Log.h 
    8385        Sensor.h 
     
    8587        TelldusMain.h 
    8688        TellStick.h 
    87         EventUpdateManager.h 
     89        Timer.h 
    8890) 
    8991FIND_PACKAGE(Threads REQUIRED) 
  • telldus-core/service/ClientCommunicationHandler.cpp

    rad1b18 r36bfa0  
    7777                int deviceId = TelldusCore::Message::takeInt(&msg); 
    7878                (*intReturn) = d->deviceManager->doAction(deviceId, TELLSTICK_TURNON, 0); 
     79 
    7980        } else if (function == L"tdTurnOff") { 
    8081                int deviceId = TelldusCore::Message::takeInt(&msg); 
     
    207208                int reserved = TelldusCore::Message::takeInt(&msg); 
    208209                (*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); 
    214210 
    215211        } else if (function == L"tdConnectTellStickController") { 
  • telldus-core/service/ConnectionListener_win.cpp

    r184d2e r65ef52  
    9292        d->hEvent = CreateEvent(NULL, true, false, NULL); 
    9393        oOverlap.hEvent = d->hEvent; 
     94        bool recreate = true; 
    9495         
    9596        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 
    108111 
    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; 
    112119                } 
     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); 
    113133 
    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                        } 
    130138                } 
    131139                ConnectionListenerEventData *data = new ConnectionListenerEventData(); 
     140                ResetEvent(oOverlap.hEvent); 
    132141                data->socket = new TelldusCore::Socket(hPipe); 
    133142                d->waitEvent->signal(data); 
     143 
     144                recreate = true; 
    134145        } 
    135146 
  • telldus-core/service/DeviceManager.cpp

    r06ac02 rdfae48  
    66#include "Strings.h" 
    77#include "Message.h" 
    8 #include "common.h" 
    9 #include "Log.h" 
     8 
     9#include "common.h" //TODO remove? 
     10#include "Log.h" //TODO remove? 
    1011 
    1112#include <map> 
     
    511512                                } 
    512513                                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-safe 
     514                                        deviceReturnValue = doGroupAction(DeviceManager::getDeviceParameter(deviceId, L"devices", L""), action, data, childType, deviceId, duplicateDeviceIds); //TODO make scenes infinite loops-safe 
    514515                                } 
    515516                                else{ 
  • telldus-core/service/EventHandler_win.cpp

    r485b1e r65ef52  
    5252 
    5353bool 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; 
    5966        } 
    60         int eventIndex = result - WAIT_OBJECT_0; 
    61         if (eventIndex >= d->eventCount) { 
    62                 return false; 
    63         } 
    64         return true; 
    6567} 
  • telldus-core/service/EventUpdateManager.cpp

    rf25ca4 r86554b  
    7474void EventUpdateManager::sendMessageToClients(EventUpdateData *data){ 
    7575 
     76        int connected = 0; 
    7677        for(SocketList::iterator it = d->clients.begin(); it != d->clients.end();){ 
    77  
    7878                if((*it)->isConnected()){ 
    79  
     79                        connected++; 
    8080                        TelldusCore::Message msg; 
    8181 
  • telldus-core/service/ProtocolNexa.cpp

    ree627e r245864  
    44#include "TellStick.h" 
    55#include "Strings.h" 
    6 #include "common.h" 
    76 
    87int ProtocolNexa::lastArctecCodeSwitchWasTurnOff=0;  //TODO, always removing first turnon now, make more flexible (waveman too) 
  • telldus-core/service/ProtocolOregon.cpp

    rc03018 rf58793  
    1717        if (model.compare(L"0xEA4C") == 0) { 
    1818                return decodeEA4C(data); 
    19         } else if (model.compare(L"0x1A2D")) { 
     19        } else if (model.compare(L"0x1A2D") == 0) { 
    2020                return decode1A2D(data); 
    2121        } 
     
    7070 
    7171std::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(); 
    74120} 
  • telldus-core/service/SettingsWinRegistry.cpp

    rc36430 r86554b  
    11#include "Settings.h" 
     2#include "Strings.h" 
    23#include <Windows.h> 
    34#include <sstream>  
     
    67#include <iostream> 
    78#include <fstream> 
     9#include "common.h" 
    810 
    911#include "../client/telldus-core.h" 
     
    9496        intDeviceId = getNextDeviceId(); 
    9597 
    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)); 
    99100                 
    100101        if (RegCreateKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hk, &dwDisp)) { 
     
    123124                DWORD nResult(0); 
    124125 
    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); 
    126127 
    127128                if(lngStatus == ERROR_SUCCESS){ 
     
    144145        TelldusCore::MutexLocker locker(&mutex); 
    145146         
    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)); 
    149149 
    150150        long lngSuccess = RegDeleteKey(d->rootKey, strCompleteRegPath.c_str()); 
     
    162162        HKEY hk; 
    163163 
    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)); 
    167166        long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); 
    168167                         
     
    192191        int ret = TELLSTICK_SUCCESS; 
    193192                 
    194         std::wostringstream ssRegPath;  
    195         ssRegPath << d->strRegPathDevice << intDeviceId; 
    196         std::wstring strCompleteRegPath = ssRegPath.str(); 
     193        std::wstring bla = TelldusCore::intToWstring(intDeviceId); 
     194        std::wstring strCompleteRegPath = d->strRegPathDevice; 
     195        strCompleteRegPath.append(bla); 
    197196        long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 
    198197                                 
     
    224223        HKEY hk; 
    225224 
    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)); 
    229227        long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 
    230228        if (lnExists == ERROR_SUCCESS) { 
  • telldus-core/service/TelldusMain.cpp

    rcccaf8 r542d17a  
    77#include "ControllerListener.h" 
    88#include "EventUpdateManager.h" 
     9#include "Timer.h" 
     10#include "Log.h" 
    911 
    1012#include <stdio.h> 
     
    4042        EventRef clientEvent = d->eventHandler.addEvent(); 
    4143        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(); 
    4248 
    4349        ControllerManager controllerManager(dataEvent.get()); 
     
    102108                        } 
    103109                } 
     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                } 
    104117        } 
     118 
     119        supervisor.stop(); 
    105120} 
    106121 
  • telldus-gui/Plugins/Live/__init__.js

    r5bb60a rd3227e  
    6161                } else if (action == "bell") { 
    6262                        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') ); 
    6369                } 
    6470        } 
     
    7177                        separatorId = 0; 
    7278                } 
    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'); 
    7489                isRegistered = true; 
    7590                registrationLinkVisible(false); 
  • telldus-core/service/Controller.h

    r99f0b1 r06ac02  
    1717        virtual int firmwareVersion() = 0; 
    1818        virtual int send( const std::string &message ) = 0; 
     19        virtual int reset() = 0; 
    1920 
    2021protected: 
  • telldus-core/service/ControllerManager.cpp

    rbf4589 r06ac02  
    33#include "Mutex.h" 
    44#include "TellStick.h" 
     5#include "Log.h" 
    56 
    67#include <map> 
     
    9192 
    9293        std::list<TellStickDescriptor>::iterator it = list.begin(); 
     94        Log::notice("Before for-loop"); 
    9395        for(; it != list.end(); ++it) { 
     96                Log::notice("Something in the loop"); 
    9497                //Most backend only report non-opened devices. 
    9598                //If they don't make sure we don't open them twice 
     
    97100                ControllerMap::const_iterator cit = d->controllers.begin(); 
    98101                for(; cit != d->controllers.end(); ++cit) { 
     102                        Log::notice("Something in second the loop"); 
    99103                        TellStick *tellstick = reinterpret_cast<TellStick*>(cit->second); 
    100104                        if (!tellstick) { 
     105                                Log::notice("No tellstick"); 
    101106                                continue; 
    102107                        } 
    103108                        if (tellstick->isSameAsDescriptor(*it)) { 
    104109                                found = true; 
     110                                Log::notice("FOUND"); 
    105111                                break; 
    106112                        } 
     
    112118                int controllerId = d->lastControllerId-1; 
    113119                TellStick *controller = new TellStick(controllerId, d->event, *it); 
     120                Log::notice("Is it open?"); 
    114121                if (!controller->isOpen()) { 
     122                        Log::notice("Yes it was"); 
    115123                        delete controller; 
    116124                        continue; 
     
    120128        } 
    121129} 
     130 
     131int 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  
    1515 
    1616        Controller *getBestControllerById(int id); 
    17  
    18 protected: 
    1917        void loadControllers(); 
     18        int resetController(Controller *controller); 
    2019 
    2120private: 
  • telldus-core/service/TellStick.h

    r05a816 r06ac02  
    3030        virtual int firmwareVersion(); 
    3131        virtual int pid() const; 
     32        virtual int vid() const; 
     33        virtual std::string serial() const; 
     34 
    3235        bool isOpen() const; 
    3336        bool isSameAsDescriptor(const TellStickDescriptor &d) const; 
     37        virtual int reset(); 
    3438        virtual int send( const std::string &message ); 
    3539        bool stillConnected() const; 
  • telldus-core/service/TellStick_libftdi.cpp

    re019f4 r06ac02  
    2222#include "Strings.h" 
    2323#include "common.h" 
     24#include "Log.h" 
    2425 
    2526#include <unistd.h> 
     
    9899int TellStick::pid() const { 
    99100        return d->pid; 
     101} 
     102 
     103int TellStick::vid() const { 
     104        return d->vid; 
     105} 
     106 
     107std::string TellStick::serial() const { 
     108        return d->serial; 
    100109} 
    101110 
     
    136145} 
    137146 
     147int 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 
    138157void TellStick::run() { 
    139158        int dwBytesRead = 0; 
     
    274293        ftdi_init(&ftdic); 
    275294 
     295        Log::notice("Trying to find Duo"); 
    276296        int ret = ftdi_usb_find_all(&ftdic, &devlist, vid, pid); 
    277297        if (ret > 0) { 
     298                Log::notice("Curdev > 0"); 
    278299                for (curdev = devlist; curdev != NULL; curdev = curdev->next) { 
     300                        Log::notice("Something in the loop"); 
    279301                        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...? 
    280304                        if (ret != 0) { 
    281305                                continue; 
Note: See TracChangeset for help on using the changeset viewer.