Skip to content

Commit abc032c

Browse files
committed
Added CAN next length command
1 parent 45de109 commit abc032c

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Firmware/FFBoard/Inc/CAN.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typedef struct{
3030

3131

3232
class CANPort : public CommandHandler, public PersistentStorage { // : public CanHandler if interrupt callbacks needed
33-
enum class CanPort_commands : uint32_t {speed,send};
33+
enum class CanPort_commands : uint32_t {speed,send,len};
3434
public:
3535
CANPort(CAN_HandleTypeDef &hcan);
3636
CANPort(CAN_HandleTypeDef &hcan,const OutputPin* silentPin);
@@ -87,6 +87,8 @@ class CANPort : public CommandHandler, public PersistentStorage { // : public C
8787
bool active = false;
8888
int32_t portUsers = 0;
8989

90+
CAN_TxHeaderTypeDef header = {0,0,0,CAN_RTR_DATA,8,(FunctionalState)0};
91+
9092
const std::vector<std::string> SpeedNames = {"50k","100k","125k","250k","500k","1000k"};
9193

9294
};

Firmware/FFBoard/Src/CAN.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void CANPort::registerCommands(){
3434
CommandHandler::registerCommands();
3535
registerCommand("speed", CanPort_commands::speed, "CAN speed preset (0:50k;1:100k;2:125k;3:250k;4:500k;5:1M)", CMDFLAG_GET|CMDFLAG_SET|CMDFLAG_INFOSTRING);
3636
registerCommand("send", CanPort_commands::send, "Send CAN frame. Adr&Value required", CMDFLAG_SETADR);
37+
registerCommand("len", CanPort_commands::len, "Set length of next frames", CMDFLAG_SET|CMDFLAG_GET);
3738
}
3839

3940
void CANPort::saveFlash(){
@@ -353,13 +354,18 @@ CommandStatus CANPort::command(const ParsedCommand& cmd,std::vector<CommandReply
353354
}
354355
CAN_tx_msg msg;
355356
memcpy(msg.data,&cmd.val,8);
356-
msg.header.StdId = cmd.adr;
357+
header.StdId = cmd.adr;
358+
msg.header = header;
357359
sendMessage(msg);
358360
}else{
359361
return CommandStatus::NOT_FOUND;
360362
}
361363
break;
362364
}
365+
case CanPort_commands::len:
366+
handleGetSet(cmd, replies, header.DLC);
367+
header.DLC = std::min<uint32_t>(header.DLC,8);
368+
break;
363369
default:
364370
return CommandStatus::NOT_FOUND;
365371
}

0 commit comments

Comments
 (0)