Skip to content

Commit 4d7a107

Browse files
authored
Merge pull request #202 from open-watt/sleep_command
Added `/system/sleep` CLI command
2 parents f625619 + ff29e45 commit 4d7a107

File tree

7 files changed

+37
-1
lines changed

7 files changed

+37
-1
lines changed

src/manager/console/command.d

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ nothrow @nogc:
3636

3737
Session session;
3838
Command command;
39-
CommandCompletionState state;
4039

4140
this(Session session, Command command)
4241
{

src/manager/package.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ nothrow @nogc:
9797
console.registerCommand!uptime("/system", this);
9898
console.registerCommand!sysinfo("/system", this);
9999
console.registerCommand!show_time("/system", this, "time");
100+
console.registerCommand!sleep("/system", this);
100101

101102
console.registerCommand!device_print("/device", this, "print");
102103

src/manager/system.d

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,33 @@ void show_time(Session session)
106106
session.writeLine(getDateTime());
107107
}
108108

109+
auto sleep(Session session, Duration duration)
110+
{
111+
import manager.console.command : CommandCompletionState;
112+
import manager.console.function_command : FunctionCommandState;
113+
114+
static class SleepCommandState : FunctionCommandState
115+
{
116+
nothrow @nogc:
117+
MonoTime wake_time;
118+
119+
this(Session session, Duration duration)
120+
{
121+
super(session);
122+
wake_time = getTime() + duration;
123+
}
124+
125+
override CommandCompletionState update()
126+
{
127+
if (getTime() >= wake_time)
128+
return CommandCompletionState.Finished;
129+
return CommandCompletionState.InProgress;
130+
}
131+
}
132+
133+
return defaultAllocator().allocT!SleepCommandState(session, duration);
134+
}
135+
109136
// Helper function to format bytes with appropriate unit
110137
private auto format_bytes(ulong bytes) nothrow @nogc
111138
{

src/protocol/dns/package.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ nothrow @nogc:
5151
{
5252
nothrow @nogc:
5353

54+
CommandCompletionState state = CommandCompletionState.InProgress;
55+
5456
this(Session session)
5557
{
5658
super(session);

src/protocol/http/package.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ nothrow @nogc:
6767
static class HTTPRequestState : FunctionCommandState
6868
{
6969
nothrow @nogc:
70+
71+
CommandCompletionState state = CommandCompletionState.InProgress;
72+
7073
HTTPClient client;
7174

7275
this(Session session)

src/protocol/modbus/package.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ class RequestState : FunctionCommandState
363363
{
364364
nothrow @nogc:
365365

366+
CommandCompletionState state = CommandCompletionState.InProgress;
367+
366368
String slave;
367369

368370
this(Session session, const(char)[] slave)

src/protocol/zigbee/package.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ class RequestState : FunctionCommandState
272272
{
273273
nothrow @nogc:
274274

275+
CommandCompletionState state = CommandCompletionState.InProgress;
276+
275277
EZSPClient client;
276278
bool finished = false;
277279

0 commit comments

Comments
 (0)