TTY Terminal
o Changed Linkbus to function more like a standard TTY terminal. o Cleaned up some unused defsDev1
rodzic
74d837439d
commit
559b4a3a3f
82
defs.h
82
defs.h
|
@ -286,47 +286,6 @@ typedef enum
|
|||
/******************************************************
|
||||
* UI Hardware-related definitions */
|
||||
|
||||
typedef enum lcdRow
|
||||
{
|
||||
ROW0,
|
||||
ROW1,
|
||||
NUMBER_OF_LCD_ROWS
|
||||
} LcdRowType;
|
||||
|
||||
typedef enum lcdColumn
|
||||
{
|
||||
COL0,
|
||||
COL1,
|
||||
COL2,
|
||||
COL3,
|
||||
COL4,
|
||||
COL5,
|
||||
COL6,
|
||||
COL7,
|
||||
COL8,
|
||||
COL9,
|
||||
COL10,
|
||||
COL11,
|
||||
COL12,
|
||||
COL13,
|
||||
COL14,
|
||||
COL15,
|
||||
COL16,
|
||||
COL17,
|
||||
COL18,
|
||||
COL19,
|
||||
NUMBER_OF_LCD_COLS,
|
||||
INVALID_LCD_COLUMN
|
||||
} LcdColType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON1_COLUMN = COL0,
|
||||
BUTTON2_COLUMN = COL5,
|
||||
BUTTON3_COLUMN = COL10,
|
||||
BUTTON4_COLUMN = COL15
|
||||
} ButtonColumn;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FrequencyFormat,
|
||||
|
@ -336,38 +295,6 @@ typedef enum
|
|||
|
||||
#define DISPLAY_WIDTH_STRING_SIZE (NUMBER_OF_LCD_COLS + 1)
|
||||
|
||||
typedef uint8_t BackLightSettingType;
|
||||
#define BL_OFF 0xFF
|
||||
#define BL_LOW 0xCF
|
||||
#define BL_MED 0x8F
|
||||
#define BL_HIGH 0x00
|
||||
|
||||
typedef uint8_t ContrastType;
|
||||
|
||||
typedef enum volumeSetting
|
||||
{
|
||||
VOL_ZERO = 0,
|
||||
VOL_10,
|
||||
VOL_20,
|
||||
VOL_30,
|
||||
VOL_40,
|
||||
VOL_50,
|
||||
VOL_60,
|
||||
VOL_70,
|
||||
VOL_80,
|
||||
VOL_90,
|
||||
VOL_100,
|
||||
DECREMENT_VOL,
|
||||
INCREMENT_VOL,
|
||||
VOL_NOT_SPECIFIED
|
||||
} VolumeSetting;
|
||||
|
||||
typedef enum volumeType
|
||||
{
|
||||
TONE_VOLUME,
|
||||
MAIN_VOLUME
|
||||
} VolumeType;
|
||||
|
||||
typedef enum batteryType
|
||||
{
|
||||
BATTERY_9V,
|
||||
|
@ -376,15 +303,6 @@ typedef enum batteryType
|
|||
BATTERY_UNKNOWN
|
||||
} BatteryType;
|
||||
|
||||
typedef enum buttons
|
||||
{
|
||||
BUTTON1,
|
||||
BUTTON2,
|
||||
BUTTON3,
|
||||
BUTTON4,
|
||||
NUMBER_OF_BUTTONS
|
||||
} ButtonType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Minutes_Seconds, /* minutes up to 59 */
|
||||
|
|
44
linkbus.cpp
44
linkbus.cpp
|
@ -33,6 +33,9 @@
|
|||
|
||||
/* Global Variables */
|
||||
static volatile BOOL g_bus_disabled = TRUE;
|
||||
static const char crlf[] = "\n";
|
||||
static char lineTerm[8] = "\n";
|
||||
static const char textPrompt[] = "TX> ";
|
||||
|
||||
static char g_tempMsgBuff[LINKBUS_MAX_MSG_LENGTH];
|
||||
|
||||
|
@ -333,3 +336,44 @@ void lb_broadcast_num(uint16_t data, char* str)
|
|||
|
||||
if(g_tempMsgBuff[0]) linkbus_send_text(g_tempMsgBuff);
|
||||
}
|
||||
|
||||
/***********************************************************************************
|
||||
* Support for creating and sending various Terminal Mode Linkbus messages is provided below.
|
||||
************************************************************************************/
|
||||
|
||||
void lb_send_NewPrompt(void)
|
||||
{
|
||||
linkbus_send_text((char*)crlf);
|
||||
}
|
||||
|
||||
void lb_send_NewLine(void)
|
||||
{
|
||||
linkbus_send_text((char*)crlf);
|
||||
}
|
||||
|
||||
void linkbus_setLineTerm(char* term)
|
||||
{
|
||||
sprintf(lineTerm, term);
|
||||
}
|
||||
|
||||
void lb_echo_char(uint8_t c)
|
||||
{
|
||||
g_tempMsgBuff[0] = c;
|
||||
g_tempMsgBuff[1] = '\0';
|
||||
linkbus_send_text(g_tempMsgBuff);
|
||||
}
|
||||
|
||||
BOOL lb_send_string(char* str)
|
||||
{
|
||||
if(str == NULL) return TRUE;
|
||||
if(strlen(str) > LINKBUS_MAX_MSG_LENGTH) return TRUE;
|
||||
strncpy(g_tempMsgBuff, str, LINKBUS_MAX_MSG_LENGTH);
|
||||
linkbus_send_text(g_tempMsgBuff);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void lb_send_value(uint16_t value, char* label)
|
||||
{
|
||||
sprintf(g_tempMsgBuff, "> %s=%d%s", label, value, lineTerm);
|
||||
linkbus_send_text(g_tempMsgBuff);
|
||||
}
|
||||
|
|
24
linkbus.h
24
linkbus.h
|
@ -239,4 +239,28 @@ void lb_broadcast_num(uint16_t data, char* str);
|
|||
*/
|
||||
void lb_send_Help(void);
|
||||
|
||||
/**
|
||||
*/
|
||||
void lb_send_NewPrompt(void);
|
||||
|
||||
/**
|
||||
*/
|
||||
void lb_send_NewLine(void);
|
||||
|
||||
/**
|
||||
*/
|
||||
void linkbus_setLineTerm(char* term);
|
||||
|
||||
/**
|
||||
*/
|
||||
void lb_echo_char(uint8_t c);
|
||||
|
||||
/**
|
||||
*/
|
||||
BOOL lb_send_string(char* str);
|
||||
|
||||
/**
|
||||
*/
|
||||
void lb_send_value(uint16_t value, char* label);
|
||||
|
||||
#endif /* LINKBUS_H_ */
|
||||
|
|
|
@ -237,6 +237,7 @@ void setup()
|
|||
************************************************************************/
|
||||
ISR(USART_RX_vect)
|
||||
{
|
||||
static char textBuff[LINKBUS_MAX_MSG_FIELD_LENGTH];
|
||||
static LinkbusRxBuffer* buff = NULL;
|
||||
static uint8_t charIndex = 0;
|
||||
static uint8_t field_index = 0;
|
||||
|
@ -255,87 +256,234 @@ ISR(USART_RX_vect)
|
|||
if(buff)
|
||||
{
|
||||
rx_char = toupper(rx_char);
|
||||
SMCR = 0x00; /* exit power-down mode */
|
||||
|
||||
if((rx_char == '$') || (rx_char == '!')) /* start of new message = $ */
|
||||
{
|
||||
charIndex = 0;
|
||||
buff->type = (rx_char == '!') ? LINKBUS_MSG_REPLY : LINKBUS_MSG_COMMAND;
|
||||
field_len = 0;
|
||||
msg_ID = LINKBUS_MSG_UNKNOWN;
|
||||
receiving_msg = TRUE;
|
||||
|
||||
/* Empty the field buffers */
|
||||
for(field_index = 0; field_index < LINKBUS_MAX_MSG_NUMBER_OF_FIELDS; field_index++)
|
||||
// SMCR = 0x00; // exit power-down mode
|
||||
|
||||
// if(g_terminal_mode)
|
||||
// {
|
||||
static uint8_t ignoreCount = 0;
|
||||
|
||||
if(ignoreCount)
|
||||
{
|
||||
buff->fields[field_index][0] = '\0';
|
||||
rx_char = '\0';
|
||||
ignoreCount--;
|
||||
}
|
||||
else if(rx_char == 0x1B) /* ESC sequence start */
|
||||
{
|
||||
rx_char = '\0';
|
||||
|
||||
if(charIndex < LINKBUS_MAX_MSG_FIELD_LENGTH)
|
||||
{
|
||||
rx_char = textBuff[charIndex];
|
||||
}
|
||||
|
||||
ignoreCount = 2; /* throw out the next two characters */
|
||||
}
|
||||
|
||||
field_index = 0;
|
||||
}
|
||||
else if(receiving_msg)
|
||||
{
|
||||
if((rx_char == ',') || (rx_char == ';') || (rx_char == '?')) /* new field = ,; end of message = ; */
|
||||
if(rx_char == 0x0D) /* Handle carriage return */
|
||||
{
|
||||
/* if(field_index == 0) // message ID received */
|
||||
if(field_index > 0)
|
||||
if(receiving_msg)
|
||||
{
|
||||
buff->fields[field_index - 1][field_len] = 0;
|
||||
}
|
||||
|
||||
field_index++;
|
||||
field_len = 0;
|
||||
|
||||
if(rx_char == ';')
|
||||
{
|
||||
if(charIndex >= LINKBUS_MIN_MSG_LENGTH)
|
||||
if(charIndex > 0)
|
||||
{
|
||||
buff->id = (LBMessageID)msg_ID;
|
||||
}
|
||||
receiving_msg = FALSE;
|
||||
}
|
||||
else if(rx_char == '?')
|
||||
{
|
||||
buff->type = LINKBUS_MSG_QUERY;
|
||||
if(charIndex > LINKBUS_MIN_MSG_LENGTH)
|
||||
{
|
||||
buff->id = (LBMessageID)msg_ID;
|
||||
}
|
||||
receiving_msg = FALSE;
|
||||
}
|
||||
buff->type = LINKBUS_MSG_QUERY;
|
||||
buff->id = msg_ID;
|
||||
|
||||
if(!receiving_msg)
|
||||
{
|
||||
buff = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(field_index == 0) /* message ID received */
|
||||
{
|
||||
msg_ID = msg_ID * 10 + rx_char;
|
||||
if(field_index > 0) /* terminate the last field */
|
||||
{
|
||||
buff->fields[field_index - 1][field_len] = 0;
|
||||
}
|
||||
|
||||
textBuff[charIndex] = '\0'; /* terminate last-message buffer */
|
||||
}
|
||||
|
||||
lb_send_NewLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
buff->fields[field_index - 1][field_len++] = rx_char;
|
||||
buff->id = INVALID_MESSAGE; /* print help message */
|
||||
}
|
||||
|
||||
charIndex = 0;
|
||||
field_len = 0;
|
||||
msg_ID = LINKBUS_MSG_UNKNOWN;
|
||||
|
||||
field_index = 0;
|
||||
buff = NULL;
|
||||
|
||||
receiving_msg = FALSE;
|
||||
}
|
||||
else if(rx_char)
|
||||
{
|
||||
textBuff[charIndex] = rx_char; /* hold the characters for re-use */
|
||||
|
||||
if(charIndex)
|
||||
{
|
||||
if(rx_char == 0x7F) /* Handle backspace */
|
||||
{
|
||||
charIndex--;
|
||||
if(field_index == 0)
|
||||
{
|
||||
msg_ID -= textBuff[charIndex];
|
||||
msg_ID /= 10;
|
||||
}
|
||||
else if(field_len)
|
||||
{
|
||||
field_len--;
|
||||
}
|
||||
else
|
||||
{
|
||||
buff->fields[field_index][0] = '\0';
|
||||
field_index--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(rx_char == ' ')
|
||||
{
|
||||
if(textBuff[charIndex - 1] == ' ')
|
||||
{
|
||||
rx_char = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if(field_index == 0) // message ID received */
|
||||
if(field_index > 0)
|
||||
{
|
||||
buff->fields[field_index - 1][field_len] = 0;
|
||||
}
|
||||
|
||||
field_index++;
|
||||
field_len = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(field_index == 0) /* message ID received */
|
||||
{
|
||||
msg_ID = msg_ID * 10 + rx_char;
|
||||
}
|
||||
else
|
||||
{
|
||||
buff->fields[field_index - 1][field_len++] = rx_char;
|
||||
}
|
||||
}
|
||||
|
||||
charIndex = MIN(charIndex+1, LINKBUS_MAX_MSG_FIELD_LENGTH);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if((rx_char == 0x7F) || (rx_char == ' ')) /* Handle backspace and Space */
|
||||
{
|
||||
rx_char = '\0';
|
||||
}
|
||||
else /* start of new message */
|
||||
{
|
||||
uint8_t i;
|
||||
field_index = 0;
|
||||
msg_ID = 0;
|
||||
|
||||
msg_ID = msg_ID * 10 + rx_char;
|
||||
|
||||
/* Empty the field buffers */
|
||||
for(i = 0; i < LINKBUS_MAX_MSG_NUMBER_OF_FIELDS; i++)
|
||||
{
|
||||
buff->fields[i][0] = '\0';
|
||||
}
|
||||
|
||||
receiving_msg = TRUE;
|
||||
charIndex = MIN(charIndex+1, LINKBUS_MAX_MSG_FIELD_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
if(rx_char)
|
||||
{
|
||||
lb_echo_char(rx_char);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(rx_char == 0x0D) /* Handle carriage return */
|
||||
{
|
||||
buff->id = (LBMessageID)LINKBUS_MSG_UNKNOWN;
|
||||
charIndex = LINKBUS_MAX_MSG_LENGTH;
|
||||
field_len = 0;
|
||||
msg_ID = LINKBUS_MSG_UNKNOWN;
|
||||
field_index = 0;
|
||||
buff = NULL;
|
||||
}
|
||||
|
||||
if(++charIndex >= LINKBUS_MAX_MSG_LENGTH)
|
||||
{
|
||||
receiving_msg = FALSE;
|
||||
charIndex = 0;
|
||||
}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if((rx_char == '$') || (rx_char == '!')) /* start of new message = $ */
|
||||
// {
|
||||
// charIndex = 0;
|
||||
// buff->type = (rx_char == '!') ? LINKBUS_MSG_REPLY : LINKBUS_MSG_COMMAND;
|
||||
// field_len = 0;
|
||||
// msg_ID = LINKBUS_MSG_UNKNOWN;
|
||||
// receiving_msg = TRUE;
|
||||
//
|
||||
// /* Empty the field buffers */
|
||||
// for(field_index = 0; field_index < LINKBUS_MAX_MSG_NUMBER_OF_FIELDS; field_index++)
|
||||
// {
|
||||
// buff->fields[field_index][0] = '\0';
|
||||
// }
|
||||
//
|
||||
// field_index = 0;
|
||||
// }
|
||||
// else if(receiving_msg)
|
||||
// {
|
||||
// if((rx_char == ',') || (rx_char == ';') || (rx_char == '?')) /* new field = ,; end of message = ; */
|
||||
// {
|
||||
// /* if(field_index == 0) // message ID received */
|
||||
// if(field_index > 0)
|
||||
// {
|
||||
// buff->fields[field_index - 1][field_len] = 0;
|
||||
// }
|
||||
//
|
||||
// field_index++;
|
||||
// field_len = 0;
|
||||
//
|
||||
// if(rx_char == ';')
|
||||
// {
|
||||
// if(charIndex > LINKBUS_MIN_MSG_LENGTH)
|
||||
// {
|
||||
// buff->id = msg_ID;
|
||||
// }
|
||||
// receiving_msg = FALSE;
|
||||
// }
|
||||
// else if(rx_char == '?')
|
||||
// {
|
||||
// buff->type = LINKBUS_MSG_QUERY;
|
||||
// if(charIndex >= LINKBUS_MIN_MSG_LENGTH)
|
||||
// {
|
||||
// buff->id = msg_ID;
|
||||
// }
|
||||
// receiving_msg = FALSE;
|
||||
// }
|
||||
//
|
||||
// if(!receiving_msg)
|
||||
// {
|
||||
// buff = 0;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if(field_index == 0) /* message ID received */
|
||||
// {
|
||||
// msg_ID = msg_ID * 10 + rx_char;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// buff->fields[field_index - 1][field_len++] = rx_char;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(rx_char == 0x0D) /* Handle carriage return */
|
||||
// {
|
||||
// buff->id = LINKBUS_MSG_UNKNOWN;
|
||||
// charIndex = LINKBUS_MAX_MSG_LENGTH;
|
||||
// field_len = 0;
|
||||
// msg_ID = LINKBUS_MSG_UNKNOWN;
|
||||
// field_index = 0;
|
||||
// buff = NULL;
|
||||
// }
|
||||
//
|
||||
// if(++charIndex >= LINKBUS_MAX_MSG_LENGTH)
|
||||
// {
|
||||
// receiving_msg = FALSE;
|
||||
// charIndex = 0;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue