Browse Source

Print local time of the socket instead of UTC.

master
Andrius Štikonas 3 years ago
parent
commit
6368de10a3
3 changed files with 19 additions and 14 deletions
  1. 17
    14
      consolereader.cpp
  2. 1
    0
      consolereader.h
  3. 1
    0
      socket.cpp

+ 17
- 14
consolereader.cpp View File

@@ -33,7 +33,7 @@ void ConsoleReader::run()
33 33
     listSockets();
34 34
 
35 35
     std::string command;
36
-    unsigned int number = 0;
36
+    activeSocket = 0;
37 37
     bool cont = true;
38 38
 
39 39
     while (cont) {
@@ -61,38 +61,38 @@ void ConsoleReader::run()
61 61
             uint16_t countdown;
62 62
             std::cout << "Countdown time in seconds: ";
63 63
             std::cin >> countdown;
64
-            (*sockets) [number]->setCountDown(countdown);
64
+            (*sockets) [activeSocket]->setCountDown(countdown);
65 65
             break;
66 66
         case 'C':
67
-            (*sockets) [number]->toggleCountDown();
67
+            (*sockets) [activeSocket]->toggleCountDown();
68 68
             break;
69 69
         case 'd':
70
-            (*sockets) [number]->tableData();
70
+            (*sockets) [activeSocket]->tableData();
71 71
             break;
72 72
         case 'D':
73
-            (*sockets) [number]->discover();
73
+            (*sockets) [activeSocket]->discover();
74 74
             break;
75 75
         case 'n': {
76 76
             std::string name;
77 77
             std::cout << "Please enter a new name: ";
78 78
             std::cin >> name;
79
-            (*sockets) [number]->changeSocketName(QString::fromStdString(name));
79
+            (*sockets) [activeSocket]->changeSocketName(QString::fromStdString(name));
80 80
             break;
81 81
         }
82 82
         case 'p':
83
-            (*sockets) [number]->toggle();
83
+            (*sockets) [activeSocket]->toggle();
84 84
             break;
85 85
         case 'o':
86 86
             if (command == "off")
87
-                (*sockets) [number]->powerOff();
87
+                (*sockets) [activeSocket]->powerOff();
88 88
             else if (command == "on")
89
-                (*sockets) [number]->powerOn();
89
+                (*sockets) [activeSocket]->powerOn();
90 90
             break;
91 91
         case 'P': {
92 92
             std::string password;
93 93
             std::cout << "Please enter a new password: ";
94 94
             std::cin >> password;
95
-            (*sockets) [number]->changeSocketPassword(QString::fromStdString(password));
95
+            (*sockets) [activeSocket]->changeSocketPassword(QString::fromStdString(password));
96 96
             break;
97 97
         }
98 98
         case 'q':
@@ -100,8 +100,8 @@ void ConsoleReader::run()
100 100
             emit(QCoreApplication::quit());
101 101
             break;
102 102
         case 's':
103
-            std::cin >> number;
104
-            --number; // count from 0
103
+            std::cin >> activeSocket;
104
+            --activeSocket; // count from 0
105 105
             listSockets();
106 106
             break;
107 107
         case 't': {
@@ -109,7 +109,7 @@ void ConsoleReader::run()
109 109
             std::cout << "Please enter a new timezone (integer from -11 to 12): ";
110 110
             std::cin >> timezone;
111 111
             if (timezone >= -11 && timezone <= 12)
112
-                (*sockets) [number]->changeTimezone(timezone);
112
+                (*sockets) [activeSocket]->changeTimezone(timezone);
113 113
             else
114 114
                 std::cout << "Invalid timezone";
115 115
             break;
@@ -129,6 +129,9 @@ void ConsoleReader::listSockets()
129 129
         std::cout << "Countdown: " << (*i)->countdown << " " << ((*i)->countdownEnabled ? "(enabled)" : "(disabled)")  << "\t\t Time: " << (*i)->socketDateTime.toString().toStdString() << std::endl;
130 130
     }
131 131
     std::cout << "_____________________________________________________________________________\n" << std::endl;
132
+    if (sockets->size() > 0) {
133
+        std::cout << "Active socket: " << (*sockets) [activeSocket]->socketName.toStdString() << std::endl;
134
+    }
132 135
     std::cout << "a - add unpaired socket (WiFi needed)\n";
133 136
     std::cout << "A - add unpaired socket (no WiFi needed)\n";
134 137
     std::cout << "c - set countdown\n";
@@ -137,7 +140,7 @@ void ConsoleReader::listSockets()
137 140
     std::cout << "D - resend discovery packet to the current socket\n";
138 141
     std::cout << "n - change socket name (max 16 characters)\n";
139 142
     std::cout << "p - toggle power state (there are also \"on\" and \"off\" commands)\n";
140
-    std::cout << "P - change remote password (max 12 characters)\nq - quit\ns - pick another socket (default is 1)\nt - change timezone" << std::endl;
143
+    std::cout << "P - change remote password (max 12 characters)\nq - quit\ns - select another socket (default is 1)\nt - change timezone" << std::endl;
141 144
     std::cout << "Enter command: " << std::endl;
142 145
 }
143 146
 

+ 1
- 0
consolereader.h View File

@@ -33,6 +33,7 @@ public:
33 33
 
34 34
 private:
35 35
     std::vector<Socket*> *sockets;
36
+    unsigned int activeSocket;
36 37
 };
37 38
 
38 39
 #endif  /* CONSOLEREADER_H */

+ 1
- 0
socket.cpp View File

@@ -272,6 +272,7 @@ bool Socket::parseReply(QByteArray reply)
272 272
         timeZoneSet = reply.mid(index, 1);
273 273
         ++index;
274 274
         timezone = hexToInt(reply.mid(index, 1));
275
+	socketDateTime = socketDateTime.addSecs(timezone *3600);
275 276
         ++index;
276 277
         countdownEnabled = reply.mid(index, 2) == QByteArray::fromHex("01:00");
277 278
         index += 2;

Loading…
Cancel
Save