Example #1
0
void protocol_switcher_app_init(void)
{
	telnet_client_init();
	siemensTCP_app_init();
	specserver_app_init();
	webclient_init();
	httpd_init();

	resolv_init();
#ifndef USE_STATIC_IP
    // Initialize the DHCP Client Application.
    static struct uip_eth_addr sTempAddr;
    uip_getethaddr(sTempAddr);
    dhcpc_init(&sTempAddr.addr[0], 6);
    dhcpc_request();
#else
	uip_ip4addr_t uip_dnsaddr;
	uip_ipaddr(uip_dnsaddr, DNS_IP1, DNS_IP2, DNS_IP3, DNS_IP4 );
	resolv_conf(uip_dnsaddr);
#endif
}
Example #2
0
int16_t parse_cmd_dns_server(char *cmd, char *output, uint16_t len)
{
    uip_ipaddr_t dnsaddr;

    while (*cmd == ' ')
	cmd++;

    if (*cmd != '\0') {
	/* try to parse ip */
	if (parse_ip(cmd, &dnsaddr))
	    return ECMD_ERR_PARSE_ERROR;

	resolv_conf(&dnsaddr);

	eeprom_save(dns_server, &dnsaddr, IPADDR_LEN);
	eeprom_update_chksum();
	return ECMD_FINAL_OK;
    }
    else {
	return ECMD_FINAL(print_ipaddr(resolv_getserver(), output, len));
    }
}
Example #3
0
/*-----------------------------------------------------------------------------------*/
static void 
config_apply(void)
{
#ifdef __APPLE2ENH__

  ctk_draw_setbackground(config.bkgnd);

#endif /* __APPLE2ENH__ */

  program_handler_setscreensaver(config.screensaver);

  CTK_SCREENSAVER_SET_TIMEOUT(config.timeout * 60);

  config_setlanslot(config.slot);

  if(*config.driver) {
    program_handler_load(config.driver, NULL);
  }

  if(*config.prefix == '/') {
    config_setprefixok(chdir(config.prefix) == 0);
  }

#ifdef WITH_UIP

  uip_sethostaddr(config.ipaddr);

#ifdef WITH_ETHERNET

  uip_setnetmask(config.netmask);
  uip_setdraddr(config.gateway);
  uip_ethaddr.addr[5] = config.maclsb;

#endif /* WITH_ETHERNET */

  resolv_conf(config.dnsserver);

#endif /* WITH_UIP */
}
Example #4
0
/*-----------------------------------------------------------------------------------*/
int
main(void)
{
    process_init();

    procinit_init();

#ifdef PLATFORM_BUILD
    program_handler_add(&directory_dsc, "Directory",   1);
    program_handler_add(&www_dsc,       "Web browser", 1);
#endif /* PLATFORM_BUILD */

    autostart_start(autostart_processes);

#if !UIP_CONF_IPV6
    {
        uip_ipaddr_t addr;
        uip_ipaddr(&addr, 192,168,0,111);
        uip_sethostaddr(&addr);
        log_message("IP Address:  ", inet_ntoa(*(struct in_addr*)&addr));

        uip_ipaddr(&addr, 255,255,255,0);
        uip_setnetmask(&addr);
        log_message("Subnet Mask: ", inet_ntoa(*(struct in_addr*)&addr));

        uip_ipaddr(&addr, 192,168,0,1);
        uip_setdraddr(&addr);
        log_message("Def. Router: ", inet_ntoa(*(struct in_addr*)&addr));

        uip_ipaddr(&addr, 192,168,0,1);
        resolv_conf(&addr);
        log_message("DNS Server:  ", inet_ntoa(*(struct in_addr*)&addr));
    }

#else /* UIP_CONF_IPV6 */

#if !UIP_CONF_IPV6_RPL
#ifdef HARD_CODED_ADDRESS
    uip_ipaddr_t ipaddr;
    uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
    if ((ipaddr.u16[0]!=0) || (ipaddr.u16[1]!=0) || (ipaddr.u16[2]!=0) || (ipaddr.u16[3]!=0)) {
#if UIP_CONF_ROUTER
        uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0);
#else /* UIP_CONF_ROUTER */
        uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);
#endif /* UIP_CONF_ROUTER */
#if !UIP_CONF_IPV6_RPL
        uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
        uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
#endif
    }
#endif /* HARD_CODED_ADDRESS */
#endif
#endif

    while(1) {

        process_run();

        etimer_request_poll();

        /* Allow user-mode APC to execute. */
        SleepEx(10, TRUE);

#ifdef PLATFORM_BUILD
        if(console_resize()) {
            ctk_restore();
        }
#endif /* PLATFORM_BUILD */
    }
}
Example #5
0
void
main(int argc, char **argv)
{
  contiki_argc = argc;
  contiki_argv = argv;

#else /* WITH_ARGS */

void
main(void)
{

#endif /* WITH_ARGS */

  videomode(VIDEOMODE_80COL);

  process_init();

#if 1
  ethernet_config = config_read("contiki.cfg");
#else
  {
    static struct ethernet_config config = {0xDE08, "cs8900a.eth"};
    uip_ipaddr_t addr;

    uip_ipaddr(&addr, 192,168,0,128);
    uip_sethostaddr(&addr);

    uip_ipaddr(&addr, 255,255,255,0);
    uip_setnetmask(&addr);

    uip_ipaddr(&addr, 192,168,0,1);
    uip_setdraddr(&addr);

    uip_ipaddr(&addr, 192,168,0,1);
    resolv_conf(&addr);

    ethernet_config = &config;
  }
#endif

#if (WITH_GUI && WITH_MOUSE)
  {
    static const uint8_t mouse_sprite[64] = {
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x0F, 0xE0, 0x00, 0x0F, 0xC0, 0x00, 0x0F,
      0x80, 0x00, 0x0F, 0xC0, 0x00, 0x0D, 0xE0, 0x00,
      0x08, 0xF0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x3C,
      0x00, 0x00, 0x1E, 0x00, 0x00, 0x0F, 0x00, 0x00,
      0x07, 0x80, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    memcpy((void*)0x0E00, mouse_sprite, sizeof(mouse_sprite));
    *(uint8_t*)0x07F8 = 0x0E00 / 64;
    VIC.spr0_color = COLOR_WHITE;
  }
#endif /* WITH_GUI && WITH_MOUSE */

  procinit_init();

  process_start((struct process *)&ethernet_process, (char *)ethernet_config);

  autostart_start(autostart_processes);

  log_message("Contiki up and running ...", "");

  while(1) {

    process_run();

    etimer_request_poll();
  }
}
Example #6
0
void
bootp_handle_reply(void)
{
    int i;
    struct bootp *pk = uip_appdata;

    if(pk->bp_op != BOOTREPLY)
	return;					/* ugh? shouldn't happen */

    if(pk->bp_htype != HTYPE_ETHERNET)
	return;

    for(i = 0; i < 4; i ++) {
	if(pk->bp_xid[i] != uip_udp_conn->appstate.bootp.xid[i])
	    return;				/* session id doesn't match */

	if(pk->bp_vend[i] != replycookie[i])
	    return;				/* reply cookie doesn't match */
    }


    /*
     * looks like we have received a valid bootp reply,
     * prepare to override eeprom configuration
     */
    uip_ipaddr_t ips[5];
    memset(&ips, 0, sizeof(ips));

    /* extract our ip addresses, subnet-mask and gateway ... */
    memcpy(&ips[0], pk->bp_yiaddr, 4);
    uip_sethostaddr(&ips[0]);

    debug_printf ("BOOTP: configured new ip address %d.%d.%d.%d\n",
                  ((unsigned char *) ips)[0], ((unsigned char *) ips)[1],
                  ((unsigned char *) ips)[2], ((unsigned char *) ips)[3]);

    unsigned char *ptr = pk->bp_vend + 4;
    while(*ptr != 0xFF) {
	switch(* ptr) {
	case TAG_SUBNET_MASK:
	    memcpy(&ips[1], &ptr[2], 4);
	    uip_setnetmask(&ips[1]);
	    break;

	case TAG_GATEWAY:
	    memcpy(&ips[2], &ptr[2], 4);
	    uip_setdraddr(&ips[2]);
	    break;
#ifdef DNS_SUPPORT
        case TAG_DOMAIN_SERVER:
	    memcpy(&ips[3], &ptr[2], 4);
            resolv_conf(&ips[3]);
            break;
#endif
#ifdef NTP_SUPPORT
        case TAG_NTP_SERVER:
            /* This will set the ntp connection to the server set by the bootp
             * request
             */
	    memcpy(&ips[4], &ptr[2], 4);
            ntp_conf(&ips[4]);
            break;
#endif
	}

	ptr = ptr + ptr[1] + 2;
    }

    /* Remove the bootp connection */
    uip_udp_remove(uip_udp_conn);

#ifdef BOOTP_TO_EEPROM_SUPPORT
    eeprom_save(ip, &ips[0], IPADDR_LEN);
    eeprom_save(netmask, &ips[1], IPADDR_LEN);
    eeprom_save(gateway, &ips[2], IPADDR_LEN);
#ifdef DNS_SUPPORT
    eeprom_save(dns_server, &ips[3], IPADDR_LEN);
#endif
#ifdef NTP_SUPPORT
    eeprom_save(ntp_server, &ips[4], IPADDR_LEN);
#endif
#endif /* BOOTP_TO_EEPROM_SUPPORT */

#ifdef DYNDNS_SUPPORT
    dyndns_update();
#endif

#if defined(TFTP_SUPPORT) && defined(BOOTLOADER_SUPPORT)
    if(pk->bp_file[0] == 0)
	return;					/* no boot filename provided */

    debug_putstr("load:");
    debug_putstr(pk->bp_file);
    debug_putchar('\n');

    /* create tftp connection, which will fire the download request */
    uip_ipaddr_t ip;
    uip_ipaddr(&ip, pk->bp_siaddr[0], pk->bp_siaddr[1],
	       pk->bp_siaddr[2], pk->bp_siaddr[3]);

    tftp_fire_tftpomatic(&ip, pk->bp_file);
#endif /* TFTP_SUPPORT */
}
Example #7
0
void NanodeUIP::set_nameserver_addr(byte a, byte b, byte c, byte d) {
  uip_ipaddr_t ipaddr;
  uip_ipaddr(&ipaddr, a,b,c,d);
  resolv_conf(&ipaddr);
}
Example #8
0
/*-----------------------------------------------------------------------------------*/
void
main(void)
{
  struct ethernet_config *ethernet_config;

  close(STDIN_FILENO);
  close(STDOUT_FILENO);
#if !UIP_LOGGING && !LOG_CONF_ENABLED
  close(STDERR_FILENO);
#endif /* !UIP_LOGGING && !LOG_CONF_ENABLED */

  process_init();

#if 1
  ethernet_config = config_read("contiki.cfg");
#else
  {
    static struct ethernet_config config = {0xDE08, "cs8900a.eth"};
    uip_ipaddr_t addr;

    uip_ipaddr(&addr, 192,168,0,128);
    uip_sethostaddr(&addr);

    uip_ipaddr(&addr, 255,255,255,0);
    uip_setnetmask(&addr);

    uip_ipaddr(&addr, 192,168,0,1);
    uip_setdraddr(&addr);

    uip_ipaddr(&addr, 192,168,0,1);
    resolv_conf(&addr);

    ethernet_config = &config;
  }
#endif

#if (WITH_GUI && WITH_MOUSE)
  {
    static const u8_t mouse_sprite[64] = {
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x0F, 0xE0, 0x00, 0x0F, 0xC0, 0x00, 0x0F,
      0x80, 0x00, 0x0F, 0xC0, 0x00, 0x0D, 0xE0, 0x00,
      0x08, 0xF0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x3C,
      0x00, 0x00, 0x1E, 0x00, 0x00, 0x0F, 0x00, 0x00,
      0x07, 0x80, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    memcpy((void*)0x0E00, mouse_sprite, sizeof(mouse_sprite));
    *(u8_t*)0x07F8 = 0x0E00 / 64;
    VIC.spr0_color = COLOR_WHITE;
  }
#endif /* WITH_GUI && WITH_MOUSE */

  procinit_init();

  process_start((struct process *)&ethernet_process, (char *)ethernet_config);

  autostart_start(autostart_processes);

  log_message("Contiki up and running ...", "");
  
  while(1) {

    if(process_run() < 2) {

      etimer_request_poll();
    }
  }
}
Example #9
0
int user_start(int argc, char *argv[])
{
    struct in_addr addr;
#if defined(CONFIG_EXAMPLE_UIP_DHCPC) || defined(CONFIG_EXAMPLE_UIP_NOMAC)
    uint8_t mac[IFHWADDRLEN];
#endif
#ifdef CONFIG_EXAMPLE_UIP_DHCPC
    void *handle;
#endif

    /* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLE_UIP_NOMAC
    mac[0] = 0x00;
    mac[1] = 0xe0;
    mac[2] = 0xb0;
    mac[3] = 0x0b;
    mac[4] = 0xba;
    mac[5] = 0xbe;
    uip_setmacaddr("eth0", mac);
#endif

    /* Set up our host address */

#ifdef CONFIG_EXAMPLE_UIP_DHCPC
    addr.s_addr = 0;
#else
    addr.s_addr = HTONL(CONFIG_EXAMPLE_UIP_IPADDR);
#endif
    uip_sethostaddr("eth0", &addr);

    /* Set up the default router address */

    addr.s_addr = HTONL(CONFIG_EXAMPLE_UIP_DRIPADDR);
    uip_setdraddr("eth0", &addr);

    /* Setup the subnet mask */

    addr.s_addr = HTONL(CONFIG_EXAMPLE_UIP_NETMASK);
    uip_setnetmask("eth0", &addr);

#ifdef CONFIG_EXAMPLE_UIP_DHCPC
    /* Set up the resolver */

    resolv_init();

    /* Get the MAC address of the NIC */

    uip_getmacaddr("eth0", mac);

    /* Set up the DHCPC modules */

    handle = dhcpc_open(&mac, IFHWADDRLEN);

    /* Get an IP address.  Note:  there is no logic here for renewing the address in this
     * example.  The address should be renewed in ds.lease_time/2 seconds.
     */

    printf("Getting IP address\n");
    if (handle)
    {
        struct dhcpc_state ds;
        (void)dhcpc_request(handle, &ds);
        uip_sethostaddr("eth1", &ds.ipaddr);
        if (ds.netmask.s_addr != 0)
        {
            uip_setnetmask("eth0", &ds.netmask);
        }
        if (ds.default_router.s_addr != 0)
        {
            uip_setdraddr("eth0", &ds.default_router);
        }
        if (ds.dnsaddr.s_addr != 0)
        {
            resolv_conf(&ds.dnsaddr);
        }
        dhcpc_close(handle);
        printf("IP: %s\n", inet_ntoa(ds.ipaddr));
    }
#endif

#ifdef CONFIG_NET_TCP
    printf("Starting webserver\n");
    httpd_init();
    httpd_listen();
#endif

    while(1)
    {
        sleep(3);
        printf("main: Still running\n");
#if CONFIG_NFILE_DESCRIPTORS > 0
        fflush(stdout);
#endif
    }
    return 0;
}
Example #10
0
static inline void wlan_bringup(void)
{
#if defined(CONFIG_EXAMPLES_WLAN_DHCPC) || defined(CONFIG_EXAMPLES_WLAN_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif
  struct in_addr addr;
#ifdef CONFIG_EXAMPLES_WLAN_DHCPC
  void *handle;
#endif

  /* Many embedded network interfaces must have a software assigned
   * MAC
   */

#ifdef CONFIG_EXAMPLES_WLAN_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_WLAN_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_WLAN_NETMASK);
  uip_setnetmask("eth0", &addr);

  /* Set up our host address */

#ifdef CONFIG_EXAMPLES_WLAN_DHCPC
  addr.s_addr = 0;
#else
  addr.s_addr = HTONL(CONFIG_EXAMPLES_WLAN_IPADDR);
#endif
  uip_sethostaddr("eth0", &addr);

#ifdef CONFIG_EXAMPLES_WLAN_DHCPC
  /* Set up the resolver */

  resolv_init();

  /* Get the MAC address of the NIC */

  uip_getmacaddr("eth0", mac);

  /* Set up the DHCPC modules */

  handle = dhcpc_open(&mac, IFHWADDRLEN);

  /* Get an IP address.  Note:  there is no logic here for renewing
   * the address in this example.  The address should be renewed in
   * ds.lease_time/2 seconds.
   */

  printf("Getting IP address\n");
  if (handle)
    {
      struct dhcpc_state ds;
      (void)dhcpc_request(handle, &ds);
      uip_sethostaddr("eth1", &ds.ipaddr);
      if (ds.netmask.s_addr != 0)
        {
          uip_setnetmask("eth0", &ds.netmask);
        }
      if (ds.default_router.s_addr != 0)
        {
          uip_setdraddr("eth0", &ds.default_router);
        }
      if (ds.dnsaddr.s_addr != 0)
        {
          resolv_conf(&ds.dnsaddr);
        }
      dhcpc_close(handle);
      printf("IP: %s\n", inet_ntoa(ds.ipaddr));
    }
#endif
}
Example #11
0
int discover_main(int argc, char *argv[])
{
  /* If this task is excecutated as an NSH built-in function, then the
   * network has already been configured by NSH's start-up logic.
   */

#ifndef CONFIG_NSH_BUILTIN_APPS
  struct in_addr addr;
#if defined(CONFIG_EXAMPLE_DISCOVER_DHCPC) || defined(CONFIG_EXAMPLE_DISCOVER_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif
#ifdef CONFIG_EXAMPLE_DISCOVER_DHCPC
  void *handle;
#endif

/* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLE_DISCOVER_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

#ifdef CONFIG_EXAMPLE_DISCOVER_DHCPC
  addr.s_addr = 0;
#else
  addr.s_addr = HTONL(CONFIG_EXAMPLE_DISCOVER_IPADDR);
#endif
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_DISCOVER_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_DISCOVER_NETMASK);
  uip_setnetmask("eth0", &addr);

#ifdef CONFIG_EXAMPLE_DISCOVER_DHCPC
  /* Set up the resolver */

  resolv_init();

  /* Get the MAC address of the NIC */

  uip_getmacaddr("eth0", mac);

  /* Set up the DHCPC modules */

  handle = dhcpc_open(&mac, IFHWADDRLEN);

  /* Get an IP address.  Note:  there is no logic here for renewing the address in this
   * example.  The address should be renewed in ds.lease_time/2 seconds.
   */

  printf("Getting IP address\n");
  if (handle)
    {
      struct dhcpc_state ds;
      (void)dhcpc_request(handle, &ds);
      uip_sethostaddr("eth1", &ds.ipaddr);

      if (ds.netmask.s_addr != 0)
        {
          uip_setnetmask("eth0", &ds.netmask);
        }

      if (ds.default_router.s_addr != 0)
        {
          uip_setdraddr("eth0", &ds.default_router);
        }

      if (ds.dnsaddr.s_addr != 0)
        {
          resolv_conf(&ds.dnsaddr);
        }

      dhcpc_close(handle);
      printf("IP: %s\n", inet_ntoa(ds.ipaddr));
    }

#endif /* CONFIG_EXAMPLE_DISCOVER_DHCPC */
#endif /* CONFIG_NSH_BUILTIN_APPS */

  if (discover_start() < 0)
    {
      ndbg("Could not start discover daemon.\n");
      return ERROR;
    }

  return OK;
}
Example #12
0
int
main(int argc, char **argv)
{
  contiki_argc = argc;
  contiki_argv = argv;

  /* The first one or two args are used for wpcap configuration */
  /* so this needs to be "removed" from  contiki_args.          */
  contiki_argc--;
  contiki_argv++;
#ifdef UIP_FALLBACK_INTERFACE
  contiki_argc--;
  contiki_argv++;
#endif

  process_init();

  procinit_init();

#ifdef PLATFORM_BUILD
  program_handler_add(&directory_dsc, "Directory",   1);
  program_handler_add(&www_dsc,       "Web browser", 1);
#endif /* PLATFORM_BUILD */

  autostart_start(autostart_processes);

#if !NETSTACK_CONF_WITH_IPV6
  {
    uip_ipaddr_t addr;
    uip_ipaddr(&addr, 192,168,0,111);
    uip_sethostaddr(&addr);
    log_message("IP Address:  ", inet_ntoa(*(struct in_addr*)&addr));

    uip_ipaddr(&addr, 255,255,255,0);
    uip_setnetmask(&addr);
    log_message("Subnet Mask: ", inet_ntoa(*(struct in_addr*)&addr));

    uip_ipaddr(&addr, 192,168,0,1);
    uip_setdraddr(&addr);
    log_message("Def. Router: ", inet_ntoa(*(struct in_addr*)&addr));

    uip_ipaddr(&addr, 192,168,0,1);
    resolv_conf(&addr);
    log_message("DNS Server:  ", inet_ntoa(*(struct in_addr*)&addr));
  }

#else /* NETSTACK_CONF_WITH_IPV6 */

#if !UIP_CONF_IPV6_RPL
#ifdef HARD_CODED_ADDRESS
  uip_ipaddr_t ipaddr;
  uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
  if ((ipaddr.u16[0]!=0) || (ipaddr.u16[1]!=0) || (ipaddr.u16[2]!=0) || (ipaddr.u16[3]!=0)) {
#if UIP_CONF_ROUTER
    uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0);
#else /* UIP_CONF_ROUTER */
    uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);
#endif /* UIP_CONF_ROUTER */
#if !UIP_CONF_IPV6_RPL
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
#endif
  }
#endif /* HARD_CODED_ADDRESS */
#endif
#endif

  while(1) {

    process_run();

    etimer_request_poll();

    /* Allow user-mode APC to execute. */
    SleepEx(10, TRUE);

#ifdef PLATFORM_BUILD
    if(console_resize()) {
	ctk_restore();
    }
#endif /* PLATFORM_BUILD */
  }
}
Example #13
0
File: main.c Project: jaseg/avr-uip
int main(void) {
    sei();
    uint8_t resetSource = MCUSR;
    MCUSR = 0;
    wdt_reset();
    wdt_disable();

    wdt_enable(WDTO_1S);
    WDTCSR |= (1 << WDIE);  //enable watchdog interrupt
    wdt_reset();
    cli();

    clock_init();
    usart_init(1000000, 9600);
    stdout = &uart_str;
    stderr = &uart_str;
    stdin = &uart_str;

    uip_ipaddr_t ipaddr;
    struct timer periodic_timer, arp_timer;
    uint16_t timer_OW, timer_Simple, timer_Count, timer_EEProm, timer_SendData, timer_IOalarm, timer_network;
    timer_OW = 0;
    timer_Simple = 0;
    timer_Count = 0;
    timer_EEProm = 0;
    timer_SendData = 0;
    timer_IOalarm = 0;
    timer_network = 0;
    
    if(resetSource & (1<<WDRF))
    {
        printf("Mega was reset by watchdog...\r\n");
    }

    if(resetSource & (1<<BORF))
    {
        printf("Mega was reset by brownout...\r\n");
    }

    if(resetSource & (1<<EXTRF))
    {
        printf("Mega was reset by external...\r\n");
    }

    if(resetSource & (1<<PORF))
    {
        printf("Mega was reset by power on...\r\n");
    }

//else jtag (disabled)

    //sensorScan = (uint8_t*) & tempbuf;

    if (eepromReadByte(0) == 255 || eepromReadByte(11) == 255)
    {
            printf_P(PSTR("Setting default values\r\n"));
            //Set defaults
            eepromWriteByte(0, 0); //init

            myip[0] = 192;
            myip[1] = 168;
            myip[2] = 1;
            myip[3] = 67; //47 in final versions

            netmask[0] = 255;
            netmask[1] = 255;
            netmask[2] = 255;
            netmask[3] = 0;

            gwip[0] = 192;
            gwip[1] = 168;
            gwip[2] = 1;
            gwip[3] = 1;

            dnsip[0] = 8;
            dnsip[1] = 8;
            dnsip[2] = 8;
            dnsip[3] = 8;

            eepromWriteByte(29, 80);  //web port
            eepromWriteByte(10, 0);  //dhcp off

            save_ip_addresses();
            wdt_reset();

            eepromWriteStr(200, "SBNG", 4);  //default password
            eepromWriteByte(204, '\0');
            eepromWriteByte(205, '\0');
            eepromWriteByte(206, '\0');
            eepromWriteByte(207, '\0');
            eepromWriteByte(208, '\0');
            eepromWriteByte(209, '\0');

            eepromWriteByte(100, 1); //Analog port 0 = ADC
            eepromWriteByte(101, 1); //Analog port 1 = ADC
            eepromWriteByte(102, 1); //Analog port 2 = ADC
            eepromWriteByte(103, 1); //Analog port 3 = ADC
            eepromWriteByte(104, 1); //Analog port 4 = ADC
            eepromWriteByte(105, 1); //Analog port 5 = ADC
            eepromWriteByte(106, 1); //Analog port 6 = ADC
            eepromWriteByte(107, 1); //Analog port 7 = ADC

            eepromWriteByte(110, 0); //Digital port 0 = OUT
            eepromWriteByte(111, 0); //Digital port 1 = OUT
            eepromWriteByte(112, 0); //Digital port 2 = OUT
            eepromWriteByte(113, 0); //Digital port 3 = OUT

      	    wdt_reset();
            for (uint8_t alarm=1; alarm<=4; alarm++)
            {
                    uint16_t pos = 400 + ((alarm-1)*15); //400 415 430 445

                    eepromWriteByte(pos+0, 0); //enabled
                    eepromWriteByte(pos+1, 0); //sensorid
                    eepromWriteByte(pos+2, 0); //sensorid
                    eepromWriteByte(pos+3, 0); //sensorid
                    eepromWriteByte(pos+4, 0); //sensorid
                    eepromWriteByte(pos+5, 0); //sensorid
                    eepromWriteByte(pos+6, 0); //sensorid
                    eepromWriteByte(pos+7, 0); //sensorid
                    eepromWriteByte(pos+8, 0); //sensorid
                    eepromWriteByte(pos+9, '<'); //type
                    eepromWriteByte(pos+10, 0); //value
                    eepromWriteByte(pos+11, 0); //target
                    eepromWriteByte(pos+12, 0); //state
                    eepromWriteByte(pos+13, 0); //reverse
                    eepromWriteByte(pos+14, 0); //not-used
            }

            eepromWriteByte(1, EEPROM_VERSION);
    }
/*
    findSystemID(systemID);

    if (systemID[0] == 0) {
        printf_P(PSTR("No system id found, add a DS2401 or use old software"));
//        fprintf(&lcd_str, "?f?y0?x00No system id found?nAdd a DS2401 or use old software?n");
        wdt_disable();
        wdt_reset();
        while (true);
    } else {
*/    
        //MAC will be 56 51 99 36 14 00 with example system id
        mymac[1] = systemID[1];
        mymac[2] = systemID[2];
        mymac[3] = systemID[3];
        mymac[4] = systemID[4];
        mymac[5] = systemID[5];
//    }
//    fprintf(&lcd_str, "?y1?x00ID: %02X%02X%02X%02X%02X%02X%02X%02X?n", systemID[0], systemID[1], systemID[2], systemID[3], systemID[4], systemID[5], systemID[6], systemID[7]);

    loadSimpleSensorData();

    //Set digital pins based on selections...
    for (uint8_t i=8; i<=11; i++)
    {
            if (simpleSensorTypes[i] == 0)
            {
                    //output
                    SETBIT(DDRC, (i-6));
            } else {
                    //input
                    CLEARBIT(DDRC, (i-6));
            }
    }


    network_init();

    timer_set(&periodic_timer, CLOCK_SECOND / 2);
    timer_set(&arp_timer, CLOCK_SECOND * 10);

    uip_init();

    //sættes hvert for sig for uip og enc, skal rettes til en samlet setting, så vi kan bruge mymac
    struct uip_eth_addr mac = { {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5} };
//    struct uip_eth_addr mac = {mymac[0], mymac[1], mymac[2], mymac[3], mymac[4], mymac[5]};

    uip_setethaddr(mac);
    httpd_init();
    /*
    #ifdef __DHCPC_H__
            dhcpc_init(&mac, 6);
    #else
     */
    uip_ipaddr(ipaddr, myip[0], myip[1], myip[2], myip[3]);
    uip_sethostaddr(ipaddr);
    uip_ipaddr(ipaddr, gwip[0], gwip[1], gwip[2], gwip[3]);
    uip_setdraddr(ipaddr);
    uip_ipaddr(ipaddr, netmask[0], netmask[1], netmask[2], netmask[3]);
    uip_setnetmask(ipaddr);
    //#endif /*__DHCPC_H__*/

    printf("Setting ip to %u.%u.%u.%u \r\n", myip[0], myip[1], myip[2], myip[3]);

    resolv_init();
    uip_ipaddr(ipaddr, dnsip[0], dnsip[1], dnsip[2], dnsip[3]);
    resolv_conf(ipaddr);
    webclient_init();

    printf("Stokerbot NG R3 ready  -  Firmware %u.%u ...\r\n", SBNG_VERSION_MAJOR, SBNG_VERSION_MINOR);
//    fprintf(&lcd_str, "?y2?x00Firmware %u.%u ready.", SBNG_VERSION_MAJOR, SBNG_VERSION_MINOR);

//    SPILCD_init();

    wdt_reset();

    while (1) {
        //Only one event may fire per loop, listed in order of importance
        //If an event is skipped, it will be run next loop
        if (tickDiff(timer_Count) >= 1) {
            timer_Count = tick;
            wdt_reset(); //sikre at watchdog resetter os hvis timer systemet fejler, vi når her hvert 2ms
            updateCounters(); //bør ske i en interrupt istedet, for at garentere 2ms aflæsning
        } else if (tickDiffS(timer_IOalarm) >= 5) {
            printf("Timer : IO alarm \r\n");
            timer_IOalarm = tickS;
            timedAlarmCheck();
        } else if (tickDiffS(timer_OW) >= 2) {
            printf("Timer : OW \r\n");
            timer_OW = tickS;
            updateOWSensors();
        } else if (tickDiffS(timer_Simple) >= 5) {
            printf("Timer : Simple\r\n");
            timer_Simple = tickS;
            updateSimpleSensors();
        } else if (tickDiffS(timer_SendData) >= 59) {
            printf("Timer : webclient \r\n");
            timer_SendData = tickS;
            webclient_connect();
        } else if (tickDiffS(timer_EEProm) >= 60 * 30) {
            printf("Timer : eeprom \r\n");
            timer_EEProm = tickS;
            timedSaveEeprom();
        }

        //Net handling below



        if (tickDiff(timer_network) >= 1)
        {
            timer_network = tick;
            uip_len = network_read();

            if (uip_len > 0) {
                if (BUF->type == htons(UIP_ETHTYPE_IP)) {
                    uip_arp_ipin();
                    uip_input();
                    if (uip_len > 0) {
                        uip_arp_out();
                        network_send();
                    }
                } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
                    uip_arp_arpin();
                    if (uip_len > 0) {
                        network_send();
                    }
                }

            } else if (timer_expired(&periodic_timer)) {
                timer_reset(&periodic_timer);
                //FLIPBIT(PORTC,5);
    //            printf("Timers : %u %u \r\n", tick, tickS);

                for (uint8_t i = 0; i < UIP_CONNS; i++) {
                    uip_periodic(i);
                    if (uip_len > 0) {
                        uip_arp_out();
                        network_send();
                    }
                }

    #if UIP_UDP
                for (uint8_t i = 0; i < UIP_UDP_CONNS; i++) {
                    uip_udp_periodic(i);
                    if (uip_len > 0) {
                        uip_arp_out();
                        network_send();
                    }
                }
    #endif /* UIP_UDP */

                if (timer_expired(&arp_timer)) {
                    timer_reset(&arp_timer);
                    uip_arp_timer();
                }
            }
        }
    }
    return 0;
}
Example #14
0
int8_t
solometer_parse (char* ptr)
{
  char *str,*ptr1,c,*buf;
#ifdef DNS_SUPPORT
  uip_ipaddr_t dnsserver;
#endif
  int n;
  int16_t *int1_p,*int2_p,*int3_p,*int4_p;

  //buf=(char*)malloc(24);
  if(!(buf=(char*)malloc(24))) {
    //debug_printf("smt_parse: Not enough memory!\n");
    return -1;
  }
  
  int1_p = (int16_t*)(buf+16);
  int2_p = (int16_t*)(buf+18);
  int3_p = (int16_t*)(buf+20);
  int4_p = (int16_t*)(buf+22);

  ptr1 = strchr (ptr, ' ');
  if (ptr1 == NULL) {
    //debug_printf ("smt_parse: space after filename not found.\n");
    return -1;
  }

  /* Make a copy of the parameter string */
  c = *ptr1;
  *ptr1 = 0;
  if(!(str = malloc(strlen(ptr) + 1))) {
    //debug_printf("smt_parse: Not enough memory. Exiting.\n");
    *ptr1 = c;
    return -1;
  }
  ptr = strcpy(str,ptr);
  *ptr1 = c;

  urldecode(ptr);
  //debug_printf("String to parse: --%s--\n",ptr);

  if(get_string(ptr,PSTR("WRID="),buf,3)) {
    WRID[0] = (uint8_t)atoi(buf);
    eeprom_save(solometer_WRID, &WRID[0], 1);
    eeprom_update_chksum();
  }
  //debug_printf("Ausgewertet:WRID=--%u--\n",WRID[0]);

  if(get_string(ptr,PSTR("PVID="),post_cookie,11)) {
    eeprom_save(solometer_cookie, post_cookie, strlen(post_cookie) + 1);
    eeprom_update_chksum();
  }
  //debug_printf("Ausgewertet:PVID=--%s--\n",post_cookie);

  if(get_string(ptr,PSTR("HST="),post_hostname,64)) {
    eeprom_save(solometer_host, post_hostname, strlen(post_hostname) + 1);
    eeprom_update_chksum();
  }
  //debug_printf("Ausgewertet:HST=--%s--\n",post_hostname);

  if(get_string(ptr,PSTR("SCR="),post_scriptname,64)) {
    eeprom_save(solometer_script, post_scriptname, strlen(post_scriptname) + 1);
    eeprom_update_chksum();
  }
  //debug_printf("Ausgewertet:SCRPT=--%s--\n",post_scriptname);

  if(get_string(ptr,PSTR("HIP="),buf,16)) {
    n = sscanf(buf,"%d.%d.%d.%d",int1_p,int2_p,int3_p,int4_p);
    if(n == 4) {
      //debug_printf("Setting Host IP: %d %d %d %d\n",*int1_p,*int2_p,*int3_p,*int4_p);
      uip_ipaddr(&post_hostip,*int1_p,*int2_p,*int3_p,*int4_p);
      eeprom_save(solometer_hostip, post_hostip, sizeof(uip_ipaddr_t));
      eeprom_update_chksum();
      memset(buf,0,16);
      print_ipaddr(&post_hostip,buf,16);
      buf[15]=0;
    } else {
      //debug_printf("Not setting Host IP (n != 4).\n");
      buf[0] = 0;
    }
  } else {
    buf[0] = 0;
  }
  //debug_printf("Ausgewertet:HIP=--%s--\n",buf);

#ifdef DNS_SUPPORT
  if(get_string(ptr,PSTR("DNS="),buf,16)) {
    n = sscanf(buf,"%d.%d.%d.%d",int1_p,int2_p,int3_p,int4_p);
    if(n == 4) {
      //debug_printf("Setting DNS server IP\n");
      uip_ipaddr(&dnsserver,*int1_p,*int2_p,*int3_p,*int4_p);
      eeprom_save(dns_server, &dnsserver, sizeof(uip_ipaddr_t));
      eeprom_update_chksum();
      resolv_conf(&dnsserver);
      memset(buf,0,16);
      print_ipaddr(&dnsserver,buf,16);
      buf[15]=0;
    } else {
      //debug_printf("Not setting DNS server IP (n <> 4).\n");
      buf[0] = 0;
    }
  } else {
    buf[0] = 0;
  }
  //debug_printf("Ausgewertet:DNS=--%s--\n",buf);
#endif

  free(ptr);
  free(buf);
  return 0;
}
Example #15
0
void dhcp_net_main(void) {


  if(uip_newdata()) {

    switch (uip_udp_conn->appstate.dhcp.state) {
      
    case STATE_DISCOVERING:

      if (parse_msg() == DHCPOFFER) {
	send_request();
	uip_flags &= ~UIP_NEWDATA;
	uip_udp_conn->appstate.dhcp.state = STATE_REQUESTING;
	uip_udp_conn->appstate.dhcp.retry_timer   = 2; // retry
	uip_udp_conn->appstate.dhcp.retry_counter = 1;
	tick_sec = 0;
      }

      break;

    case STATE_REQUESTING:

      if (parse_msg() == DHCPACK) {
	uip_udp_conn->appstate.dhcp.state = STATE_CONFIGURED;

	uip_sethostaddr(uip_udp_conn->appstate.dhcp.ipaddr);
	uip_setdraddr(uip_udp_conn->appstate.dhcp.default_router);
	uip_setnetmask(uip_udp_conn->appstate.dhcp.netmask);

#ifdef DNS_SUPPORT
	resolv_conf(uip_udp_conn->appstate.dhcp.dnsaddr);
	//	eeprom_save(dns_server, &uip_udp_conn->appstate.dhcp.dnsaddr, IPADDR_LEN);
#endif

	// eeprom_save(ip, &uip_udp_conn->appstate.dhcp.ipaddr, IPADDR_LEN);
	// eeprom_save(netmask, &uip_udp_conn->appstate.dhcp.netmask, IPADDR_LEN);
	// eeprom_save(gateway, &uip_udp_conn->appstate.dhcp.default_router, IPADDR_LEN);

	// eeprom_update_chksum();

	/* Remove the bootp connection */
	uip_udp_remove(uip_udp_conn);

      }

      break;

    }
    
  } else {

    // No data yet
    
    switch (uip_udp_conn->appstate.dhcp.state) {
      
    case STATE_INITIAL:
    case STATE_DISCOVERING:
      
      if (tick_sec>uip_udp_conn->appstate.dhcp.retry_timer) {
	send_discover();
	uip_flags &= ~UIP_NEWDATA;
	uip_udp_conn->appstate.dhcp.state = STATE_DISCOVERING;
	if (uip_udp_conn->appstate.dhcp.retry_counter++>10)
	  return dhcp_set_static();
	uip_udp_conn->appstate.dhcp.retry_timer = 2 * uip_udp_conn->appstate.dhcp.retry_counter; // retry
	tick_sec = 0;
      }
      break;
      

    case STATE_REQUESTING:
      if (tick_sec>uip_udp_conn->appstate.dhcp.retry_timer) {
	send_request();
	uip_flags &= ~UIP_NEWDATA;
	if (uip_udp_conn->appstate.dhcp.retry_counter++>10)
	  return dhcp_set_static();
	uip_udp_conn->appstate.dhcp.retry_timer = 2; // retry
	tick_sec = 0;
      }
      break;
      
    }
    
  }


}