Skip to content

Commit

Permalink
Add a version command to simpleshell
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wolfmanjm committed May 29, 2013
1 parent 3c12031 commit 582559c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions generate-version.sh
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() );
Expand Down
10 changes: 10 additions & 0 deletions src/modules/utils/simpleshell/SimpleShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "modules/robot/Conveyor.h"
#include "DirHandle.h"
#include "mri.h"
#include "version.h"


void SimpleShell::on_module_loaded(){
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions src/modules/utils/simpleshell/SimpleShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/version.cpp
Original file line number Diff line number Diff line change
@@ -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__;
}
8 changes: 8 additions & 0 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 582559c

Please sign in to comment.