예제 #1
0
파일: rust_chan.cpp 프로젝트: jyasskin/rust
/**
 * Attempt to send data to the associated port.
 */
void rust_chan::send(void *sptr) {
    buffer.enqueue(sptr);

    rust_dom *dom = task->dom;
    if (!is_associated()) {
        W(dom, is_associated(),
          "rust_chan::transmit with no associated port.");
        return;
    }

    A(dom, !buffer.is_empty(),
      "rust_chan::transmit with nothing to send.");

    if (port->is_proxy()) {
        // TODO: Cache port task locally.
        rust_proxy<rust_task> *port_task =
            dom->get_task_proxy(port->delegate()->task);
        data_message::send(buffer.peek(), buffer.unit_sz,
            "send data", task, port_task, port->as_proxy());
        buffer.dequeue(NULL);
    } else {
        rust_port *target_port = port->delegate();
        if (target_port->task->blocked_on(target_port)) {
            dom->log(rust_log::COMM, "dequeued in rendezvous_ptr");
            buffer.dequeue(target_port->task->rendezvous_ptr);
            target_port->task->rendezvous_ptr = 0;
            target_port->task->wakeup(target_port);
            return;
        }
    }

    return;
}
예제 #2
0
파일: rust_chan.cpp 프로젝트: jyasskin/rust
rust_chan::~rust_chan() {
    task->log(rust_log::MEM | rust_log::COMM,
              "del rust_chan(task=0x%" PRIxPTR ")", (uintptr_t) this);

    A(task->dom, is_associated() == false,
      "Channel must be disassociated before being freed.");
}
예제 #3
0
파일: rust_chan.cpp 프로젝트: jyasskin/rust
/**
 * Unlink this channel from its associated port.
 */
void rust_chan::disassociate() {
    A(task->dom, is_associated(), "Channel must be associated with a port.");

    if (port->is_proxy() == false) {
        task->log(rust_log::TASK,
            "disassociating chan: 0x%" PRIxPTR " from port: 0x%" PRIxPTR,
            this, port->delegate());
        port->delegate()->chans.swap_delete(this);
    }

    // Delete reference to the port.
    port = NULL;
}
예제 #4
0
void main(void) {
	// Have to init the clock first
	init_clock();

	// These initialize variables
	// Mostly just zeroing them
	okay_to_transmit = FALSE;
	server_wants_header = FALSE;
	inside_non_blocking_interrupt = FALSE;
	last_connect_time = 0;
	check_in_period = 0;
	setup_button_pressed = FALSE;
	setup_button_time_trigger = 0;
	setup_button_time_duration = 0;
	main_mode = MAIN_MODE_INIT;
	init_internal_wattage_sensor();
	init_temperature_sensor();
	init_audio_sensor();
	init_light_sensor();
	uint8_t itor = 0;
	for (itor = 0; itor < NUMBER_OF_AUX_PORTS; itor++) {
		aux_sensor[itor] = 0;
	}

	// These initialize functions and interrupts
	init_timer();
	init_time();
	init_leds();
	init_relay();
	init_uart();
	init_transmits();
	init_buttons();
	init_roving(&roving_call_back);

	setup_button_time_trigger = new_time();
	setup_button_time_duration = new_time();
	time_set_seconds(setup_button_time_duration, 2);

	_enable_interrupts();

	// confirm roving works
	while (!enter_command_mode()) {
		reset_roving();
		wait(500);
	}
	init_adc();
	init_pll();

	// This is for the check in
	// If we are disconnected, we wait 5 seconds before trying to reconnect
	last_connect_time = new_time();
	check_in_period = new_time();
	time_set_seconds(check_in_period, 5);


	// And go!!!

	set_led_anim(led_start);

	// MAIN LOOP
	while(1) {
		handle_roving_input();

		// Check if it a long hold
		if(setup_button_pressed) {
			// If the button is pressed down
			if(time_cmp(global_time(), setup_button_time_trigger) >= 0) {
				// If enough time has passed
				if(in_setup_mode()) {
					leave_setup_mode();
				} else {
					start_setup_mode();
				}
				// Only want to check this once
				setup_button_pressed = FALSE;
			}
		}


		// MAIN BEHAVIOR
		// There is setup_mode and main_mode.
		// Setup mode is for configuring WiFi SSID and PASS
		// Main mode is for sampling
		if (in_setup_mode()) {
			if(main_mode != MAIN_MODE_SETUP) {
				stop_sampling();
				set_led_anim(led_setup_start);
				main_mode = MAIN_MODE_SETUP;
			}
			do_setup();

		} else if (in_main_mode()) { //regular mode
			if(main_mode != MAIN_MODE_SAMPLE) {
				set_led_anim(led_main_start);
				start_sampling();
				main_mode = MAIN_MODE_SAMPLE;
			}

			if(!is_associated()) {
				associate();
			} else if (!have_dhcp()) {
				get_dhcp();
			} else {
				if(is_connected()) set_led_anim(led_main_connected);
				else set_led_anim(led_main_assoc);

				if(!is_connected() && (time_cmp(global_time(), last_connect_time) >= 0) ) {
					// If we are not connected, and enough time has passed, connect
					connect();
					add_time_to_time(last_connect_time, check_in_period);
				}

				if(server_wants_header) {
					led_ping();
					exit_command_mode();
					transmit_header();
					wait(100);
				}

				if(okay_to_transmit && have_data_to_transmit()) {
					led_ping();
					exit_command_mode();
					transmit_data();
				}


			}
		} else {
			main_mode = MAIN_MODE_INIT;
			set_led_anim(led_error);
			stop_sampling();
		}
	}
}