Esempio n. 1
0
 /******************************************************************************
  * FunctionName : initSyslog
  * Description  : Initialize the syslog library
  * Parameters   : syslog_host -- the syslog host (host:port)
  * 			   host:  IP-Addr | hostname
  * Returns      : none
 *******************************************************************************/
void ICACHE_FLASH_ATTR syslog_init(char *syslog_host)
{
  if (!*syslog_host) {
    syslogState = SYSLOG_HALTED;
    return;
  }
  char host[32], *port = &host[0];

  syslog_task = register_usr_task(syslog_udp_send_event);
  syslogHost.min_heap_size = flashConfig.syslog_minheap;
  syslogHost.port = 514;
  syslogState = SYSLOG_WAIT;

  os_strncpy(host, syslog_host, 32);
  while (*port && *port != ':')			// find port delimiter
    port++;
  if (*port) {
    *port++ = '\0';
    syslogHost.port = atoi(port);
  }

  wifi_set_broadcast_if(STATIONAP_MODE); // send UDP broadcast from both station and soft-AP interface
  syslog_espconn.type = ESPCONN_UDP;
  syslog_espconn.proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
  syslog_espconn.proto.udp->local_port = espconn_port();			// set a available  port
#ifdef SYSLOG_UDP_RECV
  espconn_regist_recvcb(&syslog_espconn, syslog_udp_recv_cb);			// register a udp packet receiving callback
#endif
  espconn_regist_sentcb(&syslog_espconn, syslog_udp_sent_cb);			// register a udp packet sent callback
  espconn_create(&syslog_espconn);   						// create udp

  if (UTILS_StrToIP((const char *)host, (void*)&syslogHost.addr)) {
    syslogState = SYSLOG_SENDING;
    syslog_send_udp();
  } else {
    static struct espconn espconn_ghbn;
    espconn_gethostbyname(&espconn_ghbn, host, &syslogHost.addr, syslog_gethostbyname_cb);
    // syslog_send_udp is called by syslog_gethostbyname_cb()
  }
#ifdef SYSLOG_UDP_RECV
  DBG("syslog_init: host: %s, port: %d, lport: %d, recvcb: %p, sentcb: %p, state: %d\n",
		  host, syslogHost.port, syslog_espconn.proto.udp->local_port,
		  syslog_udp_recv_cb, syslog_udp_sent_cb, syslogState	);
#else
  DBG("syslog_init: host: %s, port: %d, lport: %d, rsentcb: %p, state: %d\n",
		  host, syslogHost.port, syslog_espconn.proto.udp->local_port,
		  syslog_udp_sent_cb, syslogState	);
#endif
}
Esempio n. 2
0
/******************************************************************************
 * FunctionName : uart_init
 * Description  : user interface for init uart
 * Parameters   : UartBautRate uart0_br - uart0 bautrate
 *                UartBautRate uart1_br - uart1 bautrate
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
{
  // rom use 74880 baut_rate, here reinitialize
  UartDev.baut_rate = uart0_br;
  uart_config(UART0);
  UartDev.baut_rate = uart1_br;
  uart_config(UART1);
  for (int i=0; i<4; i++) uart_tx_one_char(UART1, '\n');
  for (int i=0; i<4; i++) uart_tx_one_char(UART0, '\n');
  ETS_UART_INTR_ENABLE();

  // install uart1 putc callback
  os_install_putc1((void *)uart0_write_char);

  uart_recvTaskNum = register_usr_task(uart_recvTask);
}
Esempio n. 3
0
 /******************************************************************************
  * FunctionName : initSyslog
  * Description  : Initialize the syslog library
  * Parameters   : syslog_host -- the syslog host (host:port)
  * 			   host:  IP-Addr | hostname
  * Returns      : none
 *******************************************************************************/
void ICACHE_FLASH_ATTR syslog_init(char *syslog_host)
{

  DBG("[%uµs] %s\n", WDEV_NOW(), __FUNCTION__);
  if (!*syslog_host) {
    syslog_set_status(SYSLOG_HALTED);
    return;
 }

  if (syslog_host == NULL) {
    // disable and unregister syslog handler
    syslog_set_status(SYSLOG_HALTED);
    if (syslog_espconn != NULL) {
      if (syslog_espconn->proto.udp) {
        // there's no counterpart to espconn_create...
        os_free(syslog_espconn->proto.udp);
	  }
      os_free(syslog_espconn);
    }
    syslog_espconn = NULL;

    // clean up syslog queue
    syslog_entry_t *pse = syslogQueue;
    while (pse != NULL) {
      syslog_entry_t *next = pse->next;
      os_free(pse);
      pse = next;
    }
    syslogQueue = NULL;
    return;
  }

  char host[32], *port = &host[0];
  os_strncpy(host, syslog_host, 32);
  while (*port && *port != ':')			// find port delimiter
    port++;

  if (*port) {
    *port++ = '\0';
    syslogHost.port = atoi(port);
  }

  if (syslogHost.port == 0)
    syslogHost.port = 514;

  // allocate structures, init syslog_handler
  if (syslog_espconn == NULL)
    syslog_espconn = (espconn *)os_zalloc(sizeof(espconn));

  if (syslog_espconn->proto.udp == NULL)
    syslog_espconn->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));

  syslog_espconn->type = ESPCONN_UDP;
  syslog_espconn->proto.udp->local_port = espconn_port();			// set a available  port
#ifdef SYSLOG_UDP_RECV
  espconn_regist_recvcb(syslog_espconn, syslog_udp_recv_cb);			// register a udp packet receiving callback
#endif
  espconn_regist_sentcb(syslog_espconn, syslog_udp_sent_cb);			// register a udp packet sent callback
  syslog_task = register_usr_task(syslog_udp_send_event);
  syslogHost.min_heap_size = flashConfig.syslog_minheap;

// the wifi_set_broadcast_if must be handled global in connection handler...
//  wifi_set_broadcast_if(STATIONAP_MODE); // send UDP broadcast from both station and soft-AP interface
  espconn_create(syslog_espconn);   						// create udp

  if (UTILS_StrToIP((const char *)host, (void*)&syslogHost.addr)) {
    syslog_set_status(SYSLOG_READY);
  } else {
    // we use our own espconn structure to avoid side effects...
    if (syslog_dnsconn == NULL)
      syslog_dnsconn = (espconn *)os_zalloc(sizeof(espconn));

    if (syslog_dnsconn->proto.udp == NULL)
      syslog_dnsconn->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));

    syslog_set_status(SYSLOG_DNSWAIT);
    espconn_gethostbyname(syslog_dnsconn, host, &syslogHost.addr, syslog_gethostbyname_cb);
  }
}