void ieee802frame154_dump( TiFrame * f )
{
    int8 len;
    TiIEEE802Frame154Descriptor meta;

    len = frame_length(f);
	if (len > 0)
	{   
		dbc_putchar( '>' );
	 	dbc_n8toa( len );
		 ieee802frame154_open( &meta );
        if (ieee802frame154_parse(&meta, frame_startptr(f), frame_length(f)))
        {
			dbc_putchar( ':' );
			dbc_write_n8toa( frame_startptr(f), len );
			dbc_putchar( 0xFC );
			dbc_putchar( '\r' );
			dbc_putchar( '\n' );
			}
		else{
            // if parsing failed, then we also output the data
            dbc_putchar( 0xFC );
			dbc_write_n8toa( frame_startptr(f), len );
			dbc_putchar( '\r' );
			dbc_putchar( '\n' );
			}
		}
		 else{
        // If the f doesn't contain any data, then still output some flag for indication.
        dbc_putchar( 0xFB );
        dbc_putchar( 0xFB );
    }
}
Esempio n. 2
0
/*
 * assume: the timer object is initialized successfully.
 */
TiAloha * aloha_open( TiAloha * mac, TiFrameTxRxInterface * rxtx, uint8 chn, uint16 panid, 
	uint16 address, TiTimer * timer, TiFunEventHandler listener, void * lisowner, uint8 option )
{
    void * provider;

    // assert( the rxtx driver has already been opened );
    // assert( mac->timer is already opened but not start yet );

	rtl_assert((rxtx != NULL) && (timer != NULL));

	mac->state = ALOHA_STATE_IDLE;
    mac->rxtx = rxtx;
	mac->timer = timer;
	mac->listener = listener;
	mac->lisowner = lisowner;
	mac->retry = 0;
	mac->backoff = CONFIG_ALOHA_MIN_BACKOFF;
    mac->panto = panid;
    mac->shortaddrto = FRAME154_BROADCAST_ADDRESS;
    mac->panfrom = panid;
    mac->shortaddrfrom = address;
    mac->seqid = 0;
    mac->sendoption = 0x00;
    mac->sendfailed = 0;
	mac->option = option;
    mac->txbuf = frame_open( &(mac->txbuf_memory[0]), FRAME_HOPESIZE(CONFIG_ALOHA_MAX_FRAME_SIZE), 0, 0, 0 );
	
    hal_assert( mac->timer != NULL );

    // initialize the frame transceiver component
	// attention enable ACK support for aloha protocol. the current implementation depends
    // on low level transceiver component to provide ACK mechanism. 

    provider = rxtx->provider;
	rxtx->setchannel( provider, chn );
	rxtx->setpanid( provider, panid );
	rxtx->setshortaddress( provider, address );
    rxtx->enable_addrdecode( provider );
	rxtx->enable_autoack( provider );

    ieee802frame154_open( &(mac->desc) );

    // initialize the random number generator with a random seed. you can replace 
    // the seed with other values.
    //
    // @attention: generally, the random generator can be initialized when the whole
    // application started. if so, you needn't call rand_open() to initialize it 
    // again here.

    rand_open( 0x3212 );

    return mac;
}
Esempio n. 3
0
/**
 * open the TiNanoSync component for time sync operation
 *
 * @attention
 * - the rxtx component should be ready for sending and receving. the TiNanoSync 
 *  component assumes the rxtx has already opened and initialized successfully.
 */
TiNanoSync * nanosync_open( TiNanoSync * sync, uint8 mode, TiRtc * rtc, TiFrameTxRxInterface * rxtx, 
	uint8 chn, uint16 panid, uint16 address, char * buf,uint16 period, uint8 option )

{
	rtl_assert((rxtx != NULL) );
	sync->mode = mode;
	sync->rtc = rtc;
    sync->rxtx = rxtx;
	sync->panto = panid;
	sync->shortaddrto = FRAME154_BROADCAST_ADDRESS;
	sync->panfrom = panid;
	sync->shortaddrfrom = address;
	sync->seqid = 0;
	sync->option = option;

	ieee802frame154_open( &(sync->desc) );

	return sync;
}
Esempio n. 4
0
void _output_frame( TiFrame * frame, TiUartAdapter * uart )
{
    static TiIEEE802Frame154Descriptor m_desc;
    TiIEEE802Frame154Descriptor * desc;

	if (frame_totallength(frame) > 0)
	{   
		dbc_putchar( '>' );
	 	dbc_n8toa( frame_totallength(frame) );

        desc = ieee802frame154_open( &m_desc );
        // ? if (ieee802frame154_parse(desc, frame_startptr(frame), frame_length(frame)))
        if (ieee802frame154_parse(desc, frame_startptr(frame), frame_capacity(frame)))
        {
            // if the frame received is parsed successfully, then output it to the
            // computer through debugging channel

            //ieee802frame154_set_sequence( desc, seqid ++ );
		    //ieee802frame154_set_panto( desc, CONFIG_ALOHA_DEFAULT_PANID );
		    //ieee802frame154_set_shortaddrto( desc, CONFIG_ALOHA_REMOTE_ADDRESS );
		    //ieee802frame154_set_panfrom( desc, CONFIG_ALOHA_PANID);
		    //ieee802frame154_set_shortaddrfrom( desc, CONFIG_ALOHA_LOCAL_ADDRESS );

            // todo: you can output more
            // reference frame_dump() in rtl_frame.c

            dbc_n8toa( ieee802frame154_sequence(desc) );
			dbc_putchar( ':' );
			dbc_write( frame_startptr(frame), frame_capacity(frame) );
		}
		else{
	        // if the frame received is parsed failed, then output the error frame
            // to the computer through debugging channel

	        dbc_putchar( 'X' );
			dbc_putchar( ':' );
			dbc_write( frame_startptr(frame), frame_capacity(frame) );
		}
		dbc_putchar( '\r' );
		dbc_putchar( '\n' );
	}
}
Esempio n. 5
0
void ieee802frame154_dumpmembuf( char * buf, int len )
{
    TiIEEE802Frame154Descriptor * desc;

	 if (len > 0)
	{   
		dbc_putchar( '>' );
	 	dbc_n8toa( len );

        desc = ieee802frame154_open( &m_desc );
        if (ieee802frame154_parse(desc, buf, len))
        {
            // if the frame received is parsed successfully, then output it to the
            // computer through debugging channel

            //ieee802frame154_set_sequence( desc, seqid ++ );
		    //ieee802frame154_set_panto( desc, CONFIG_ALOHA_DEFAULT_PANID );
		    //ieee802frame154_set_shortaddrto( desc, CONFIG_ALOHA_REMOTE_ADDRESS );
		    //ieee802frame154_set_panfrom( desc, CONFIG_ALOHA_PANID);
		    //ieee802frame154_set_shortaddrfrom( desc, CONFIG_ALOHA_LOCAL_ADDRESS );

            // todo: you can output more
            // reference frame_dump() in rtl_frame.c
           
            dbc_n8toa( ieee802frame154_sequence(desc) );
			dbc_putchar( ':' );
			dbo_write( buf, len );
		}
		else{
	        // if the frame received is parsed failed, then output the error frame
            // to the computer through debugging channel

	        dbc_putchar( 'X' );
			dbc_putchar( ':' );
			dbo_write( buf, len );
		}
		dbc_putchar( '\n' );
	}
}
void ieee802frame154_dump( TiFrame * f )
{
    int8 len;
    TiIEEE802Frame154Descriptor meta;

    len = frame_length(f);
	if (len > 0)
	{   
		
		dbc_putchar( 0xFA );
		dbc_putchar( 0xFA );
	    dbc_putchar( frame_curlayer(f) );
	 	dbc_putchar( len );

        // if the frame received is parsed successfully, then output it to the
        // computer through debugging channel
        //
        ieee802frame154_open( &meta );
        if (ieee802frame154_parse(&meta, frame_startptr(f), frame_length(f)))
        {
            // todo: you can output more
            // reference frame_dump() in rtl_frame.c

			dbc_putchar( 0xFB );
			dbc_write( frame_startptr(f), len );
			dbc_putchar( 0xFC );
		}
		else{
            // if parsing failed, then we also output the data
            dbc_putchar( 0xFC );
			dbc_write( frame_startptr(f), len );
		}
	}
    else{
        // If the f doesn't contain any data, then still output some flag for indication.
        dbc_putchar( 0xFB );
        dbc_putchar( 0xFB );
    }
}
Esempio n. 7
0
uintx _nanosync_broadcast( TiNanoSync * sync, uint8 option )//这一句函数不知道能不能实现?
{    
	
	TiIEEE802Frame154Descriptor * desc;
	uintx ret;
    char * payload;
	uintx count=0;
	uint16 time;
	uint8 time_1,time_2;

	ieee802frame154_open( &(sync->desc) );
    
    

	desc = ieee802frame154_format( &(sync->desc), &(sync->txbuf[0]), sizeof(sync->txbuf), FRAME154_DEF_FRAMECONTROL_DATA );
	rtl_assert( desc != NULL );

	

	ieee802frame154_set_sequence( desc, sync->seqid );
	ieee802frame154_set_panfrom( desc, sync->panfrom );
	ieee802frame154_set_shortaddrfrom( desc, sync->shortaddrfrom );
	ieee802frame154_set_panto( desc, FRAME154_BROADCAST_PAN );
	ieee802frame154_set_shortaddrto( desc, FRAME154_BROADCAST_ADDRESS );

    payload = ieee802frame154_msdu( desc );
	
    payload[0] = CONFIG_NANOSYNC_IDENTIFIER;
    payload[1] = sync->seqid;
    payload[2] = NANOSYNC_CMD_RESPONSE;
    // @todo
	time = sync->rtc->curtime.year;
	time_2 = (uint8)(time);//low byte
	time_1 = (uint8)(time >> 8);//high byte
	payload[3] = time_1;
	payload[4] = time_2;
	payload[5] = sync->rtc->curtime.month;
	payload[6] = sync->rtc->curtime.day;
	payload[7] = sync->rtc->curtime.hour;
	payload[8] = sync->rtc->curtime.min;
	payload[9] = sync->rtc->curtime.sec;
	/*payload[5] = 0xd1;//测试用的
    payload[6] = 0xd2;//测试用的
	payload[7] = 0xd3;//测试用的
	payload[8] = 0xd4;//测试用的
	payload[9] = 0xd5;//测试用的*/
	time = sync->rtc->curtime.msec;
	time_2 = (uint8)(time);//low byte
	time_1 = (uint8)(time >> 8);//high byte
	payload[10] = time_1;
	payload[11] = time_2;
   /* payload[10] = 0xd6;//测试用的
	payload[11] = 0xd7;//测试用的*/
    

    // the last parameter 0x00 indicate this send doesn't require ACK. it's actually broadcast 
	count = sync->rxtx->send( sync->rxtx->provider, sync->txbuf, sizeof(sync->txbuf), 0x00 );
	if (count > 0)
	{
		sync->seqid ++;
	}

	

	return count;	
}