From 582559c6048e2a90777e4cd3bf9bbc6ce84618c2 Mon Sep 17 00:00:00 2001 From: Jim Morris Date: Wed, 29 May 2013 04:02:12 -0700 Subject: [PATCH] Add a version command to simpleshell Print out version and build date on startup makfile generates a new src/version.cpp with current git branch and hash and build date time --- generate-version.sh | 8 ++++++++ makefile | 1 + src/main.cpp | 4 ++++ src/modules/utils/simpleshell/SimpleShell.cpp | 10 ++++++++++ src/modules/utils/simpleshell/SimpleShell.h | 2 ++ src/version.cpp | 7 +++++++ src/version.h | 8 ++++++++ 7 files changed, 40 insertions(+) create mode 100755 generate-version.sh create mode 100644 src/version.cpp create mode 100644 src/version.h diff --git a/generate-version.sh b/generate-version.sh new file mode 100755 index 00000000..d9a2c645 --- /dev/null +++ b/generate-version.sh @@ -0,0 +1,8 @@ +echo "#include \"version.h\"" > src/version.cpp +echo "const char *Version::get_build(void) const {" >> src/version.cpp +echo " return \"`git symbolic-ref HEAD 2> /dev/null | cut -b 12-`-`git log --pretty=format:\"%h\" -1`\";" >> src/version.cpp +echo "}" >> src/version.cpp +echo "const char *Version::get_build_date(void) const {" >> src/version.cpp +echo " return __DATE__ \" \" __TIME__;" >> src/version.cpp +echo "}" >> src/version.cpp + diff --git a/makefile b/makefile index cc62fa21..b4017ae8 100644 --- a/makefile +++ b/makefile @@ -4,6 +4,7 @@ DIRS = mbed src DIRSCLEAN = $(addsuffix .clean,$(DIRS)) all: + @generate-version.sh @echo Building mbed SDK @ $(MAKE) -C mbed @echo Building Smoothie diff --git a/src/main.cpp b/src/main.cpp index 7d9b7955..7993548d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,6 +38,8 @@ #include "libs/Watchdog.h" +#include "version.h" + #define second_usb_serial_enable_checksum CHECKSUM("second_usb_serial_enable") // Watchdog wd(5000000, WDT_MRI); @@ -76,6 +78,8 @@ int main() { Kernel* kernel = new Kernel(); kernel->streams->printf("Smoothie ( grbl port ) version 0.7.2 with new accel @%ldMHz\r\n", SystemCoreClock / 1000000); + Version version; + kernel->streams->printf(" Build version %s, Build date %s\r\n", version.get_build(), version.get_build_date()); // Create and add main modules kernel->add_module( new Laser() ); diff --git a/src/modules/utils/simpleshell/SimpleShell.cpp b/src/modules/utils/simpleshell/SimpleShell.cpp index f6422908..8e7dec3a 100644 --- a/src/modules/utils/simpleshell/SimpleShell.cpp +++ b/src/modules/utils/simpleshell/SimpleShell.cpp @@ -15,6 +15,7 @@ #include "modules/robot/Conveyor.h" #include "DirHandle.h" #include "mri.h" +#include "version.h" void SimpleShell::on_module_loaded(){ @@ -61,6 +62,8 @@ void SimpleShell::on_console_line_received( void* argument ){ this->dfu_command(get_arguments(possible_command),new_message.stream ); else if (check_sum == help_command_checksum) this->help_command(get_arguments(possible_command),new_message.stream ); + else if (check_sum == version_command_checksum) + this->version_command(get_arguments(possible_command),new_message.stream ); } // Convert a path indication ( absolute or relative ) into a path ( absolute ) @@ -143,6 +146,12 @@ void SimpleShell::cat_command( string parameters, StreamOutput* stream ){ } +// print out build version +void SimpleShell::version_command( string parameters, StreamOutput* stream){ + Version vers; + stream->printf("Build version: %s, Build date: %s, System Clock: %ldMHz\r\n", vers.get_build(), vers.get_build_date(), SystemCoreClock / 1000000); +} + // Reset the system void SimpleShell::reset_command( string parameters, StreamOutput* stream){ stream->printf("Smoothie out. Peace. Rebooting in 5 seconds...\r\n"); @@ -163,6 +172,7 @@ void SimpleShell::break_command( string parameters, StreamOutput* stream){ void SimpleShell::help_command( string parameters, StreamOutput* stream ){ stream->printf("Commands:\r\n"); + stream->printf("version\r\n"); stream->printf("ls [folder]\r\n"); stream->printf("cd folder\r\n"); stream->printf("pwd\r\n"); diff --git a/src/modules/utils/simpleshell/SimpleShell.h b/src/modules/utils/simpleshell/SimpleShell.h index 4246b39a..27238449 100644 --- a/src/modules/utils/simpleshell/SimpleShell.h +++ b/src/modules/utils/simpleshell/SimpleShell.h @@ -22,6 +22,7 @@ #define dfu_command_checksum CHECKSUM("dfu") #define break_command_checksum CHECKSUM("break") #define help_command_checksum CHECKSUM("help") +#define version_command_checksum CHECKSUM("version") class SimpleShell : public Module { public: @@ -39,6 +40,7 @@ class SimpleShell : public Module { void reset_command(string parameters, StreamOutput* stream ); void dfu_command(string parameters, StreamOutput* stream ); void help_command(string parameters, StreamOutput* stream ); + void version_command(string parameters, StreamOutput* stream ); private: string current_path; diff --git a/src/version.cpp b/src/version.cpp new file mode 100644 index 00000000..2329ab03 --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,7 @@ +#include "version.h" +const char *Version::get_build(void) const { + return "placeholder"; +} +const char *Version::get_build_date(void) const { + return __DATE__ " " __TIME__; +} diff --git a/src/version.h b/src/version.h new file mode 100644 index 00000000..01f01a56 --- /dev/null +++ b/src/version.h @@ -0,0 +1,8 @@ +#ifndef _VERSION__H +#define _VERSION__H +class Version { + public: + const char *get_build(void) const; + const char *get_build_date(void) const; +}; +#endif -- 2.20.1