Quellcode durchsuchen

usart init service soft

balbekova vor 7 Jahren
Ursprung
Commit
f280464ac7

+ 3 - 8
service_hw/Commands/bt_6701_commands.c

@@ -25,7 +25,7 @@
 #include "sntp.h"
 #include "d_inouts.h"
 #include "config_service.h"
-#include "ports.h"
+#include "usart.h"
 
 #include "FreeRTOS.h"
 #include "task.h"
@@ -64,25 +64,20 @@ void TestProcessing(void)
   */
 void Test_U232(void)
 {
-    // Подготавливаем буферы приема и счетчики байт
-    memset(recvBufRS232, 0, RS232_MAX_REC_LEN);
-    indexRS232 = 0;
-    
     // Отправляем символы в RS232
     for (uint16_t i = 0; i < 1023; i++)
-        RS232_SendByte('A');
+    	ups_putchar('A');
   
     vTaskDelay(10);
     
   
     for (uint16_t i = 0; i < 1023; i++)
     {
-        if (recvBufRS232[i] != 'A') {
+        if (ups_getchar(10) != 'A') {
             printf("U232 FAIL\r\n");
             TEST_SetTest(TEST_WAIT);
             return;
         }
-          
     }  
     
     printf("U232 OK\r\n");

+ 34 - 0
service_hw/Commands/commands_api.c

@@ -52,10 +52,17 @@ bool macIsInstalled = false;
 bool fUpdatable = false;
 bool fDefPressed = false;
 
+bool testEthernet = false;
+bool testRtc = false;
+bool testSerno = false;
+bool testT2Ready = false;
+bool testSet = false;
+
 #define MSG_LEN   300
 char msg[MSG_LEN];
 
 extern char STM_ID[33];
+uint8_t MAC[6];
 
 /**
   * @brief  
@@ -245,6 +252,33 @@ void COM_TestSerno(void)
   }
 }
 
+/**
+  * @brief  Устанавливает mac адрес исходя из unique id
+  */
+void COM_SetMAC(void)
+{
+  uint8_t octet1 = 0;
+  uint8_t octet2 = 0;
+  uint8_t octet3 = 0;
+
+  for (uint8_t i = 0; i < 4; i++)
+  {
+    octet1 ^= STM_ID[i];
+	octet2 ^= STM_ID[i + 4];
+	octet3 ^= STM_ID[i + 8];
+  }
+
+  /* Восьмой бит первого октета должен быть равен 0 */
+
+  MAC[0] = octet1 & 0xFE;
+  MAC[1] = octet2;
+  MAC[2] = octet3;
+
+  MAC[3] = 0x00;
+  MAC[4] = 0x00;
+  MAC[5] = 0x00;
+}
+
 /**
   * @brief  Установить статут тестирования (T0, T1, etc)
   */

+ 5 - 0
service_hw/Commands/commands_api.h

@@ -83,6 +83,11 @@ void COM_ReadTestState(void);
   */
 void COM_TestSerno(void);
 
+/**
+  * @brief  Устанавливает mac адрес исходя из unique id
+  */
+void COM_SetMAC(void);
+
 /**
   * @brief  Установить статут тестирования (T0, T1, etc)
   */

+ 102 - 0
service_hw/Console/config.h

@@ -0,0 +1,102 @@
+/**
+Microrl library config files
+Autor: Eugene Samoylov aka Helius (ghelius@gmail.com)
+*/
+#ifndef _MICRORL_CONFIG_H_
+#define _MICRORL_CONFIG_H_
+
+#define MICRORL_LIB_VER "1.5.1"
+
+/*********** CONFIG SECTION **************/
+/*
+Command line length, define cmdline buffer size. Set max number of chars + 1,
+because last byte of buffer need to contain '\0' - NULL terminator, and 
+not use for storing inputed char.
+If user input chars more then it parametrs-1, chars not added to command line.*/
+#define _COMMAND_LINE_LEN (1+100)									// for 32 chars
+
+/*
+Command token number, define max token it command line, if number of token 
+typed in command line exceed this value, then prints message about it and
+command line not to be parced and 'execute' callback will not calls.
+Token is word separate by white space, for example 3 token line:
+"IRin> set mode test" */
+#define _COMMAND_TOKEN_NMB 8
+
+/*
+Define you prompt string here. You can use colors escape code, for highlight you prompt,
+for example this prompt will green color (if you terminal supports color)*/
+#define _PROMPT_DEFAULT "\033[32mBT-6037v2 >\033[0m "	// green color
+
+/*
+Define prompt text (without ESC sequence, only text) prompt length, it needs because if you use
+ESC sequence, it's not possible detect only text length*/
+#define _PROMPT_LEN       12
+
+/*Define it, if you wanna use completion functional, also set completion callback in you code,
+now if user press TAB calls 'copmlitetion' callback. If you no need it, you can just set 
+NULL to callback ptr and do not use it, but for memory saving tune, 
+if you are not going to use it - disable this define.*/
+#define _USE_COMPLETE
+
+/*Define it, if you wanna use history. It s work's like bash history, and
+set stored value to cmdline, if UP and DOWN key pressed. Using history add
+memory consuming, depends from _RING_HISTORY_LEN parametr */
+#define _USE_HISTORY
+
+/*
+History ring buffer length, define static buffer size.
+For saving memory, each entered cmdline store to history in ring buffer,
+so we can not say, how many line we can store, it depends from cmdline len,
+but memory using more effective. We not prefer dinamic memory allocation for
+small and embedded devices. Overhead is 2 char on each saved line*/
+#define _RING_HISTORY_LEN 64
+
+/*
+Enable Handling terminal ESC sequence. If disabling, then cursor arrow, HOME, END will not work,
+use Ctrl+A(B,F,P,N,A,E,H,K,U,C) see README, but decrease code memory.*/
+#define _USE_ESC_SEQ
+
+/*
+Use snprintf from you standard complier library, but it gives some overhead.
+If not defined, use my own u16int_to_str variant, it's save about 800 byte of code size
+on AVR (avr-gcc build).
+Try to build with and without, and compare total code size for tune library.
+*/
+#define _USE_LIBC_STDIO
+
+/*
+Enable 'interrupt signal' callback, if user press Ctrl+C */
+#define _USE_CTLR_C
+
+/*
+Print prompt at 'microrl_init', if enable, prompt will print at startup, 
+otherwise first prompt will print after first press Enter in terminal
+NOTE!: Enable it, if you call 'microrl_init' after your communication subsystem 
+already initialize and ready to print message */
+#undef _ENABLE_INIT_PROMPT
+
+/*
+New line symbol */
+#define _ENDL_CR
+
+#if defined(_ENDL_CR)
+#define ENDL "\r"
+#elif defined(_ENDL_CRLF)
+#define ENDL "\r\n"
+#elif defined(_ENDL_LF)
+#define ENDL "\n"
+#elif defined(_ENDL_LFCR)
+#define ENDL "\n\r"
+#else
+#error "You must define new line symbol."
+#endif
+
+/********** END CONFIG SECTION ************/
+
+
+#if _RING_HISTORY_LEN > 256
+#error "This history implementation (ring buffer with 1 byte iterator) allow 256 byte buffer size maximum"
+#endif
+
+#endif

+ 681 - 0
service_hw/Console/microrl.c

@@ -0,0 +1,681 @@
+/**
+Author: Samoylov Eugene aka Helius (ghelius@gmail.com)
+BUGS and TODO:
+-- add echo_off feature
+-- rewrite history for use more than 256 byte buffer
+*/
+
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include "microrl.h"
+#ifdef _USE_LIBC_STDIO
+#include <stdio.h>
+#endif
+
+//#define DBG(...) fprintf(stderr, "\033[33m");fprintf(stderr,__VA_ARGS__);fprintf(stderr,"\033[0m");
+
+char * prompt_default = _PROMPT_DEFAULT;
+
+#ifdef _USE_HISTORY
+
+#ifdef _HISTORY_DEBUG
+//*****************************************************************************
+// print buffer content on screen
+static void print_hist (ring_history_t * pThis)
+{
+	printf ("\n");
+	for (int i = 0; i < _RING_HISTORY_LEN; i++) {
+		if (i == pThis->begin)
+			printf ("b");
+		else 
+			printf (" ");
+	}
+	printf ("\n");
+	for (int i = 0; i < _RING_HISTORY_LEN; i++) {
+		if (isalpha(pThis->ring_buf[i]))
+			printf ("%c", pThis->ring_buf[i]);
+		else 
+			printf ("%d", pThis->ring_buf[i]);
+	}
+	printf ("\n");
+	for (int i = 0; i < _RING_HISTORY_LEN; i++) {
+		if (i == pThis->end)
+			printf ("e");
+		else 
+			printf (" ");
+	}
+	printf ("\n");
+}
+#endif
+
+//*****************************************************************************
+// remove older message from ring buffer
+static void hist_erase_older (ring_history_t * pThis)
+{
+	int new_pos = pThis->begin + pThis->ring_buf [pThis->begin] + 1;
+	if (new_pos >= _RING_HISTORY_LEN)
+		new_pos = new_pos - _RING_HISTORY_LEN;
+	
+	pThis->begin = new_pos;
+}
+
+//*****************************************************************************
+// check space for new line, remove older while not space
+static int hist_is_space_for_new (ring_history_t * pThis, int len)
+{
+	if (pThis->ring_buf [pThis->begin] == 0)
+		return true;
+	if (pThis->end >= pThis->begin) {
+		if (_RING_HISTORY_LEN - pThis->end + pThis->begin - 1 > len)
+			return true;
+	}	else {
+		if (pThis->begin - pThis->end - 1> len)
+			return true;
+	}
+	return false;
+}
+
+//*****************************************************************************
+// put line to ring buffer
+static void hist_save_line (ring_history_t * pThis, char * line, int len)
+{
+	if (len > _RING_HISTORY_LEN - 2)
+		return;
+	while (!hist_is_space_for_new (pThis, len)) {
+		hist_erase_older (pThis);
+	}
+	// if it's first line
+	if (pThis->ring_buf [pThis->begin] == 0) 
+		pThis->ring_buf [pThis->begin] = len;
+	
+	// store line
+	if (len < _RING_HISTORY_LEN-pThis->end-1)
+		memcpy (pThis->ring_buf + pThis->end + 1, line, len);
+	else {
+		int part_len = _RING_HISTORY_LEN-pThis->end-1;
+		memcpy (pThis->ring_buf + pThis->end + 1, line, part_len);
+		memcpy (pThis->ring_buf, line + part_len, len - part_len);
+	}
+	pThis->ring_buf [pThis->end] = len;
+	pThis->end = pThis->end + len + 1;
+	if (pThis->end >= _RING_HISTORY_LEN)
+		pThis->end -= _RING_HISTORY_LEN;
+	pThis->ring_buf [pThis->end] = 0;
+	pThis->cur = 0;
+#ifdef _HISTORY_DEBUG
+	print_hist (pThis);
+#endif
+}
+
+//*****************************************************************************
+// copy saved line to 'line' and return size of line
+static int hist_restore_line (ring_history_t * pThis, char * line, int dir)
+{
+	int cnt = 0;
+	// count history record	
+	int header = pThis->begin;
+	while (pThis->ring_buf [header] != 0) {
+		header += pThis->ring_buf [header] + 1;
+		if (header >= _RING_HISTORY_LEN)
+			header -= _RING_HISTORY_LEN; 
+		cnt++;
+	}
+
+	if (dir == _HIST_UP) {
+		if (cnt >= pThis->cur) {
+			int header = pThis->begin;
+			int j = 0;
+			// found record for 'pThis->cur' index
+			while ((pThis->ring_buf [header] != 0) && (cnt - j -1 != pThis->cur)) {
+				header += pThis->ring_buf [header] + 1;
+				if (header >= _RING_HISTORY_LEN)
+					header -= _RING_HISTORY_LEN;
+				j++;
+			}
+			if (pThis->ring_buf[header]) {
+					pThis->cur++;
+				// obtain saved line
+				if (pThis->ring_buf [header] + header < _RING_HISTORY_LEN) {
+					memset (line, 0, _COMMAND_LINE_LEN);
+					memcpy (line, pThis->ring_buf + header + 1, pThis->ring_buf[header]);
+				} else {
+					int part0 = _RING_HISTORY_LEN - header - 1;
+					memset (line, 0, _COMMAND_LINE_LEN);
+					memcpy (line, pThis->ring_buf + header + 1, part0);
+					memcpy (line + part0, pThis->ring_buf, pThis->ring_buf[header] - part0);
+				}
+				return pThis->ring_buf[header];
+			}
+		}
+	} else {
+		if (pThis->cur > 0) {
+				pThis->cur--;
+			int header = pThis->begin;
+			int j = 0;
+
+			while ((pThis->ring_buf [header] != 0) && (cnt - j != pThis->cur)) {
+				header += pThis->ring_buf [header] + 1;
+				if (header >= _RING_HISTORY_LEN)
+					header -= _RING_HISTORY_LEN;
+				j++;
+			}
+			if (pThis->ring_buf [header] + header < _RING_HISTORY_LEN) {
+				memcpy (line, pThis->ring_buf + header + 1, pThis->ring_buf[header]);
+			} else {
+				int part0 = _RING_HISTORY_LEN - header - 1;
+				memcpy (line, pThis->ring_buf + header + 1, part0);
+				memcpy (line + part0, pThis->ring_buf, pThis->ring_buf[header] - part0);
+			}
+			return pThis->ring_buf[header];
+		} else {
+			/* empty line */
+			return 0;
+		}
+	}
+	return -1;
+}
+#endif
+
+
+
+
+
+
+
+
+//*****************************************************************************
+// split cmdline to tkn array and return nmb of token
+static int split (microrl_t * pThis, int limit, char const ** tkn_arr)
+{
+	int i = 0;
+	int ind = 0;
+	while (1) {
+		// go to the first whitespace (zerro for us)
+		while ((pThis->cmdline [ind] == '\0') && (ind < limit)) {
+			ind++;
+		}
+		if (!(ind < limit)) return i;
+		tkn_arr[i++] = pThis->cmdline + ind;
+		if (i >= _COMMAND_TOKEN_NMB) {
+			return -1;
+		}
+		// go to the first NOT whitespace (not zerro for us)
+		while ((pThis->cmdline [ind] != '\0') && (ind < limit)) {
+			ind++;
+		}
+		if (!(ind < limit)) return i;
+	}
+	return i;
+}
+
+
+//*****************************************************************************
+inline static void print_prompt (microrl_t * pThis)
+{
+	//pThis->print (pThis->prompt_str);
+  printf(pThis->prompt_str);
+}
+
+//*****************************************************************************
+inline static void terminal_backspace (microrl_t * pThis)
+{
+		pThis->print ("\033[D \033[D");
+}
+
+//*****************************************************************************
+inline static void terminal_newline (microrl_t * pThis)
+{
+	pThis->print (ENDL);
+}
+
+#ifndef _USE_LIBC_STDIO
+//*****************************************************************************
+// convert 16 bit value to string
+// 0 value not supported!!! just make empty string
+// Returns pointer to a buffer tail
+static char *u16bit_to_str (unsigned int nmb, char * buf)
+{
+	char tmp_str [6] = {0,};
+	int i = 0, j;
+	if (nmb <= 0xFFFF) {
+		while (nmb > 0) {
+			tmp_str[i++] = (nmb % 10) + '0';
+			nmb /=10;
+		}
+		for (j = 0; j < i; ++j)
+			*(buf++) = tmp_str [i-j-1];
+	}
+	*buf = '\0';
+	return buf;
+}
+#endif
+
+
+//*****************************************************************************
+// set cursor at position from begin cmdline (after prompt) + offset
+static void terminal_move_cursor (microrl_t * pThis, int offset)
+{
+	char str[16] = {0,};
+#ifdef _USE_LIBC_STDIO 
+	if (offset > 0) {
+		snprintf (str, 16, "\033[%dC", offset);
+	} else if (offset < 0) {
+		snprintf (str, 16, "\033[%dD", -(offset));
+	}
+#else 
+	char *endstr;
+	strcpy (str, "\033[");
+	if (offset > 0) {
+		endstr = u16bit_to_str (offset, str+2);
+		strcpy (endstr, "C");
+	} else if (offset < 0) {
+		endstr = u16bit_to_str (-(offset), str+2);
+		strcpy (endstr, "D");
+	} else
+		return;
+#endif	
+	pThis->print (str);
+}
+
+//*****************************************************************************
+static void terminal_reset_cursor (microrl_t * pThis)
+{
+	char str[16];
+#ifdef _USE_LIBC_STDIO
+	snprintf (str, 16, "\033[%dD\033[%dC", \
+						_COMMAND_LINE_LEN + _PROMPT_LEN + 2, _PROMPT_LEN);
+
+#else
+	char *endstr;
+	strcpy (str, "\033[");
+	endstr = u16bit_to_str ( _COMMAND_LINE_LEN + _PROMPT_LEN + 2,str+2);
+	strcpy (endstr, "D\033["); endstr += 3;
+	endstr = u16bit_to_str (_PROMPT_LEN, endstr);
+	strcpy (endstr, "C");
+#endif
+	pThis->print (str);
+}
+
+//*****************************************************************************
+// print cmdline to screen, replace '\0' to wihitespace 
+static void terminal_print_line (microrl_t * pThis, int pos, int cursor)
+{
+	pThis->print ("\033[K");    // delete all from cursor to end
+
+	char nch [] = {0,0};
+	int i;
+	for (i = pos; i < pThis->cmdlen; i++) {
+		nch [0] = pThis->cmdline [i];
+		if (nch[0] == '\0')
+			nch[0] = ' ';
+		pThis->print (nch);
+	}
+	
+	terminal_reset_cursor (pThis);
+	terminal_move_cursor (pThis, cursor);
+}
+
+//*****************************************************************************
+void microrl_init (microrl_t * pThis, void (*print) (const char *)) 
+{
+	memset(pThis->cmdline, 0, _COMMAND_LINE_LEN);
+#ifdef _USE_HISTORY
+	memset(pThis->ring_hist.ring_buf, 0, _RING_HISTORY_LEN);
+	pThis->ring_hist.begin = 0;
+	pThis->ring_hist.end = 0;
+	pThis->ring_hist.cur = 0;
+#endif
+	pThis->cmdlen =0;
+	pThis->cursor = 0;
+	pThis->execute = NULL;
+	pThis->get_completion = NULL;
+#ifdef _USE_CTLR_C
+	pThis->sigint = NULL;
+#endif
+	pThis->prompt_str = prompt_default;
+	pThis->print = print;
+#ifdef _ENABLE_INIT_PROMPT
+	print_prompt (pThis);
+#endif
+}
+
+//*****************************************************************************
+void microrl_set_complete_callback (microrl_t * pThis, char ** (*get_completion)(int, const char* const*))
+{
+	pThis->get_completion = get_completion;
+}
+
+//*****************************************************************************
+void microrl_set_execute_callback (microrl_t * pThis, int (*execute)(int, const char* const*))
+{
+	pThis->execute = execute;
+}
+#ifdef _USE_CTLR_C
+//*****************************************************************************
+void microrl_set_sigint_callback (microrl_t * pThis, void (*sigintf)(void))
+{
+	pThis->sigint = sigintf;
+}
+#endif
+
+#ifdef _USE_ESC_SEQ
+static void hist_search (microrl_t * pThis, int dir)
+{
+	int len = hist_restore_line (&pThis->ring_hist, pThis->cmdline, dir);
+	if (len >= 0) {
+		pThis->cursor = pThis->cmdlen = len;
+		terminal_reset_cursor (pThis);
+		terminal_print_line (pThis, 0, pThis->cursor);
+	}
+}
+
+//*****************************************************************************
+// handling escape sequences
+static int escape_process (microrl_t * pThis, char ch)
+{
+	if (ch == '[') {
+		pThis->escape_seq = _ESC_BRACKET;
+		return 0;
+	} else if (pThis->escape_seq == _ESC_BRACKET) {
+		if (ch == 'A') {
+#ifdef _USE_HISTORY
+			hist_search (pThis, _HIST_UP);
+#endif
+			return 1;
+		} else if (ch == 'B') {
+#ifdef _USE_HISTORY
+			hist_search (pThis, _HIST_DOWN);
+#endif
+			return 1;
+		} else if (ch == 'C') {
+			if (pThis->cursor < pThis->cmdlen) {
+				terminal_move_cursor (pThis, 1);
+				pThis->cursor++;
+			}
+			return 1;
+		} else if (ch == 'D') {
+			if (pThis->cursor > 0) {
+				terminal_move_cursor (pThis, -1);
+				pThis->cursor--;
+			}
+			return 1;
+		} else if (ch == '7') {
+			pThis->escape_seq = _ESC_HOME;
+			return 0;
+		} else if (ch == '8') {
+			pThis->escape_seq = _ESC_END;
+			return 0;
+		} 
+	} else if (ch == '~') {
+		if (pThis->escape_seq == _ESC_HOME) {
+			terminal_reset_cursor (pThis);
+			pThis->cursor = 0;
+			return 1;
+		} else if (pThis->escape_seq == _ESC_END) {
+			terminal_move_cursor (pThis, pThis->cmdlen-pThis->cursor);
+			pThis->cursor = pThis->cmdlen;
+			return 1;
+		}
+	}
+
+	/* unknown escape sequence, stop */
+	return 1;
+}
+#endif
+
+//*****************************************************************************
+// insert len char of text at cursor position
+static int microrl_insert_text (microrl_t * pThis, char * text, int len)
+{
+	int i;
+	if (pThis->cmdlen + len < _COMMAND_LINE_LEN) {
+		memmove (pThis->cmdline + pThis->cursor + len,
+						 pThis->cmdline + pThis->cursor,
+						 pThis->cmdlen - pThis->cursor);
+		for (i = 0; i < len; i++) {
+			pThis->cmdline [pThis->cursor + i] = text [i];
+			if (pThis->cmdline [pThis->cursor + i] == ' ') {
+				pThis->cmdline [pThis->cursor + i] = 0;
+			}
+		}
+		pThis->cursor += len;
+		pThis->cmdlen += len;
+		pThis->cmdline [pThis->cmdlen] = '\0';
+		return true;
+	}
+	return false;
+}
+
+//*****************************************************************************
+// remove one char at cursor
+static void microrl_backspace (microrl_t * pThis)
+{
+	if (pThis->cursor > 0) {
+		terminal_backspace (pThis);
+		memmove (pThis->cmdline + pThis->cursor-1,
+						 pThis->cmdline + pThis->cursor,
+						 pThis->cmdlen-pThis->cursor+1);
+		pThis->cursor--;
+		pThis->cmdline [pThis->cmdlen] = '\0';
+		pThis->cmdlen--;
+	}
+}
+
+
+#ifdef _USE_COMPLETE
+
+//*****************************************************************************
+static int common_len (char ** arr)
+{
+	int len = 0;
+	int i = 1;
+	while (1) {
+		while (arr[i]!=NULL) {
+			if ((arr[i][len] != arr[i-1][len]) || 
+					(arr[i][len] == '\0') || 
+					(arr[i-1][len]=='\0')) 
+				return len;
+			len++;
+		}
+		i++;
+	}
+	return 0;
+}
+
+//*****************************************************************************
+static void microrl_get_complite (microrl_t * pThis) 
+{
+	char const * tkn_arr[_COMMAND_TOKEN_NMB];
+	char ** compl_token; 
+	
+	if (pThis->get_completion == NULL) // callback was not set
+		return;
+	
+	int status = split (pThis, pThis->cursor, tkn_arr);
+	if (pThis->cmdline[pThis->cursor-1] == '\0')
+		tkn_arr[status++] = "";
+	compl_token = pThis->get_completion (status, tkn_arr);
+	if (compl_token[0] != NULL) {
+		int i = 0;
+		int len;
+
+		if (compl_token[1] == NULL) {
+			len = strlen (compl_token[0]);
+		} else {
+			len = common_len (compl_token);
+			terminal_newline (pThis);
+			while (compl_token [i] != NULL) {
+				pThis->print (compl_token[i]);
+				pThis->print (" ");
+				i++;
+			}
+			terminal_newline (pThis);
+			print_prompt (pThis);
+		}
+		
+		if (len) {
+			microrl_insert_text (pThis, compl_token[0] + strlen(tkn_arr[status-1]), 
+																	len - strlen(tkn_arr[status-1]));
+			if (compl_token[1] == NULL) 
+				microrl_insert_text (pThis, " ", 1);
+		}
+		terminal_reset_cursor (pThis);
+		terminal_print_line (pThis, 0, pThis->cursor);
+	} 
+}
+#endif
+
+//*****************************************************************************
+void new_line_handler(microrl_t * pThis){
+	char const * tkn_arr [_COMMAND_TOKEN_NMB];
+	int status;
+
+	terminal_newline (pThis);
+#ifdef _USE_HISTORY
+	if (pThis->cmdlen > 0)
+		hist_save_line (&pThis->ring_hist, pThis->cmdline, pThis->cmdlen);
+#endif
+	status = split (pThis, pThis->cmdlen, tkn_arr);
+	if (status == -1){
+		//          pThis->print ("ERROR: Max token amount exseed\n");
+		pThis->print ("ERROR:too many tokens");
+		pThis->print (ENDL);
+	}
+	if ((status > 0) && (pThis->execute != NULL))
+		pThis->execute (status, tkn_arr);
+	print_prompt (pThis);
+	pThis->cmdlen = 0;
+	pThis->cursor = 0;
+	memset(pThis->cmdline, 0, _COMMAND_LINE_LEN);
+#ifdef _USE_HISTORY
+	pThis->ring_hist.cur = 0;
+#endif
+}
+
+//*****************************************************************************
+
+void microrl_insert_char (microrl_t * pThis, int ch)
+{
+#ifdef _USE_ESC_SEQ
+	if (pThis->escape) {
+		if (escape_process(pThis, ch))
+			pThis->escape = 0;
+	} else {
+#endif
+		switch (ch) {
+			//-----------------------------------------------------
+#ifdef _ENDL_CR
+			case KEY_CR:
+				new_line_handler(pThis);
+			break;
+			case KEY_LF:
+			break;
+#elif defined(_ENDL_CRLF)
+			case KEY_CR:
+				pThis->tmpch = KEY_CR;
+			break;
+			case KEY_LF:
+			if (pThis->tmpch == KEY_CR)
+				new_line_handler(pThis);
+			break;
+#elif defined(_ENDL_LFCR)
+			case KEY_LF:
+				pThis->tmpch = KEY_LF;
+			break;
+			case KEY_CR:
+			if (pThis->tmpch == KEY_LF)
+				new_line_handler(pThis);
+			break;
+#else
+			case KEY_CR:
+			break;
+			case KEY_LF:
+				new_line_handler(pThis);
+			break;
+#endif
+			//-----------------------------------------------------
+#ifdef _USE_COMPLETE
+			case KEY_HT:
+				microrl_get_complite (pThis);
+			break;
+#endif
+			//-----------------------------------------------------
+			case KEY_ESC:
+#ifdef _USE_ESC_SEQ
+				pThis->escape = 1;
+#endif
+			break;
+			//-----------------------------------------------------
+			case KEY_NAK: // ^U
+					while (pThis->cursor > 0) {
+					microrl_backspace (pThis);
+				}
+				terminal_print_line (pThis, 0, pThis->cursor);
+			break;
+			//-----------------------------------------------------
+			case KEY_VT:  // ^K
+				pThis->print ("\033[K");
+				pThis->cmdlen = pThis->cursor;
+			break;
+			//-----------------------------------------------------
+			case KEY_ENQ: // ^E
+				terminal_move_cursor (pThis, pThis->cmdlen-pThis->cursor);
+				pThis->cursor = pThis->cmdlen;
+			break;
+			//-----------------------------------------------------
+			case KEY_SOH: // ^A
+				terminal_reset_cursor (pThis);
+				pThis->cursor = 0;
+			break;
+			//-----------------------------------------------------
+			case KEY_ACK: // ^F
+			if (pThis->cursor < pThis->cmdlen) {
+				terminal_move_cursor (pThis, 1);
+				pThis->cursor++;
+			}
+			break;
+			//-----------------------------------------------------
+			case KEY_STX: // ^B
+			if (pThis->cursor) {
+				terminal_move_cursor (pThis, -1);
+				pThis->cursor--;
+			}
+			break;
+			//-----------------------------------------------------
+			case KEY_DLE: //^P
+#ifdef _USE_HISTORY
+			hist_search (pThis, _HIST_UP);
+#endif
+			break;
+			//-----------------------------------------------------
+			case KEY_SO: //^N
+#ifdef _USE_HISTORY
+			hist_search (pThis, _HIST_DOWN);
+#endif
+			break;
+			//-----------------------------------------------------
+			case KEY_DEL: // Backspace
+			case KEY_BS: // ^U
+				microrl_backspace (pThis);
+				terminal_print_line (pThis, pThis->cursor, pThis->cursor);
+			break;
+#ifdef _USE_CTLR_C
+			case KEY_ETX:
+			if (pThis->sigint != NULL)
+				pThis->sigint();
+			break;
+#endif
+			//-----------------------------------------------------
+			default:
+			if (((ch == ' ') && (pThis->cmdlen == 0)) || IS_CONTROL_CHAR(ch))
+				break;
+			if (microrl_insert_text (pThis, (char*)&ch, 1))
+				terminal_print_line (pThis, pThis->cursor-1, pThis->cursor);
+			
+			break;
+		}
+#ifdef _USE_ESC_SEQ
+	}
+#endif
+}

+ 118 - 0
service_hw/Console/microrl.h

@@ -0,0 +1,118 @@
+
+#ifndef MICRORL_H_
+#define MICRORL_H_
+
+#include "config.h"
+
+#define true  1
+#define false 0
+
+ /* define the Key codes */
+#define KEY_NUL 0 /**< ^@ Null character */
+#define KEY_SOH 1 /**< ^A Start of heading, = console interrupt */
+#define KEY_STX 2 /**< ^B Start of text, maintenance mode on HP console */
+#define KEY_ETX 3 /**< ^C End of text */
+#define KEY_EOT 4 /**< ^D End of transmission, not the same as ETB */
+#define KEY_ENQ 5 /**< ^E Enquiry, goes with ACK; old HP flow control */
+#define KEY_ACK 6 /**< ^F Acknowledge, clears ENQ logon hand */
+#define KEY_BEL 7 /**< ^G Bell, rings the bell... */
+#define KEY_BS  8 /**< ^H Backspace, works on HP terminals/computers */
+#define KEY_HT  9 /**< ^I Horizontal tab, move to next tab stop */
+#define KEY_LF  10  /**< ^J Line Feed */
+#define KEY_VT  11  /**< ^K Vertical tab */
+#define KEY_FF  12  /**< ^L Form Feed, page eject */
+#define KEY_CR  13  /**< ^M Carriage Return*/
+#define KEY_SO  14  /**< ^N Shift Out, alternate character set */
+#define KEY_SI  15  /**< ^O Shift In, resume defaultn character set */
+#define KEY_DLE 16  /**< ^P Data link escape */
+#define KEY_DC1 17  /**< ^Q XON, with XOFF to pause listings; "okay to send". */
+#define KEY_DC2 18  /**< ^R Device control 2, block-mode flow control */
+#define KEY_DC3 19  /**< ^S XOFF, with XON is TERM=18 flow control */
+#define KEY_DC4 20  /**< ^T Device control 4 */
+#define KEY_NAK 21  /**< ^U Negative acknowledge */
+#define KEY_SYN 22  /**< ^V Synchronous idle */
+#define KEY_ETB 23  /**< ^W End transmission block, not the same as EOT */
+#define KEY_CAN 24  /**< ^X Cancel line, MPE echoes !!! */
+#define KEY_EM  25  /**< ^Y End of medium, Control-Y interrupt */
+#define KEY_SUB 26  /**< ^Z Substitute */
+#define KEY_ESC 27  /**< ^[ Escape, next character is not echoed */
+#define KEY_FS  28  /**< ^\ File separator */
+#define KEY_GS  29  /**< ^] Group separator */
+#define KEY_RS  30  /**< ^^ Record separator, block-mode terminator */
+#define KEY_US  31  /**< ^_ Unit separator */
+
+#define KEY_DEL 127 /**< Delete (not a real control character...) */
+
+#define IS_CONTROL_CHAR(x) ((x)<=31)
+
+// direction of history navigation
+#define _HIST_UP   0
+#define _HIST_DOWN 1
+// esc seq internal codes
+#define _ESC_BRACKET  1
+#define _ESC_HOME     2
+#define _ESC_END      3
+
+#ifdef _USE_HISTORY
+// history struct, contain internal variable
+// history store in static ring buffer for memory saving
+typedef struct {
+	char ring_buf [_RING_HISTORY_LEN];
+	int begin;
+	int end;
+	int cur;
+} ring_history_t;
+#endif
+
+// microrl struct, contain internal library data
+typedef struct {
+#ifdef _USE_ESC_SEQ
+	char escape_seq;
+	char escape;
+#endif
+#if (defined(_ENDL_CRLF) || defined(_ENDL_LFCR))
+	char tmpch;
+#endif
+#ifdef _USE_HISTORY
+	ring_history_t ring_hist;          // history object
+#endif
+	char * prompt_str;                 // pointer to prompt string
+	char cmdline [_COMMAND_LINE_LEN];  // cmdline buffer
+	int cmdlen;                        // last position in command line
+	int cursor;                        // input cursor
+	int (*execute) (int argc, const char * const * argv );            // ptr to 'execute' callback
+	char ** (*get_completion) (int argc, const char * const * argv ); // ptr to 'completion' callback
+	void (*print) (const char *);                                     // ptr to 'print' callback
+#ifdef _USE_CTLR_C
+	void (*sigint) (void);
+#endif
+} microrl_t;
+
+// init internal data, calls once at start up
+void microrl_init (microrl_t * pThis, void (*print)(const char*));
+
+// set echo mode (true/false), using for disabling echo for password input
+// echo mode will enabled after user press Enter.
+void microrl_set_echo (int);
+
+// set pointer to callback complition func, that called when user press 'Tab'
+// callback func description:
+//   param: argc - argument count, argv - pointer array to token string
+//   must return NULL-terminated string, contain complite variant splitted by 'Whitespace'
+//   If complite token found, it's must contain only one token to be complitted
+//   Empty string if complite not found, and multiple string if there are some token
+void microrl_set_complete_callback (microrl_t * pThis, char ** (*get_completion)(int, const char* const*));
+
+// pointer to callback func, that called when user press 'Enter'
+// execute func param: argc - argument count, argv - pointer array to token string
+void microrl_set_execute_callback (microrl_t * pThis, int (*execute)(int, const char* const*));
+
+// set callback for Ctrl+C terminal signal
+#ifdef _USE_CTLR_C
+void microrl_set_sigint_callback (microrl_t * pThis, void (*sigintf)(void));
+#endif
+
+// insert char to cmdline (for example call in usart RX interrupt)
+void microrl_insert_char (microrl_t * pThis, int ch);
+
+#endif

+ 337 - 0
service_hw/Console/port_microrl.c

@@ -0,0 +1,337 @@
+/******************************* (C) LiteMesh **********************************
+ * @module  Console
+ * @file    portConsole.c
+ * @version 1.0.0
+ * @date    XX.XX.XXXX
+ * $brief   Port functions console lib
+ *******************************************************************************
+ * @history     Version  Author         Comment
+ * XX.XX.XXXX   1.0.0    Telenkov D.A.  First release.
+ *******************************************************************************
+ */
+
+#include "stm32f4xx.h" 
+#include "port_microrl.h"
+#include "microrl.h"
+#include "config.h"
+#include "sntp.h"
+#include "gpio.h"
+#include "bt_6701_settings.h"
+#include "commands_api.h"
+
+#ifdef PRINTF_STDLIB
+#include <stdio.h>
+#endif
+#ifdef PRINTF_CUSTOM
+#include "tinystdio.h"
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+#define _AVR_DEMO_VER "1.0"
+
+// definition commands word
+#define _CMD_HELP        "help"
+#define _CMD_CLEAR       "clear"
+#define _CMD_CLR         "clear_port"
+#define _CMD_LED         "led"
+#define _CMD_ETH         "ETH"
+#define _CMD_PSVOLT      "PSVOLT"
+#define _CMD_LOADVOLT    "LOADVOLT"
+#define _CMD_BATVOLT     "BATVOLT"
+#define _CMD_BATVOLTK    "BATVOLTK"
+#define _CMD_BATVOLTR    "BATVOLTR"
+#define _CMD_BAT1VOLT    "BAT1VOLT"
+#define _CMD_BAT2VOLT    "BAT2VOLT"
+#define _CMD_BAT3VOLT    "BAT3VOLT"
+#define _CMD_BAT4VOLT    "BAT4VOLT"
+#define _CMD_BATCUR      "BATCUR"
+#define _CMD_LOADCUR     "LOADCUR"
+#define _CMD_LOADCURK    "LOADCURK"
+#define _CMD_DIDOOR      "DIDOOR"
+#define _CMD_DIRV        "DIRV"
+#define _CMD_LOW150      "LOW150"
+#define _CMD_HILOW230    "HILOW230"
+#define _CMD_HIGH264     "HIGH264"
+#define _CMD_MPSOFF      "MPSOFF"
+#define _CMD_CANTX       "CANTX"
+#define _CMD_CANRX       "CANRX"
+#define _CMD_DAC         "DAC"
+#define _CMD_SD          "SD"
+#define _CMD_ONEWIRE     "OW"
+#define _CMD_SET         "SET"
+#define _CMD_DEF         "DEF"
+#define _CMD_RTC         "RTC"
+#define _CMD_SERNO       "SERNO"
+
+#define _CMD_STATUS      "STATUS"
+#define _CMD_FREQ        "FREQ"
+#define _CMD_50HZ        "50HZ"
+#define _CMD_LOW         "LOW"
+#define _CMD_HILOW       "HILOW"
+#define _CMD_HI          "HI"
+#define _CMD_T2READY     "T2READY"
+
+#define _CMD_U232U485    "U232U485"
+#define _CMD_DRY         "DRY"
+#define _CMD_U232F       "U232F"
+
+#define _CMD_RST         "reset"
+
+// arguments for set/clear
+#define _SCMD_PB  "port_b"
+#define _SCMD_PD  "port_d"
+
+#define _NUM_OF_CMD 
+#define _NUM_OF_SETCLEAR_SCMD 2
+
+//available  commands
+char * keyworld [] = {
+  _CMD_HELP,
+  _CMD_CLEAR,
+  _CMD_LED,
+  _CMD_ETH,
+  _CMD_PSVOLT,
+  _CMD_LOADVOLT,
+  _CMD_BATVOLT,
+  _CMD_BATVOLTK,
+  _CMD_BATVOLTR,
+  _CMD_BAT1VOLT,
+  _CMD_BAT2VOLT,
+  _CMD_BAT3VOLT,
+  _CMD_BAT4VOLT,
+  _CMD_BATCUR,
+  _CMD_LOADCUR,
+  _CMD_LOADCURK,
+  _CMD_DIDOOR,
+  _CMD_DIRV,
+  _CMD_LOW150,
+  _CMD_HILOW230,
+  _CMD_HIGH264,
+  _CMD_MPSOFF,
+  _CMD_CANTX,
+  _CMD_CANRX,
+  _CMD_DAC,
+  _CMD_SD,
+  _CMD_ONEWIRE,
+  _CMD_SET,
+  _CMD_DEF,
+  _CMD_RTC,
+  _CMD_SERNO,
+  
+  _CMD_STATUS,
+  _CMD_FREQ,
+  _CMD_50HZ,
+  _CMD_LOW,
+  _CMD_HILOW,
+  _CMD_HI,
+  _CMD_T2READY,
+  
+  _CMD_U232U485,
+  _CMD_DRY,
+  _CMD_U232F,
+  
+  _CMD_RST
+};
+
+// 'set/clear' command argements
+char * set_clear_key [] = {_SCMD_PB, _SCMD_PD};
+
+// array for comletion
+char * compl_world [_NUM_OF_CMD + 1];
+
+microrl_t rl;
+microrl_t *prl = &rl;
+
+// параметр команды
+#define PARAM_LEN  20
+char param[PARAM_LEN];
+
+float value = 0.0;
+	
+extern bool testLed;
+extern bool testEthernet;
+extern bool testDef;
+extern bool testSet;
+extern bool testRtc;
+extern bool testSerno;
+extern bool testT2Ready;
+
+/**
+  * @brief  
+  * @retval 
+  */
+void MICRORL_Init(void)
+{
+  microrl_init(prl, print);
+  microrl_set_execute_callback (prl, execute);
+  
+}
+
+/**
+  * @brief  Print callback for microrl library
+  * @retval 
+  */
+void print (const char *str)
+{
+  //printf(str);
+}
+
+/**
+  * @brief  
+  * @retval 
+  */
+void MICRORL_GetChar(uint8_t ch)
+{
+  microrl_insert_char(prl, ch);
+}
+
+//*****************************************************************************
+// execute callback for microrl library
+// do what you want here, but don't write to argv!!! read only!!
+int execute (int argc, const char * const * argv)
+{
+	int i = 0;
+	uint16_t len = 0;
+	
+	// just iterate through argv word and compare it with your commands
+	while (i < argc) 
+	{
+	  memset(param, 0, PARAM_LEN);  
+	  
+	  if (strcmp (argv[i], _CMD_HELP) == 0) 
+      {
+ 		print ("microrl library v");
+		print (MICRORL_LIB_VER);
+		print ("\n\r");
+		print_help ();        // print help
+	  } 
+      else if (strcmp (argv[i], _CMD_CLEAR) == 0) 
+      {
+		print ("\033[2J");    // ESC seq for clear entire screen
+		print ("\033[H");     // ESC seq for move cursor at left-top corner
+	  }  
+	  /* Тестовая команда */
+      else if (strcmp (argv[i], _CMD_LED) == 0) 
+      {
+		//testLed = true;
+		// TODO Убрать затычку
+		printf("STATUS T1OK\r");
+		return 0;
+      } 
+	  /* Тест Ethernet */
+	  else if (strcmp (argv[i], _CMD_ETH) == 0) 
+      {
+        COM_SetMAC();
+		//testEthernet = true;
+        TEST_SetTest(TEST_ETHERNET);
+        print ("\n\r");
+        return 0;
+      }
+	  /* Тест кнопки SET */
+	  else if (strcmp (argv[i], _CMD_SET) == 0) 
+      {
+		testSet = true;
+		print ("\n\r");
+		return 0;
+      }
+	  /* Тест кнопки DEF */
+	  else if (strcmp (argv[i], _CMD_DEF) == 0) 
+      {
+		//testDef = true;
+        TEST_SetTest(TEST_DEF);
+		print ("\n\r");
+		return 0;
+      }
+	  /* Тест RTC */
+	  else if (strcmp (argv[i], _CMD_RTC) == 0) 
+      {
+		if (++i < argc)
+        {
+          len = strlen(argv[i]);
+          strncpy(param, argv[i], len);
+		  SNTP_SetServerAddr(param);
+		  testRtc = true;
+          print ("\n\r");
+          return 0;
+        }
+		print ("\n\r");
+      }
+	  /* Установка SERNO */
+	  else if (strcmp (argv[i], _CMD_SERNO) == 0) 
+      {
+		if (++i < argc)
+        {
+          len = strlen(argv[i]);
+          strncpy(param, argv[i], len);
+		  SETTINGS_SetSerno(param);
+		  //testSerno = true;
+          TEST_SetTest(TEST_SERNO);
+          print ("\n\r");
+          return 0;
+        }
+		print ("\n\r");
+      }
+	  
+      /* -------------------------------------------------------------------- */
+      /*                        Тесты для SmartUPS                            */
+      
+      /* Тест сухих контактов */
+	  else if (strcmp (argv[i], _CMD_DRY) == 0) 
+      {
+		//testSet = true;
+        TEST_SetTest(TEST_DRY);
+		print ("\n\r");
+		return 0;
+      }
+      
+      /* Тест дополнительных пинов RS232 */
+	  else if (strcmp (argv[i], _CMD_U232F) == 0) 
+      {
+		//testSet = true;
+        TEST_SetTest(TEST_U232F);
+		print ("\n\r");
+		return 0;
+      }
+      
+	  /* -------------------------------------------------------------------- */
+	  /*                          Тесты этапа Т2                              */
+	  /* Статус тестера */
+	  else if (strcmp (argv[i], _CMD_STATUS) == 0) 
+      {
+		//printf("STATUS %s\r", sSettings.sFlags.testState);
+        printf("STATUS %s\r", SETTINGS_GetTestState());
+		return 0;
+      }
+	  /* T2READY */
+	  else if (strcmp (argv[i], _CMD_T2READY) == 0) 
+      {
+		testT2Ready = true;		
+		return 0;
+      }
+	  
+	  /* Перезагрузить контроллер */
+      else if (strcmp (argv[i], _CMD_RST) == 0) 
+      {
+        NVIC_SystemReset();
+      }  
+      else 
+      {
+		print ("command: '");
+		print ((char*)argv[i]);
+		print ("' Not found.\n\r");
+	  }
+	  i++;
+	}
+	return 0;
+}
+
+void print_help (void)
+{
+	print ("Use TAB key for completion\n\rCommand:\n\r");
+	print ("\tclear               - clear screen\n\r");
+    print ("\tdac                 - send test value\n\r");
+}
+
+/******************************* (C) LiteMesh *********************************/

+ 20 - 17
service_hw/Ports/ports.h → service_hw/Console/port_microrl.h

@@ -1,9 +1,9 @@
 /******************************* (C) LiteMesh **********************************
- * @module  buttons_api
- * @file    buttons_api.h
+ * @module  Console
+ * @file    portConsole.h
  * @version 1.0.0
  * @date    XX.XX.XXXX
- * $brief   buttons_api
+ * $brief   Port functions console lib
  *******************************************************************************
  * @history     Version  Author         Comment
  * XX.XX.XXXX   1.0.0    Telenkov D.A.  First release.
@@ -11,25 +11,28 @@
  */
 
 /* Define to prevent recursive  ----------------------------------------------*/
-#ifndef __PORTS_H
-#define __PORTS_H
-
-#include <stdbool.h>
-
-#define RS232_PORT       USART3
-
-#define RS232_MAX_REC_LEN   1500
+#ifndef PORT_MICRORL_H
+#define PORT_MICRORL_H
+ 
+/**
+  * @brief  
+  */
+void MICRORL_Init(void);
 
 /**
   * @brief  
   */
-void RS232_Init(void);
+void MICRORL_GetChar(uint8_t ch);
+
+/**
+  * @brief  Print callback for microrl library
+  */
+void print (const char * str);
 
-void RS232_SendByte(char byte);
+int execute (int argc, const char * const * argv);
 
-extern char        recvBufRS232[];     // Входной буфер для RS232
-extern uint16_t    indexRS232;
+void print_help (void);
 
-#endif /* #ifndef __PORTS_H */
+#endif /* #ifndef PORTCONSOLE_H */
 
-/****************************** (C) LiteMesh ***************** end of file ****/
+/****************************** (C) LiteMesh ***************** end of file ****/

+ 16 - 0
service_hw/Hardware/hw_init.c

@@ -22,6 +22,7 @@
 #include "gpio.h"
 #include "spi_flash.h"
 #include "stm32_uid.h"
+#include "port_microrl.h"
 
 #include "FreeRTOS.h"
 #include "task.h"
@@ -35,6 +36,19 @@
 
 char STM_ID[33];
 
+void service_com_task(void* params)
+{
+	int c;
+	for(;;){
+		c = service_getchar(portMAX_DELAY);
+		if(c >= 0)
+		{
+			 MICRORL_GetChar((uint8_t)c);
+		}
+	}
+
+}
+
 /**
   * @brief  Инициализация необходимых модулей
   */
@@ -47,6 +61,7 @@ void BT_6702_Init(void)
 	spi_flash_init();
    
 	InitUSART();
+	MICRORL_Init();
   
     SETTINGS_Load();
     
@@ -60,6 +75,7 @@ void BT_6702_Init(void)
     
     TM_RTC_Init(TM_RTC_ClockSource_External);
 
+    xTaskCreate(service_com_task, ( char * ) "service_com_task", configMINIMAL_STACK_SIZE * 2, NULL, tskIDLE_PRIORITY, NULL);
     // Создает таски для выполнения команд тестера 
     xTaskCreate(vTestCommands, "TestProcessing", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
   

+ 4 - 4
service_hw/Makefile

@@ -29,8 +29,8 @@ INCLUDES += -I../thirdparty/TinyStdio
 INCLUDES += -IUser
 INCLUDES += -IHardware
 INCLUDES += -ICommands
-INCLUDES += -IPorts
 INCLUDES += -ISettings
+INCLUDES += -IConsole
 INCLUDES += -I.
 
 CSRC = $(wildcard ../stm32/stm32f4xx_spl/src/*.c)
@@ -40,21 +40,21 @@ CSRC += $(wildcard ../thirdparty/TinyStdio/*.c)
 CSRC += $(wildcard User/*.c)
 CSRC += $(wildcard Hardware/*.c)
 CSRC += $(wildcard Commands/*.c)
-CSRC += $(wildcard Ports/*.c)
 CSRC += $(wildcard Settings/*.c)
+CSRC += $(wildcard Console/*.c)
 CSRC += $(wildcard *.c)
 
 INCLUDES += -Ileds
 INCLUDES += -Ibuttons
 INCLUDES += -I../modules/jumper
 INCLUDES += -I../modules/d_inouts
-INCLUDES += -I../modules/common/ring_buf.h
+INCLUDES += -I../modules/common/
 INCLUDES += -I../modules
 CSRC += $(wildcard leds/*.c)
 CSRC += $(wildcard buttons/*.c)
 CSRC += $(wildcard ../modules/jumper/*.c)
 CSRC += $(wildcard ../modules/d_inouts/*.c)
-CSRC += $(wildcard ../modules/common/ring_buf.c)
+CSRC += $(wildcard ../modules/common/*.c)
 CSRC += $(wildcard ../modules/*.c)
 
 CFLAGS += -DOS_FREERTOS

+ 0 - 92
service_hw/Ports/ports.c

@@ -1,92 +0,0 @@
-/********************************* (C) РОТЕК ***********************************
- * @module  buttons_api
- * @file    buttons_api.c
- * @version 1.0.0
- * @date    XX.XX.XXXX
- * $brief   buttons_api
- *******************************************************************************
- * @history     Version  Author         Comment
- * XX.XX.XXXX   1.0.0    Telenkov D.A.  First release.
- *******************************************************************************
- */
-
-#include "stm32f4xx.h"  
-#include "ports.h"
-
-#include "FreeRTOS.h"
-#include "task.h"
-
-char        recvBufRS232[RS232_MAX_REC_LEN];     // Входной буфер для RS232
-uint16_t    indexRS232;
-
-/**
-  * @brief  
-  */
-void RS232_Init(void)
-{
-    GPIO_InitTypeDef  GPIO_InitStructure;
-    USART_InitTypeDef USART_InitStructure;
-    NVIC_InitTypeDef  NVIC_InitStructure;
-    
-    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
-    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
-  
-    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
-    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
-    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
-    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
-    GPIO_Init(GPIOD, &GPIO_InitStructure);
-  
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
-    GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);  
-  
-    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
-    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
-    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
-    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
-    NVIC_Init(&NVIC_InitStructure);
-  
-    NVIC_SetPriority (USART3_IRQn, 5); 
-  
-    USART_InitStructure.USART_BaudRate = 115200;
-    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
-    USART_InitStructure.USART_StopBits = USART_StopBits_1;
-    USART_InitStructure.USART_Parity = USART_Parity_No;
-    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
-    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
-    USART_Init(RS232_PORT, &USART_InitStructure);
-
-    USART_Cmd(RS232_PORT, ENABLE);      
-      
-    USART_ITConfig(RS232_PORT, USART_IT_RXNE, ENABLE);
-    USART_ITConfig(RS232_PORT, USART_IT_TXE, DISABLE);
-}
-
-/**
-  * @brief  RS232
-  */
-/*void USART3_IRQHandler(void)
-{
-    char byte;
-    
-    if(USART_GetITStatus(RS232_PORT, USART_IT_RXNE) != RESET)
-    {
-        byte = (uint8_t)(RS232_PORT->DR & (uint16_t)0x01FF);
-        
-        recvBufRS232[indexRS232++] = byte;
-    
-        // Защита от выхода за границу отведенного буфера
-        if (indexRS232 == (RS232_MAX_REC_LEN - 1))
-            indexRS232 = 0;
-    }
-}*/
-
-void RS232_SendByte(char byte)
-{
-    while(USART_GetFlagStatus(RS232_PORT, USART_FLAG_TXE) == RESET) {}
-    RS232_PORT->DR = (byte & (uint16_t)0x01FF);
-}
-
-
-/********************************* (C) РОТЕК **********************************/

+ 5 - 0
service_hw/Settings/bt_6701_settings.h

@@ -24,6 +24,11 @@ char * SETTINGS_GetTestState(void);
   */
 void BT_6701_SetBootParamsDef(void);
 
+/**
+  * @brief  Устанавливает Serno, но не сохраняет новые настройки во флеш
+  */
+void SETTINGS_SetSerno(char *serno);
+
 /**
   * @brief  Устанавливает mac, но не сохраняет новые настройки во флеш
   */