Пример #1
0
void otapi_log_code(ot_int label_len, ot_u8* label, ot_u16 code) {
/// Emergency logging: Used for kernel panics or other such things.
    mpipedrv_kill();
    
    //code = PLATFORM_ENDIAN16(code);
    otapi_log_msg(MSG_raw, label_len, 2, label, (ot_u8*)&code);
}
Пример #2
0
void main(void) {
    ///1. Standard Power-on routine (Clocks, Timers, IRQ's, etc)
    ///2. Standard OpenTag Init (most stuff actually will not be used)
    platform_poweron();
    platform_init_OT();

    ///3. Initialize the User Applet & interrupts
    app_init();

    ///4a. The device will wait (and block anything else) until you connect
    ///    it to a valid console app.
    mpipedrv_standby();

    ///4b. Load a message to show that main startup has passed
    otapi_log_msg(MSG_utf8, 6, 26, (ot_u8*)"SYS_ON", (ot_u8*)"System on and Mpipe active");

    ///5. MAIN RUNTIME (post-init)  <BR>
    ///<LI> Use a main loop with platform_ot_run(), and nothing more. </LI>
    ///<LI> You could put code before or after sys_runtime_manager, which will
    ///     run before or after the (task + kernel).  If you do, keep the code
    ///     very short or else you are risking timing glitches.</LI>
    ///<LI> To run any significant amount of user code, use tasks. </LI>
    while(1) {
        platform_ot_run();
    }
}
Пример #3
0
void ext_systask(ot_task task) {
    session_tmpl    s_tmpl;

    if (task->event == 1) {
        task->event = 0;
        
        // this is the same as the length of the response window,
        // which is set in applet_send_query()
        task->nextevent = 512;  
    
        // Generate a pseudo random 16 bit number to be used as a ping check value
        app.pingval = platform_prand_u16();
    
        // Log a message.  It is scheduled, and the RF task has higher priority,
        // so if you are sending a DASH7 dialog this log message will usually
        // come-out after the dialog finishes.
#       if (OT_FEATURE(MPIPE))
        otapi_log_msg(MSG_raw, 5, 2, (ot_u8*)"PING:", (ot_u8*)&app.pingval);
#       endif
    
        // Load the session template: Only used for communication tasks
        s_tmpl.channel      = task->cursor;
        s_tmpl.flagmask     = 0;
        s_tmpl.subnetmask   = 0;
        otapi_task_immediate(&s_tmpl, &applet_send_query);
    }
    
    // Turn off the task after 512 ticks (what is set above)
    // Note that this task will not be activated by the button press or ALP
    // when event != 0, because those routines have conditionals in them.
    //else {
    //    task->event = 0;
    //}
}
Пример #4
0
void network_sig_route(void* route, void* session) {
/// network_sig_route() will have route >= 0 on successful request processing.
/// "route" will always be set to -1, which will cause the Data Link Layer to 
/// ignore the rest of the session and keep listening (sniffing).
    static const ot_u8 unknown_rx[10]   = "UNKNOWN_RX";
    static const ot_u8 opentag_rx[10]   = "OPENTAG_RX";
    ot_u8* label;

    // A valid packet has been received.
    // You can look at the response in the TX Queue (and log it if you want).
    // We just log the request and mark it as known or unknown.
    if (*(ot_int*)route >= 0) {
        label = (ot_u8*)opentag_rx;
    }
    else {
        label = (ot_u8*)unknown_rx;
    }
    
    // Log the received packet data (with 10 character label)
    otapi_log_msg(MSG_raw, 10, rxq.length, label, rxq.front);
    
    // Turn on Green LED to indicate received packet
    // Activate the app task, which will turn off the LED in 30 ticks
    otapi_led1_on();
    sys_task_setevent(APP_TASK, 1);
    sys_preempt(APP_TASK, 30);

    // Tell DLL to disregard session, no matter what.
    *(ot_int*)route = -1;
}
Пример #5
0
void network_sig_route(void* route, void* session) {
	static const ot_u8 label_dialog[]	= { 9, 'M','2','_','D','i','a','l','o','g' };
	static const ot_u8 label_nack[]		= { 7, 'M','2','_','N','a','c','k' };
	static const ot_u8 label_stream[]	= { 9, 'M','2','_','S','t','r','e','a','m' };
	static const ot_u8 label_snack[]	= { 7, 'M','2','_','S','N','a','c','k' };

	static const ot_u8* labels[] 		= { label_dialog,
											label_nack,
											label_stream,
											label_snack };
	ot_u8 protocol;

	protocol = ((m2session*)session)->protocol & 3;
	otapi_log_msg(	MSG_raw,
					labels[protocol][0],
					rxq.length,
					(ot_u8*)&(labels[protocol][1]),
					rxq.front	);
}
Пример #6
0
void ext_systask(ot_task task) {
    advert_tmpl     adv_tmpl;
    session_tmpl    s_tmpl;

    if (task->event == 1) {
        task->event++;
        
        // this is the same as the length of the response window,
        // which is set in applet_send_query()
        task->nextevent = 512;  
    
        // Generate a pseudo random 16 bit number to be used as a ping check value
        app.pingval = platform_prand_u16();
    
#       if defined(BOARD_eZ430Chronos)

#       else
        // Log a message.  It is scheduled, and the RF task has higher priority,
        // so if you are sending a DASH7 dialog this log message will usually
        // come-out after the dialog finishes.
        otapi_log_msg(MSG_raw, 5, 8, (ot_u8*)"PING:", (ot_u8*)&app.pingval);
#       endif
        
        // Advert Tmpl: most of the parameters are for special purposes only
        adv_tmpl.channel    = 7;
        adv_tmpl.duration   = 1024;
        
        // Load the session template: Only used for communication tasks
        s_tmpl.channel      = task->cursor;
        s_tmpl.flagmask     = 0;
        s_tmpl.subnetmask   = 0;
        
        otapi_task_advertise(&adv_tmpl, &s_tmpl, &applet_send_query);
    }
    
    // Turn off the task after 512 ticks (what is set above)
    // Note that this task will not be activated by the button press or ALP
    // when event != 0, because those routines have conditionals in them.
    else {
        task->event = 0;
    }
}
Пример #7
0
void network_sig_route(ot_int code, ot_int protocol) {
#if (MPIPE_FOR_DEBUGGING)
	static const ot_u8 label_dialog[]	= { 9, 'M','2','_','D','i','a','l','o','g' };
	static const ot_u8 label_nack[]		= { 7, 'M','2','_','N','a','c','k' };
	static const ot_u8 label_stream[]	= { 9, 'M','2','_','S','t','r','e','a','m' };
	static const ot_u8 label_unknown[]	= { 4, 'P','K','T','?' };

	static const ot_u8* labels[] 		= { label_dialog,
											label_nack,
											label_stream,
											label_unknown };
	if ( (ot_u16)protocol > 2 )
		protocol = 3;

	otapi_log_msg(	MSG_raw,
					labels[protocol][0],
					rxq.length,
					(ot_u8*)&(labels[protocol][1]),
					rxq.front	);
#endif
}
Пример #8
0
void ext_systask(ot_task task) {
    static const char msg0[] = "Sending Beacon";
    static const char msg1[] = "Sending Query ";
    static const char msg2[] = "Go to Gateway ";
    static const char msg3[] = "Go to Endpoint";
    static const char *msglist[] = { msg0, msg1, msg2, msg3 };

	ot_int app_select;
	session_tmpl s_tmpl;

	// Disable this task after running, by setting event to 0
	app_select  = task->event - 1;
	task->event = 0;

	// Log a message.  It is scheduled, and the RF task has higher priority,
	// so if you are sending a DASH7 dialog this log message will usually
	// come-out after the dialog finishes.
	otapi_log_msg(MSG_utf8, 3, 14, (ot_u8*)"CMD", (ot_u8*)msglist[app_select]);

	// Load the session template: Only used for communication tasks
	s_tmpl.channel      = 0x00;
	s_tmpl.flagmask     = 0;
	s_tmpl.subnetmask   = 0;

	switch (app_select) {
	// Communication Task Commands
	///@todo Change Query command to use otapi_task_immediate_advertise()
	///@note You can actually call otapi_task... functions directly from
	/// the alp_extproc function without breaking anything.
	case 0: otapi_task_immediate(&s_tmpl, &applet_send_beacon);   break;
	case 1: otapi_task_immediate(&s_tmpl, &applet_send_query);   break;

	// Direct System Control Commands
	case 2: opmode_goto_gateway();  break;
	case 3: opmode_goto_endpoint(); break;
	}
}
Пример #9
0
void sys_sig_rfaterminate(ot_int pcode, ot_int scode) {
/// Hint: RFxRX_e1 label means the received frame has bad CRC.
    ot_u8   loglabel[8] = {'R', 'F', 'F', 0, 'X', '_', 0, 0};
    ot_u8*  logdata;
    ot_int  logdata_len;

    otapi_led2_off();   //Orange LED off
    otapi_led1_off();   //Green LED off

    /// Error Handler:
    /// <LI> If there is an error code, put the code in the log label.     </LI>
    /// <LI> Else if the code is for RX termination, just return.  You can
    ///      comment this and uncomment cases 1 & 2 from the switch block if
    ///      you want to log on RX termination.  </LI>
    /// <LI> Else, the code is for TX or CCA.  Append the channel number to 
    ///      the log label (in hex) </LI> 
    if (scode < 0) {
        loglabel[6] = 'e';
        loglabel[7] = (ot_int)('0') - scode;
    }
    else if (pcode < 3) {
    	return;
    }
    else {
    	otutils_bin2hex(&(phymac[0].channel), &loglabel[6], 1);
    }

    /// Look at the control code an form the label to reflect the type
    switch (pcode) {
        /// RX driver process termination:
        /// (1) background scan ended, (2) or foreground scan ended
        //case 1: loglabel[2] = 'B';
        //case 2: loglabel[3] = 'R';
        //        logdata_len = rxq.length;
        //        logdata     = rxq.front;
        //        break;

        /// TX CCA/CSMA driver process termination:
        /// (3) TX CSMA process ended
        case 3: loglabel[2] = 'C';
                loglabel[3] = 'C';
                loglabel[4] = 'A';
                logdata_len = 0;
                logdata     = NULL; // suppress compiler warning
                break;

        /// TX driver process termination
        /// Background Flood (4) or Foreground TX (5): turn-on green and log TX
        case 4: loglabel[2] = 'B';
        case 5: loglabel[3] = 'T';
                logdata_len = txq.length;
                logdata     = txq.front;
                break;

        /// Unknown code, don't log any data
        default: return;
    }

    /// Log in ASCII hex the prepared driver message
    otapi_log_msg(MSG_raw, 8, logdata_len, loglabel, logdata);
}