Commit fab9547e authored by jdelange's avatar jdelange

* po-hi-c/src/po_hi_lua.c

   po-hi-c/src/po_hi_time.c
   po-hi-c/examples/aadlv2/lua/hello2.lua
   - Fix time integration in LUA



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@3686 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent c0e6fa96
function toto()
return 1,2;
end
-- comment
function lua_sample()
print ("HELLO2");
time = time_get();
print ("Current time in milliseconds: " .. time);
print ("HELLO MAXIME");
sec, nsec = time_get();
sec = sec + 5;
time_delay_until (sec, nsec);
a,b = toto ();
print ("r1 : " .. a .. "r2 : " .. b);
end
......@@ -11,6 +11,7 @@
#include <po_hi_lua.h>
#include <po_hi_debug.h>
#include <po_hi_time.h>
#include <po_hi_types.h>
#ifdef __PO_HI_USE_LUA
......@@ -31,17 +32,37 @@ int __po_hi_lua_time_wait (lua_State* state)
return 0;
}
int __po_hi_lua_time_delay_until (lua_State* state)
{
__po_hi_time_t delay;
int sec;
int nsec;
sec = lua_tonumber (state, 1);
nsec = lua_tonumber (state, 2);
delay.sec = sec;
delay.nsec = nsec;
__po_hi_delay_until (&delay);
return 0;
}
int __po_hi_lua_time_get (lua_State* state)
{
int ret;
__po_hi_time_t now;
__po_hi_get_time (&now);
ret = now.sec * 1000 + now.nsec / 1000000;
__PO_HI_DEBUG_INFO ("[LUA] time_get sec =%llu\n", now.sec);
__PO_HI_DEBUG_INFO ("[LUA] time_get nsec =%llu\n", now.nsec);
lua_pushnumber (state, now.sec);
lua_pushnumber (state, now.nsec);
lua_pushnumber (state, ret);
return 1;
return 2;
}
......@@ -64,6 +85,7 @@ int __po_hi_lua_load (__po_hi_lua_context_t* context, const char* filename)
lua_register (context->state, "time_wait", __po_hi_lua_time_wait);
lua_register (context->state, "time_get", __po_hi_lua_time_get);
lua_register (context->state, "time_delay_until", __po_hi_lua_time_delay_until);
if (luaL_dofile (context->state,filename) != 0)
{
......
......@@ -124,11 +124,13 @@ int __po_hi_delay_until (const __po_hi_time_t* time)
if (pthread_mutex_init (&mutex, NULL) != 0)
{
__PO_HI_DEBUG_INFO ("[TIME] __po_hi_delay_until: cannot initialize mutex\n");
return (__PO_HI_ERROR_PTHREAD_MUTEX);
}
if (pthread_cond_init (&cond, NULL) != 0)
{
__PO_HI_DEBUG_INFO ("[TIME] __po_hi_delay_until: cannot initialize cond\n");
pthread_mutex_destroy (&mutex);
return (__PO_HI_ERROR_PTHREAD_COND);
}
......@@ -139,6 +141,7 @@ int __po_hi_delay_until (const __po_hi_time_t* time)
if ( (ret != 0) && (ret != ETIMEDOUT))
{
__PO_HI_DEBUG_INFO ("[TIME] __po_hi_delay_until: delay until error\n");
ret = __PO_HI_ERROR_PTHREAD_COND;
}
else
......
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