+
+void cli_putstr(char* s){
+ if(!cli_tx)
+ return;
+ while(*s)
+ cli_tx(*s++);
+}
+
+void cli_putstr_P(PGM_P s){
+ char c;
+ if(!cli_tx)
+ return;
+ for(;;){
+ c = pgm_read_byte(s++);
+ if(!c)
+ return;
+ cli_tx(c);
+ }
+}
+
+void cli_hexdump(void* data, uint16_t length){
+ char hex_tab[] = {'0', '1', '2', '3',
+ '4', '5', '6', '7',
+ '8', '9', 'A', 'B',
+ 'C', 'D', 'E', 'F'};
+ if(!cli_tx)
+ return;
+ while(length--){
+ cli_tx(hex_tab[(*((uint8_t*)data))>>4]);
+ cli_tx(hex_tab[(*((uint8_t*)data))&0xf]);
+ data = (uint8_t*)data +1;
+ }
+}
+
+void cli_hexdump2(void* data, uint16_t length){
+ char hex_tab[] = {'0', '1', '2', '3',
+ '4', '5', '6', '7',
+ '8', '9', 'A', 'B',
+ 'C', 'D', 'E', 'F'};
+ if(!cli_tx)
+ return;
+ while(length--){
+ cli_tx(hex_tab[(*((uint8_t*)data))>>4]);
+ cli_tx(hex_tab[(*((uint8_t*)data))&0xf]);
+ cli_tx(' ');
+ data = (uint8_t*)data +1;
+ }
+}
+
+static
+void cli_auto_help(uint16_t maxcmdlength, PGM_VOID_P cmdlist){
+ cmdlist_entry_t item;
+ uint16_t i;
+ if(!cli_tx)
+ return;
+
+ cli_putstr_P(PSTR("\r\n[auto help] available commands:\r\n"
+ " <command> - <params> - <address>\r\n"));
+ for(;;){
+ item.cmd_name = (void*)pgm_read_word(cmdlist+0);
+ item.cmd_param_str = (void*)pgm_read_word(cmdlist+2);
+ item.cmd_function = (void_fpt)pgm_read_word(cmdlist+4);
+ cmdlist = (uint8_t*)cmdlist+CMDLIST_ENTRY_SIZE;
+ if(item.cmd_name==NULL){
+ return;
+ }
+ cli_tx(' ');
+ cli_putstr_P(item.cmd_name);
+ i=maxcmdlength-strlen_P(item.cmd_name);
+ while(i--)
+ cli_tx(' ');
+ cli_putstr_P(PSTR(" - "));
+ if(item.cmd_param_str==NULL){
+ cli_putstr_P(PSTR("none \t- 0x"));
+ } else {
+ if(item.cmd_param_str==(void*)1){
+ cli_putstr_P(PSTR("yes \t- 0x"));
+ } else {
+ cli_putstr_P(item.cmd_param_str);
+ cli_putstr_P(PSTR(" \t- 0x"));
+ }