Esempio n. 1
0
/**
 * Setup program. When user_init runs the debug printouts will not always
 * show on the serial console. So i run the inits in here, 2 seconds later.
 */
static void ICACHE_FLASH_ATTR
setup(void) {
  ping_init(&pingA, 2, 0, PING_MM); // trigger=GPIO2, echo=GPIO0, set the pins to the same value for one-pin-mode
  ping_init(&pingB, 4, 5, PING_MM); // trigger=GPIO4, echo=GPIO5, set the pins to the same value for one-pin-mode

  // Start repeating loop timer
  os_timer_disarm(&loop_timer);
  os_timer_setfn(&loop_timer, (os_timer_func_t *) loop, NULL);
  os_timer_arm(&loop_timer, PING_SAMPLE_PERIOD, true);
}
Esempio n. 2
0
/* This function initializes applications */
static void
apps_init()
{
#if LWIP_DNS_APP && LWIP_DNS
  /* wait until the netif is up (for dhcp, autoip or ppp) */
  sys_timeout(5000, dns_dorequest, NULL);
#endif /* LWIP_DNS_APP && LWIP_DNS */

#if LWIP_CHARGEN_APP && LWIP_SOCKET
  chargen_init();
#endif /* LWIP_CHARGEN_APP && LWIP_SOCKET */

#if LWIP_PING_APP && LWIP_RAW && LWIP_ICMP
  ping_init();
#endif /* LWIP_PING_APP && LWIP_RAW && LWIP_ICMP */

#if LWIP_NETBIOS_APP && LWIP_UDP
  netbios_init();
#endif /* LWIP_NETBIOS_APP && LWIP_UDP */

#if LWIP_HTTPD_APP && LWIP_TCP
#ifdef LWIP_HTTPD_APP_NETCONN
  http_server_netconn_init();
#else /* LWIP_HTTPD_APP_NETCONN */
  httpd_init();
#endif /* LWIP_HTTPD_APP_NETCONN */
#endif /* LWIP_HTTPD_APP && LWIP_TCP */

#if LWIP_NETIO_APP && LWIP_TCP
  netio_init();
#endif /* LWIP_NETIO_APP && LWIP_TCP */

#if LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP
  rtp_init();
#endif /* LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP */

#if LWIP_SNTP_APP && LWIP_SOCKET
  sntp_init();
#endif /* LWIP_SNTP_APP && LWIP_SOCKET */

#if LWIP_SHELL_APP && LWIP_NETCONN
  shell_init();
#endif /* LWIP_SHELL_APP && LWIP_NETCONN */
#if LWIP_TCPECHO_APP
#if LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN)
  tcpecho_init();
#else /* LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN) */
  echo_init();
#endif
#endif /* LWIP_TCPECHO_APP && LWIP_NETCONN */
#if LWIP_UDPECHO_APP && LWIP_NETCONN
  udpecho_init();
#endif /* LWIP_UDPECHO_APP && LWIP_NETCONN */
#if LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET
  socket_examples_init();
#endif /* LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET */
#ifdef LWIP_APP_INIT
  LWIP_APP_INIT();
#endif
}
Esempio n. 3
0
void doPingLoop()
{
    timer_prescaler_t prescaler = TIMER_ONE_1024TH;
    ping_init(prescaler);

    while (1)
    {
        unsigned cm = ping_cm_busy_wait(prescaler);
        printf0("%d cm\r\n", cm);
    }

}
Esempio n. 4
0
void
xep_init(void)
{
	disco_init(); /* init sevice discovery first */
	chatstates_init();
	composing_init();
	delay_init();
	muc_init();
	oob_init();
	ping_init();
	registration_init();
	vcard_init();
	version_init();
}
Esempio n. 5
0
int
main (int argc, char **argv)
{
  int index;
  int status = 0;

  set_program_name (argv[0]);
  
  if (getuid () == 0)
    is_root = true;

  /* Parse command line */
  iu_argp_init ("ping6", program_authors);
  argp_parse (&argp, argc, argv, 0, &index, NULL);

  ping = ping_init (0, getpid ());
  if (ping == NULL)
    /* ping_init() prints our error message.  */
    exit (1);

  setsockopt (ping->ping_fd, SOL_SOCKET, SO_BROADCAST, (char *) &one, sizeof (one));

  /* Reset root privileges */
  setuid (getuid ());

  argc -= index;
  argv += index;

  if (count != 0)
    ping_set_count (ping, count);

  if (socket_type != 0)
    ping_set_sockopt (ping, socket_type, &one, sizeof (one));

  if (options & OPT_INTERVAL)
    ping_set_interval (ping, interval);

  init_data_buffer (patptr, pattern_len);

  while (argc--)
    {
      status |= ping_echo (*argv++);
      ping_reset (ping);
    }

  return status;
}
Esempio n. 6
0
int
ping_main (struct Ping_Options *Ping_Opt)
{
  int one = 1;
  int ret = 0;

  if (getuid () == 0)
    is_root = true;

  /* Parse command line */
  parse_opt(Ping_Opt);
  
  ping = ping_init (ICMP_ECHO, getpid ());
  if (ping == NULL)
    /* ping_init() prints our error message.  */
    exit (1);

  ping_set_sockopt (ping, SO_BROADCAST, (char *) &one, sizeof (one));

  /* Reset root privileges */
  setuid (getuid ());

  if (count != 0)
    ping_set_count (ping, count);

  if (socket_type != 0)
    ping_set_sockopt (ping, socket_type, &one, sizeof (one));

  if (options & OPT_INTERVAL)
    ping_set_interval (ping, interval);

  init_data_buffer (patptr, pattern_len);
  ret = ping_echo (Ping_Opt->Host);

  Ping_Opt->SuccessCount = ping->ping_num_recv;
  Ping_Opt->FailureCount = ping->ping_num_xmit - ping->ping_num_recv;
  Ping_Opt->AverageResponseTime = ping->avg_time;
  Ping_Opt->MaximumResponseTime = ping->max_time;
  Ping_Opt->MinimumResponseTime = ping->min_time;

  free (ping);
  free (data_buffer);
  
  return ret;
}
Esempio n. 7
0
/*!
 * @brief main function
 */
int main(void)
{
  ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;

  app_low_level_init();
  OSA_Init();
  lwip_init();

  IP4_ADDR(&fsl_netif0_ipaddr, 192,168,2,102);
  IP4_ADDR(&fsl_netif0_netmask, 255,255,255,0);
  IP4_ADDR(&fsl_netif0_gw, 192,168,2,100);
  netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, ethernet_input);
  netif_set_default(&fsl_netif0);
  netif_set_up(&fsl_netif0);

  ping_init();

  return 0;
}
Esempio n. 8
0
gint main(gint argc, gchar *argv[]) {
	pingData.shadowlib = &ping_functionTable;

	ping_init(&pingData);

	ping_new(argc, argv);

	gint epolld = epoll_create(1);
	if(epolld == -1) {
		ping_log(G_LOG_LEVEL_WARNING, __FUNCTION__, "Error in epoll_create");
		close(epolld);
		return -1;
	}

	struct epoll_event ev;
	ev.events = EPOLLIN | EPOLLOUT;

	/* watch the server epoll descriptors */
	if(pingData.epolld) {
		ev.data.fd = pingData.epolld;
		epoll_ctl(epolld, EPOLL_CTL_ADD, ev.data.fd, &ev);
	}

	struct epoll_event events[10];
	int nReadyFDs;

	while(TRUE) {
		/* wait for some events */
		nReadyFDs = epoll_wait(epolld, events, 10, 0);
		if(nReadyFDs == -1) {
			ping_log(G_LOG_LEVEL_WARNING, __FUNCTION__, "Error in epoll_wait");
			return -1;
		}

		//ping_log(G_LOG_LEVEL_MESSAGE, __FUNCTION__, "have %d fds ready", nReadyFDs);
		for(int i = 0; i < nReadyFDs; i++) {
			ping_activate();
		}
	}

	return 0;
}
Esempio n. 9
0
int main(void)
#endif
{
  ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;
  
  app_low_level_init();
  OSA_Init();
  
  LWIP_DEBUGF(PING_DEBUG,("TCP/IP initializing...\r\n"));  
  tcpip_init(NULL,NULL);
  LWIP_DEBUGF(PING_DEBUG,("TCP/IP initialized.\r\n"));

  IP4_ADDR(&fsl_netif0_ipaddr, 192,168,2,102);
  IP4_ADDR(&fsl_netif0_netmask, 255,255,255,0);
  IP4_ADDR(&fsl_netif0_gw, 192,168,2,100);

  netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, tcpip_input);
  netif_set_default(&fsl_netif0);

  ping_init();
}
Esempio n. 10
0
void doSweepLoop()
{
    sei();

    servo_data_t *servo = create_jim_servo();

    ir_init(ADC_ONE_64TH, ADC_AREF, 2);
    timer_prescaler_t prescaler = TIMER_ONE_1024TH;
    ping_init(prescaler);
    oi_t *oiSensor = malloc(sizeof(oi_t));
    oi_tare_encoders(&(oiSensor->left_encoder), &(oiSensor->right_encoder));
    int velocity = 0;
    int radius = 0;
    int leftWheelVelocity = 0;
    int rightWheelVelocity = 0;
    oi_full_mode();

    ir_enable_continous_mode();
    sendPing();

    printf0("creating stored ir sensor lookup table...\r\n");
    list_t *lookup_table = create_jims_ir_sensor_lookup_table();
    printf0("done...\r\n");
    while (1)
    {
        char c = '\0';

        char ping_available = 0;
        unsigned p_cm;
        if (volatile_ping_capture_complete)
        {
            ping_available = 1;
            unsigned long end_capture_count = tmr1_read_input_capture_count();
            unsigned long end_time_cap = (volatile_timer1_overflows << 16) | end_capture_count;
            unsigned long delta = end_time_cap - volatile_ping_send_pulse_start_time;
            p_cm = ping_count_to_cm(prescaler, delta);

            //send again
            sendPing();
        }

        int requestIrCalibration = 0;
        handleInput(servo, &leftWheelVelocity, &rightWheelVelocity, &requestIrCalibration);

        if (requestIrCalibration)
        {
            lfreefree(lookup_table);
            cli();
            lookup_table = create_ir_lookup_table_from_ping(servo, prescaler);
            sei();
        }

        unsigned voltage = ir_read_voltage_avg(1);
        unsigned calculatedDist = ir_lookup_distance(lookup_table, voltage);
        double ir_cm = calculatedDist * 0.254;
        ir_cm = calculatedDist / 10;
        char buff[200];
        ftoa(buff, ir_cm);

        //unsigned p_cm; //= ping_cm_busy_wait(prescaler);
        //p_cm = ping_count_to_cm(prescaler, volatile_timer1_capture_count);

        unsigned curDeg = servo_calculate_position_deg(servo);

        //printf0("%d volts \t\t calculatedDist= %u \r\n", voltage, calculatedDist);
        printf0("%uº \t %s ir_cm [%u v]\t", curDeg, buff, voltage);
        printf0(" pw=%u\t", servo->cur_pulse_width);
        if (ping_available)
            printf0("%u p_cm\t", p_cm);
        printf0("\r\n");
    }
}
Esempio n. 11
0
/**
 * Initiates the GPIO for one-pin mode.
 */
bool ICACHE_FLASH_ATTR
ping_initOnePinMode(Ping_Data *pingData, int8_t triggerAndEchoPin, Ping_Unit unit) {
  return ping_init(pingData, triggerAndEchoPin, triggerAndEchoPin, unit);
}
Esempio n. 12
0
void 
netmain_init(void)
{
   int   e;
   int   i;
   char *   msg;
#ifdef IP_V6
   ip6_addr host;
#endif

   printf("\n%s\n", name);
   printf("Copyright 1997-2006 by InterNiche Technologies. All rights reserved. \n");

#ifndef SUPERLOOP
   /* call this to do pre-task setup including intialization of port_prep */
   msg = pre_task_setup();
   if (msg)
      panic(msg);
#endif

#ifdef INCLUDE_NVPARMS     /* system uses InterNiche NV system */
   e = get_nv_params();    /* get flash parameters into data structs */
   if (e)
   {
      printf("fatal error (%d) reading NV parameters.\n", e);
      panic("nv");
   }

   /* set static iface IP info up from stored parameters. These may 
   be overwritten from command line parms or DHCP later. */
   for (i = 0; i < STATIC_NETS; i++)
   {
      netstatic[i].n_ipaddr = inet_nvparms.ifs[i].ipaddr;
      netstatic[i].snmask = inet_nvparms.ifs[i].subnet;
      netstatic[i].n_defgw = inet_nvparms.ifs[i].gateway;
#ifdef IP_MULTICAST
      /* Create a dummy entry for the Ethernet interface mcastlist */
      /* If this entry is set to NULL, multicast is not supported  */
      /* on this interface */
      netstatic[i].n_mcastlist = mcastlist;
#endif   /* IP_MULTICAST */
#ifdef IP_V6
      IP6CPY(&host, &inet_nvparms.ifs[i].ipv6addr);
      if ( (host.addr[0] == 0xFE) && (host.addr[1] == 0xC0))
      {
         netstatic[i].v6addrs[IPA_SITE] = ip6_mkaddr(&netstatic[i], 
            IPA_SITE, &host);
      }
      else if ( (host.addr[0] == 0xFE) && (host.addr[1] == 0x80) )
      {
         printf ("[IPV6 init]error : bad IPV6 address\n");
      }
      else if (host.addr[0] != 0)
      {
         netstatic[i].v6addrs[IPA_GLOBAL] = ip6_mkaddr(&netstatic[i], 
            IPA_GLOBAL, &host );
      }
#endif
   }

#ifdef DNS_CLIENT
   /* set DNS client's server list from nvparms information */
   MEMCPY(dns_servers, inet_nvparms.dns_servers, sizeof(dns_servers));

#ifdef DNS_CLIENT_UPDT
   MEMCPY(soa_mname, inet_nvparms.dns_zone_name, sizeof(soa_mname));
#endif   /* DNS_CLIENT_UPDT */

#endif   /* DNS_CLIENT */

#ifdef USE_COMPORT
   comportcfg.comport = comport_nvparms.comport;
   comportcfg.LineProtocol = comport_nvparms.LineProtocol;
#endif   /* USE_COMPORT */
#endif   /* INCLUDE_NVPARMS */

#ifndef INCLUDE_NVPARMS
#ifdef USE_COMPORT
   comportcfg.comport = 0x01;
   comportcfg.LineProtocol = PPP;   /* Default to PPP */
#endif   /* USE_COMPORT */
#endif   /* INCLUDE_NVPARMS */

   msg = ip_startup();
   if (msg)
   {
      printf("inet startup error: %s\n", msg);
      panic("IP");
   }

#if defined(MEMDEV_SIZE) && defined(VFS_FILES)
   init_memdev(); /* init the mem and null test devices */
#endif

#ifdef IP_MULTICAST
#ifdef INCLUDE_TCP
   /* call the IP multicast test program */
   u_mctest_init();
#endif
#endif  

   /* clear debugging flags. Port can optionally turn them
    * back on in post_task_setup();
    * NDEBUG = UPCTRACE | IPTRACE | TPTRACE ;  
    */
   NDEBUG = 0;    

   /* print IP address of the first interface - for user's benefit */
   printf("IP address of %s : %s\n" , ((NET)(netlist.q_head))->name,
      print_ipad(((NET)(netlist.q_head))->n_ipaddr));
 
#ifndef SUPERLOOP
   /* call this per-target routine after basic tasks & net are up */
   msg = post_task_setup();
   if (msg)
      panic(msg);
#endif

#ifdef PING_APP
   ping_init();
#endif   /* PING_APP */

#ifdef RAWIPTEST
   raw_test_init();
#endif   /* RAWIPTEST */

#if defined(TFTP_CLIENT) || defined(TFTP_SERVER)
   tftp_init();
#endif   /* TFTP */

#ifdef TESTMENU
   install_menu(testmenu);
#endif   /* TESTMENU */

#ifdef USE_AUTOIP
   Upnp_init();      /* start Auto IP before DHCP client */
#endif   /* USE_AUTOIP */

#ifdef DHCP_CLIENT
	if( POWERUP_CONFIG_DHCP_ENABLED )
   		dhc_setup();   /* kick off any DHCP clients */
#endif   /* DHCP_CLIENT */

#ifdef DHCP_SERVER
#ifdef INCLUDE_NVPARMS
   if(dhserve_nvparms.ServeDHCP)
#endif
   {
      e = dhcp_init();
      if(e)
      {
         dprintf("Error %d starting DHCP server.\n",e);
      }
      else
      {
         exit_hook(dhcpsrv_cleanup);
         dprintf("Started DHCP server\n");
      }
   }
#endif /* DHCP_SERVER */

#ifdef IN_MENUS
   printf(prompt);
#endif

#ifdef UDPSTEST
   e=udp_echo_init();
   if ( e == SUCCESS )
   {
      exit_hook(udp_echo_cleanup);
   }
   else
      dprintf("Error %d starting UDP Echo server.\n",e);
#endif

#ifdef RIP_SUPPORT
   e=rip_init();
   if ( e == SUCCESS )
   {
      exit_hook(rip_cleanup);
   }
   else
      dprintf("Error %d starting RIP server.\n",e);
#endif

#ifdef INICHE_SYSLOG
   e =syslog_init();
   if (e == SUCCESS)
      exit_hook(closelog);
   else
      dprintf("Error %d initializing syslog client.\n",e);
#endif

#ifdef FTP_CLIENT
   fc_callback=ftpc_callback;
#endif

/* The following initializations take place when SUPERLOOP is enabled.
 * Otherwise they would be done in the respective task.
 */

#ifdef SUPERLOOP

#ifdef INCLUDE_SNMP
   e = snmp_init();
   if (e == SUCCESS)
      exit_hook(snmp_cleanup);
   else
      dprintf("Error %d initializing SNMP agent.\n",e);
#endif   /* INCLUDE_SNMP */

#ifdef WEBPORT
   e = http_init(); /* start up http server */
   if (e)
      dprintf("Error %d starting HTTP server.\n",e);
#endif   /* WEBPORT */

#ifdef FTP_SERVER
   e = ftps_init();
   if ( e == SUCCESS )
   {
      exit_hook(ftps_cleanup);
   }
   else
      dprintf("Error %d starting FTP server.\n",e);
#endif   /* FTP_SERVER */

#ifdef TELNET_SVR
   e=tel_init();
   if ( e == SUCCESS )
   {
      exit_hook(tel_cleanup);
   }
   else
      dprintf("Error %d starting TELNET server.\n",e);
#endif

#ifdef TCP_ECHOTEST
   e=tcp_echo_init();
   if ( e == SUCCESS )
   {
      exit_hook(tcp_echo_cleanup);
   }
   else
      dprintf("Error %d starting TCP Echo server.\n",e);
#endif
#ifdef TCP_CIPHERTEST
   e=tcp_cipher_init();
   if ( e == SUCCESS )
   {
      exit_hook(tcp_cipher_cleanup);
   }
   else
      dprintf("Error %d starting TCP cipher server.\n",e);
#endif
#ifdef USE_CRYPTOENG
   e = ce_init();
   if(e != 0)
   {
      dprintf("ce_init() failed\n");
      panic("prep_modules");
   }
#endif

#ifdef SMTP_ALERTS
   smtp_init ();
#endif

#endif   /* SUPERLOOP */

   USE_ARG(e);    /* Avoid compiler warnings */
   USE_ARG(i);

} /* end of netmain_init() */
Esempio n. 13
0
/* This function initializes applications */
static void
apps_init(void)
{
#if LWIP_DNS_APP && LWIP_DNS
  /* wait until the netif is up (for dhcp, autoip or ppp) */
  sys_timeout(5000, dns_dorequest, NULL);
#endif /* LWIP_DNS_APP && LWIP_DNS */

#if LWIP_CHARGEN_APP && LWIP_SOCKET
  chargen_init();
#endif /* LWIP_CHARGEN_APP && LWIP_SOCKET */

#if LWIP_PING_APP && LWIP_RAW && LWIP_ICMP
  ping_init();
#endif /* LWIP_PING_APP && LWIP_RAW && LWIP_ICMP */

#if LWIP_NETBIOS_APP && LWIP_UDP
  netbiosns_init();
#ifndef NETBIOS_LWIP_NAME
#if LWIP_NETIF_HOSTNAME
  netbiosns_set_name(netif_default->hostname);
#else
  netbiosns_set_name("NETBIOSLWIPDEV");
#endif
#endif
#endif /* LWIP_NETBIOS_APP && LWIP_UDP */

#if LWIP_HTTPD_APP && LWIP_TCP
#ifdef LWIP_HTTPD_APP_NETCONN
  http_server_netconn_init();
#else /* LWIP_HTTPD_APP_NETCONN */
  httpd_init();
#endif /* LWIP_HTTPD_APP_NETCONN */
#endif /* LWIP_HTTPD_APP && LWIP_TCP */

#if LWIP_MDNS_RESPONDER
  mdns_resp_init();
#if LWIP_NETIF_HOSTNAME
  mdns_resp_add_netif(netif_default, netif_default->hostname, 3600);
#else
  mdns_resp_add_netif(netif_default, "lwip", 3600);
#endif
  mdns_resp_add_service(netif_default, "lwipweb", "_http", DNSSD_PROTO_TCP, HTTPD_SERVER_PORT, 3600, srv_txt, NULL);
#endif

#if LWIP_NETIO_APP && LWIP_TCP
  netio_init();
#endif /* LWIP_NETIO_APP && LWIP_TCP */

#if LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP
  rtp_init();
#endif /* LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP */

#if LWIP_SNTP_APP && LWIP_SOCKET
  sntp_init();
#endif /* LWIP_SNTP_APP && LWIP_SOCKET */

#if LWIP_SHELL_APP && LWIP_NETCONN
  shell_init();
#endif /* LWIP_SHELL_APP && LWIP_NETCONN */
#if LWIP_TCPECHO_APP
#if LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN)
  tcpecho_init();
#else /* LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN) */
  tcpecho_raw_init();
#endif
#endif /* LWIP_TCPECHO_APP && LWIP_NETCONN */
#if LWIP_UDPECHO_APP && LWIP_NETCONN
  udpecho_init();
#endif /* LWIP_UDPECHO_APP && LWIP_NETCONN */
#if LWIP_LWIPERF_APP
  lwiperf_start_tcp_server_default(lwiperf_report, NULL);
#endif
#if LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET
  socket_examples_init();
#endif /* LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET */
#ifdef LWIP_APP_INIT
  LWIP_APP_INIT();
#endif
}