nsresult
nsComposerCommandsUpdater::Notify(nsITimer *timer)
{
  NS_ASSERTION(timer == mUpdateTimer.get(), "Hey, this ain't my timer!");
  TimerCallback();
  return NS_OK;
}
Exemplo n.º 2
0
 static void * ThreadCallback(void * args)
 {
     while (timer)
     {
         TimerCallback();
         usleep(IDLE_MICS);
     }
     thread = 0;
     pthread_exit(0);
     return 0;
 }
Exemplo n.º 3
0
AnimatePluginInterface::AnimatePluginInterface()
{
    m_renderDome = false;
    m_domeRenderDelegate = DomeRenderer::New();
    m_domeRenderDelegate->UsedOn();
    m_renderState = new DomeRenderState;
    m_renderSize[0] = 1024;
    m_renderSize[1] = 1024;
    m_useMinCamDistance = false;
    m_minCamDistance = 0.1;
    m_currentFrame = 0;
    m_numberOfFrames = 100;
    m_timelineWidget = 0;
    m_cameraAnim = new CameraAnimation;
    m_tfAnim = new TFAnimation;
    m_minCamDistanceAnim = new DoubleValueAnimation;
    m_playbackTimer = new QTimer;
    connect( m_playbackTimer, SIGNAL(timeout()), this, SLOT(TimerCallback()) );
    m_playbackTime = new QTime;
    m_playbackInitialFrame = 0;
}
Exemplo n.º 4
0
int UavcanNode::run()
{
	(void)pthread_mutex_lock(&_node_mutex);

	// XXX figure out the output count
	_output_count = 2;

	_armed_sub = orb_subscribe(ORB_ID(actuator_armed));
	_test_motor_sub = orb_subscribe(ORB_ID(test_motor));
	_actuator_direct_sub = orb_subscribe(ORB_ID(actuator_direct));

	memset(&_outputs, 0, sizeof(_outputs));

	/*
	 * Set up the time synchronization
	 */

	const int slave_init_res = _time_sync_slave.start();

	if (slave_init_res < 0) {
		warnx("Failed to start time_sync_slave");
		_task_should_exit = true;
	}

	/* When we have a system wide notion of time update (i.e the transition from the initial
	 * System RTC setting to the GPS) we would call uavcan_stm32::clock::setUtc() when that
	 * happens, but for now we use adjustUtc with a correction of the hrt so that the
	 * time bases are the same
	 */
	uavcan_stm32::clock::adjustUtc(uavcan::UtcDuration::fromUSec(hrt_absolute_time()));
	_master_timer.setCallback(TimerCallback(this, &UavcanNode::handle_time_sync));
	_master_timer.startPeriodic(uavcan::MonotonicDuration::fromMSec(1000));



	const int busevent_fd = ::open(uavcan_stm32::BusEvent::DevName, 0);

	if (busevent_fd < 0) {
		warnx("Failed to open %s", uavcan_stm32::BusEvent::DevName);
		_task_should_exit = true;
	}

	/*
	 * XXX Mixing logic/subscriptions shall be moved into UavcanEscController::update();
	 *     IO multiplexing shall be done here.
	 */

	_node.setModeOperational();

	/*
	 * This event is needed to wake up the thread on CAN bus activity (RX/TX/Error).
	 * Please note that with such multiplexing it is no longer possible to rely only on
	 * the value returned from poll() to detect whether actuator control has timed out or not.
	 * Instead, all ORB events need to be checked individually (see below).
	 */
	add_poll_fd(busevent_fd);

	/*
	 * setup poll to look for actuator direct input if we are
	 * subscribed to the topic
	 */
	if (_actuator_direct_sub != -1) {
		_actuator_direct_poll_fd_num = add_poll_fd(_actuator_direct_sub);
	}

	while (!_task_should_exit) {

		switch (_fw_server_action) {
		case Start:
			_fw_server_status =  start_fw_server();
			break;

		case Stop:
			_fw_server_status = stop_fw_server();
			break;

		case CheckFW:
			_fw_server_status = request_fw_check();
			break;

		case None:
		default:
			break;
		}

		// update actuator controls subscriptions if needed
		if (_groups_subscribed != _groups_required) {
			subscribe();
			_groups_subscribed = _groups_required;
		}

		// Mutex is unlocked while the thread is blocked on IO multiplexing
		(void)pthread_mutex_unlock(&_node_mutex);

		perf_end(_perfcnt_esc_mixer_total_elapsed); // end goes first, it's not a mistake

		const int poll_ret = ::poll(_poll_fds, _poll_fds_num, PollTimeoutMs);

		perf_begin(_perfcnt_esc_mixer_total_elapsed);

		(void)pthread_mutex_lock(&_node_mutex);

		node_spin_once();  // Non-blocking

		bool new_output = false;

		// this would be bad...
		if (poll_ret < 0) {
			DEVICE_LOG("poll error %d", errno);
			continue;

		} else {
			// get controls for required topics
			bool controls_updated = false;

			for (unsigned i = 0; i < actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS; i++) {
				if (_control_subs[i] > 0) {
					if (_poll_fds[_poll_ids[i]].revents & POLLIN) {
						controls_updated = true;
						orb_copy(_control_topics[i], _control_subs[i], &_controls[i]);
					}
				}
			}

			/*
			  see if we have any direct actuator updates
			 */
			if (_actuator_direct_sub != -1 &&
			    (_poll_fds[_actuator_direct_poll_fd_num].revents & POLLIN) &&
			    orb_copy(ORB_ID(actuator_direct), _actuator_direct_sub, &_actuator_direct) == OK &&
			    !_test_in_progress) {
				if (_actuator_direct.nvalues > actuator_outputs_s::NUM_ACTUATOR_OUTPUTS) {
					_actuator_direct.nvalues = actuator_outputs_s::NUM_ACTUATOR_OUTPUTS;
				}

				memcpy(&_outputs.output[0], &_actuator_direct.values[0],
				       _actuator_direct.nvalues * sizeof(float));
				_outputs.noutputs = _actuator_direct.nvalues;
				new_output = true;
			}

			// can we mix?
			if (_test_in_progress) {
				memset(&_outputs, 0, sizeof(_outputs));

				if (_test_motor.motor_number < actuator_outputs_s::NUM_ACTUATOR_OUTPUTS) {
					_outputs.output[_test_motor.motor_number] = _test_motor.value * 2.0f - 1.0f;
					_outputs.noutputs = _test_motor.motor_number + 1;
				}

				new_output = true;

			} else if (controls_updated && (_mixers != nullptr)) {

				// XXX one output group has 8 outputs max,
				// but this driver could well serve multiple groups.
				unsigned num_outputs_max = 8;

				// Do mixing
				_outputs.noutputs = _mixers->mix(&_outputs.output[0], num_outputs_max, NULL);

				new_output = true;
			}
		}

		if (new_output) {
			// iterate actuators, checking for valid values
			for (uint8_t i = 0; i < _outputs.noutputs; i++) {
				// last resort: catch NaN, INF and out-of-band errors
				if (!isfinite(_outputs.output[i])) {
					/*
					 * Value is NaN, INF or out of band - set to the minimum value.
					 * This will be clearly visible on the servo status and will limit the risk of accidentally
					 * spinning motors. It would be deadly in flight.
					 */
					_outputs.output[i] = -1.0f;
				}

				// never go below min
				if (_outputs.output[i] < -1.0f) {
					_outputs.output[i] = -1.0f;
				}

				// never go above max
				if (_outputs.output[i] > 1.0f) {
					_outputs.output[i] = 1.0f;
				}
			}

			// Output to the bus
			_outputs.timestamp = hrt_absolute_time();
			perf_begin(_perfcnt_esc_mixer_output_elapsed);
			_esc_controller.update_outputs(_outputs.output, _outputs.noutputs);
			perf_end(_perfcnt_esc_mixer_output_elapsed);
		}


		// Check motor test state
		bool updated = false;
		orb_check(_test_motor_sub, &updated);

		if (updated) {
			orb_copy(ORB_ID(test_motor), _test_motor_sub, &_test_motor);

			// Update the test status and check that we're not locked down
			_test_in_progress = (_test_motor.value > 0);
			_esc_controller.arm_single_esc(_test_motor.motor_number, _test_in_progress);
		}

		// Check arming state
		orb_check(_armed_sub, &updated);

		if (updated) {
			orb_copy(ORB_ID(actuator_armed), _armed_sub, &_armed);

			// Update the armed status and check that we're not locked down and motor
			// test is not running
			bool set_armed = _armed.armed && !_armed.lockdown && !_test_in_progress;

			arm_actuators(set_armed);
		}
	}

	(void)::close(busevent_fd);

	teardown();
	warnx("exiting.");

	exit(0);
}
Exemplo n.º 5
0
mdaLooplex::~mdaLooplex ()  //destroy any buffers...
{
  for(IdleList *item=idleList.next; item; item=item->next)  //remove from idle list, stop timer if last item
  {
    if(item->effect == this) 
    { 
      item->remove = true;
      #if _WIN32 //and stop timer in case our last instance is about to unload
        TimerCallback(0, 0, 0, 0);
      #elif __linux__
        TimerCallback();
      #else
        TimerCallback(0, 0);
      #endif
      break; 
    }
  }

  if(programs) delete [] programs;
  
  if(buffer)
  {
    FILE *fp; //dump loop to file

    if(buflen && (fp = fopen("looplex.wav", "wb")))
    {
      char wh[44];
      memcpy(wh, "RIFF____WAVEfmt \20\0\0\0\1\0\2\0________\4\0\20\0data____", 44);
  
      VstInt32 l = 36 + buflen * 2;
      wh[4] = (char)(l & 0xFF);  l >>= 8;
      wh[5] = (char)(l & 0xFF);  l >>= 8;
      wh[6] = (char)(l & 0xFF);  l >>= 8;
      wh[7] = (char)(l & 0xFF);

      l = (VstInt32)(Fs + 0.5f);
      wh[24] = (char)(l & 0xFF);  l >>= 8;
      wh[25] = (char)(l & 0xFF);  l >>= 8;
      wh[26] = (char)(l & 0xFF);  l >>= 8;
      wh[27] = (char)(l & 0xFF);

      l = 4 * (VstInt32)(Fs + 0.5f);
      wh[28] = (char)(l & 0xFF);  l >>= 8;
      wh[29] = (char)(l & 0xFF);  l >>= 8;
      wh[30] = (char)(l & 0xFF);  l >>= 8;
      wh[31] = (char)(l & 0xFF);

      l = buflen * 2;
      wh[40] = (char)(l & 0xFF);  l >>= 8;
      wh[41] = (char)(l & 0xFF);  l >>= 8;
      wh[42] = (char)(l & 0xFF);  l >>= 8;
      wh[43] = (char)(l & 0xFF);
      
      fwrite(wh, 1, 44, fp);

      #if __BIG_ENDIAN__
        char *c = (char *)buffer;
        char t;

        for(l=0; l<buflen; l++) //swap endian-ness
        {
          t = *c;
          *c = *(c + 1);
          c++;
          *c = t;
          c++;
        }
      #endif
      
      fwrite(buffer, sizeof(short), buflen, fp);
      fclose(fp);
    }

    delete [] buffer;
  }
Exemplo n.º 6
0
static int itf_sd_run(long argc, unsigned long data)
{
	pkt_hdr *ph = NULL;
	Pkt rec;
	struct pktrec tmp;
	int i = 0;

	if (itf_sd_init() < 0) {
		itf_sd_exit();
		return -1;
	}

	while (ap_is_running()) {
		if (++i == 5000) {
			timer_mgr_run_timerlist(NULL, g_timer, 0, 0);
			i = 0;
		}
		if ((ph = ReadDbus()) == NULL) {
			SLEEP_US(5000);
			continue;
		}

		if ((pkthdr_get_type(ph) != PKTTYPE_CDR) &&
				(pkthdr_get_type(ph) != PKTTYPE_EVENT)) {
			LGWRERROR(ph, pkthdr_get_plen(ph), "Wrong cdr received, type %u, subtype %u.",
					pkthdr_get_type(ph), pkthdr_get_subtype(ph));
			free(ph);
			continue;
		}
		if ((pkthdr_get_subtype(ph) != PKTTYPE_CDR_BSSAP /* PKTTYPE_EVENT_BSSAP */) &&
				(pkthdr_get_subtype(ph) != PKTTYPE_CDR_IUCS /* PKTTYPE_EVENT_IUCS */)) {
			LGWRERROR(ph, pkthdr_get_plen(ph), "Wrong subtype of cdr/event");
			free(ph);
			continue;
		}
		if (rec.Decode((char *)ph, pkthdr_get_plen(ph)) < 0) {
			LGWRERROR(ph, pkthdr_get_plen(ph), "Failed to decode packet:");
			free(ph);
			continue;
		}

		++g_recieve_msg;
		tmp.rec = (Pkt *)&rec;
		pkthdr_set_sync(&(tmp.hdr));
		pkthdr_set_ts(&(tmp.hdr), rec.u32ReportTimeS, rec.u32ReportTimeNS);

		switch (rec.u8Type)
		{
		case PKTTYPE_CDR:
			if (rec.tdata.cdrbssap.u16LAC == 0) {
				std::map<unsigned int, unsigned int>::iterator it;

				it = ci2lac.find((unsigned int)rec.tdata.cdrbssap.u16CI);
				if (it != ci2lac.end()) {
					rec.tdata.cdrbssap.u16LAC = it->second;
					LOGDEBUG("LAC updated to %u for CI %u",
							it->second, it->first);
				}
				else {
					LOGDEBUG("LAC unknown for CI %u", rec.tdata.cdrbssap.u16CI);
				}
			}
			switch (rec.tdata.cdrbssap.u8CDRType) {
				case 1:
				case 2:
					/* 通话 */
					adapter_write(call_adap_to, &tmp, sizeof(rec));
					++g_call_msg;
					break;
				case 4:
				case 5:
					/* 开关机 */
					++g_power_msg;
					adapter_write(power_adap_to, &tmp, sizeof(rec));
					break;
				case 6:
				case 7:
					/* 正常/周期位置更新 */
					++g_location_msg;
					adapter_write(location_adap_to, &tmp, sizeof(rec));
					break;
				case 12:
				case 13:
					/* SMS */
					++g_sms_msg;
					adapter_write(sms_adap_to, &tmp, sizeof(rec));
					break;
			}
			break;

		case PKTTYPE_EVENT:
			if (rec.tdata.eventbssap.u16FromLAC == 0) {
				std::map<unsigned int, unsigned int>::iterator it;

				it = ci2lac.find((unsigned int)rec.tdata.eventbssap.u16ToCI);
				if (it != ci2lac.end()) {
					rec.tdata.eventbssap.u16FromLAC = it->second;
					LOGDEBUG("LAC updated to %u for CI %u",
							it->second, it->first);
				}
				else {
					LOGDEBUG("LAC unknown for CI %u", rec.tdata.eventbssap.u16ToCI);
				}
			}
			switch (rec.u8Protocol) {
				case 1:
				case 2:
					/* 内部切换事件及成功切出事件 */
					++g_switch_msg;
					adapter_write(switch_adap_to, &tmp, sizeof(rec));
					break;
				default:
					break;
			}
			break;

		default:
			LOGERROR("Unknown subtype %u", pkthdr_get_subtype(ph));
			break;
		}

		free(ph);
	}

	TimerCallback(0, 0, NULL, NULL);
	itf_sd_exit();
	return 0;
}
Exemplo n.º 7
0
		// Calculate increments for motion
		calc_motion_intervals();

		// Start thread
		bw_motion->RunWorkerAsync();
	}
	
	// ================================================================
	// motion_DoWork: 
	// Every 20 ms update angles until motion complete
	// ================================================================
	void Form1::motion_DoWork(System::Object^ sender, DoWorkEventArgs^ e)
	{
		// Make a new thread for timer
		TimerCallback^ tcb_1 = gcnew TimerCallback(this, &GUI_1::Form1::tmr_Tick);
		AutoResetEvent^ autoEvent = gcnew AutoResetEvent(false);
		tmr_1 = gcnew System::Threading::Timer(tcb_1, 0, 1000, 1000);

		while (1)
		{
			int flag_counter = 0;
			if (FLAG_NEW_VALUES)
			{
				for (int i = 0; i < 9; i++)
				{
					if (flags_new_value[i])
					{
						if (angles_to_AVR[i] == final_values[i]) // If desired and current angles equal
						{
							increments[i] = 0;