File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -517,6 +517,29 @@ static void handleCommand() {
517
517
server.send (200 , " text/plain" , " No reply to save command" );
518
518
}
519
519
}
520
+ else if (cmd == " stop" ) {
521
+ if (OICan::StartStop (0 )) {
522
+ server.send (200 , " text/plain" , " Inverter halted" );
523
+ }
524
+ else {
525
+ server.send (200 , " text/plain" , " Stop command failed" );
526
+ }
527
+ }
528
+ else if (cmd.startsWith (" start" )) {
529
+ String str (cmd);
530
+ int modeStart = str.indexOf (' ' );
531
+ int opmode = str.substring (modeStart, str.indexOf (' \r ' )).toInt ();
532
+
533
+ if (OICan::StartStop (opmode)) {
534
+ server.send (200 , " text/plain" , " Inverter started" );
535
+ }
536
+ else {
537
+ server.send (200 , " text/plain" , " Start command failed" );
538
+ }
539
+ }
540
+ else {
541
+ server.send (200 , " text/plain" , " Unknown command" );
542
+ }
520
543
521
544
digitalWrite (LED_BUILTIN, LOW);
522
545
}
Original file line number Diff line number Diff line change 54
54
#define SDO_CMD_SAVE 0
55
55
#define SDO_CMD_LOAD 1
56
56
#define SDO_CMD_RESET 2
57
-
57
+ #define SDO_CMD_DEFAULTS 3
58
+ #define SDO_CMD_START 4
59
+ #define SDO_CMD_STOP 5
58
60
59
61
namespace OICan {
60
62
@@ -577,7 +579,24 @@ bool SaveToFlash() {
577
579
578
580
setValueSdo (SDO_INDEX_COMMANDS, SDO_CMD_SAVE, 0U );
579
581
580
- if (twai_receive (&rxframe, pdMS_TO_TICKS (200 )) == ESP_OK) {
582
+ if (twai_receive (&rxframe, pdMS_TO_TICKS (200 )) == ESP_OK && rxframe.data [0 ] == SDO_WRITE_REPLY) {
583
+ return true ;
584
+ }
585
+ else {
586
+ return false ;
587
+ }
588
+ }
589
+
590
+ bool StartStop (int opmode)
591
+ {
592
+ if (state != IDLE) return false ;
593
+
594
+ twai_message_t rxframe;
595
+ uint8_t subIdx = opmode == 0 ? SDO_CMD_STOP : SDO_CMD_START;
596
+
597
+ setValueSdo (SDO_INDEX_COMMANDS, subIdx, opmode);
598
+
599
+ if (twai_receive (&rxframe, pdMS_TO_TICKS (200 )) == ESP_OK && rxframe.data [0 ] == SDO_WRITE_REPLY) {
581
600
return true ;
582
601
}
583
602
else {
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ SetResult AddCanMapping(String json);
33
33
SetResult RemoveCanMapping (String json);
34
34
SetResult SetValue (String name, double value);
35
35
double GetValue (String name);
36
+ bool StartStop (int opmode);
36
37
bool SaveToFlash ();
37
38
String StreamValues (String names, int samples);
38
39
int StartUpdate (String fileName);
You can’t perform that action at this time.
0 commit comments