Commit ee153849 authored by julien.delange's avatar julien.delange
Browse files

* ASN1 marshallers now works!



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@719 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 06196fb9
......@@ -34,7 +34,7 @@ endif
GCC=$(CC)
CFLAGS=-Wall $(USER_CFLAGS) $(TARGET_CFLAGS)
CFLAGS=-Wall $(USER_CFLAGS) $(TARGET_CFLAGS) -g
CPPFLAGS=$(CFLAGS) $(USER_CPPFLAGS)
LDFLAGS=$(TARGET_LDFLAGS) $(USER_LDFLAGS)
......@@ -120,7 +120,7 @@ generate-asn1-deployment:
GENERATED_OBJS += real.o asn1_deployment.o asn1crt.o
LDFLAGS += -lm
CFLAGS+=-DPO_HI_USE_ASN1
CFLAGS+=-DPO_HI_USE_ASN1 -I../../
else
generate-asn1-deployment:
......
......@@ -142,6 +142,10 @@ int __po_hi_driver_sockets_asn1_send (__po_hi_task_id task_id,
request->port = destination_port;
__po_hi_marshall_asn1_request (request, &asn1_pkt);
asn1_pkt.sender_port = 0;
asn1_pkt.sender_thread = 0;
asn1_pkt.receiver_thread = 0;
asn1_pkt.receiver_port = 0;
__DEBUGMSG("[SOCKETS ASN1] Marshall ASN1 Packet, kind=%d\n", asn1_pkt.msg.kind);
BitStream_Init (&asn1_bitstream, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING);
if ( ! Pkt_Encode (&asn1_pkt, &asn1_bitstream, &asn1_error_code, TRUE))
......@@ -150,9 +154,10 @@ int __po_hi_driver_sockets_asn1_send (__po_hi_task_id task_id,
return __PO_HI_ERROR_TRANSPORT_SEND;
}
size_to_write = BitStream_GetLength (&asn1_bitstream);
// size_to_write = BitStream_GetLength (&asn1_bitstream);
size_to_write = Pkt_REQUIRED_BYTES_FOR_ENCODING;
len = write (nodes[associated_device].socket, &asn1_bitstream, size_to_write);
len = write (nodes[associated_device].socket, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING);
if (len != size_to_write)
{
......@@ -164,6 +169,16 @@ int __po_hi_driver_sockets_asn1_send (__po_hi_task_id task_id,
__DEBUGMSG (" [SUCCESS len=%d]\n", len);
__DEBUGMSG ("[DRIVER_SOCKETS] Sent message content: |0x");
{
int n;
for (n=0 ; n < len ; n++)
{
__DEBUGMSG ("%x", asn1_buffer[n]);
}
}
__DEBUGMSG ("|\n");
return __PO_HI_SUCCESS;
}
......@@ -177,14 +192,15 @@ void* __po_hi_sockets_asn1_poller (void)
int sock;
int max_socket;
fd_set selector;
__po_hi_byte_t asn1_buffer[__PO_HI_ASN1_PKT_SIZE];
struct sockaddr_in sa;
__po_hi_node_t dev;
__po_hi_node_t dev_init;
__po_hi_request_t received_request;
int asn1_error_code;
__po_hi_byte_t asn1_buffer[Pkt_REQUIRED_BYTES_FOR_ENCODING];
__po_hi_asn1_pkt_t asn1_pkt;
int asn1_error_code;
BitStream asn1_bitstream;
struct sockaddr_in sa;
max_socket = 0; /* Used to compute the max socket number, useful for listen() call */
......@@ -252,20 +268,39 @@ void* __po_hi_sockets_asn1_poller (void)
if ( (rnodes[dev].socket != -1 ) && FD_ISSET(rnodes[dev].socket, &selector))
{
__DEBUGMSG ("[DRIVER SOCKETS] Receive message from dev %d\n", dev);
BitStream_AttachBuffer (&asn1_bitstream, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING);
len = recv (rnodes[dev].socket, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING, 0);
memset (asn1_buffer, '\0', Pkt_REQUIRED_BYTES_FOR_ENCODING);
len = recv (rnodes[dev].socket, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING, MSG_WAITALL);
__DEBUGMSG ("[DRIVER SOCKETS] Message received len=%d\n",len);
__DEBUGMSG ("[DRIVER_SOCKETS] Received message content: |0x");
{
int n;
for (n=0 ; n < len ; n++)
{
__DEBUGMSG ("%x", asn1_buffer[n]);
}
}
__DEBUGMSG ("|\n");
BitStream_AttachBuffer (&asn1_bitstream, asn1_buffer, Pkt_REQUIRED_BYTES_FOR_ENCODING);
if (len == 0)
{
rnodes[dev].socket = -1;
continue;
}
if (! Pkt_Decode (&asn1_pkt, &asn1_bitstream, &asn1_error_code))
{
__DEBUGMSG ("[SOCKETS ASN1] Unable to decode, error_code=%d\n", asn1_error_code);
continue;
}
__DEBUGMSG("[SOCKETS ASN1] Unmarshall ASN1 Packet of kind=%d\n", asn1_pkt.msg.kind);
__po_hi_unmarshall_asn1_request (&received_request, &asn1_pkt);
__DEBUGMSG ("[SOCKETS ASN1 deliver for port : %d\n", (int)received_request.port);
__DEBUGMSG ("[SOCKETS ASN1] deliver for port : %d\n", (int)received_request.port);
__po_hi_main_deliver (&received_request);
}
}
......
......@@ -144,6 +144,8 @@ void __po_hi_driver_sockets_init (__po_hi_device_id id)
continue;
}
__DEBUGMSG ("[DRIVER SOCKETS] Will initialize connection with device %d\n", dev);
memset (dev_addr, '\0', 16);
dev_port = 0;
......@@ -159,6 +161,7 @@ void __po_hi_driver_sockets_init (__po_hi_device_id id)
if (dev_port == 0)
{
__DEBUGMSG ("[DRIVER SOCKETS] Invalid remote port\n");
continue;
}
......@@ -168,9 +171,7 @@ void __po_hi_driver_sockets_init (__po_hi_device_id id)
if (nodes[dev].socket == -1 )
{
#ifdef __PO_HI_DEBUG
__DEBUGMSG ("[DRIVER SOCKETS] Socket for node %d is not created", node);
#endif
return;
}
......
......@@ -6,6 +6,7 @@
* For more informations, please visit http://ocarina.enst.fr
*
* Copyright (C) 2007-2009, GET-Telecom Paris.
* Copyright (C) 2010, European Space Agency (ESA)
*/
#include <pthread.h>
......@@ -25,8 +26,11 @@
pthread_cond_t cond_init;
pthread_mutex_t mutex_init;
int initialized_tasks;
int nb_tasks_to_init;
int initialized_tasks = 0;
/* The barrier is initialized with __PO_HI_NB_TASKS +1
* members, because the main function must pass the barrier
*/
int nb_tasks_to_init = __PO_HI_NB_TASKS + 1;
void __po_hi_initialize_add_task ()
{
......@@ -38,10 +42,10 @@ int __po_hi_initialize ()
{
#ifdef RTEMS_POSIX
#include <rtems/rtems/clock.h>
rtems_status_code status;
rtems_time_of_day time;
rtems_status_code status;
rtems_time_of_day time;
time.year = 1988;
time.year = 1988;
time.month = 12;
time.day = 31;
time.hour = 9;
......@@ -58,15 +62,8 @@ int __po_hi_initialize ()
return (__PO_HI_ERROR_PTHREAD_MUTEX);
}
/* The barrier is initialized with __PO_HI_NB_TASKS +1
* members, because the main function must pass the barrier
*/
nb_tasks_to_init = __PO_HI_NB_TASKS + 1;
__DEBUGMSG ("[MAIN] Have %d tasks to init\n", nb_tasks_to_init);
initialized_tasks = 0;
if (pthread_cond_init (&cond_init, NULL) != 0)
{
return (__PO_HI_ERROR_PTHREAD_COND);
......@@ -91,7 +88,7 @@ int __po_hi_wait_initialization ()
initialized_tasks++;
__DEBUGMSG ("[MAIN] %d task(s) initialized\n", initialized_tasks);
__DEBUGMSG ("[MAIN] %d task(s) initialized (total to init =%d)\n", initialized_tasks, nb_tasks_to_init);
while (initialized_tasks < nb_tasks_to_init)
{
......
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