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() {
517517 server.send (200 , " text/plain" , " No reply to save command" );
518518 }
519519 }
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+ }
520543
521544 digitalWrite (LED_BUILTIN, LOW);
522545}
Original file line number Diff line number Diff line change 5454#define SDO_CMD_SAVE 0
5555#define SDO_CMD_LOAD 1
5656#define SDO_CMD_RESET 2
57-
57+ #define SDO_CMD_DEFAULTS 3
58+ #define SDO_CMD_START 4
59+ #define SDO_CMD_STOP 5
5860
5961namespace OICan {
6062
@@ -577,7 +579,24 @@ bool SaveToFlash() {
577579
578580 setValueSdo (SDO_INDEX_COMMANDS, SDO_CMD_SAVE, 0U );
579581
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) {
581600 return true ;
582601 }
583602 else {
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ SetResult AddCanMapping(String json);
3333SetResult RemoveCanMapping (String json);
3434SetResult SetValue (String name, double value);
3535double GetValue (String name);
36+ bool StartStop (int opmode);
3637bool SaveToFlash ();
3738String StreamValues (String names, int samples);
3839int StartUpdate (String fileName);
You can’t perform that action at this time.
0 commit comments