Exemplo n.º 1
0
//uart.send(1,string1,number,...[stringn])
static int uart_send( lua_State* L )
{
  uint16_t id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( uart, id );
  
  const char* buf;
  size_t len;
  int total = lua_gettop( L ), s;
  
  for( s = 2; s <= total; s ++ )
  {
    if( lua_type( L, s ) == LUA_TNUMBER )
    {
      len = lua_tointeger( L, s );
      if( len > 255 ) return luaL_error( L, "invalid number" );
      MicoUartSend( LUA_USR_UART,(char*)len,1);
    }
    else
    {
      luaL_checktype( L, s, LUA_TSTRING );
      buf = lua_tolstring( L, s, &len );
      MicoUartSend( LUA_USR_UART, buf,len);
    }
  }
  return 0;
}
Exemplo n.º 2
0
/*************************************************
* Function: MX_SendDataToMoudle
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
u32 MX_SendDataToMoudle(u8 *pu8Data, u16 u16DataLen)
{
#ifdef ZC_MODULE_DEV     
    AC_RecvMessage((ZC_MessageHead *)pu8Data);
#else    
    u8 u8MagicFlag[4] = {0x02,0x03,0x04,0x05};
	MicoUartSend(UART_FOR_APP, u8MagicFlag, 4);
	MicoUartSend(UART_FOR_APP, pu8Data, u16DataLen);
#endif
    return ZC_RET_OK;
}
Exemplo n.º 3
0
int alink_uart_put(char *buf, int len)
{
  if(_uart_reload_timer.handle != NULL)
    mico_reload_timer(&_uart_reload_timer);
  MicoUartSend(UART_FOR_APP, buf, len);
  return 0;
}
Exemplo n.º 4
0
OSStatus MVDDevInterfaceSend(unsigned char *inBuf, unsigned int inBufLen)
{
  OSStatus err = kUnknownErr;

  //dev_if_log("MVD => MCU:[%d]=%.*s", inBufLen, inBufLen, inBuf);
  err = MicoUartSend(UART_FOR_MCU, inBuf, inBufLen);
  require_noerr_action( err, exit, dev_if_log("ERROR: send to USART error! err=%d", err) );
  return kNoErr;
  
exit:
  return err;
}
Exemplo n.º 5
0
OSStatus user_uart_send(unsigned char *inBuf, unsigned int inBufLen)
{
  OSStatus err = kUnknownErr;

  user_uart_log("Module => UART:[%d]=%.*s", inBufLen, inBufLen, inBuf);
  err = MicoUartSend(UART_FOR_MCU, inBuf, inBufLen);
  require_noerr_action( err, exit, user_uart_log("ERROR: send to USART error! err=%d", err) );
  return kNoErr;
  
exit:
  return err;
}
Exemplo n.º 6
0
OSStatus sppWlanCommandProcess(unsigned char *inBuf, int *inBufLen, int inSocketFd, mico_Context_t * const inContext)
{
  spp_log_trace();
  (void)inSocketFd;
  (void)inContext;
  OSStatus err = kUnknownErr;

  err = MicoUartSend(UART_FOR_APP, inBuf, *inBufLen);

  *inBufLen = 0;
  return err;
}
Exemplo n.º 7
0
size_t __write( int handle, const unsigned char * buffer, size_t size )
{
  UNUSED_PARAMETER(handle);
  
  if ( buffer == 0 )
  {
    return 0;
  }

  MicoUartSend( STDIO_UART, (const char*)buffer, size );
  
  return size;
}
Exemplo n.º 8
0
/******************************************
Fun: 写入发送数据到串口
Input:buf:写入的buf;bufloc:写入的位置;data:转义的数据 
Output:void
Return:true: 写入串口buf成功,false:失败
******************************************/
_Bool WrUartBuf(u8* src,  u8 len)
{
#ifdef OS
	if(0 == MicoUartSend(UART_FOR_APP, src, len))
	{
		return true;
	}
#else
	if(FifoInput(&modsendfifo, src, len))
	{
		return 1;
	}
#endif
	return 0;
}
Exemplo n.º 9
0
size_t __write( int handle, const unsigned char * buffer, size_t size )
{
  UNUSED_PARAMETER(handle);
  
  if ( buffer == 0 )
  {
    return 0;
  }

#ifndef MICO_DISABLE_STDIO
  MicoUartSend( STDIO_UART, (const char*)buffer, size );
#endif
  
  return size;
}
OSStatus user_uartSend(unsigned char *inBuf, unsigned int inBufLen)
{
  OSStatus err = kUnknownErr;

  if( (NULL == inBuf) || ( 0 == inBufLen) ){
    err = kParamErr;
    user_uart_log("ERROR: user_uartSend input params error!");
    goto exit;
  }
  
  user_uart_log("KIT => MCU:[%d]=%.*s", inBufLen, inBufLen, inBuf);
  
  err = MicoUartSend(USER_UART, inBuf, inBufLen);
  require_noerr_action( err, exit, user_uart_log("ERROR: send to USART error! err=%d", err) );
  return kNoErr;
  
exit:
  return err;
}
void run( void *arg )
{
  char *name = (char *)arg;
  char debug[20];

  while(1)
  {
    MUTEX_LOCK();
    if( g_tickets <= 0 ){
      MUTEX_UNLOCK();
      goto exit;
    }

    g_tickets--;
    sprintf( debug, "Thread %s, %d\r\n", name, g_tickets );
    MicoUartSend(STDIO_UART, debug, strlen(debug) );

    MUTEX_UNLOCK();
  } 

exit:
  os_mutex_log( "thread: %s exit now", name );
  mico_rtos_delete_thread(NULL);
}
Exemplo n.º 12
0
//-----------------------------------
static uint32_t Send_Byte (uint8_t c)
{
  MicoUartSend( MICO_UART_1, &c, 1 );
  return 0;
}
Exemplo n.º 13
0
int fputc(int ch, FILE *f) {
  MicoUartSend( STDIO_UART, &ch, 1 );
  return ch;
}
Exemplo n.º 14
0
int putchar(int ch)
{
  g_ch = ch;	
  MicoUartSend( STDIO_UART, &g_ch, 1 );
  return ch;
}
Exemplo n.º 15
0
int putchar(int ch)
{
  MicoUartSend( STDIO_UART, &ch, 1 );
  return ch;
}
Exemplo n.º 16
0
static void mf_putc(char ch)
{
  MicoUartSend( MFG_TEST, &ch, 1);
}
Exemplo n.º 17
0
void mf_printf(char *str)
{
  MicoUartSend( MFG_TEST, str, strlen(str));
}
Exemplo n.º 18
0
void mico_mfg_test(mico_Context_t *inContext)
{
  network_InitTypeDef_adv_st wNetConfig;
  int testCommandFd, scanFd;
  uint8_t *buf = NULL;
  int recvLength = -1;
  fd_set readfds;
  struct timeval_t t;
  struct sockaddr_t addr;
  socklen_t addrLen;
  mico_uart_config_t uart_config;
  volatile ring_buffer_t  rx_buffer;
  volatile uint8_t *       rx_data;
  OSStatus err;
  
  buf = malloc(1500);
  require_action(buf, exit, err = kNoMemoryErr);
  rx_data = malloc(2048);
  require_action(rx_data, exit, err = kNoMemoryErr);
  
  /* Connect to a predefined Wlan */
  memset( &wNetConfig, 0x0, sizeof(network_InitTypeDef_adv_st) );
  
  strncpy( (char*)wNetConfig.ap_info.ssid, "William Xu", maxSsidLen );
  wNetConfig.ap_info.security = SECURITY_TYPE_AUTO;
  memcpy( wNetConfig.key, "mx099555", maxKeyLen );
  wNetConfig.key_len = strlen( "mx099555" );
  wNetConfig.dhcpMode = DHCP_Client;
  
  wNetConfig.wifi_retry_interval = 100;
  micoWlanStartAdv(&wNetConfig);
  
  /* Initialize UART interface */
  uart_config.baud_rate    = 115200;
  uart_config.data_width   = DATA_WIDTH_8BIT;
  uart_config.parity       = NO_PARITY;
  uart_config.stop_bits    = STOP_BITS_1;
  uart_config.flow_control = FLOW_CONTROL_DISABLED;
  uart_config.flags = UART_WAKEUP_DISABLE;
  
  ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, 2048 );
  MicoUartInitialize( UART_FOR_APP, &uart_config, (ring_buffer_t *)&rx_buffer );
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "MFG UART Recv", uartRecvMfg_thread, 0x300, (void*)inContext );
  
  /* Initialize UDP interface */
  t.tv_sec = 5;
  t.tv_usec = 0;
  
  scanFd = socket(AF_INET, SOCK_DGRM, IPPROTO_UDP);
  require_action(IsValidSocket( scanFd ), exit, err = kNoResourcesErr );
  
  addr.s_port = 23230;
  addr.s_ip = INADDR_ANY;
  err = bind(scanFd, &addr, sizeof(addr));
  require_noerr(err, exit);
  
  testCommandFd = socket(AF_INET, SOCK_DGRM, IPPROTO_UDP);
  require_action(IsValidSocket( testCommandFd ), exit, err = kNoResourcesErr );
  
  addr.s_port = 23231;
  addr.s_ip = INADDR_ANY;
  err = bind(testCommandFd, &addr, sizeof(addr));
  require_noerr(err, exit);
  
  while(1) {
    /*Check status on erery sockets on bonjour query */
    FD_ZERO( &readfds );
    FD_SET( testCommandFd, &readfds );
    FD_SET( scanFd, &readfds );
    select( 1, &readfds, NULL, NULL, &t );
    
    /* Scan and return MAC address */ 
    if (FD_ISSET(scanFd, &readfds)) {
      recvLength = recvfrom(scanFd, buf, 1500, 0, &addr, &addrLen); 
      sendto(scanFd, inContext->micoStatus.mac, sizeof(inContext->micoStatus.mac), 0, &addr, addrLen);
    }
    
    /* Recv UDP data and send to COM */
    if (FD_ISSET(testCommandFd, &readfds)) {
      recvLength = recvfrom(testCommandFd, buf, 1500, 0, &addr, &addrLen); 
      MicoUartSend(UART_FOR_APP, buf, recvLength);
    }
  }
  
exit:
  if(buf) free(buf);  
}