Commit 40e6dff7 authored by Rafal Babski's avatar Rafal Babski

linux_serial_minimal driver improvements

parent 5cb004f4
......@@ -186,7 +186,7 @@ static void setup_termios(struct termios* tty, __po_hi_device_id id)
#define PACKET_ESCAPE_BYTE '\x1B'
// 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)
static uint32_t encode_packet(uint8_t* data, const uint32_t data_length, const uint8_t* msg_content, const uint32_t msg_length)
{
if(msg_length <= 8)
{
......@@ -206,7 +206,7 @@ static int encode_packet(uint8_t* data, const int data_length, const uint8_t* ms
return 0;
}
int length = 0;
uint32_t length = 0;
data[length++] = PACKET_START_BYTE;
......@@ -354,21 +354,28 @@ enum PACKET_DECODER_STATE
ESCAPE_STARTED
};
__po_hi_msg_t __po_hi_c_driver_serial_linux_poller_msg;
static uint8_t packet_decoder_buffer[PACKET_DECODER_BUFFER_SIZE];
static int packet_decoder_index = 0;
static enum PACKET_DECODER_STATE packet_decoder_state;
static void process_packet(uint8_t* data, int size)
{
uint32_t port = 7;
uint32_t length = size;
__PO_HI_DEBUG_DEBUG ("[LINUX SERIAL] Processing packet\n");
__po_hi_c_driver_linux_serial_minimal_request.port = (__po_hi_local_port_t) 7;
__PO_HI_DEBUG_DEBUG ("[LINUX SERIAL] Copying data (%d bytes)\n", size);
memcpy(&__po_hi_c_driver_linux_serial_minimal_request.vars, data, size);
uint8_t* request_size_pointer = ((uint8_t*)&__po_hi_c_driver_linux_serial_minimal_request.vars) + size;
__PO_HI_DEBUG_DEBUG ("[LINUX SERIAL] Copying size (%d bytes)\n", size);
memcpy(request_size_pointer, &size, 4);
__PO_HI_DEBUG_DEBUG ("[LINUX SERIAL] Packet deliver\n", size);
__po_hi_msg_reallocate(&__po_hi_c_driver_serial_linux_poller_msg);
memcpy(__po_hi_c_driver_serial_linux_poller_msg.content, &port, 4);
memcpy(__po_hi_c_driver_serial_linux_poller_msg.content + 4, data, size);
memcpy(__po_hi_c_driver_serial_linux_poller_msg.content + (__PO_HI_MESSAGES_MAX_SIZE - 8), &length, 4);
__po_hi_c_driver_serial_linux_poller_msg.length = __PO_HI_MESSAGES_MAX_SIZE;
__po_hi_unmarshall_request(&__po_hi_c_driver_linux_serial_minimal_request,
&__po_hi_c_driver_serial_linux_poller_msg);
__PO_HI_DEBUG_DEBUG ("[LINUX SERIAL] Deliver to port %u\n", __po_hi_c_driver_linux_serial_minimal_request.port);
__po_hi_main_deliver(&__po_hi_c_driver_linux_serial_minimal_request);
}
......@@ -471,16 +478,16 @@ int __po_hi_c_driver_linux_serial_minimal_sender (__po_hi_task_id task_id, __po
__po_hi_marshall_request (request, &__po_hi_c_driver_linux_serial_minimal_sender_msg);
int msg_length = __po_hi_msg_length(&__po_hi_c_driver_linux_serial_minimal_sender_msg);
uint32_t msg_length = (uint32_t) __po_hi_msg_length(&__po_hi_c_driver_linux_serial_minimal_sender_msg);
uint8_t* msg_content = (uint8_t*) malloc(msg_length);
__po_hi_msg_get_data(msg_content,
&__po_hi_c_driver_linux_serial_minimal_sender_msg,
0,
msg_length);
int data_length = msg_length * 2 + 2;
uint32_t 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);
uint32_t length = encode_packet(data, data_length, msg_content, msg_length);
if(length > 0)
{
......@@ -489,7 +496,7 @@ int __po_hi_c_driver_linux_serial_minimal_sender (__po_hi_task_id task_id, __po
{
__PO_HI_DEBUG_DEBUG (" [LINUX SERIAL] write %d bytes in loop to device\n", length);
for (n = 0 ; n < length ; n++)
for (n = 0 ; n < (int)length ; n++)
{
write (po_hi_c_driver_serial_fd_write, &(data[n]), 1);
usleep (po_hi_c_driver_serial_sending_wait);
......@@ -515,18 +522,18 @@ int __po_hi_c_driver_linux_serial_minimal_sender (__po_hi_task_id task_id, __po
{
__PO_HI_DEBUG_CRITICAL (" [LINUX SERIAL] failed !\n");
}
else if((0 <= n)&(n < length))
else if((0 <= n)&(n < (int)length))
{
__PO_HI_DEBUG_CRITICAL (" [LINUX SERIAL] Unable write - write returned %d !\n", n);
}
else
{
__PO_HI_DEBUG_DEBUG (" [LINUX SERIAL] OK !\n");
__PO_HI_DEBUG_CRITICAL (" [LINUX SERIAL] OK !\n");
}
}
__PO_HI_DEBUG_DEBUG ("[LINUX SERIAL] write() returns %d, message sent: 0x", n);
__PO_HI_DEBUG_DEBUG ("[LINUX SERIAL] write() returns %d, message sent: 0x\n", n);
}
__po_hi_mutex_unlock (&__po_hi_c_driver_linux_serial_minimal_send_mutex);
......
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