Commit f30d2697 authored by Rafal Babski's avatar Rafal Babski

linux_serial_minial driver - code improvements

parent 68751956
......@@ -99,6 +99,7 @@ static void setup_bit_size(struct termios* tty, __po_hi_c_serial_conf_t* serialc
}
else
{
__PO_HI_DEBUG_DEBUG("Setting bit 8\n");
tty->c_cflag |= CS8;
}
}
......@@ -184,20 +185,27 @@ static void setup_termios(struct termios* tty, __po_hi_device_id id)
#define PACKET_STOP_BYTE '\x03'
#define PACKET_ESCAPE_BYTE '\x1B'
static int encode_packet(uint8_t* data, const uint8_t* msg_content, const int msg_length)
// process packet data generated by PolyORB to send it using UART
static int encode_packet(uint8_t* data, const int data_length, const uint8_t* msg_content, const int msg_length)
{
if(msg_length <= 8)
{
__PO_HI_DEBUG_DEBUG ("Encoding packet Not enaugh msg_length, %d\n", msg_length);
__PO_HI_DEBUG_DEBUG ("Encoding packet - not enough msg_length, at least 9 bytes is required, got %d\n", msg_length);
// the message is empty
return 0;
}
// first four bytes of msg_content - port
uint8_t* data_ptr = (uint8_t*) (msg_content + 4); // skip port to access data
// first four bytes of msg_content - port number
uint8_t* data_ptr = (uint8_t*) (msg_content + 4); // skip port number to access data
// last four bytes of msg_content - actual msg length
uint32_t* length_ptr = (uint32_t*)(msg_content + (msg_length - 4));
if(data_length < *length_ptr * 2 + 2)
{
__PO_HI_DEBUG_CRITICAL ("Encoding packet - not enough data_length, at least %d bytes is required, got %d\n", *length_ptr, data_length);
return 0;
}
int length = 0;
data[length++] = PACKET_START_BYTE;
......@@ -470,8 +478,9 @@ int __po_hi_c_driver_linux_serial_minimal_sender (__po_hi_task_id task_id, __po
0,
msg_length);
uint8_t* data = (uint8_t*)malloc(msg_length * 2 + 1);
int length = encode_packet(data, msg_content, msg_length);
int data_length = msg_length * 2 + 2;
uint8_t* data = (uint8_t*)malloc(data_length);
int length = encode_packet(data, data_length, msg_content, msg_length);
if(length > 0)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment