From 7091b2ea358162b513f50d682107d9617f98817d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 4 Apr 2017 14:02:59 +0200 Subject: [PATCH] [ion] Add software version, patch level and serial number Change-Id: I011eeb2d8596f63e0c2fdedf353d544dc8a8a202 --- Makefile | 2 ++ ion/Makefile | 10 ++++++++++ ion/include/ion.h | 2 ++ ion/src/device/device.cpp | 2 +- ion/src/shared/software_version.cpp | 20 ++++++++++++++++++++ ion/src/simulator/init.cpp | 4 ++++ 6 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 ion/src/shared/software_version.cpp diff --git a/Makefile b/Makefile index 62a51e587..0dcf18ca8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ include build/config.mak +VERSION ?= 1.0.0 + ifndef USE_LIBA $(error platform.mak should define USE_LIBA) endif diff --git a/ion/Makefile b/ion/Makefile index 73e1aa017..cf9916488 100644 --- a/ion/Makefile +++ b/ion/Makefile @@ -1,8 +1,18 @@ +GIT := $(shell command -v git 2> /dev/null) +PATCH_LEVEL = NONE +ifdef GIT + PATCH_LEVEL = `git rev-parse HEAD` +endif + + + SFLAGS += -Iion/include -DKD_CONFIG_H=1 +ion/src/shared/software_version.o: SFLAGS += -DPATCH_LEVEL=$(PATCH_LEVEL) -DVERSION=$(VERSION) include ion/src/$(PLATFORM)/Makefile objs += $(addprefix ion/src/shared/, \ events.o \ + software_version.o \ ) tests += $(addprefix ion/test/,\ diff --git a/ion/include/ion.h b/ion/include/ion.h index 309d1f3aa..f7f16180e 100644 --- a/ion/include/ion.h +++ b/ion/include/ion.h @@ -27,6 +27,8 @@ void msleep(long ms); void usleep(long us); const char * serialNumber(); +const char * softwareVersion(); +const char * patchLevel(); /* CAUTION: This is a complete reset! */ void reset(); diff --git a/ion/src/device/device.cpp b/ion/src/device/device.cpp index 0077158cf..2b93d435f 100644 --- a/ion/src/device/device.cpp +++ b/ion/src/device/device.cpp @@ -74,7 +74,7 @@ const char * Ion::serialNumber() { static char serialNumber[25] = {0}; if (serialNumber[0] == 0) { uint8_t * rawUniqueID = (uint8_t *)0x1FFF7A10; - for (int i=0; i<24; i++) { + for (int i=0; i<12; i++) { uint8_t d = *rawUniqueID++; serialNumber[2*i] = hex(d & 0xF); serialNumber[2*i+1] = hex(d >> 4); diff --git a/ion/src/shared/software_version.cpp b/ion/src/shared/software_version.cpp new file mode 100644 index 000000000..522e83fcf --- /dev/null +++ b/ion/src/shared/software_version.cpp @@ -0,0 +1,20 @@ +#include + +#define STR_EXPAND(arg) #arg +#define STR(arg) STR_EXPAND(arg) + +#ifndef PATCH_LEVEL +#error This file expects PATCH_LEVEL to be defined +#endif + +const char * Ion::softwareVersion() { + return STR(VERSION); +} + +const char * Ion::patchLevel() { + static char patchLevel[20] = {0}; + if (patchLevel[0] == 0) { + strlcpy(patchLevel, STR(PATCH_LEVEL), 6+1); + } + return patchLevel; +} diff --git a/ion/src/simulator/init.cpp b/ion/src/simulator/init.cpp index 4069fedb7..10dbf48cc 100644 --- a/ion/src/simulator/init.cpp +++ b/ion/src/simulator/init.cpp @@ -81,3 +81,7 @@ void Ion::msleep(long ms) { } } } + +const char * Ion::serialNumber() { + return "Simulator"; +}