From d42b4b938733ee55060bb12f8eedf60742adf681 Mon Sep 17 00:00:00 2001
From: Carl Philipp Klemm <philipp@uvos.xyz>
Date: Mon, 9 Oct 2023 11:27:15 +0200
Subject: [PATCH] add the ability to print the last 8 bytes of the firmware git
 revision

---
 coincellhell.c              | 7 +++++++
 coincellhell/coincellhell.h | 1 +
 coincellhell/usbcommands.h  | 1 +
 main.c                      | 6 ++++++
 4 files changed, 15 insertions(+)

diff --git a/coincellhell.c b/coincellhell.c
index ca98017..5417b23 100644
--- a/coincellhell.c
+++ b/coincellhell.c
@@ -228,6 +228,13 @@ uint32_t coincellhell_get_seconds(struct coincellhell* hell)
 	return seconds;
 }
 
+const uint8_t* coincellhell_get_fw_git_revision(struct coincellhell* hell)
+{
+	static uint8_t gitrev[9] = {0};
+	usbshm_readControlTransferSync(hell->priv, COMMAND_GET_FIRMWARE_GITREV, 0, 0, gitrev, 8);
+	return gitrev;
+}
+
 void coincellhell_disconnect(struct coincellhell* hell)
 {
 	usbshm_distroy(hell->priv);
diff --git a/coincellhell/coincellhell.h b/coincellhell/coincellhell.h
index 2a1c337..3282493 100644
--- a/coincellhell/coincellhell.h
+++ b/coincellhell/coincellhell.h
@@ -169,6 +169,7 @@ int coincellhell_write_eeprom(struct coincellhell* hell, uint16_t addr, uint16_t
 uint16_t coincellhell_read_eeprom(struct coincellhell* hell, uint16_t addr);
 uint8_t coincellhell_read_oscal(struct coincellhell* hell);
 uint32_t coincellhell_get_seconds(struct coincellhell* hell);
+const uint8_t* coincellhell_get_fw_git_revision(struct coincellhell* hell);
 
 #ifdef __cplusplus
 }
diff --git a/coincellhell/usbcommands.h b/coincellhell/usbcommands.h
index 47e8990..05a8ef4 100644
--- a/coincellhell/usbcommands.h
+++ b/coincellhell/usbcommands.h
@@ -22,6 +22,7 @@ typedef enum {
 	COMMAND_READ_EEPROM,
 	COMMAND_WRITE_EEPROM,
 	COMMAND_READ_OSCAL,
+	COMMAND_GET_FIRMWARE_GITREV,
 } usb_command_t;
 
 typedef enum {
diff --git a/main.c b/main.c
index 77d0c8e..796d3ff 100644
--- a/main.c
+++ b/main.c
@@ -47,6 +47,7 @@ static void print_commands(void)
 	puts("disable\t\t\t | disable the heaters");
 	puts("read [ADDRESS] [LENGTH]\t | read from the device eeprom at address");
 	puts("write [ADDRESS] [LENGTH] | write to the device eeprom at address");
+	puts("git\t\t\t | get the git revision of the firmware on the device");
 }
 
 static int convert_string_to_heater_id(const char* str)
@@ -296,6 +297,11 @@ static int process_commands(char** commands, size_t command_count, struct coince
 	{
 		printf("Seconds: %u\n", coincellhell_get_seconds(hell));
 	}
+	else if(strcmp(commands[0], "git") == 0)
+	{
+		const uint8_t* rev = coincellhell_get_fw_git_revision(hell);
+		printf("Git: %x%x%x%x%x%x%x%x\n", rev[0], rev[1], rev[2], rev[3], rev[4], rev[5], rev[6], rev[7]);
+	}
 	else
 	{
 		printf("%s is not a valid command!", commands[0]);
-- 
GitLab