Пример #1
0
// Open Listener / Server
void transport_open_listener( lua_State *L, ServerHandle *handle )
{
	// Get args & Set up connection
	unsigned uart_id, tmr_id;

	check_num_args( L,3 ); // 1st arg is uart num, 2nd arg is tmr_id, 3nd is handle
	if ( !lua_isnumber( L, 1 ) )
		luaL_error( L, "1st arg must be uart num" );

	if ( !lua_isnumber( L, 2 ) )
		luaL_error( L, "2nd arg must be timer num" );

	// @@@ Error handling could likely be better here
	uart_id = lua_tonumber( L, 1 );
	if( !platform_uart_exists( uart_id ) )
		luaL_error( L, "invalid uart id" );

	tmr_id = lua_tonumber( L, 2 );
	if( !platform_timer_exists( tmr_id ) )
		luaL_error( L, "invalid timer id" );

	handle->ltpt.fd = ( int )uart_id;
	handle->ltpt.tmr_id = tmr_id;

	// Setup uart
	platform_uart_setup( (unsigned int) uart_id, 115200, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 );
}
Пример #2
0
LUALIB_API int luaopen_uart( lua_State *L )
{
  unsigned id;
  char name[ 10 ];
  
  luaL_register( L, AUXLIB_UART, uart_map );
  
  // Add all UART interfaces to our module
  for( id = 0; id < PLATFORM_UART_TOTAL; id ++ )
    if( platform_uart_exists( id ) )
    {
      sprintf( name, "UART%d", id );
      lua_pushnumber( L, id );
      lua_setfield( L, -2, name );        
    }
    
  // Add the stop bits and parity constants (for uart.setup)
  lua_pushnumber( L, PLATFORM_UART_PARITY_EVEN );
  lua_setfield( L, -2, "PAR_EVEN" );
  lua_pushnumber( L, PLATFORM_UART_PARITY_ODD );
  lua_setfield( L, -2, "PAR_ODD" );  
  lua_pushnumber( L, PLATFORM_UART_PARITY_NONE );
  lua_setfield( L, -2, "PAR_NONE" );  
  lua_pushnumber( L, PLATFORM_UART_STOPBITS_1 );
  lua_setfield( L, -2, "STOP_1" );
  lua_pushnumber( L, PLATFORM_UART_STOPBITS_1_5 );
  lua_setfield( L, -2, "STOP_1_5" );  
  lua_pushnumber( L, PLATFORM_UART_STOPBITS_2 );
  lua_setfield( L, -2, "STOP_2" );    
  
  // Add the "none" and "infinite" constant used in recv()
  lua_pushnumber( L, 0 );
  lua_setfield( L, -2, "NO_TIMEOUT" );
  lua_pushnumber( L, PLATFORM_UART_INFINITE_TIMEOUT );
  lua_setfield( L, -2, "INF_TIMEOUT" );
  
  return 1;
}