Skip to content

Commit a1eb105

Browse files
committed
Implement user space SDO jsphuebner/libopeninv#25
1 parent 7cfcf9f commit a1eb105

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ OBJSL = stm32_sine.o hwinit.o stm32scheduler.o params.o terminal.o terminal_prj
5151
my_string.o digio.o sine_core.o my_fp.o fu.o inc_encoder.o printf.o anain.o \
5252
temp_meas.o param_save.o throttle.o errormessage.o pwmgeneration.o \
5353
picontroller.o terminalcommands.o vehiclecontrol.o \
54-
stm32_can.o canmap.o canhardware.o cansdo.o
54+
stm32_can.o canmap.o canhardware.o cansdo.o sdocommands.o
5555

5656
ifeq ($(CONTROL), SINE)
5757
OBJSL += pwmgeneration-sine.o

src/stm32_sine.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@
4646
#include "stm32_can.h"
4747
#include "canmap.h"
4848
#include "cansdo.h"
49+
#include "sdocommands.h"
4950

5051
#define PRINT_JSON 0
52+
#define START_COMMAND_SUBINDEX 4
53+
#define STOP_COMMAND_SUBINDEX 5
5154

5255
HWREV hwRev; //Hardware variant of board we are running on
5356

@@ -220,13 +223,13 @@ static void Ms10Task(void)
220223
PwmGeneration::SetOpmode(MOD_OFF);
221224
Throttle::cruiseSpeed = -1;
222225
TerminalCommands::EnableSaving();
223-
canSdo->EnableSaving();
226+
SdoCommands::EnableSaving();
224227
}
225228
else if (0 == initWait)
226229
{
227230
//Disable saving in Run mode
228231
TerminalCommands::DisableSaving();
229-
canSdo->DisableSaving();
232+
SdoCommands::DisableSaving();
230233
PwmGeneration::SetTorquePercent(0);
231234
Throttle::RampThrottle(0); //Restart ramp
232235
Encoder::Reset();
@@ -356,6 +359,29 @@ void Param::Change(Param::PARAM_NUM paramNum)
356359
}
357360
}
358361

362+
static void ProcessCustomSdoCommands(CanSdo::SdoFrame* sdoFrame)
363+
{
364+
if (sdoFrame->index == SDO_INDEX_COMMANDS && sdoFrame->cmd == SDO_WRITE)
365+
{
366+
switch (sdoFrame->subIndex)
367+
{
368+
case START_COMMAND_SUBINDEX:
369+
if (sdoFrame->data < MOD_LAST)
370+
{
371+
Param::SetInt(Param::opmode, sdoFrame->data);
372+
sdoFrame->cmd = SDO_WRITE_REPLY;
373+
sdoFrame->data = 0;
374+
}
375+
break;
376+
case STOP_COMMAND_SUBINDEX:
377+
Param::SetInt(Param::opmode, 0);
378+
sdoFrame->cmd = SDO_WRITE_REPLY;
379+
sdoFrame->data = 0;
380+
break;
381+
}
382+
}
383+
}
384+
359385
static void UpgradeParameters()
360386
{
361387
Param::SetInt(Param::version, 4); //backward compatibility
@@ -441,11 +467,22 @@ extern "C" int main(void)
441467
while(1)
442468
{
443469
char c = 0;
470+
CanSdo::SdoFrame* sdoFrame = sdo.GetPendingUserspaceSdo();
444471
t.Run();
472+
445473
if (canSdo->GetPrintRequest() == PRINT_JSON)
446474
{
447475
TerminalCommands::PrintParamsJson(canSdo, &c);
448476
}
477+
if (0 != sdoFrame)
478+
{
479+
SdoCommands::ProcessStandardCommands(sdoFrame);
480+
481+
if (sdoFrame->cmd == SDO_ABORT)
482+
ProcessCustomSdoCommands(sdoFrame);
483+
484+
sdo.SendSdoReply(sdoFrame);
485+
}
449486
}
450487

451488
return 0;

0 commit comments

Comments
 (0)