Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "embedded-pio"]
path = embedded-pio
url = git@github.com:badgerloop-software/embedded-pio.git
1 change: 1 addition & 0 deletions embedded-pio
Submodule embedded-pio added at ce0f7c
16 changes: 16 additions & 0 deletions include/candecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "canmanager.h"

class CANDecoder : public CANManager {
public:

CANDecoder(CAN_TypeDef* canPort, CAN_PINS pins, int frequency = DEFAULT_CAN_FREQ);

/* Reads input message and does any logic handling needed
* Intended to be implemented by class extension per board
*/
void readHandler(CAN_message_t msg);

/* Send all of this board's message over CAN
*/
void sendSignal();
};
5 changes: 5 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
platform = ststm32
board = nucleo_f767zi
framework = arduino
build_flags = -DHAL_CAN_MODULE_ENABLED
lib_extra_dirs = ./embedded-pio
lib_deps = pazi88/STM32_CAN@^1.1.2


63 changes: 63 additions & 0 deletions src/candecoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "candecoder.h"

#define IS_FIRST_CAN false

#if IS_FIRST_CAN
#define RECEIVE_BASE_ID 0x000
#define SEND_BASE_ID 0x100
#define INT8_VAL 16
#define INT16_VAL 30271
#define FLOAT_VAL 9.8
#define BOOL_VAL true
#else
#define RECEIVE_BASE_ID 0x100
#define SEND_BASE_ID 0x000
#define INT8_VAL 234
#define INT16_VAL 57219
#define FLOAT_VAL 8.6
#define BOOL_VAL false
#endif

uint8_t int8Received;
uint16_t int16Received;
float floatReceived;
bool boolReceived;

int numMessagesReceived[4] = {0,0,0,0};

CANDecoder::CANDecoder(CAN_TypeDef* canPort, CAN_PINS pins, int frequency) : CANManager(canPort, pins, frequency){};

void CANDecoder::readHandler(CAN_message_t msg) {
switch (msg.id) {
case (RECEIVE_BASE_ID + 0):
int8Received = *(int8_t*)msg.buf;
numMessagesReceived[0]++;
break;
case (RECEIVE_BASE_ID + 1):
int16Received = *(int16_t*)msg.buf;
numMessagesReceived[1]++;
break;
case (RECEIVE_BASE_ID + 2):
floatReceived = *(float*)msg.buf;
numMessagesReceived[2]++;
break;
case (RECEIVE_BASE_ID + 3):
boolReceived = *(bool*)msg.buf;
numMessagesReceived[3]++;
break;
}
}

void CANDecoder::sendSignal() {
uint8_t test8int = INT8_VAL;
this->sendMessage(SEND_BASE_ID + 0, (void*)&test8int, sizeof(test8int));

uint16_t test16int = INT16_VAL;
this->sendMessage(SEND_BASE_ID + 1, (void*)&test16int, sizeof(test16int));

float testFloat = FLOAT_VAL;
this->sendMessage(SEND_BASE_ID + 2, (void*)&testFloat, sizeof(testFloat));

bool testBoolean = BOOL_VAL;
this->sendMessage(SEND_BASE_ID + 3, (void*)&testBoolean, sizeof(testBoolean));
}
34 changes: 25 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
#include <Arduino.h>
#include "STM32_CAN.h"
#include "candecoder.h"

// put function declarations here:
int myFunction(int, int);
CANDecoder candecoder(CAN1, ALT_2, 500000);

extern uint8_t int8Received;
extern uint16_t int16Received;
extern float floatReceived;
extern bool boolReceived;

extern int numMessagesReceived[4];

int counter = 0;

void setup() {
// put your setup code here, to run once:
int result = myFunction(2, 3);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
}
candecoder.sendSignal();
candecoder.runQueue(50); // 50ms, so 20 sets of messages sent per second
counter++;

// put function definitions here:
int myFunction(int x, int y) {
return x + y;
// print out debug info every second (instead of every 50ms)
if (counter > 20) {
counter = 0;
Serial.println(int8Received);
Serial.println(int16Received);
Serial.println(floatReceived);
Serial.println(boolReceived);
printf("%d | %d | %d | %d\n\n", numMessagesReceived[0], numMessagesReceived[1], numMessagesReceived[2], numMessagesReceived[3]);
}
}