Skip to content

Commit b841a8e

Browse files
Fix/implement faux can (#59)
* init commit + fixes * adjust faux can baudrate * merge with main * removed commented blocks and moved around some CAN things * removed ethernet socket defs from globals * reworked CAN Interface to use singleton struct for TELEM and FAUX objects * added TODO --------- Co-authored-by: mansi-b29 <133283027+mansi-b29@users.noreply.github.com>
1 parent 2c14a9b commit b841a8e

11 files changed

Lines changed: 84 additions & 90 deletions

File tree

include/VCF_Constants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ namespace VCFInterfaceConstants {
101101
constexpr float BRAKE_PRESSURE_REAR_SCALE = 1.0;
102102
constexpr float BRAKE_PRESSURE_REAR_OFFSET = 0;
103103

104+
/* VCF CAN Constants */
105+
constexpr uint32_t TELEM_CAN_BAUDRATE = 1000000; // 1 000 000 = 1 Mbit/s
106+
constexpr uint32_t FAUX_CAN_BAUDRATE = 500000; // 500 000 = 500 Kbit/s
104107
}
105108

106109
// calibration and processing constants

include/VCF_Globals.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,7 @@
2727
/* From MCP23017 Library */
2828
#include "MCP23017.h"
2929

30-
31-
/* Interface and system data structs */
32-
// using VCFData_sInstance = etl::singleton<VCFData_s>;
33-
3430
/* IOExpander setup */
3531
using IOExpanderInstance = etl::singleton<MCP23017>;
3632

37-
/* Digital Steering Setup */
38-
using OrbisBRInstance = etl::singleton<OrbisBR>;
39-
40-
/* Ethernet sockets */
41-
extern qindesign::network::EthernetUDP VCF_socket;
42-
extern qindesign::network::EthernetUDP VCR_socket;
43-
4433
#endif /* VCF_GLOBALS */

lib/interfaces/include/VCFCANInterfaceImpl.h

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
/* Globally accessible types */
2121
using CANRXBufferType = Circular_Buffer<uint8_t, (uint32_t)16, sizeof(CAN_message_t)>;
2222
using CANTXBufferType = Circular_Buffer<uint8_t, (uint32_t)128, sizeof(CAN_message_t)>;
23-
template <CAN_DEV_TABLE CAN_DEV> using FlexCAN_Type = FlexCAN_T4<CAN_DEV, RX_SIZE_256, TX_SIZE_16>;
23+
24+
// Definitions of VCF CAN bus types
25+
using TelemCAN_t = FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16>;
26+
using FrontAuxCAN_t = FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16>;
2427

2528
/* Interfaces accessible to this one */
2629
struct CANInterfaces {
@@ -33,30 +36,33 @@ struct CANInterfaces {
3336
ACUInterface &acu_interface;
3437
VCRInterface &vcr_interface;
3538
};
39+
using CANInterfacesInstance = etl::singleton<CANInterfaces>;
3640

37-
struct VCFCANInterfaceObjects {
41+
struct VCFCANInterface {
42+
VCFCANInterface(etl::delegate<void (CANInterfaces &, const CAN_message_t &, unsigned long, CANInterfaceType_e)> recv_switch_func)
43+
: can_recv_switch(recv_switch_func)
44+
{}
3845

39-
VCFCANInterfaceObjects(etl::delegate<void(CANInterfaces &, const CAN_message_t &, unsigned long, CANInterfaceType_e)> recv_switch, FlexCAN_T4_Base * main_can): MAIN_CAN(main_can),can_recv_switch(recv_switch)
40-
{}
46+
TelemCAN_t TELEM_CAN;
4147

42-
43-
FlexCAN_T4_Base* MAIN_CAN;
44-
// TODO fix this. needs to be a pointer to an in-main global created instance of CAN3. this also cannot be a base type.
45-
CANRXBufferType main_can_rx_buffer;
46-
CANTXBufferType main_can_tx_buffer;
47-
etl::delegate<void(CANInterfaces &, const CAN_message_t &, unsigned long, CANInterfaceType_e)> can_recv_switch;
48-
48+
CANRXBufferType telem_can_rx_buffer;
49+
CANTXBufferType telem_can_tx_buffer;
50+
51+
FrontAuxCAN_t FRONT_AUX_CAN;
52+
53+
CANRXBufferType front_aux_can_rx_buffer;
54+
CANTXBufferType front_aux_can_tx_buffer;
55+
56+
etl::delegate<void (CANInterfaces &, const CAN_message_t &, unsigned long, CANInterfaceType_e)> can_recv_switch;
4957
};
58+
using VCFCANInterfaceInstance = etl::singleton<VCFCANInterface>;
5059

5160
namespace VCFCANInterfaceImpl {
5261
void on_main_can_recv(const CAN_message_t &msg);
53-
void vcf_recv_switch(CANInterfaces &interfaces, const CAN_message_t &msg, unsigned long millis, CANInterfaceType_e interface_type);
62+
void on_faux_can_recv(const CAN_message_t &msg);
63+
64+
void vcf_recv_switch(CANInterfaces &interfaces, const CAN_message_t &msg, unsigned long millis, CANInterfaceType_e interface_type); //vcf can receive
5465
void send_all_CAN_msgs(CANTXBufferType &buffer, FlexCAN_T4_Base *can_interface);
55-
56-
extern FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> main_can;
57-
58-
using VCFCANInterfaceObjectsInstance = etl::singleton<VCFCANInterfaceObjects>;
59-
using CANInterfacesInstance = etl::singleton<CANInterfaces>;
6066
}
6167

6268
#endif // VCFCANINTERFACEIMPL_H

lib/interfaces/include/VCFEthernetInterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef VCF_ETHERNET_INTERFACE_H
22
#define VCF_ETHERNET_INTERFACE_H
33

4+
#include "QNEthernet.h"
45
#include "hytech_msgs.pb.h"
56
#include "SharedFirmwareTypes.h"
67
#include "ADCInterface.h"
@@ -31,6 +32,10 @@ namespace VCFEthernetInterface
3132

3233
constexpr const size_t ver_hash_len = 9;
3334
constexpr float SHDN_HIGH_THRESHOLD = 12.0; // threshold for shutdown being considered high
35+
36+
/* Ethernet sockets */
37+
extern qindesign::network::EthernetUDP VCF_socket;
38+
extern qindesign::network::EthernetUDP VCR_socket;
3439
}
3540

3641
#endif /* VCF_ETHERNET_INTERFACE_H */

lib/interfaces/include/VCRInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class VCRInterface
4141

4242
void receive_inverter_status_4(const CAN_message_t &can_msg);
4343

44+
4445
VehicleState_e get_vehicle_state() {return _vehicle_state_value;}
4546
DrivetrainState_e get_drivetrain_state() {return _drivetrain_state_value;}
4647
InverterBusVolts_s get_dc_bus_voltage() {return _bus_voltages;}

lib/interfaces/src/VCFCANInterfaceImpl.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
#include "VCFCANInterfaceImpl.h"
22
#include "BuzzerController.h"
33

4-
namespace VCFCANInterfaceImpl {
4+
namespace VCFCANInterfaceImpl {
55
void on_main_can_recv(const CAN_message_t &msg)
66
{
77
uint8_t buf[sizeof(CAN_message_t)];
88
memmove(buf, &msg, sizeof(msg)); // NOLINT (memory operations are fine)
9-
VCFCANInterfaceObjectsInstance::instance().main_can_rx_buffer.push_back(buf, sizeof(CAN_message_t));
9+
VCFCANInterfaceInstance::instance().telem_can_rx_buffer.push_back(buf, sizeof(CAN_message_t));
10+
}
11+
12+
void on_faux_can_recv(const CAN_message_t &msg)
13+
{
14+
VCFCANInterfaceInstance::instance().TELEM_CAN.write(msg); //immediately forward onto telem can to view data
15+
uint8_t buf[sizeof(CAN_message_t)];
16+
memmove(buf, &msg, sizeof(msg)); // NOLINT (memory operations are fine)
17+
VCFCANInterfaceInstance::instance().front_aux_can_rx_buffer.push_back(buf, sizeof(CAN_message_t));
18+
19+
// Serial.println("msg recvd");
20+
// Serial.print("MB: "); Serial.print(msg.mb);
21+
// Serial.print(" ID: 0x"); Serial.print(msg.id, HEX);
22+
// Serial.print(" EXT: "); Serial.print(msg.flags.extended);
23+
// Serial.print(" LEN: "); Serial.print(msg.len);
24+
// Serial.print(" DATA: ");
25+
// for ( uint8_t i = 0; i < 8; i++ ) {
26+
// Serial.print(msg.buf[i]); Serial.print(" ");
27+
// }
28+
// Serial.print(" TS: "); Serial.println(msg.timestamp);
1029
}
1130

1231
void vcf_recv_switch(CANInterfaces &interfaces, const CAN_message_t &msg, unsigned long millis, CANInterfaceType_e interface_type)
@@ -53,7 +72,6 @@ namespace VCFCANInterfaceImpl {
5372
interfaces.vcr_interface.receive_inverter_status_4(msg);
5473
break;
5574
}
56-
5775
default:
5876
break;
5977
}

platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ lib_deps =
5252
${common.lib_deps_shared}
5353
arkhipenko/TaskScheduler@^3.8.5
5454
https://github.com/ssilverman/QNEthernet#v0.26.0
55-
https://github.com/hytech-racing/shared_firmware_interfaces.git#985966ca09f9427e6c636fd42f7640176aec11ee
55+
https://github.com/hytech-racing/shared_firmware_interfaces.git
5656
blemasle/MCP23017@^2.0.0
5757
https://github.com/adafruit/Adafruit_NeoPixel.git
5858
https://github.com/KSU-MS/pio-git-hash-gen#7998b5b3f8a2464209b0e73338717998bcf511ee
@@ -186,7 +186,7 @@ test_ignore =
186186
test_systems
187187
lib_deps =
188188
${common.lib_deps_shared}
189-
https://github.com/hytech-racing/shared_firmware_interfaces.git#29a9cb09f91b684382e897de780d8d52a14659a7
189+
https://github.com/hytech-racing/shared_firmware_interfaces.git
190190
blemasle/MCP23017@^2.0.0
191191
https://github.com/KSU-MS/pio-git-hash-gen#7998b5b3f8a2464209b0e73338717998bcf511ee
192192

src/VCF_Globals.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)