Example #1
0
/**
 * In this function, the hardware should be initialized.
 * Called from g2100if_init().
 *
 * @param netif the already initialized lwip network interface structure
 *        for this g2100if
 */
static void
low_level_init(struct netif *netif)
{
  struct g2100if *g2100if = netif->state;

  zg_init();
  
  /* set MAC hardware address length */
  netif->hwaddr_len = ETHARP_HWADDR_LEN;

  U8* zg_mac = zg_get_mac();

  /* set MAC hardware address */
  netif->hwaddr[0] = zg_mac[0];
  netif->hwaddr[1] = zg_mac[1];
  netif->hwaddr[2] = zg_mac[2];
  netif->hwaddr[3] = zg_mac[3];
  netif->hwaddr[4] = zg_mac[4];
  netif->hwaddr[5] = zg_mac[5];

  /* maximum transfer unit */
  netif->mtu = 1500;
  
  /* device capabilities */
  /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
  netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_LINK_UP;
 
}
Example #2
0
uint8_t macInitialize(uint8_t *address) { // 0 if success, 1 on error
    uint8_t i;
    uint8_t *p;

    INTDDR &= ~(1 << INTPIN); // Interrupt PIN

    debugPrint("Initializing WiFi...");

    zg_init();

    debugPrint(" Done!\nConnecting...");

    addConditionalTask(zg_isr, zgInterruptOccured); // Emulate INT0
    do {
        zg_drv_process();
    } while (!macLinkIsUp());

    debugPrint(" Done!\n");

    p = zg_get_mac(); // Global Var. in g2100.c
    for (i = 0; i < 6; i++) {
        ownMacAddress[i] = p[i];
        address[i] = ownMacAddress[i];
    }

    return 0;
}
Example #3
0
void vNet_SetAddress_M1(uint16_t addr)
{
	uint8_t ip_addr[4];
	
	// Translate and set the address
	eth_vNettoIP(addr, &ip_addr[0]);
	eth_SetIPAddress(&ip_addr[0]);
	
	// Get the MAC Address from the Wifi controller and set it 
	// into the uIP stack
	U8* mac_addr_hw = zg_get_mac();
	memcpy(mac_addr, mac_addr_hw, 6);
	
	vNet_Begin_M1(0);								// Start listen on socket

}
Example #4
0
static int handle_tdtp_connection(struct tdtp_state *t)
{
        char *p, *tmp, *to_free = NULL;
//        char version[32];
        u8_t new_motor = 0, new_direction = 0, new_pwm = 0, new_time = 0;
        U8 *mac = NULL;
	PSOCK_BEGIN(&t->p);
        if(uip_connected() && !(uip_timedout())
           && !(uip_closed()) && !(uip_aborted())) {
#ifdef MOG_DEBUG
                printf("connectedr\n");
#endif
                mac = zg_get_mac();
                /* sprintf(version, "dialadong-001|%02X:%02X:%02X:%02X:%02X:%02X", */
                /*         mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]); */
                /* uip_send(version, strlen(version)); */
                uip_send("dialadong-001|",15);
                uip_send(hex_convert(mac[0]),3);
                uip_send(hex_convert(mac[1]),3);
                uip_send(hex_convert(mac[2]),3);
                uip_send(hex_convert(mac[3]),3);
                uip_send(hex_convert(mac[4]),3);
                uip_send(hex_convert(mac[5]),3);
                uip_send("dialadong-001|00:1E:C0:00:0B:DB", 32);
        } else if(uip_newdata()) {
                memset(&t->inputbuffer, 0, sizeof(t->inputbuffer));
		PSOCK_READTO(&t->p, '\n');
	#ifdef MOG_DEBUG
		printf("hello %d:%s:\r\n", uip_datalen(), t->inputbuffer);
	#endif
                tmp = to_free = strdup(t->inputbuffer);
                if(tmp) {
                        p = strsep(&tmp, ",");
                        if(p) {
                                new_motor = atoi(p);
                                p = strsep(&tmp, ",");
                        }
                        if(p) {
                                new_direction = atoi(p);
                                p = strsep(&tmp, ",");
                        }
                        if(p) {
                                new_pwm = atoi(p);
                                p = strsep(&tmp, ",");
                        }
                        if(p) {
                                new_time = atoi(p);
#ifdef MOG_DEBUG
                                printf("hello :%d:%d:%d:%d:\r\n", new_motor, new_direction, new_pwm, new_time);
#endif
                                uip_send(t->inputbuffer,sizeof(t->inputbuffer));
                                //do stuff here
                        }
                }
	} else if(uip_closed()) {
#ifdef MOG_DEBUG
                printf("failure closed\r\n");
#endif
		uip_abort();
                tdtp_state = 1;
	} else if(uip_aborted()) {
#ifdef MOG_DEBUG
                printf("failure aborted\r\n");
#endif
		uip_abort();
                tdtp_state = 1;
	} else if(uip_timedout()) {
#ifdef MOG_DEBUG
                printf("failure timedout\r\n");
#endif
		uip_abort();
                tdtp_state = 1;
        }

        if(to_free)
                free(to_free);

	PSOCK_END(&t->p);
	return 0;
}