Пример #1
0
static void vMain( void *pvParameters )
{
	buffer_t *buffer;
	vTaskDelay(500 / portTICK_RATE_MS );
	pause(200);
	debug_init(115200);
	pause(300);
	
	if(stack_start(NULL)==START_SUCCESS)
	{
		debug("Start Ok\r\n");
	}

	buffer = stack_buffer_get(0);
	if (buffer)
	{
		buffer->from = MODULE_NRP;
		buffer->to = MODULE_NRP;
		buffer->options.type = BUFFER_CONTROL;
		buffer_push_uint8(buffer, NRPC_RESET);
		stack_buffer_push(buffer);
	}
	LED2_ON();
	vTaskDelay(500 / portTICK_RATE_MS );	
	LED2_OFF();
	LED1_OFF();
	for( ;; )
	{
		//LED1_ON();
		vTaskDelay(5000 / portTICK_RATE_MS );
		//LED1_OFF();
	}
}
Пример #2
0
static void vSensorTask( void *pvParameters )
{
	portTickType xLastWakeTime;
	uint16_t count = 0;
	uint8_t bl_state = 0;
	uint8_t bl_state_p = 0;
	pause(200);
	debug_init(115200);
	pause(300);

	if(stack_start(NULL)==START_SUCCESS)
	{
		debug("Start Ok\r\n");
	}

	xLastWakeTime = xTaskGetTickCount();
	LED1_ON();
	vTaskDelayUntil( &xLastWakeTime, 1000 / portTICK_RATE_MS );
	LED1_OFF();

	P6DIR |= 0xC0;
	P6DIR &= ~0x0F;
	P6OUT |= 0xC0;
	P5DIR &= ~0x80;
	P2DIR &= ~0x01;
		
	for (;;)
	{
		vTaskDelayUntil( &xLastWakeTime, 20 / portTICK_RATE_MS );
		bl_state &= ~ 0x33;
		/*read example board buttons*/
		if (P2IN & 0x01) 
		{
			bl_state |= 0x10;
		}
		if (P5IN & 0x80)
		{
		 	bl_state |= 0x20;
		}
		/*setup example board LEDs according to button changes*/
		if ((bl_state ^ bl_state_p) & 0x10)
		{
			P6OUT ^= 0x40;
		}
		if ((bl_state ^ bl_state_p) & 0x20)
		{
			P6OUT ^= 0x80;
		}
		if (P6OUT & 0x40) bl_state |= 0x01;
		if (P6OUT & 0x80) bl_state |= 0x02;
		if (bl_state != bl_state_p)
		{
			ssi_sensor_update(2, (uint32_t) bl_state);
		}	
		bl_state_p = bl_state;
		
		if (adc_state == 0)
		{	/*adc read complete, new values available*/
			ssi_sensor_update(0, (uint32_t) adc_value[2]);
			ssi_sensor_update(1, (uint32_t) adc_value[0]);
			adc_state = 16;
		}
		
		if (count++ >= 49)
		{
			uint8_t channels[] = {0,1,2};
			
			LED1_ON();
			adc_read(channels,sizeof(channels));
			count = 0;
		}
		else
		{
			LED1_OFF();
		}
	}
}
Пример #3
0
/* 
 * The main method of the Cluster Membership Monitor 
 */
int
main( int argc,
      char *argv[] )
{
    int c;
    cmm_nodeid_t node_id = CMM_INVALID_NODE_ID;
    char *filename = NULL;
    cmm_error_t err;
    cm_trace_level_t trace_level = CM_TRACE_LEVEL_NOTICE;
    fifo_t *lobby_to_sender, *stack_to_sender;
    int pipe_stack[2];
    struct sigaction action;

    /* Read and verify the input arguments */

    while ( (c=getopt(argc, argv, "n:f:d")) != EOF ) {
        switch (c) {
        case 'n' :
            node_id = atoi( argv[optind-1] );
            break;
            
        case 'f' :
            filename = strdup(optarg);
            if (!filename) {
                cm_trace(CM_TRACE_LEVEL_ERROR, 
                         "strdup failed" );
                exit(1);
            }
            break;
            
        case 'd' :
            trace_level = CM_TRACE_LEVEL_DEBUG;
            break;
        }
    }

    if ( node_id == CMM_INVALID_NODE_ID ) {
        usage( argv[0],
               "The node id paramater has to be specified" );
    }

    if ( filename == NULL ) {
        usage( argv[0],
               "The configuration file parameter has to be specified" );
    }

    daemonize();
    
    cm_openlog("CMM", trace_level);

    /* Block the SIGPIPE signals */
    
    action.sa_handler = SIG_IGN;
    if (sigaction(SIGPIPE, &action, NULL)) {
        cm_trace(CM_TRACE_LEVEL_ERROR,
                 "sigaction failed");
        cm_closelog();
        return(1);
    }

    cm_trace(CM_TRACE_LEVEL_NOTICE,
             "The local node id is %d",
             node_id );

    cm_trace(CM_TRACE_LEVEL_DEBUG,
             "The configuration file is %s",
             filename );


    err = cnt_init( filename, node_id );
    if (err != CMM_OK) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "cnt_init failed [%d]",
                 err );
        return(1);
    }

    cnt_print();

    if ( pipe(pipe_stack) ) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "pipe failed" );
        return(1);
    }
    
    cm_trace(CM_TRACE_LEVEL_DEBUG,
             "stack pipe has been created (%d %d)",
             pipe_stack[0], pipe_stack[1] );
    
    stack_to_sender = fifo_init(NULL);
    if (!stack_to_sender) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "fifo_init failed" );
        return(1);
    }

    lobby_to_sender = fifo_init(stack_to_sender);
    if (!lobby_to_sender) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "fifo_init failed" );
        return(1);
    }

    /* start the lobby server thread to listen to incoming messages from 
     * the predecessor node 
     */

    err = lobby_start( RING_PORT,
                       pipe_stack[1],
                       lobby_to_sender );
    if (err != CMM_OK) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "lobby_start failed [%d]",
                 err );
        return(1);
    }

    /* start the sender server thread to establish connection with the 
     * successor node and send messages to it from the lobby_to_sender and 
     * the stack_to_sender fifos
     */
    err = sender_start( lobby_to_sender,
                        stack_to_sender );
    if (err != CMM_OK) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "sender_start failed [%d]",
                 err );
        return(1);
    }

    /* Start the api server */

    err = api_init();
    if (err != CMM_OK) {
        cm_trace(CM_TRACE_LEVEL_ERROR, 
                 "api_init failed [%d]",
                 err );
        return(1);
    }
/*     err = heartbeat_start(); */
/*     if (err != CMM_OK) { */
/*         cm_trace(CM_TRACE_LEVEL_ERROR,  */
/*                  "heartbeat init failed [%d]", err); */
/*         return (1); */
/*     } */
    stack_start( pipe_stack[0], stack_to_sender );

    cm_trace(CM_TRACE_LEVEL_ERROR, 
             "The stack exited !");
    
    cm_closelog();

    return(0);
}
Пример #4
0
static void vbeacon_rfd( void *pvParameters )
{
	buffer_t *buffer=0;
	uint8_t send=0, *ptr, i, sqn=0;
	int16_t byte;
	uint16_t count = 0;
	pause(200);
	debug_init(115200);
	pause(300);

	stack_event 		= open_stack_event_bus();		/* Open socket for stack status message */
	stack_service_init( stack_event,NULL, 0 , NULL );	

	if(stack_start(NULL)==START_SUCCESS)
	{
		debug("Start Ok\r\n");
	}
/*****************************************************************************************************/

/****************************************************************************************************/
	for (;;)
	{
		byte = debug_read_blocking(10);
		if(byte != -1)
		{
			switch(byte)
			{	
				case 'm':
					ptr=mac_get_mac_pib_parameter(MAC_IEEE_ADDRESS);
					if(ptr)
					{
						ptr +=7;
						debug("Devices mac-address: ");
						for(i=0; i< 8 ;i++)
						{
							if(i)
								debug(":");
							debug_hex(*ptr--);
						}
						debug("\r\n");
					}
					break;
				case 'b':
					debug_int(uxQueueMessagesWaiting(buffers));
					debug(" buffers available.\r\n");
					break;	

				case 'c':
					ptr=mac_get_mac_pib_parameter(MAC_CURRENT_CHANNEL);
					if(ptr)
					{
						debug("Current channel: ");
						debug_int(*ptr);
						debug("\r\n");
					}
					break;

				case '\r':
					
					debug("\r\n");
					break;

				default:
					debug_put(byte);
					break;
			}	
		}
		if(send && data)
		{	
			buffer_t *buf = socket_buffer_get(data);
			if (buf)
			{
				/* Create data packet */
				/*buf->buf[buf->buf_end++] = 'S';
				buf->buf[buf->buf_end++] = 'e';
				buf->buf[buf->buf_end++] = 'n';
				buf->buf[buf->buf_end++] = 's';
				buf->buf[buf->buf_end++] = 'o';
				buf->buf[buf->buf_end++] = 'r';
				buf->buf[buf->buf_end++] = '_';
				buf->buf[buf->buf_end++] = mac_long.address[1];
				buf->buf[buf->buf_end++] = mac_long.address[0];*/
				buf->buf[buf->buf_end++] = sqn;
				buf->buf[buf->buf_end++] = 0xc2;
				buf->buf[buf->buf_end++] = 0x00;
				buf->buf[buf->buf_end++] = 0x08;
				buf->buf[buf->buf_end++] = 0x00;
				buf->buf[buf->buf_end++] = 0x08;
				buf->buf[buf->buf_end++] = 0x00;
				buf->buf[buf->buf_end++] = 0x10;
				buf->buf[buf->buf_end++] = 0x23;
				buf->buf[buf->buf_end++] = 0x16;
				if (socket_sendto(data, &cord_address, buf) != pdTRUE)
				{	
					debug("Data send failed.\r\n");
					socket_buffer_free(buf);
					buf=0;
				}
				if(sqn==0x0f)
					sqn=0;
				else
					sqn++;
				send=0;
			}
		}
		if (count++ >= 400)
		{
			send=1;
			count = 0;
		}
		if(stack_event)
		{
			buffer=0;
			buffer = waiting_stack_event(10);
			if(buffer)
			{
				switch (parse_event_message(buffer))
				{
					case BROKEN_LINK:
						debug("Route broken to ");
						debug("\r\n");
						debug_address(&(buffer->dst_sa));
						debug("\r\n");
						break;

					case ASSOCIATION_WITH_COORDINATOR:
						debug("Assoc ok ");
						if(get_coord_address(&cord_address) == pdTRUE)
						{
							data = socket(MODULE_CUDP, 0);	/* Socket for response data from port number 61619 */
							if (data)
							{
								if (socket_bind(data, &cord_address) != pdTRUE)
								{
									debug("Bind failed.\r\n");
								}
							}
						}
						break;
					case NOT_ASSOCIATED:
						debug("Application design error:\r\n");
						debug("RFD try send data before association\r\n");
						break;
					case ASSOCIATION_LOST:
						if(socket_close(data) == pdTRUE)
						{
							data=0;
							scan_network();
						}
						break;

					
					case TOO_LONG_PACKET:
						debug("Payload Too Length, to  ");
						debug("\r\n");
						break;
			
					default:
						break;
				}

				if(buffer)
				{
					socket_buffer_free(buffer);
					buffer = 0;
				}
			}
		}
		LED1_ON();
		LED1_OFF();
	}
}