Skip to content

Commit 6a1e891

Browse files
authored
Hash Gen and Dash HB (#207)
1 parent f31ca6d commit 6a1e891

File tree

17 files changed

+140
-0
lines changed

17 files changed

+140
-0
lines changed

common/common_defs/common_defs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,15 @@
5656
#define HSI_TRIM_DAQ 17
5757
#define HSI_TRIM_A_BOX 16
5858

59+
// Convert 8 byte char array to uint64_t in little-endian format
60+
#define EIGHT_CHAR_TO_U64_LE(x)\
61+
((uint64_t)(x[0]) | \
62+
(uint64_t)(x[1]) << 8 | \
63+
(uint64_t)(x[2]) << 16 | \
64+
(uint64_t)(x[3]) << 24 | \
65+
(uint64_t)(x[4]) << 32 | \
66+
(uint64_t)(x[5]) << 40 | \
67+
(uint64_t)(x[6]) << 48 | \
68+
(uint64_t)(x[7]) << 56)
69+
5970
#endif /* COMMON_DEFS_H_ */

common/daq/generation/gen_embedded_can.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
""" gen_embedded_can.py: Generates embedded code for CAN message parsing using structures with bit fields """
22

33
import generator
4+
import subprocess
45

56
#
67
# GENERATION STRINGS
78
#
9+
gen_git_hash_start = "BEGIN GIT HASH DEF"
10+
gen_git_hash_stop = "END GIT HASH DEF"
811
gen_id_start = "BEGIN AUTO ID DEFS"
912
gen_id_stop = "END AUTO ID DEFS"
1013
gen_dlc_start = "BEGIN AUTO DLC DEFS"
@@ -34,6 +37,17 @@
3437

3538
DEFAULT_PERIPHERAL = "CAN1"
3639

40+
def get_git_hash():
41+
"""
42+
Returns the short git has of the current commit
43+
"""
44+
try:
45+
result = subprocess.run(['git', 'rev-parse', '--short=7', 'HEAD'],
46+
capture_output=True, text=True, check=True)
47+
return result.stdout.strip()
48+
except (subprocess.CalledProcessError, FileNotFoundError):
49+
return "unknown"
50+
3751
def find_rx_messages(rx_names):
3852
"""
3953
Searches the entire config for the definitions of the specified messages
@@ -187,6 +201,11 @@ def configure_node(node_config, node_paths):
187201
with open(node_paths[0], "r") as h_file:
188202
h_lines = h_file.readlines()
189203

204+
# Git hash definition
205+
git_hash = get_git_hash()
206+
git_hash_lines = [f"#define GIT_HASH \"{git_hash}\"\n"]
207+
h_lines = generator.insert_lines(h_lines, gen_git_hash_start, gen_git_hash_stop, git_hash_lines)
208+
190209
# with open(node_paths)
191210

192211
# Message IDs and DLCs

common/daq/node_configs/Dashboard.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@
276276
],
277277
"msg_period": 1000,
278278
"msg_priority": 3
279+
},
280+
{
281+
"msg_name": "dash_version",
282+
"msg_desc": "Dashboard version",
283+
"signals": [
284+
{
285+
"sig_name": "git_hash",
286+
"type": "uint64_t",
287+
"sig_desc": "int representation of git short hash"
288+
}
289+
],
290+
"msg_priority": 5,
291+
"msg_period": 5000
279292
}
280293
],
281294
"rx": [

common/daq/node_configs/Main_Module.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,19 @@
650650
],
651651
"msg_period": 15,
652652
"msg_priority": 3
653+
},
654+
{
655+
"msg_name": "main_version",
656+
"msg_desc": "Main version",
657+
"signals": [
658+
{
659+
"sig_name": "git_hash",
660+
"type": "uint64_t",
661+
"sig_desc": "int representation of git short hash"
662+
}
663+
],
664+
"msg_priority": 5,
665+
"msg_period": 5000
653666
}
654667
],
655668
"rx": [

common/daq/node_configs/PDU.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@
227227
],
228228
"msg_period": 1000,
229229
"msg_priority": 3
230+
},
231+
{
232+
"msg_name": "pdu_version",
233+
"msg_desc": "PDU version",
234+
"signals": [
235+
{
236+
"sig_name": "git_hash",
237+
"type": "uint64_t",
238+
"sig_desc": "int representation of git short hash"
239+
}
240+
],
241+
"msg_priority": 5,
242+
"msg_period": 5000
230243
}
231244
],
232245
"rx": [

common/daq/node_configs/a_box.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,19 @@
486486
],
487487
"msg_period": 1000,
488488
"msg_priority": 3
489+
},
490+
{
491+
"msg_name": "abox_version",
492+
"msg_desc": "ABox version",
493+
"signals": [
494+
{
495+
"sig_name": "git_hash",
496+
"type": "uint64_t",
497+
"sig_desc": "int representation of git short hash"
498+
}
499+
],
500+
"msg_priority": 5,
501+
"msg_period": 5000
489502
}
490503
],
491504
"rx": [

common/daq/node_configs/daq.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@
6363
],
6464
"msg_period": 1000,
6565
"msg_priority": 3
66+
},
67+
{
68+
"msg_name": "daq_version",
69+
"msg_desc": "DAQ version",
70+
"signals": [
71+
{
72+
"sig_name": "git_hash",
73+
"type": "uint64_t",
74+
"sig_desc": "int representation of git short hash"
75+
}
76+
],
77+
"msg_priority": 5,
78+
"msg_period": 5000
6679
}
6780
],
6881
"rx": [

common/daq/node_configs/torque_vector.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,19 @@
285285
],
286286
"msg_period": 1000,
287287
"msg_priority": 3
288+
},
289+
{
290+
"msg_name": "tv_version",
291+
"msg_desc": "Torque Vector version",
292+
"signals": [
293+
{
294+
"sig_name": "git_hash",
295+
"type": "uint64_t",
296+
"sig_desc": "int representation of git short hash"
297+
}
298+
],
299+
"msg_priority": 5,
300+
"msg_period": 5000
288301
}
289302
],
290303
"rx": [

source/a_box/can/can_parse_starter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
// Make this match the node name within the can_config.json
2020
#define NODE_NAME "a_box"
2121

22+
/* BEGIN GIT HASH DEF */
23+
/* END GIT HASH DEF */
24+
2225
// Message ID definitions
2326
/* BEGIN AUTO ID DEFS */
2427
/* END AUTO ID DEFS */

source/bootloader/can/can_parse_starter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ extern void canTxSendToBack(CanMsgTypeDef_t* msg);
2525
// Make this match the node name within the can_config.json
2626
#define NODE_NAME "bootloader"
2727

28+
/* BEGIN GIT HASH DEF */
29+
/* END GIT HASH DEF */
30+
2831
// Message ID definitions
2932
/* BEGIN AUTO ID DEFS */
3033
/* END AUTO ID DEFS */

0 commit comments

Comments
 (0)