Example #1
0
int main()
{
    log_printf(LOG_VERBOSE, "[StartProgram]...........\n");
    log_printf(LOG_VERBOSE, "[HW-VERSION]: %s\n", HW_VERSION);
    log_printf(LOG_VERBOSE, "[SW_VERSION]: %s\n", SW_VERSION);
    log_printf(LOG_NOTICE, "COMPILE_TIME[%s: %s]\n", __DATE__, __TIME__);

#ifdef USE_IN_ARM
    sleep(10);
#endif
    unsigned char buf[MQTT_PLAYLOADLEN];
    unsigned char readbuf[MQTT_PLAYLOADLEN];

    signal(SIGINT, cfinish);
    signal(SIGTERM, cfinish);

    global_loop = EV_DEFAULT;
    global_ev_all.mainloop = global_loop;

    Network n;  //必须  //mqtt network实体
    gateway_setting_init();
    gwmsg_init();
    devlist_gateway_msg_init();
//	dev_init();
    NewNetwork(&n);
    MQTTClient(&global_ev_all.client, &n, KEEPALIVE_INTERVAL, buf, MQTT_PLAYLOADLEN, readbuf, MQTT_PLAYLOADLEN);

    mqtt_init();
    zigbee_init();
    ev_run(global_ev_all.mainloop, 0); //run...

    log_printf(LOG_ERROR, "[Stopping]...\n");
    MQTTDisconnect(&global_ev_all.client);
    n.disconnect(&n);

    return 0;
}
Example #2
0
int main(void)
{

	board_init();
    uint16_t count;
	// Insert application code here, after the board has been initialized.
	
	sysclk_init();
	spi_task_init();
	pmic_init();
	alarm_task_init();
	scheduler_init();
	alarm("Device Restarted");
    zigbee_init();

    PORTC.INT0MASK |= PIN3_bm;
	PORTC.INTCTRL |= PORT_INT0LVL_LO_gc;
	PORTC.PIN3CTRL |= (PORT_ISC1_bm);
	//PORTC.PIN3CTRL |= (PORT_ISC1_bm | PORT_ISC2_bm);
	
	sei();
	

	
	addr_t destShortTemp, destLongTemp;

	destShortTemp.PANid = 0xBABE;
	destShortTemp.shortAddr = 0x0000;
	destShortTemp.mode = MAC_SHORT_ADDRESS;
	
	destLongTemp.PANid = 0x1122;
	destLongTemp.extAddr = 0x9999999999999999;
	destLongTemp.mode = MAC_LONG_ADDRESS;
	
	security_t sec;

	

if(ioport_pin_is_high(ZIGBEE_COORD_GPIO))
	{
		nwk_nlme_nf_t nf;
		nf.beaconOrder = 0xf;
		nf.BatteryLifeExt = NO;
		nf.scanChannels = 0x00000800;
		nf.scanDuration = 0x2;
		nf.superframeOrder = 0xf;
		NWK_nlme_formNetworkReq(&nf);

	}
else{		
	nwk_join_t join;
	join.extedPANid = 0x0000222388894343;
	join.capabilityInfo.altPanCoord = NO;
	join.capabilityInfo.powerSource = 0;
	join.capabilityInfo.devType = 0;
	join.capabilityInfo.reserved2 = 0;
	join.capabilityInfo.secEnabled = 0;
	join.capabilityInfo.allocAddr = 0x01;
	join.duration = 2;
	join.scanChannels = 0x00000800;
	join.securityEnabled = NO;
	join.rejoinNetwork = JOINED_THRU_ASSOC;
	
	addr_t dest;
	dest.shortAddr = 0x0000;
	dest.PANid = 0x3ac6;
	dest.mode = 0x02;
	MAC_mlme_assocReq(&dest, DEFAULT_CHANNELPAGE, DEFAULT_CHANNEL, *((uint8_t *)&join.capabilityInfo), &sec);
}

	scheduler();
	

    return 0;
}
Example #3
0
int main(void)
{

	board_init();
    uint16_t count;
	// Insert application code here, after the board has been initialized.
	
	sysclk_init();
	spi_task_init();
	pmic_init();
	alarm_task_init();
	scheduler_init();
	alarm("Device Restarted");
    zigbee_init();

    PORTC.INT0MASK |= PIN3_bm;
	PORTC.INTCTRL |= PORT_INT0LVL_LO_gc;
	PORTC.PIN3CTRL |= (PORT_ISC1_bm);
	//PORTC.PIN3CTRL |= (PORT_ISC1_bm | PORT_ISC2_bm);
	
	sei();
	

	
	addr_t destShortTemp, destLongTemp;

	destShortTemp.PANid = 0xBABE;
	destShortTemp.shortAddr = 0x0000;
	destShortTemp.mode = MAC_SHORT_ADDRESS;
	
	destLongTemp.PANid = 0x1122;
	destLongTemp.extAddr = 0x9999999999999999;
	destLongTemp.mode = MAC_LONG_ADDRESS;
	
	security_t sec;

//	MAC_beaconReqCommand();//LOOKS GOOD
//	if((MAC_isPanCoord()) == 0)
	{
		
	nwk_leaveCmdOptionField_t temp;
	temp.removeChild = YES;
	
	NWK_cmd_linkStatus();
	
/*	_delay_ms(500);
	MAC_mlme_assocReq(&destShortTemp, 0x00000000, 11, 0x8e, &sec);


	_delay_ms(5000);
	mac_mlme_disassocReq(DEV_WISHES_TO_LEAVE);
	*/
	}	
//	MAC_assocRequestCommand(&destShortTemp);//LOOKS GOOD
//	MAC_assocResponceCommand(mlme_assoc_t *assoc);
//	MAC_disassocCommand(&destShortTemp);//LOOKS GOOD
//	MAC_dataRequestCommand(&destShortTemp);//LOOKS GOOD
//	MAC_panIDConflictCommand();//LOOKS GOOD
//	MAC_orphanCommand();//LOOKS GOOD
//	MAC_beaconReqCommand();
//	MAC_commandCoordRealign(&destShortTemp, &sec);

	scheduler();
	

    return 0;
}