MCU
Loading...
Searching...
No Matches
Functions | Variables
AMS_interface_test.h File Reference
#include <Arduino.h>
#include <unity.h>
#include "AMSInterface.h"
#include "SysClock.h"
#include "CAN_testing_utilities.h"
Include dependency graph for AMS_interface_test.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void test_AMS_unpacking_BMS_status_message ()
 
void test_AMS_unpacking_BMS_temperatures_message ()
 
void test_current_shunt_CAN_message ()
 
void test_bms_voltages_CAN_message ()
 
void test_em_measurements_CAN_message ()
 
void test_AMS_charge_critical_threshold ()
 
void test_AMS_filtered_readings ()
 
void test_AMS_heartbeat ()
 

Variables

CANBufferType CAN_BUFFER
 

Function Documentation

◆ test_AMS_charge_critical_threshold()

void test_AMS_charge_critical_threshold ( )

Definition at line 107 of file AMS_interface_test.h.

108{
109
110}

◆ test_AMS_filtered_readings()

void test_AMS_filtered_readings ( )

Definition at line 112 of file AMS_interface_test.h.

113{
114
115}

◆ test_AMS_heartbeat()

void test_AMS_heartbeat ( )

Definition at line 117 of file AMS_interface_test.h.

118{
119 //setting arbitrary pin 20
121
122 unsigned long starting_millis = millis();
123 SysTick_s starting_tick;
124 starting_tick.millis = starting_millis;
125
126 ams_interface.init(starting_tick);
127 ams_interface.set_start_state();
128 TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(starting_millis + 1000));
129 TEST_ASSERT_EQUAL(false, ams_interface.heartbeat_received(starting_millis + 2000));
130
131 starting_millis = millis();
132 ams_interface.set_heartbeat(starting_millis);
133 TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(starting_millis + 100));
134 TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(starting_millis + 1000));
135 TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(starting_millis + 1999));
136 TEST_ASSERT_EQUAL(false, ams_interface.heartbeat_received(starting_millis + 2000));
137 TEST_ASSERT_EQUAL(false, ams_interface.heartbeat_received(starting_millis + 2010));
138
139}
CANBufferType CAN_BUFFER
this class is for interfacing with the AMS (accumulator management system)
Definition: AMSInterface.h:27
SafetySystem safety_system & ams_interface
Definition: main.cpp:219

◆ test_AMS_unpacking_BMS_status_message()

void test_AMS_unpacking_BMS_status_message ( )

Definition at line 10 of file AMS_interface_test.h.

11{
12 /*
13 Need clarification on what these states are.
14 Why is nothing else in the message read by AMSInterface
15 */
16 BMS_status bms_status{};
17 bms_status.set_state(5);
18
19}

◆ test_AMS_unpacking_BMS_temperatures_message()

void test_AMS_unpacking_BMS_temperatures_message ( )

Definition at line 21 of file AMS_interface_test.h.

22{
23
24}

◆ test_bms_voltages_CAN_message()

void test_bms_voltages_CAN_message ( )

Definition at line 52 of file AMS_interface_test.h.

53{
54
55 // Declaring & instantiating new AMSInterface (to read from CAN message)
56 AMSInterface interface(&CAN_BUFFER, 8);
57
58
59 // ----------- CONSTANTS (FOR TESTING PURPOSES) ----------- //
60 // 4.0 volts with a 0.0001 scale factor is 40000. 40000 in hex is 9C40 // Cell should never go above 3.972
61 // 3.9 volts with a 0.0001 scale factor is 39000. 39000 in hex is 9858
62 // 3.8 volts with a 0.0001 scale factor is 38000. 38000 in hex is 9470
63 // 3.7 volts with a 0.0001 scale factor is 37000. 37000 in hex is 9088
64 // 3.6 volts with a 0.0001 scale factor is 36000. 36000 in hex is 8CA0
65 // 3.5 volts with a 0.0001 scale factor is 35000. 35000 in hex is 88B8
66 // 3.4 volts with a 0.0001 scale factor is 34000. 34000 in hex is 84D0
67 // 3.3 volts with a 0.0001 scale factor is 33000. 33000 in hex is 80E8
68 // 3.2 volts with a 0.0001 scale factor is 32000. 32000 in hex is 7D00
69 // 3.1 volts with a 0.0001 scale factor is 31000. 31000 in hex is 7918
70 // 3.0 volts with a 0.0001 scale factor is 30000. 30000 in hex is 7530
71 // 2.9 volts with a 0.0001 scale factor is 29000. 29000 in hex is 7148 // Cell should never go below 3.0
72
73 // BMS_VOLTAGES_t has avg, low, high, and total voltage for each cell. BMS_VOLTAGES_t reads off the CAN line as big-endian.
74 // 3.7 avg 3.5 low 3.9 high
75 CAN_message_t bms_voltages_can_msg = generate_can_msg_from_uint_16s(0x9088U, 0x88B8U, 0x9858U, 0xFFFFU, false);
76
77 interface.retrieve_voltage_CAN(bms_voltages_can_msg); // Reads CAN message into the acu_shunt_measurements_ member variable
78 BMS_VOLTAGES_t received_voltages = interface.get_bms_voltages();
79
80
81
82 // Tests to ensure that the values read off of the CAN line are as expected (ideally should never fail)
83 TEST_ASSERT_EQUAL(0x9088U, received_voltages.average_voltage_ro);
84 TEST_ASSERT_EQUAL(0x88B8U, received_voltages.low_voltage_ro);
85 TEST_ASSERT_EQUAL(0x9858U, received_voltages.high_voltage_ro);
86 TEST_ASSERT_EQUAL(0xFFFFU, received_voltages.total_voltage_ro);
87
88}
CAN_message_t generate_can_msg_from_uint_16s(uint16_t first, uint16_t second, uint16_t third, uint16_t fourth, bool use_little_endian)

◆ test_current_shunt_CAN_message()

void test_current_shunt_CAN_message ( )

Tests the AMSInterface's "retrieve_current_shunt_CAN()" function.

Definition at line 29 of file AMS_interface_test.h.

30{
31
32 // Declaring & instantiating new AMSInterface (to read from CAN message)
33 AMSInterface interface(&CAN_BUFFER, 8);
34
35
36
37 // Creating a new CAN message, feeding it into the interface, and then retrieving it
38 CAN_message_t acu_can_msg = generate_can_msg_from_uint_16s(0x0001U, 0x0002U, 0x0003U, 0x0000U, false);
39
40 interface.retrieve_current_shunt_CAN(acu_can_msg); // Reads CAN message into the acu_shunt_measurements_ member variable
41 ACU_SHUNT_MEASUREMENTS_t received_shunt_measurements = interface.get_acu_shunt_measurements();
42
43
44
45 // Tests to ensure that the values read off of the CAN line are as expected (ideally should never fail)
46 TEST_ASSERT_EQUAL(0x0001U, received_shunt_measurements.current_shunt_read_ro);
47 TEST_ASSERT_EQUAL(0x0002U, received_shunt_measurements.pack_filtered_read_ro);
48 TEST_ASSERT_EQUAL(0x0003U, received_shunt_measurements.ts_out_filtered_read_ro);
49
50}

◆ test_em_measurements_CAN_message()

void test_em_measurements_CAN_message ( )

Definition at line 90 of file AMS_interface_test.h.

91{
92
93 // Declaring & instantiating new AMSInterface (to read from CAN message)
94 AMSInterface interface(&CAN_BUFFER, 8);
95
96 CAN_message_t em_measurements_can = generate_can_msg_from_uint_32s(HYTECH_em_current_ro_toS(23.9f), HYTECH_em_voltage_ro_toS(530.5f), true);
97
98 interface.retrieve_em_measurement_CAN(em_measurements_can); // Reads CAN message into the acu_shunt_measurements_ member variable
99 EM_MEASUREMENT_t received_em_measurement = interface.get_em_measurements();
100
101 // Tests to ensure that the values read off of the CAN line are as expected (ideally should never fail)
102 TEST_ASSERT_EQUAL(23.9f, HYTECH_em_current_ro_fromS(received_em_measurement.em_current_ro));
103 TEST_ASSERT_EQUAL(530.5f, HYTECH_em_voltage_ro_fromS(received_em_measurement.em_voltage_ro));
104
105}
CAN_message_t generate_can_msg_from_uint_32s(uint32_t first, uint32_t second, bool use_little_endian)

Variable Documentation

◆ CAN_BUFFER

CANBufferType CAN_BUFFER

Definition at line 8 of file AMS_interface_test.h.