Browse Source

New ML support - upgrade scripts and source

Robert Pelnar 6 years ago
parent
commit
82af3f1a93

+ 20 - 0
lang_upgrade/!upgrade.sh

@@ -0,0 +1,20 @@
+#!/bin/sh
+# upgrade.sh
+#
+
+if [ -e ../lang_backup ]; then
+ echo 'folder ../lang_backup already exist!'
+else
+ ./clean.sh
+ ./make_msgs.sh
+ ./find_msgs.sh
+ ./make_source.sh
+ echo 'backup old files...'
+ mkdir ../lang_backup
+ mv ../Firmware/langtool.* ../lang_backup/
+ mv ../Firmware/language*.* ../lang_backup/
+ echo 'copying new files...'
+ cp ./source/* ../Firmware/
+ echo 'finished'
+fi
+read

+ 6 - 2
lang_upgrade/clean.sh

@@ -1,7 +1,11 @@
 #!/bin/sh
 #
 
+echo "removing output files"
 rm msgs*.txt
 rm make_msgs.out
-rm messages.h
-rm messages.c
+rm replace_*.out
+rm ./source/*
+rmdir ./source
+echo "step0 finished... press key"
+read

+ 29 - 45
lang_upgrade/find_msgs.sh

@@ -2,62 +2,46 @@
 #
 echo 'find_msgs.sh'
 
+#list all source files from source folder except *language* files
 files=$(ls ../Firmware/*.c* | grep -v 'language'; ls ../Firmware/*.h | grep -v 'language'; )
 
-echo -n ' processing msgs_en.txt ...'
+echo ' processing msgs_en.txt and msgs_common.txt...'
 #msgs=$(cat msgs_en.txt | cut -f 1 -d' ')
 msgs=$(cat msgs_en.txt msgs_common.txt | cut -f 1 -d' ')
 #msgs=$(cat msgs_common.txt | cut -f 1 -d' ')
 echo "$msgs" | while read msg; do
  echo -n "$msg "
- found=$(grep -c "$msg" $files | sed "/:0$/d;s/.*:/+/g")
+ found=$(grep -c -E "\b$msg\b" $files | sed "/:0$/d;s/.*:/+/g")
  echo $(("0"$found))
-done  | tee msgs_usage.txt_0
+done | tee msgs_usage.txt_0
 cat msgs_usage.txt_0 | sort -k2 -n >msgs_usage.txt
 rm msgs_usage.txt_0
-echo "finished.."
-read
-exit
-
-#replace #define(length=xx,lines=xx)
-cat msgs_en.txt_0 | sed -E "s/^#define\(length=([0-9]*),[ \t]*lines=([0-9]*)\)[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\3 c=\1 r=\2 \4/g" >msgs_en.txt_1
-#replace #define(length=xx)
-cat msgs_en.txt_1 | sed -E "s/^#define\(length=([0-9]*)\)[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\2 c=\1 r=0 \3/g" >msgs_en.txt_2
-#replace #define
-cat msgs_en.txt_2 | sed -E "s/^#define[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\1 c=0 r=0 \2/g" >msgs_en.txt
-#remove tmp files
-rm msgs_en.txt_*
-echo "ok"
 
-echo -n ' processing language_cz.h ...'
-#list all defines from language_cz.h
-cat ../Firmware/language_cz.h | grep "^#define" >msgs_cz.txt_0
-cat msgs_cz.txt_0 | sed -E "s/^#define[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\1 \2/g" >msgs_cz.txt
-#remove tmp files
-rm msgs_cz.txt_*
-echo "ok"
+#list messages that are not used
+msgs=$(cat msgs_usage.txt | grep " 0$" | cut -f1 -d' ')
+#make regular expression from the list - replace spaces with '\b|\b' (match whole words)
+msgs='\b'$(echo $msgs | sed "s/ /\\\b\\\|\\\b/g")'\b'
+#grep unused messages
+cat msgs_en.txt | grep "$msgs" > msgs_en_unused.txt
+cat msgs_common.txt | grep "$msgs" > msgs_common_unused.txt
+
+#list messages used once
+msgs=$(cat msgs_usage.txt | grep " 1$" | cut -f1 -d' ')
+#make regular expression from the list - replace spaces with '\b|\b' (match whole words)
+msgs='\b'$(echo $msgs | sed "s/ /\\\b\\\|\\\b/g")'\b'
+#grep unused messages
+cat msgs_en.txt | grep "$msgs" > msgs_en_used_once.txt
+cat msgs_common.txt | grep "$msgs" > msgs_common_used_once.txt
+
+#list messages used once more (exclude unused and used once)
+msgs=$(cat msgs_usage.txt | grep -v " 0$" | grep -v " 1$" | cut -f1 -d' ')
+#make regular expression from the list - replace spaces with '\b|\b' (match whole words)
+msgs='\b'$(echo $msgs | sed "s/ /\\\b\\\|\\\b/g")'\b'
+#grep unused messages
+cat msgs_en.txt | grep "$msgs" > msgs_en_used_more.txt
+cat msgs_common.txt | grep "$msgs" > msgs_common_used_more.txt
+
+echo "step2 finished... press key"
 
-echo "finished.."
 read
 exit
-
-
-
-
-
-
-#cat msgs_en.txt_3 | grep "^XXX" >msgs_en.txt_4
-
-#cat msgs_en.txt_0 | sed -E "s/^#define\(length=([0-9]{2}), lines=([0-9]{2})\)[ ]*([^ ]*)/\3 \2 \1/g" >msgs_en.txt_1
-#cat msgs_en.txt_0 | sed -E "s/^#define\(length=([0-9]{2})\)[ ]*([^ ]*)/\2 \1/g" >msgs_en.txt_1
-#cat msgs_en.txt_1 | sed -E "s/^#define[ ]*([^ ]*)/\1/g" >msgs_en.txt_2
-#[0-9]{+2}
-#cat ../Firmware/language_en.h | sed "s/^#define(length=[0-9]*)//g" >msgs_en.txt_0
-#msgs=$(ls ../Firmware/*.c* | grep -v 'language'; ls ../Firmware/*.h | grep -v 'language'; )
-#echo "$files" | while read fn; do
-# if grep "MSG_SD_INSERTED" $fn >/dev/null; then
-#  echo $fn
-# fi
-#done
-echo "finished.."
-read

+ 2 - 2
lang_upgrade/make_msgs.sh

@@ -34,7 +34,7 @@ process_language_common()
  #cat ../Firmware/language_common.h | grep -E "^[+]*define" | sed "s/lenght/length/g" >msgs_common.txt_0
  cat ../Firmware/language_common.h | grep -E "^define" | sed "s/lenght/length/g" >msgs_common.txt_0
   #replace define and +define
- cat msgs_common.txt_0 | sed -E "s/^[+]*define[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\1 \2/g" | sort >msgs_common.txt
+ cat msgs_common.txt_0 | sed -E "s/^[+]*define[ \t]*([^ \t]*)[ \t]*([^ \t]*[ \t]*\"[^\"]*\"*)/\1 c=0 r=0 \2/g" | sort >msgs_common.txt
  #calculate msgcount
  msgcount=$(grep -c '' msgs_common.txt)
  #calculate charcount
@@ -89,5 +89,5 @@ process_language_xx pl
 process_language_xx es
 
 
-echo "finished.."
+echo "step1 finished... press key"
 read

+ 13 - 8
lang_upgrade/readme.txt

@@ -1,5 +1,11 @@
 lang_upgrade - scripts for migration to new multilanguage support design
 
+upgrade.sh - entire process:
+Run scripts: clean.sh, make_msgs.sh, find_msgs.sh, make_source.sh.
+Backup (move) all language*.h and language*.cpp files from source to folder '../lang_backup'.
+Copy folder ./source/*.* to ../Firmware, new files will be messages.h, messages.c, language.h, language.c and other source will be replaced.
+After this step should be source compilable in english version, LANG_MODE in config.h is set to 0 (primary language only)
+
 
 0. clean.sh
 delete all output files
@@ -15,14 +21,13 @@ make_msgs.sh also reports number of messages in each language_xx.h file and tota
 2. find_msgs.sh
 Find usage of each message and output listing in to file msgs_usage.txt in format: MSG_xx nn.
 MSG_xx is identifier, nn is number of occurrences. Output is sorted by number of occurrences (ascending order).
+Generate filtered msgs_en.txt and msgs_common.txt files. Each file is sorted to three output files - unused, used once and used more.
+Output files will be:
+ msgs_common_unused.txt, msgs_common_used_more.txt, msgs_common_used_once.txt
+ msgs_en_unused.txt, msgs_en_used_more.txt, msgs_en_used_once.txt
 
-3. replace_msgs.sh
-List all unused messages to file msgs_unused.txt.
+3. make_source.sh
 Copy all source files to folder ./source
-Replace all single-used messages in all ./source/*.c* files directly with the english version string constant and comment at end of line.
+Replace all messages used once in all ./source/*.c* files directly with the english version string constant and comment at end of line.
 Generate messages.h and messages.c source files with messages used twice and more.
-
-4. upgrade.sh
-Backup (move) all language*.h and language*.cpp files from source to folder '../backup'.
-Copy folder ./source/*.* to ../Firmware, new files will be messages.h, messages.c, language.h and other source will be replaced.
-After this step should be source compilable in english version, LANG_MODE in config.h is set to LANG_MODE_SINGLE.
+Replace line '' in Marlin_main.cpp with comment.

+ 27 - 0
lang_upgrade/src/config.h

@@ -0,0 +1,27 @@
+#ifndef _CONFIG_H
+#define _CONFIG_H
+
+
+//ADC configuration
+#define ADC_CHAN_MSK      0b0000001001011111 //used AD channels bit mask (0,1,2,3,4,6,9)
+#define ADC_CHAN_CNT      7         //number of used channels)
+#define ADC_OVRSAMPL      16        //oversampling multiplier
+#define ADC_CALLBACK      adc_ready //callback function ()
+
+//SM4 configuration
+#define SM4_DEFDELAY      500       //default step delay [us]
+
+//TMC2130 - Trinamic stepper driver
+//pinout - hardcoded
+//spi:
+#define TMC2130_SPI_RATE       0 // fosc/4 = 4MHz
+#define TMC2130_SPCR           SPI_SPCR(TMC2130_SPI_RATE, 1, 1, 1, 0)
+#define TMC2130_SPSR           SPI_SPSR(TMC2130_SPI_RATE)
+
+//LANG - Multi-language support
+#define LANG_MODE               0 // primary language only
+//#define LANG_MODE               1 // sec. language support
+#define LANG_SIZE_RESERVED 0x3000 // reserved space for secondary language (12kb)
+
+
+#endif //_CONFIG_H

+ 63 - 0
lang_upgrade/src/language.c

@@ -0,0 +1,63 @@
+//language.c
+#include "language.h"
+#include <inttypes.h>
+#include <avr/pgmspace.h>
+
+
+// Currectly active language selection.
+unsigned char lang_selected = 0;
+
+#if (LANG_MODE == 0) //primary language only
+#else //(LANG_MODE == 0)
+//reserved xx kbytes for secondary language table
+static const char _SEC_LANG[LANG_SIZE_RESERVED] PROGMEM_I2 = "_SEC_LANG";
+#endif //(LANG_MODE == 0)
+
+//lang_table_t structure - 16byte header
+typedef struct
+{
+	struct
+	{
+		uint32_t magic;
+		uint16_t size;
+		uint16_t count;
+		uint16_t checksum;
+		uint16_t reserved0;
+		uint32_t reserved1;
+	} header;
+	uint16_t table[];
+} lang_table_t;
+
+//lang_table pointer
+lang_table_t* lang_table = 0;
+
+
+const char* lang_get_translation(const char* s)
+{
+	if (lang_selected == 0) return s + 2; //primary language selected
+	if (lang_table == 0) return s + 2; //sec. lang table not found
+	uint16_t ui = pgm_read_word(((uint16_t*)s)); //read string id
+	if (ui == 0xffff) return s + 2; //translation not found
+	ui = pgm_read_word(((uint16_t*)(((char*)lang_table + 16 + ui*2)))); //read relative offset
+	return (const char*)((char*)lang_table + ui + 16); //return calculated pointer
+}
+
+const char* lang_select(unsigned char lang)
+{
+#if (LANG_MODE == 0) //primary language only
+	return 0;
+#else //(LANG_MODE == 0)
+	if (lang == 0) //primary language
+	{
+		lang_table = 0;
+		lang_selected = 0;
+		return;
+	}
+	uint16_t ui = (uint16_t)&_SEC_LANG; //pointer to _SEC_LANG reserved space
+	ui += 0x0100; //add 1 page
+	ui &= 0xff00; //align to page
+	lang_table = ui; //set table pointer
+	ui = pgm_read_word(((uint16_t*)(((char*)lang_table + 16)))); //read relative offset of first string (language name)
+	return (const char*)((char*)lang_table + ui + 16); //return calculated pointer
+#endif //(LANG_MODE == 0)
+}

+ 87 - 0
lang_upgrade/src/language.h

@@ -0,0 +1,87 @@
+//language.h
+#ifndef LANGUAGE_H
+#define LANGUAGE_H
+
+#include "config.h"
+
+#define PROTOCOL_VERSION "1.0"
+
+#ifdef CUSTOM_MENDEL_NAME
+   // #define CUSTOM_MENDEL_NAME CUSTOM_MENDEL_NAME
+#else
+    #define MACHINE_NAME "Mendel"
+#endif
+
+#ifndef MACHINE_UUID
+   #define MACHINE_UUID "00000000-0000-0000-0000-000000000000"
+#endif
+
+#define MSG_FW_VERSION                   "Firmware"
+
+#define STRINGIFY_(n) #n
+#define STRINGIFY(n) STRINGIFY_(n)
+
+#if (LANG_MODE == 0)
+//#define _i PSTR
+//#define _I(s) (__extension__({static const char __c[] __attribute__((section("Txt_i"))) = s; &__c[0];}))
+#endif //(LANG_MODE == 0)
+
+//section progmem0 will be used for localized translated strings
+#define PROGMEM_I2 __attribute__((section(".progmem0")))
+//section progmem1 will be used for localized strings in english
+#define PROGMEM_I1 __attribute__((section(".progmem1")))
+//section progmem2 will be used for not localized strings in english
+#define PROGMEM_N1 __attribute__((section(".progmem2")))
+
+#if (LANG_MODE == 0) //primary language only
+#define _I(s) (__extension__({static const char __c[] PROGMEM_I1 = s; &__c[0];}))
+#define ISTR(s) s
+#define _i(s) _I(s)
+#define _T(s) s
+#else //(LANG_MODE == 0)
+#define _I(s) (__extension__({static const char __c[] PROGMEM_I1 = "\xff\xff"s; &__c[0];}))
+#define ISTR(s) "\xff\xff"s
+#define _i(s) lang_get_translation(_I(s))
+#define _T(s) lang_get_translation(s)
+#endif //(LANG_MODE == 0)
+#define _N(s) (__extension__({static const char __c[] PROGMEM_N1 = s; &__c[0];}))
+#define _n(s) _N(s)
+
+
+// Language indices into their particular symbol tables.
+#define LANG_ID_EN 0
+#define LANG_ID_CZ 1
+// Language is not defined and it shall be selected from the menu.
+#define LANG_ID_FORCE_SELECTION 254
+// Language is not defined on a virgin RAMBo board.
+#define LANG_ID_UNDEFINED 255
+
+// Default language ID, if no language is selected.
+#define LANG_ID_DEFAULT LANG_ID_CZ
+
+// Number of languages available in the language table.
+#define LANG_NUM 2
+
+
+#if defined(__cplusplus)
+extern "C" {
+#endif //defined(__cplusplus)
+
+// Currectly active language selection.
+extern unsigned char lang_selected;
+
+extern const char* lang_get_translation(const char* s);
+extern const char* lang_select(unsigned char lang);
+
+#if defined(__cplusplus)
+}
+#endif //defined(__cplusplus)
+
+#define CAT2(_s1, _s2) _s1
+#define CAT4(_s1, _s2, _s3, _s4) _s1
+#define MSG_LANGUAGE_NAME_EXPLICIT(i) ((i==0)?PSTR("ENG"):PSTR("CZE"))
+
+#include "messages.h"
+
+#endif //__LANGUAGE_H
+

+ 9 - 0
lang_upgrade/src/messages.c

@@ -0,0 +1,9 @@
+//messages.c
+#include "language.h"
+
+//this is because we need include Configuration_prusa.h (CUSTOM_MENDEL_NAME)
+#define bool char
+#define true 1
+#define false 0
+#include "Configuration_prusa.h"
+

+ 6 - 0
lang_upgrade/src/messages.h

@@ -0,0 +1,6 @@
+//messages.h
+
+// Common serial messages
+#define MSG_MARLIN "Marlin"
+
+// LCD Menu Messages