bool LiberaSinglePathE::is_Down_allowed(Tango::AttReqType type)
{
	if (	//	Compare device state with not allowed states for READ 
		get_state() == Tango::UNKNOWN)
	{
	
	/*----- PROTECTED REGION ID(LiberaSinglePathE::read_DownStateAllowed_READ) ENABLED START -----*/

	/*----- PROTECTED REGION END -----*/	//	LiberaSinglePathE::read_DownStateAllowed_READ

		return false;
	}
	return true;
}
static int cmd_char_write(gpointer user_data, const char *handle, const char* data, int type)
{
  GAttrib *attrib = user_data;
  uint8_t *value;
  size_t len;
  int hdl, ret;

  /* we need to enable notifications very early, as well change mode
   * when we receive an exception to quit
   */
  if ((get_state() != STATE_DATARCVD) && (get_state() != STATE_CONNECTED)) {
    printf("Device is not connected\n");
    return -1;
  }

  hdl = strtohandle(handle);
  if (hdl <= 0) {
    printf("A valid handle is needed\n");
    return -2;
  }

  len = gatt_attr_data_from_string(data, &value);
  if (len == 0) {
    printf("Invalid value(s) passed\n");
    return -3;
  }

  if (type == WRITE_REQUEST) {
    ret = gatt_write_char(attrib, hdl, value, len, NULL, NULL);
  } else if (type == WRITE_COMMAND) {
    ret = gatt_write_cmd(attrib, hdl, value, len, NULL, NULL);
  }

  g_free(value);

  return 0;
}
Beispiel #3
0
static
int state_handler(const char *path, const char *types, lo_arg **argv, int argc,
		 lo_message msg, void *user_data)
{
	lo_address src = lo_message_get_source( msg );
	lo_server serv = (lo_server)user_data;
	int result;
	
	// Send back reply
	result = lo_send_from( src, serv, LO_TT_IMMEDIATE,
	              "/deck/state", "s", get_state_name( get_state() ) );
	if (result<1) fprintf(stderr, "Error: sending reply failed: %s\n", lo_address_errstr(src));

    return 0;
}
Beispiel #4
0
void mt_task_queue::wait_for_finish(gtask const & t) {
    if (!t || get_state(t).load() > task_state::Running) return;
    unique_lock<mutex> lock(m_mutex);
    submit_core(t, get_default_prio());
    if (get_state(t).load() <= task_state::Running) {
        int additionally_required_workers = 0;
        if (g_current_task) {
            additionally_required_workers++;
            if (m_sleeping_workers == 0) {
                spawn_worker();
            } else {
                m_wake_up_worker.notify_one();
            }
        }
        scoped_add<int> inc_required(m_required_workers, additionally_required_workers);
        get_sched_info(t).wait(lock, [&] {
            return get_state(t).load() > task_state::Running;
        });
    }
    switch (get_state(t).load()) {
        case task_state::Failed: case task_state::Success: return;
        default: throw exception("invalid task state");
    }
}
Beispiel #5
0
bool
manageable_window(Window win, XWindowAttributes *attr, bool trans)
{
	Window dummy;

	if (!XGetWindowAttributes(dpy, win, attr))
		return false;
	if (trans && !XGetTransientForHint(dpy, win, &dummy))
		return false;
	if (!trans && (attr->override_redirect ||
				XGetTransientForHint(dpy, win, &dummy)))
		return false;
	return (attr->map_state == IsViewable ||
			get_state(win) == IconicState);
}
Beispiel #6
0
char * io_get_line(){
  int i = 0, c;
  if(last_char == 13 || last_char == 10){
    if(get_state() == STATE_EXECUTE) puts(" ok");
    else if(get_state() == STATE_COMPILE) puts(" compiled");
    else puts(" whoops bad state");
    putchar('\r');
  }
  if(feof(stdin)) return NULL;
  last_char = 0;
  while((c = getchar()) !=EOF) {

    if(i >= MAX_LINE_SIZE){
      printf("\r\nMaximum line size exceeded");
      bye();
    }

    if(c == 10 || c == 13) {
      stmt[i++] = '\0';
      last_char = c;
      return stmt;
    }
    if(c == 127){
      if(i>0){
        i--;
        printf("\b");
      }
    } else{
      stmt[i++] = c;
      if(raw_mode){
         putchar(c);
      }
    }
  }
  return NULL;
}
Beispiel #7
0
		inline static bool register_state(NetGuard_State* state) 
		{
			ng_slogdebug("NetGuard_State_Handler","register state '%s' ",state->GetName().c_str());
			if (!onlyInstance) {
				ng_slogerror("NetGuard_State_Handler","cant register state '%s' - NetGuard_State_Handler not present",state->GetName().c_str());
				return false;
			}
			if (get_state(state->GetName())) {
				ng_slogerror("NetGuard_State_Handler","cant register state '%s' - already known",state->GetName().c_str());
				return false;
			}
			ng_slogdebug_spam("NetGuard_State_Handler","did register state '%s' ",state->GetName().c_str());
			onlyInstance->states.insert(pair<std::string, NetGuard_State*>(state->GetName(), state));
			return true;
		}
/******************************************************************
*	printf_loop() 
*	prints diagnostics to console
*   this only gets started if executing from terminal
*******************************************************************/
void* printf_loop(void* ptr){
	state_t last_state, new_state; // keep track of last state 
	while(1){
		new_state = get_state();
		// check if this is the first time since being paused
		if(new_state==RUNNING && last_state!=RUNNING){
			printf("\nRUNNING: Hold upright to balance.\n");
			printf(" theta t_ref phi   p_ref gamma   u \n");
		}
		else if(new_state==PAUSED && last_state!=PAUSED){
			printf("\nPAUSED: press pause again to start.\n");
		}
		last_state = new_state;
		
		// decide what to print or exit
		switch (new_state){	
		case RUNNING: { // show all the things
			printf("\r");
			printf("% 0.2f ", cstate.current_theta);
			printf("% 0.2f ", setpoint.theta);
			printf("% 0.2f ", cstate.current_phi);
			printf("% 0.2f ", setpoint.phi);
			printf("% 0.2f ", cstate.current_gamma);
			printf("% 0.2f ", cstate.current_u);
			
			if(setpoint.arm_state == ARMED)
				printf(" ARMED");
			else
				printf("DISARMED");
			printf("   "); // clear remaining characters
			fflush(stdout);
			break;
			}
		case PAUSED: { // only print theta when paused
			printf("\rtheta: %0.2f   ", cstate.current_theta);
			break;
			}
		case EXITING:{
			return NULL;
			}
		default: {
			break; // this is only for UNINITIALIZED state
			}
		}
		usleep(200000);
	}
	return NULL;
} 
Beispiel #9
0
/*
 * Print source code for test that replays this game,
 * and asserts reaching the same end game state
 */
void Game::print_recorded_test(std::ostream& out, RecordedInput& recorded_input) {
    out.precision(20);  // print with larger than max precision

    out << "/***************************************************************************" << endl
        << " *                                                                         *" << endl
        << " *   This program is free software; you can redistribute it and/or modify  *" << endl
        << " *   it under the terms of the GNU General Public License as published by  *" << endl
        << " *   the Free Software Foundation; either version 2 of the License, or     *" << endl
        << " *   (at your option) any later version.                                   *" << endl
        << " *                                                                         *" << endl
        << " ***************************************************************************/" << endl
        << endl
        << endl
        << "#include <pacman/util/Point.h>" << endl
        << "#include <pacman/model/GhostState.h>" << endl
        << "#include <pacman/model/PacmanState.h>" << endl
        << "#include <pacman/model/GameState.h>" << endl
        << "#include <pacman/specification/Food.h>" << endl
        << "#include <pacman/test/playback_test.h>" << endl
        << "" << endl
        << "#include <vector>" << endl
        << "" << endl
        << "using ::PACMAN::MODEL::GhostState;" << endl
        << "using ::PACMAN::MODEL::Ghosts;" << endl
        << "using ::PACMAN::MODEL::PacmanState;" << endl
        << "using ::PACMAN::MODEL::ExternalGameState;" << endl
        << "using ::PACMAN::MODEL::Action;" << endl
        << "using ::PACMAN::MODEL::PLAYER_PACMAN;" << endl
        << "using namespace ::PACMAN::SPECIFICATION;" << endl
        << "" << endl
        << "namespace PACMAN {" << endl
        << "    namespace TEST {" << endl
        << endl
        << "void test() {" << endl
        << "    const int steps = " << steps << ";" << endl
        << endl;

    get_state().print(out, "    ");

    out << endl
        << "    std::vector<Action> path = ";
    recorded_input.print_path(out);
    out << ";" << endl
        << "    playback_test(path, game_state, PLAYER_PACMAN, steps);" << endl
        << "}" << endl
        << endl
        << "}}";
}
Beispiel #10
0
void TaskBase::print_status (emstream& ser_dev)
{
	ser_dev.puts (pcTaskGetTaskName (handle));
	ser_dev.putchar ('\t');
	if (strlen ((const char*)(pcTaskGetTaskName (handle))) < 8)
	{
		ser_dev.putchar ('\t');
	}
	ser_dev << (uint8_t)(uxTaskPriorityGet (handle)) << PMS ("\t")
			<< get_state ()
		#if (INCLUDE_uxTaskGetStackHighWaterMark == 1)
			<< PMS ("\t") << uxTaskGetStackHighWaterMark(handle) << PMS ("/") 
			<< (size_t)(get_total_stack ()) << PMS ("\t")
		#endif
			<< PMS ("\t") << runs;
}
size_t TipHydrolysis::perform(double time, double r,
                              filaments::container_t &filaments,
                              concentrations::container_t &concentrations) {
    for (size_t fi = 0; fi < filaments.size(); ++fi) {
        if (_old_state == get_state(*filaments[fi])) {
            if (r < _rate && filaments[fi]->length() > 0) {
                perform_filament(*filaments[fi]);
                return fi;
            }
            r -= _rate;
            r = std::max(r, 0.0);
        }
    }

    return 0;
}
void
YetiStalactite::update(float elapsed_time)
{
  // Respawn instead of removing once squished
  if(get_state() == STATE_SQUISHED && check_state_timer()) {
    set_state(STATE_ACTIVE);
    state = STALACTITE_HANGING;
    // Hopefully we shouldn't come into contact with anything...
    sprite->set_action("normal");
    set_pos(start_position);
    set_colgroup_active(COLGROUP_TOUCHABLE);
  }

  // Call back to badguy to do normal stuff
  BadGuy::update(elapsed_time);
}
Beispiel #13
0
static uint16_t SPIReadADC(uint8_t channel)
{
    uint8_t ii;
    uint32_t result;
    uint32_t setup;

    //Setting up pins

    // In case pin was already been low, we put it high
    // so we can initiate communication after setting up pins
    set_output(SPI_CS, HIGH);
    set_output(SPI_DATA, LOW);
    set_output(SPI_CLK, LOW);
    low(SPI_CS);   // Active chip select by setting pin low

    // Sending configuration to device
    setup = channel | 0b11000;
    for(ii = 0; ii < 5; ++ii) 
    {
        pulse_out(SPI_CLK, 1);
        if ((setup & 0b10000) == 0b10000)
        {
            high(SPI_DATA);
        }            
        else
        {
            low(SPI_DATA); // is MSB != 0
        }            
        setup <<= 1;  // shift left
    }

    pulse_out(SPI_CLK, HIGH); //Empty clock, for sampling
    pulse_out(SPI_CLK, HIGH); //Device returns low, NULL bit, we ignore it...
    input(SPI_DATA);

    // read ADC result 12 bit
    result = 0;
    for(ii = 0; ii < 12; ++ii) 
    {
        // We are sending pulse, clock signal, to ADC, because on falling edge it will return data...
        pulse_out(SPI_CLK, HIGH);
        // Shifting bit to left, to make room for current one...
        result <<= 1;
        result = result | (get_state(SPI_DATA) & 0x01);
    }
    high(SPI_CS);
}
Beispiel #14
0
static gboolean
textview_query_tooltip (GtkTextView *text_view,
                        gint x,
                        gint y,
                        gboolean keyboard_mode,
                        GtkTooltip *tooltip,
                        gpointer user_data)
{
	GtkTextBuffer *buffer;
	guint32 state;
	gboolean res = FALSE;

	if (keyboard_mode)
		return FALSE;

	buffer = gtk_text_view_get_buffer (text_view);
	g_return_val_if_fail (buffer != NULL, FALSE);

	state = get_state (buffer);

	if ((state & E_BUFFER_TAGGER_STATE_IS_HOVERING_TOOLTIP) != 0) {
		gchar *url;
		GtkTextIter iter;

		gtk_text_view_window_to_buffer_coords (
			text_view,
			GTK_TEXT_WINDOW_WIDGET,
			x, y, &x, &y);
		gtk_text_view_get_iter_at_location (text_view, &iter, x, y);

		url = get_url_at_iter (buffer, &iter);
		res = url && *url;

		if (res) {
			gchar *str;

			/* To Translators: The text is concatenated to a form: "Ctrl-click to open a link http://www.example.com" */
			str = g_strconcat (_("Ctrl-click to open a link"), " ", url, NULL);
			gtk_tooltip_set_text (tooltip, str);
			g_free (str);
		}

		g_free (url);
	}

	return res;
}
Beispiel #15
0
int main(int argc, char *argv[]){
    initialize_cape();
    
	int i;
	int ch = 0;
	int all = 0;
	// micros is in the middle of range
	int micros = (SERVO_MIN_US+SERVO_MAX_US)/2;

	// check if user gave command line argument for which servo to use
	if (argc==1){
		// if not, drive all servos
		all = 1;
    }
	// set the single channel to use
	else{
		ch = atoi(argv[1]);
		all = 0;
		if(ch>SERVO_CHANNELS || ch<1){
			printf("choose a channel between 1 and %d\n", SERVO_CHANNELS);
			return -1;
		}
	}
	printf("\n");
	printf("sending center pulses, width: %d microseconds\n", micros);
	printf("press ctrl-c to exit\n");
	
	while(get_state()!=EXITING){
		// if user gave no arguments, send single pulse to each servo
		if(all){

			for(i=0; i<SERVO_CHANNELS; i++){
				send_servo_pulse_us(i+1,micros);
			}
		}
		// or send to just the one requested servo
		else{
			send_servo_pulse_us(ch,micros);
		}
		
		// Send pulses at roughly 50hz
		usleep(20000); 
	}
    
	cleanup_cape();
    return 0;
}
Beispiel #16
0
int process_args(int argc, char* argv[], query_arg_t* msg) {
    if(argc < 4) print_usage(argv[0]);
    
    int state = get_state(argv);
    unsigned int addr = get_hextoi(argv, 2);
    unsigned short offset = get_hextoi(argv, 3);
    unsigned int value = 0;
    
    if(state == D_WRITE && argc < 5) print_usage(argv[0]);
    else if (state == D_WRITE) value = get_hextoi(argv, 4);
    
    msg->address = addr;
    msg->offset  = offset;
    msg->value   = value;
    
    return state;
}
Beispiel #17
0
/***********************************************************************
*	battery_checker()
*	super slow loop checking battery voltage
************************************************************************/
void* battery_checker(void* ptr){
	float new_v;
	while(get_state()!=EXITING){
		new_v = getBattVoltage();
		// check if there is a bad reading
		if (new_v>9.0 || new_v<5.0){
			// printf("problem reading battery\n");
			// use nominal for now
			new_v = config.v_nominal;
		}
		cstate.vBatt = new_v;
		usleep(1000000);
		usleep(1000000);
		usleep(1000000);
	}
	return NULL;
}
void* blinking_function(void* ptr){
	int toggle = 1;

	while(get_state()!=EXITING){
		if(toggle){
			enable_servo_power_rail();
			toggle = 0;
		}
		else{
			disable_servo_power_rail();
			toggle = 1;
		}
		usleep(500000);
	}

	return NULL;
}
int main(){
	initialize_cape();
	
	setGRN(HIGH);
	setRED(HIGH);

	printf("\n\nRaw data for encoders 1,2,3\n");

	while(get_state() != EXITING){
		printf("\r%3li %3li %3li  ", get_encoder_pos(1),get_encoder_pos(2),get_encoder_pos(3));
		fflush(stdout);
		usleep(50000);
	}
	
	cleanup_cape();
	return 0;
}
 void
 IBeamTool::set_leading_x (const int x)
 {
   shared_ptr<TimelineState> state = get_state();
   
   // The line below needs handled differently now;  ////////////TODO GTK-3
   //
   //const bool set_playback_period = dragType == Selection;
   
   TimeVar newStartPoint (state->getViewWindow().x_to_time(x));
   Offset selectionLength (pinnedDragTime, newStartPoint);
   
   if (newStartPoint > pinnedDragTime)
     newStartPoint=pinnedDragTime; // use the smaller one as selection start
   
   selectionControl (TimeSpan (newStartPoint, Duration(selectionLength)));
 }
double TipHydrolysis::R(double time,
                        const filaments::container_t &filaments,
                        const concentrations::container_t &concentrations,
                        size_t previous_filament_index) {
    State previous_state = _states[previous_filament_index];
    State this_state = get_state(*filaments[previous_filament_index]);
    _states[previous_filament_index] = this_state;

    if (_old_state == previous_state) {
        --_count;
    }
    if (_old_state == this_state) {
        ++_count;
    }

    return _rate * _count;
}
double TipHydrolysis::initial_R(double time,
                                const filaments::container_t &filaments,
                                const concentrations::container_t &concentrations) {
    _states.reserve(filaments.size());
    _states.resize(filaments.size());
    size_t fi = 0;
    _count = 0;
    for ( ; fi < filaments.size(); ++fi) {
        State fstate = get_state(*filaments[fi]);
        _states[fi] = fstate;
        if (_old_state == fstate) {
            ++_count;
        }
    }

    return _rate * _count;
}
Beispiel #23
0
static void
abitmap_draw_scroller (DIALOG *d, int pos, int total, int visible)
{
	int s = get_state (d);
	int min_h = theme->bitmaps[B_SCROLLER_HANDLE][s].bmp->h;
	int bar_h = d->h * visible / total;
	int bar_p;

	if (bar_h < min_h)
		bar_h = min_h;

	bar_p = (d->h - bar_h) * pos / (total - visible);

	abitmap_draw_area (d, B_SCROLLER, 0, 0, 12, d->h, 2, 0);

	abitmap_draw_area (d, B_SCROLLER_HANDLE, 0, bar_p, 12, bar_h, 2, 0);
}
Beispiel #24
0
drmaa2_error drmaa2_j_wait_started (const drmaa2_j j, const time_t timeout) {
    drmaa2_jstate state;
    drmaa2_error return_status = DRMAA2_SUCCESS;
    while (1) {
        state = get_state(j);
        if (state != DRMAA2_QUEUED && state != DRMAA2_QUEUED_HELD) {
            break;
        }
        else if (timeout == DRMAA2_ZERO_TIME || (timeout != DRMAA2_INFINITE_TIME && timeout <= time(NULL))) {
            drmaa2_lasterror_v = return_status = DRMAA2_TIMEOUT;
            drmaa2_lasterror_text_v = "A timeout occured while waiting for a job start.";
            break;
        }
        sleep(1);
    }
    return return_status;
}
Beispiel #25
0
void handle_keypresses()
{
	struct timeval timeout;
	fd_set readfds;
	int retval = -1;

	// Make STDOUT unbuffered (if it is a terminal)
	if (isatty(STDOUT_FILENO))
		setbuf(stdout, NULL);

	// Turn off input buffering on STDIN
	set_input_mode( );
	
	// Check for keypresses
	while (get_state() != MADJACK_STATE_QUIT) {

		// Display position
		if (!quiet && isatty(STDOUT_FILENO)) {
			printf("[%1.1f/%1.1f]         \r", input_file->position, input_file->duration);
		}

		// Set timeout to 1/10 second
		timeout.tv_sec = 0;
		timeout.tv_usec = 100000;

		// Watch socket to see when it has input.
		FD_ZERO(&readfds);
		FD_SET(STDIN_FILENO, &readfds);
		retval = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout);

		// Check return value 
		if (retval < 0) {
			// Something went wrong
			perror("select()");
			break;
			
		} else if (retval > 0) {
		
			read_keypress();

		}
	}

	// Restore the input mode
	reset_input_mode();
}
/******************************************************************
*	mavlink_listener()
*	listen for RC mavlink packets for driving around
*******************************************************************/
void* mavlink_listener(void* ptr){
	ssize_t recsize;
	socklen_t fromlen;
	uint8_t buf[MAV_BUF_LEN];
	int i;
	
	int16_t chan3_scaled, chan4_scaled;
	
	while(get_state() != EXITING){
		recsize = recvfrom(sock, (void *)buf, MAV_BUF_LEN, 0, (struct sockaddr *)&gcAddr, &fromlen);
		if (recsize > 0){
			// Something received - print out all bytes and parse packet
			mavlink_message_t msg;
			mavlink_status_t status;
			for (i = 0; i < recsize; ++i){
				if (mavlink_parse_char(MAVLINK_COMM_0, buf[i], &msg, &status)){
					// Packet received, do something
					printf("\nReceived packet: SYS: %d, COMP: %d, LEN: %d, MSG ID: %d\n", msg.sysid, msg.compid, msg.len, msg.msgid);
					// if the packet is scaled RC channels, drive around!!
					if(msg.msgid == MAVLINK_MSG_ID_RC_CHANNELS_SCALED){
						chan3_scaled =	\
						mavlink_msg_rc_channels_scaled_get_chan3_scaled(&msg);
						chan4_scaled =	\
						mavlink_msg_rc_channels_scaled_get_chan4_scaled(&msg);
						if(user_interface.input_mode |= DSM2){
							user_interface.input_mode = MAVLINK;
							// chan_scaled are integers from +- 10000,
							// scale them to normalized floats
							user_interface.drive_stick = (float)chan3_scaled \
																/10000.0;
							user_interface.turn_stick = (float)chan4_scaled \
															/10000.0;
						}
					}
				}
			}
		}
		else{
			printf("%d ",recsize);
			printf("error in recvfrom\n");
		}
		usleep(10000);
	}
	return NULL;
}
void disconnect_io()
{
  printf("disconnect_io()\n");

  if (get_state() == STATE_DISCONNECTED) {
    return;
  }

  g_attrib_unref(attrib);
  attrib = NULL;
  mtu = 0;

  g_io_channel_shutdown(iochannel, FALSE, NULL);
  g_io_channel_unref(iochannel);
  iochannel = NULL;

  set_state(STATE_DISCONNECTED);
}
Beispiel #28
0
/***********************************************************************
*	void* mode_unpressed_handler(void* ptr) 
*	wait on rising edge of mode button
************************************************************************/
void* mode_unpressed_handler(void* ptr){
	int fd;
    fd = open("/dev/input/event1", O_RDONLY);
    struct input_event ev;
	while (get_state() != EXITING){
        read(fd, &ev, sizeof(struct input_event));
		// uncomment printf to see how event codes work
		// printf("type %i key %i state %i\n", ev.type, ev.code, ev.value); 
        if(ev.type==1 && ev.code==2){ //only new data
			if(ev.value == 0){
				mode_btn_state = UNPRESSED; //pressed
				(*mode_unpressed_func)();
			}
		}
		usleep(10000); // wait
    }
	return NULL;
}
//--------------------------------------------------------
bool TemperatureMeter::is_temperature_allowed(TANGO_UNUSED(Tango::AttReqType type))
{

	//	Check access type.
	if ( type==Tango::READ_REQ )
	{
		//	Compare device state with not allowed states for READ 
		if (get_state()==Tango::OFF)
		{
		/*----- PROTECTED REGION ID(TemperatureMeter::temperatureStateAllowed_READ) ENABLED START -----*/
		
		/*----- PROTECTED REGION END -----*/	//	TemperatureMeter::temperatureStateAllowed_READ
			return false;
		}
		return true;
	}
	return true;
}
Beispiel #30
0
void pim_interface::shutdown() {
	if (get_state() != NOT_READY)
		send_hellox(0);

	neighbours_def n = neighbours;

	neighbours.clear();

	for (neighbours_def::const_iterator j = n.begin(); j != n.end(); ++j) {
		pim->lost_neighbour(*j);
		(*j)->shutdown();
		delete *j;
	}

	((conf_node *)conf())->dettach_watcher(this);

	owner()->dettach_node(this);
}