int Getc( int channel ){	
	int tid = -1;
	struct empty_message req_msg;
	
	struct char_message rpl;
	
	if(channel == COM1){
		//we are sending to train, get the tid
		tid = WhoIs("u1receive");
		req_msg.message_type = UART1_INPUT_SERVER_GETC_REQUEST_MESSAGE;
	}else if(channel == COM2){
		//we are sending to terminal, get the tid
		tid = WhoIs("u2receive");
		req_msg.message_type = INPUT_SERVER_GETC_REQUEST_MESSAGE;		
	}else{
		return -3; //NOT A PROPER COM CHANNEL
	}
	
	//check the return value of WhoIs
	if(tid < 0){ return -1; }
	
	//send the message to the server
	//int status = Send(tid, (char *) &req_msg, sizeof(req_msg), (char *) &rpl, sizeof(rpl));
	Send(tid, (char *) &req_msg, sizeof(req_msg), (char *) &rpl, sizeof(rpl));
	
	//TODO: add in checking for the return of the send and the reply
	//success
	return (int) rpl.c;
}
void stopping_distance_task() {

	TRAIN = 36;

//	int term_tid = WhoIs("term_tid");
	int train_tid = WhoIs(TRAIN_COMMAND);
	int uart_tid = WhoIs(UART_SERVER);
	int sensor_tid = WhoIs(SENSOR_SERVER);
	int clock_tid = WhoIs(CLOCK_SERVER);

	Delay(100, clock_tid);
	TrainCommandSwitchStraight(16, train_tid);
	TrainCommandSwitchCurved(15, train_tid);
	TrainCommandSwitchStraight(9, train_tid);

	TrainCommandSpeed(TRAIN, 0, train_tid);

	int speed;
	for (speed = 14; speed >= 10; speed--) {
		Printf("\rPress enter to start at speed %d .. ", speed);
		Getc(COM2, uart_tid);

		TrainCommandSpeed(TRAIN, speed, train_tid);

		int time;
		int sensor_node;

		do {
			SensorGetNextTriggered(&sensor_node, &time, sensor_tid);
		} while (sensor_node != E8);

		TrainCommandSpeed(TRAIN, 0, train_tid);
	}
}
Exemple #3
0
static
INT
UartpOpen
    (
        IN IO_CHANNEL channel,
        OUT IO_DEVICE* device
    )
{
    if (ChannelCom1 == channel)
    {
        device->readTaskId = WhoIs(UART_COM1_READ_NAME);
        ASSERT(SUCCESSFUL(device->readTaskId));

        device->writeTaskId = WhoIs(UART_COM1_WRITE_NAME);
        ASSERT(SUCCESSFUL(device->writeTaskId));

        return 0;
    }
    else if (ChannelCom2 == channel)
    {
        device->readTaskId = WhoIs(UART_COM2_READ_NAME);
        ASSERT(SUCCESSFUL(device->readTaskId));

        device->writeTaskId = WhoIs(UART_COM2_WRITE_NAME);
        ASSERT(SUCCESSFUL(device->writeTaskId));

        return 0;
    }
    else
    {
        ASSERT(FALSE);
        return -1;
    }
}
Exemple #4
0
static void initDriver(Driver* me, int firstTime) {
  char uiName[] = UI_TASK_NAME;
  me->ui = WhoIs(uiName);
  me->CC = 0;
  me->speedAfterReverse = -1;
  me->rerouteCountdown = -1;
  me->nextSetSwitchNode = -1;
  me->reserveFailedLandmark.type = LANDMARK_BAD;

  char trackName[] = TRACK_NAME;
  me->trackManager = WhoIs(trackName);
  me->route.length = 0;
  me->stopCommited = 0; // haven't enabled speed zero yet.
  me->useLastSensorNow = 0;
  me->stopNow = 0;
  me->positionFinding = 0;
  me->currentlyLost = 0;
  me->testMode = 0;
  me->stopSensorHit = 0;
  me->nextSensorIsTerminal = 0;
  me->lastSensorIsTerminal = 0;
  me->lastSensorVal = 0; // NOte to ui to don't print sensor.
  me->setSwitchNaggerCount = 0;

  char timename[] = TIMESERVER_NAME;
  me->timeserver = WhoIs(timename);

  DriverInitMsg init;
  Receive(&(me->trainController), (char*)&init, sizeof(DriverInitMsg));
  Reply(me->trainController, (char*)1, 0);
  me->trainNum = init.trainNum;
  me->uiMsg.nth = init.nth;
  me->uiMsg.trainNum = (char)init.trainNum;
  char com1Name[] = IOSERVERCOM1_NAME;
  me->com1 = WhoIs(com1Name);
  me->uiMsg.type = UPDATE_TRAIN;

  me->speed = 0;
  me->speedDir = ACCELERATE;
  me->distanceToNextSensor = 0;
  me->distanceFromLastSensor = 0;
  me->lastSensorActualTime = 0;
  me->lastSensorDistanceError = 0;

  if (firstTime) {
    me->delayer = Create(1, trainDelayer);
    me->stopDelayer = Create(1, trainStopDelayer);
    me->sensorWatcher = Create(3, trainSensor);
    me->navigateNagger = Create(2, trainNavigateNagger);
  }
  me->routeRemaining = -1;

  me->isAding = 0;

  initStoppingDistance((int*)me->d);
  initVelocity((int*)me->v);
  initAccelerationProfile((int*)me->a);
}
Exemple #5
0
void ipc1 () {
  bwprintf (COM2, "ipc1: I am %d\r\n", MyTid());
  bwprintf (COM2, "ipc1: Registering as LOL\r\n");
  RegisterAs ("LOL"); RegisterAs ("POO");
  bwprintf (COM2, "ipc1: Registration complete.\r\n");
  bwprintf (COM2, "ipc1: WhoIs(\"LOL\") = %d\r\n",WhoIs("LOL"));
  bwprintf (COM2, "ipc1: Exiting.\r\n");
  bwprintf (COM2, "ipc1: WhoIs(\"POO\") = %d\r\n",WhoIs("POO"));
  Exit();
}
void stopping_distance_task() {

	TRAIN = 38;


//	int term_tid = WhoIs("term_tid");
	int train_tid = WhoIs("train_server");
	int uart_tid = WhoIs("uart_server");
	int sensor_tid = WhoIs("sensor_server");
	int clock_tid = WhoIs("clock_server");

	init_tracka(track);

	Delay(100, clock_tid);
	TrainCommandSwitchStraight(16, train_tid);
	TrainCommandSwitchCurved(15, train_tid);
	TrainCommandSwitchStraight(9, train_tid);

	Printf("press 'a' for train 37, 'b' for 38\r");
	if (Getc(COM2, uart_tid) == 'a') TRAIN = 37;
	else TRAIN = 38;

	TrainCommandSpeed(TRAIN, 0, train_tid);

	int speed;
	for (speed = 14; speed >= 1; speed--) {

		Printf("\rPress enter to start at speed %d .. ", speed);
		Getc(COM2, uart_tid);

		TrainCommandSpeed(TRAIN, 14, train_tid);

		int module, sensor, time;
		struct track_node *sensor_node;

		int sample_time = 0;
		do {
			SensorGetNextTriggered(&module, &sensor, &time, sensor_tid);
			sensor_node = &track[SENSOR_TO_NODE(module,sensor)];

//			Printf("\rTriggered %s", sensor_node->name);
		} while (strcmp(sensor_node->name,"D14"));

		TrainCommandSpeed(TRAIN, speed, train_tid);

		do {
			SensorGetNextTriggered(&module, &sensor, &time, sensor_tid);
			sensor_node = &track[SENSOR_TO_NODE(module,sensor)];
//			Printf("\rTriggered %s", sensor_node->name);
		} while (strcmp(sensor_node->name,"E8"));
		TrainCommandSpeed(TRAIN, 0, train_tid);

	}

}
int Putc( int channel, char ch ){
	int tid = -1;
	int copy_length = 0;
	//int status = 0;
	
	struct number_message rpl;
	
	if(channel == COM1) {
		//we are sending to train, get the tid
		tid = WhoIs("u1send");

		//check the return value of WhoIs
		if(tid < 0){ return -1; }

		struct char_message msg;

		//copy the character into the message
		msg.c = ch;

		msg.message_type = UART1_PRINT_SERVER_INPUT_MESSAGE;

		//send the message to the server
		//status = Send(tid, (char *) &msg, sizeof(msg), (char *) &rpl, sizeof(rpl));
		Send(tid, (char *) &msg, sizeof(msg), (char *) &rpl, sizeof(rpl));	
		
	} else if(channel == COM2) {		
		//we are sending to terminal, get the tid
		tid = WhoIs("u2send");
		
		//check the return value of WhoIs
		if(tid < 0){ return -1; }

		struct short_str_message msg;
		
		//copy the character into the message
		msg.str[0] = ch;
		msg.str[1] = '\0';
		copy_length = 2 + 4;
		
		msg.message_type = PRINT_SERVER_STRING_MESSAGE;
	
		//send the message to the server
		//status = Send(tid, (char *) &msg, copy_length, (char *) &rpl, sizeof(rpl));
		Send(tid, (char *) &msg, copy_length, (char *) &rpl, sizeof(rpl));
	} else {
		return -3; //NOT A PROPER COM CHANNEL
	}
	

	
	//TODO: add in checking for the return of the send and the reply
	//success
	return 0;
}
static void initDriver(MultiTrainDriver* me) {

  char uiName[] = UI_TASK_NAME;
  me->ui = WhoIs(uiName);
  me->CC = 0;
  me->speedAfterReverse = -1;
  me->rerouteCountdown = -1;
  me->nextSetSwitchNode = -1;
  me->reserveFailedLandmark.type = LANDMARK_BAD;

  char trackName[] = TRACK_NAME;
  me->trackManager = WhoIs(trackName);
  me->route.length = 0;
  me->stopCommited = 0; // haven't enabled speed zero yet.
  me->useLastSensorNow = 0;
  me->stopNow = 0;
  me->testMode = 0;
  me->stopSensorHit = 0;
  me->setSwitchNaggerCount = 0;
  me->isReversing = 0;

  char timename[] = TIMESERVER_NAME;
  me->timeserver = WhoIs(timename);

  MultiTrainInitMsg init;
  Receive(&(me->trainController), (char*)&init, sizeof(MultiTrainInitMsg));
  Reply(me->trainController, (char*)1, 0);

  // Create dumb drivers
  me->infoUpdater = -1;
  me->tailMode = 0;
  me->numTrainInGroup = 1;
  me->trainId[0] = CreateDumbTrain(init.nth, (int)init.trainNum);
  me->trainNum = init.trainNum;
  RegisterMulti(init.trainNum);

  me->speed = 0;
  me->speedDir = ACCELERATE;

  me->sensorWatcher = Create(3, trainSensor);
  me->courier = Create(3, multiTrainDriverCourier);

  me->routeRemaining = -1;
  me->stoppedCount = 0;
  me->route.length = 0;

  me->minFollowingDist = 100;
  me->maxFollowingDist = 150;
}
void UpdatePositionDisplay( int train_number, int speed, char* pos_node, int pos_offset, int error, int max_error, char* dest_node, int dest_offset, char* state ) {
	int tid = -1;
	tid = WhoIs( "trainsTAB" );

	//check the return value of WhoIs
	if( tid < 0 ) {
		return;
	}

	//create the message
	struct train_position_output_message msg;

	msg.message_type = TRAIN_POSITION_OUTPUT_MESSAGE;
	msg.train_nums = train_number;
	msg.train_speeds = speed;
	safestrcpy( msg.train_pos_node, pos_node, 6 );
	msg.train_pos_off = pos_offset;
	msg.train_err = error;
	msg.train_max_err = max_error;
	safestrcpy( msg.train_dest_node, dest_node, 6 );
	msg.train_dest_off = dest_offset;
	safestrcpy( msg.train_state, state, 6 );

	//send the message via courier
	CourierSend( tid, (char *)&msg, sizeof (msg) );
}
int QueryAllSensors( char * sensorbuf ) {
	struct sensor_reply_message rpl;
	struct two_number_message msg;
	int tid = -1, status = 0, i = 0;

	tid = WhoIs( "mdiserv" );

	//check the return value of WhoIs
	if( tid < 0 ) {
		return -1;
	}

	msg.message_type = QUERY_ALL_SENSORS_MESSAGE;

	Send( tid, (char *)&msg, sizeof (msg), (char *)&rpl, sizeof (rpl) );

	if( status < 0 || (rpl.message_type == SENSOR_REPLY_MESSAGE) ) {
		return -1;
	}

	for( i = 0; i < CONFIG_SENSOR_RESULT_LENGTH; i++ ) {
		sensorbuf[i] = rpl.sensordata[i];
	}

	return 0;
}
int SetSwitch( int sw, int setting ) {
	struct number_message rpl;
	struct two_number_message msg;
	int tid = -1, status = 0;

	if( setting != SWITCH_STRAIGHT && setting != SWITCH_CURVED ) {
		return -2;
	}

	tid = WhoIs( "switchserv" );

	//check the return value of WhoIs
	if( tid < 0 ) {
		return -1;
	}

	msg.message_type = SWITCH_CTRL_MESSAGE;
	msg.num1 = sw;
	msg.num2 = setting;

	Send( tid, (char *)&msg, sizeof (msg), (char *)&rpl, sizeof (rpl) );

	if( status < 0 || ((rpl.message_type & MESSAGE_SEMANTIC_MASK) != SEMANTIC_ACK) ) {
		return -1;
	}

	return 0;
}
Exemple #12
0
void sensor_notifier() {
    // Find the sensor server.
    int sensor_server_tid = -2;
    do {
        sensor_server_tid = WhoIs("SensorServer");
        dlog("Sensor Server Tid %d\n", sensor_server_tid);
    } while (sensor_server_tid < 0);

    // Set up sensors.
    enable_sensor_reset();

    // Delay a bit to read old data and then clear it.
    Delay(10);
    ReadClear(COM1);

    // Poll sensor data and forward it.
    SensorServerMessage msg;
    SensorServerMessage rply;
    msg.type = SENSOR_EVENT_REQUEST;

    char old_data[SENSOR_DATA_SIZE] = {0,0,0,0,0,0,0,0,0,0};
    for(;;) {
        dump_sensors();
        
        int i = 0;
        for (; i < SENSOR_DATA_SIZE; ++i) {
            char new_data = (char)Getc(COM1);
            msg.data[i] = new_data & ~old_data[i];
            old_data[i] = new_data;
        }

        Send(sensor_server_tid, (char *)&msg, sizeof(msg), (char *)&rply, sizeof(rply));
        dassert(rply.type == SENSOR_EVENT_RESPONSE, "Invalid Response from SensorServer");
    }
}
Exemple #13
0
INT
SwitchGetDirection
    (
        IN INT sw,
        OUT SWITCH_DIRECTION* direction
    )
{
    INT result;
    UINT index = SwitchpToIndex(sw);

    if (index < NUM_SWITCHES)
    {
        result = WhoIs(SWITCH_SERVER_NAME);

        if (SUCCESSFUL(result))
        {
            INT switchServerId = result;
            SWITCH_REQUEST request = { GetDirectionRequest, (UCHAR) sw };

            result = Send(switchServerId, &request, sizeof(request), direction, sizeof(*direction));
        }
    }
    else
    {
        result = -1;
    }

    return result;
}
Exemple #14
0
int Delay(int ticks)
{
  int clock_tid;
  int r, t = MyTid();
  char msg[5];
  char *ip;

  clock_tid = WhoIs("clck");
  clock_tid = 2;

  msg[0] = 'd';
  ip = (char *)&ticks;
  msg[1] = *ip++;
  msg[2] = *ip++;
  msg[3] = *ip++;
  msg[4] = *ip++;
  DPRINT("Delayed tid %d with msg \'%x%x%x%x%x\' to server at tid %d\r\n",
         MyTid(), msg[0], msg[1], msg[2], msg[3], msg[4], clock_tid);

  //if (t == 5) { bwputstr(COM2, "YAYA\r\n"); }
  r = Send(clock_tid, msg, 5, NULL, 0);
  if (r < 0) {
    DPRINTERR("Send() from inside Delay() failed with retval %d\r\n", r);
    PANIC;
  }
  return 0;
}
Exemple #15
0
void switch_server() {
    server_tid = MyTid();

    switches_init();

    // Find the location server.
    tid_t location_server_tid = -2;
    do {
        location_server_tid = WhoIs("LocationServer");
        dlog("Location Server Tid %d\n", location_server_tid);
    } while (location_server_tid < 0);

    tid_t tid;
    SwitchServerMessage msg, reply;
    while (1) {
        Receive(&tid, (char *) &msg, sizeof(msg));
        switch (msg.type) {
        case SET_SWITCH:
            reply.type = SET_SWITCH_RESPONSE;
            Reply(tid, (char *) &reply, sizeof(reply));
            switch_set(msg.switch_no, msg.direction, location_server_tid);
            break;
        default:
            break;
        }
    }
}
void uart1_receiver_notifier() {
	bwdebug( DBG_SYS, UART1_RECEIVER_DEBUG_AREA, "UART1_RECEIVER_NOTIFIER: enters" );

	int server_tid = WhoIs("uart1_receiver");
	UART_request request;
	
	int receive_buffer = 0;


	FOREVER {
		//Wait until there is data in UART1
		//bwprintf( COM2, "F\n" );
		bwdebug( DBG_SYS, UART1_RECEIVER_DEBUG_AREA, "UART1_RECEIVER_NOTIFIER: waiting for data" );
		AwaitEvent( UART1_RECEIVE_READY, (int) &receive_buffer );
		bwdebug( DBG_SYS, UART1_RECEIVER_DEBUG_AREA, "UART1_RECEIVER_NOTIFIER: data received" );
		//bwprintf( COM2, "G\n" );

		//Configure the request
		request.type = UART1_RECEIVE_NOTIFIER_REQUEST;
		request.ch = receive_buffer;

		//Send data to the server (uart1_receiver_server)
		Send(server_tid, (char *) &request, sizeof(request), (char *) 0, 0);
	}
}
Exemple #17
0
void RPSClient_Initialize(RPSClient * client) {
	client->tid = MyTid();
	RNG_Initialize(&client->rng, client->tid);
	client->server_id = WhoIs((char*) RPS_SERVER_NAME);
	client->num_rounds_to_play = 5;
	client->running = 1;
}
Exemple #18
0
int sem_init( Semaphore* sem, int count )
{
    sem->srv_tid = WhoIs( SEMAPHORE_SERVER_NAME );
    sem->count = count;
    rbuf_init( &sem->wait_queue, ( uchar* )sem->wait_queue_buf, sizeof( int ), sizeof( int ) * SEMAPHORE_WAIT_QUEUE_SIZE );

    return ERR_NONE;
}
Exemple #19
0
static void sensorQueryResponseWorker() {
  char com1Name[] = IOSERVERCOM1_NAME;
  int com1 = WhoIs(com1Name);
  char timeName[] = TIMESERVER_NAME;
  int time = WhoIs(timeName);

  int parent = MyParentsTid();

  for (;;) {
    SensorMsg msg;
    char c = Getc(com1);
    msg.type = QUERY_RESPONSE_WORKER;
    msg.data = c;
    msg.time = Time(time);
    Send(parent, (char *)&msg, sizeof(SensorMsg), (char *)NULL, 0);
  }
}
void command_track( struct char_buffer* cbuff, int* track, struct track_node * track_data ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	char str_arg2[CONFIG_CLI_MAX_CHARACTERS];

	if(
		next_token( cbuff, str_arg1 ) == 0 ||
		str_arg1[0] == '\0' ||
		str_arg1[1] != '\0' ||
		next_token( cbuff, str_arg2 ) != 0 ) {
		CommandOutput( "[TRACK]\tInvalid Arguments" );
		return;
	}

	//check the switch state
	if( str_arg1[0] != 'a' && str_arg1[0] != 'b' ) {
		CommandOutput( "[TRACK]\tInvalid track designation" );
		return;
	}

	if( *track != TRACK_UNINITIALIZED ) {
		CommandOutput( "[TRACK]\tTrack Already Selected" );
		return;
	}

	if( str_arg1[0] == 'a' ) {
		*track = TRACK_A;
		CommandOutput( "[TRACK]\tSelecting Track A" );
		init_tracka( track_data );
	} else {
		*track = TRACK_B;
		CommandOutput( "[TRACK]\tSelecting Track B" );
		init_trackb( track_data );
	}

	//Send a message to the route server, telling them which track should be used
	struct number_message msg, rpl;
	int tid = WhoIs( "routeserv" );
	while( tid < 0 ) {
		tid = WhoIs( "routeserv" );
	}
	msg.message_type = ROUTE_SERVER_INIT_MESSAGE;
	msg.num = *track;
	Send( tid, (char *)&msg, sizeof (msg), (char *)&rpl, sizeof (msg) );
}
void trainSensorNotifier() {
	int i;
	int parent_tid = MyParentTid();
	int com1_tid = WhoIs(COM1_REG_NAME);

	int sensor_next = 0;
	int data_changed = TRUE;
	char query = SENSOR_READ_MULTI + SENSOR_DECODER_TOTAL;

	SensorMsg msg;
	msg.type = SENSOR_DATA;
	for(i = 0; i < SENSOR_BYTES_TOTAL; i++) {
		msg.sensor_data[i] = 0;
	}
	
	/* Filter out left over sensor data */
	while(1) {
		if(sensor_next == 0 && data_changed) {
			Putc(com1_tid, query);
			data_changed = 0;
		}
		else break;

		int new_data = Getc(com1_tid);
		assert(new_data >= 0, "Fail to get");
		if(new_data != 0) data_changed = TRUE;

		sensor_next = (sensor_next + 1) % SENSOR_BYTES_TOTAL;
	}

	data_changed = FALSE;

	Putc(com1_tid, SENSOR_AUTO_RESET);
	while(1) {
		if(sensor_next == 0) {
			if(data_changed) {
				data_changed = FALSE;
				// Deliver sensor data to the parent
				Send(parent_tid, (char *)(&msg), SENSOR_BYTES_TOTAL, NULL, 0);
			}
			// Request sensor data again
			Putc(com1_tid, query);
		}

		// Get and save new data
		int new_data = Getc(com1_tid);
		assert(new_data >= 0, "Fail to get");
		if(msg.sensor_data[sensor_next] != new_data) {
			msg.sensor_data[sensor_next] = new_data & 0xff;
			data_changed = TRUE;
		}

		// Increment the counter
		sensor_next = (sensor_next + 1) % SENSOR_BYTES_TOTAL;
	}
}
Exemple #22
0
int Time()
{
  int clock_tid;
  int time, r;

  clock_tid = WhoIs("clck");
  r = Send(clock_tid, "t", 1, (char *)&time, 4);
  /* XXX check return value XXX */
  return time;
}
void command_game( struct char_buffer* cbuff ) {
	char str_arg1[CONFIG_CLI_MAX_CHARACTERS];
	if( next_token( cbuff, str_arg1 ) != 0 ) {
		CommandOutput( "[Q]\tInvalid Arguments" );
		return;
	}

	//hand over the character stream to the game task
	Send( WhoIs("gameKEY"), (char*)0, 0, (char*)0, 0 );
}
Exemple #24
0
void ClockClient_Start() {
	ClockClient client;
	ClockClient_Initialize(&client);
	robprintfbusy((const unsigned char *)"ClockClient TID=%d: start\n", client.tid);
	
	assertf(client.server_tid, "ClockClient: server not found. got=%d", client.server_tid);
	assertf(client.server_tid, "ClockClient: parent not found. got=%d", client.parent_tid);
	
	K3Message * send_message = (K3Message *) client.send_buffer;
	K3Message * reply_message = (K3Message *) client.reply_buffer;
	
	send_message->message_type = MESSAGE_TYPE_HELLO;
	
	Send(client.parent_tid, client.send_buffer, MESSAGE_SIZE, client.reply_buffer, MESSAGE_SIZE);
	
	assertf(reply_message->message_type == MESSAGE_TYPE_ACK, "ClockClient TID=%d: failed to get ACK message\n");
	
	client.delay_time = reply_message->delay_time;
	client.num_delays = reply_message->num_delays;
	
	robprintfbusy((const unsigned char *)"ClockClient TID=%d: Got delay_time=%d, num_delays=%d\n", client.tid, client.delay_time, client.num_delays);
	
	int i;
	for (i = 0; i < client.num_delays; i++) {
		//robprintfbusy((const unsigned char *)"ClockClient TID=%d: About to delay %d, i=%d\n", client.tid, client.delay_time, i);
		Delay(client.delay_time);
		robprintfbusy((const unsigned char *)"ClockClient TID=%d: I just delayed delay_time=%d, i=%d\n", client.tid, client.delay_time, i);
	}

	//robprintfbusy((const unsigned char *)"ClockClient TID=%d: Finished, telling idletask we're shutting down.\n", client.tid);


	send_message->message_type = MESSAGE_TYPE_SHUTDOWN;
	
	i = 0;
	int admin_tid;
	
	while (1) {
		admin_tid = WhoIs((char*) ADMINISTRATOR_TASK_NAME);
		
		if (admin_tid) {
			break;
		}
		i++;
		
		assertf(i < 1000, "ClockClient TID=%d: Didn't get an admin tid");
	}
	
	Send(admin_tid, client.send_buffer, MESSAGE_SIZE, client.reply_buffer, MESSAGE_SIZE);
	assertf(reply_message->message_type == MESSAGE_TYPE_ACK, "ClockClient TID=%d: failed to get ACK message\n");
	
	robprintfbusy((const unsigned char *)"ClockClient TID=%d: Exit\n", client.tid);
	
	Exit();
}
void notifier() {
	char cs_name[] = CS_REG_NAME;
	int cs_tid = WhoIs(cs_name);
	assert(cs_tid >= 0, "Notifier cannot find clock server's tid");

	char send[1] = "";
	while (1) {
		AwaitEvent(EVENT_TIME_ELAP, NULL, 0);
		Send(cs_tid, send, 1, NULL, 0);
	}
}
Exemple #26
0
int Time()
{
    static int clockServerTid = -1;
    if (clockServerTid < 0)
    {
        clockServerTid = WhoIs(CLOCK_SERVER_NAME);
    }
    ClockReq req;
    req.type = TIME;
    Send(clockServerTid, &req, sizeof(req), &(req.data), sizeof(int));
    return req.data;
}
int DelayUntil( int ticks ) {
	assert(ticks >= 0, "DelayUntil ticks is negative");

	char cs_name[] = CS_REG_NAME;
	int cs_tid = WhoIs(cs_name);
	assert(cs_tid >= 0, "DelayUntil: cannot find clock server's tid");

	DelayUntilQuery query;
	query.type = CS_QUERY_TYPE_DELAY_UNTIL;
	query.delay_time = (unsigned int) ticks;
	return Send(cs_tid, (char*)(&query), sizeof(DelayUntilQuery), NULL, 0);
}
// -----------------------------------------------------------------------------------------------------------------------------------------------
// Sensors Server Notifier
// -----------------------------------------------------------------------------------------------------------------------------------------------
void sensors_server_notifier(){
	bwdebug( DBG_SYS, SENSORS_SERVER_DEBUG_AREA, "SENSORS_SERVER_NOTIFIER: enters" );

	// Initialization
	Init_sensor_msg init_msg; 
	Sensor_msg sensor_msg; 
	Cmd_request cmd_request; 
	int sensor_server_tid, my_tid, last_recieved; 
	char *sensor_data; 
	
	bwdebug( DBG_SYS, SENSORS_SERVER_DEBUG_AREA, "SENSORS_SERVER_NOTIFIER: recieving init info" );
	Receive( &sensor_server_tid, (char *)&init_msg, sizeof(init_msg) );
	//Reply( sensor_server_tid, 0, 0 );
	sensor_data = init_msg.sensor_data_buff; 
	
	int cmd_server_tid = WhoIs( COMMAND_SERVER_NAME );
	bwassert( cmd_server_tid >= 0, "SENSORS SERVER: This task requires the command server to be able to operate." ); 
	
	// Reset the sensors
	bwdebug( DBG_SYS, SENSORS_SERVER_DEBUG_AREA, "SENSORS_SERVER_NOTIFIER: Resetting sensors" );
	my_tid = MyTid(); 
	cmd_request.type = QUERY_CMD_REQUEST; 
	cmd_request.cmd.cmd_type = RESET_SENSORS_CMD_TYPE; 	
	cmd_request.cmd.sender_tid = my_tid; 
	Send( cmd_server_tid, ( char * ) &cmd_request, sizeof( cmd_request ), 0, 0  );
	
	// Receive trash?
	bwdebug( DBG_SYS, SENSORS_SERVER_DEBUG_AREA, "SENSORS_SERVER_NOTIFIER: recieving trash" );
	cmd_request.type = QUERY_CMD_REQUEST; 
	cmd_request.cmd.cmd_type = QUERY_SENSORS_CMD_TYPE; 
	cmd_request.cmd.sensors = sensor_data; 
	Send( cmd_server_tid, ( char * ) &cmd_request, sizeof( cmd_request ), 0, 0  ); 

	bwdebug( DBG_SYS, SENSORS_SERVER_DEBUG_AREA, "SENSORS_SERVER_NOTIFIER: Unblocking sensor server" );
	Reply( sensor_server_tid, 0, 0 );
	
	// Configure the messages. 
	sensor_msg.type = SENSOR_DATA_RECEIVED_MSG; 
	
	FOREVER{
		last_recieved = Time();
		
		// Get the data from the command server
		Send( cmd_server_tid, ( char * ) &cmd_request, sizeof( cmd_request ), 0, 0  ); 
		
		// Inform the sensor server that new data arrived
		Send( sensor_server_tid, ( char * ) &sensor_msg, sizeof( sensor_msg ), 0, 0 ); 
		
		//DelayUntil( last_recieved + 100 / SENSOR_QUERY_FREQENCY );
		Delay( 20 );	// 10 
	}
}
int Time() {
	char cs_name[] = CS_REG_NAME;
	int cs_tid = WhoIs(cs_name);
	assert(cs_tid >= 0, "Time: cannot find clock server's tid");

	int ret = -1;
	TimeQuery query;
	TimeReply reply;
	query.type = CS_QUERY_TYPE_TIME;
	ret = Send(cs_tid, (char*)(&query), sizeof(TimeQuery), (char*)(&reply), sizeof(TimeReply));
	if (ret < 0) return ret;
	return reply.time;
}
Exemple #30
0
static void sensorQueryResponseTimeoutWorker() {
  char timeServerName[] = TIMESERVER_NAME;
  int timeServer= WhoIs(timeServerName);

  int parent = MyParentsTid();

  for (;;) {
    SensorMsg msg;
    msg.type = QUERY_RESPONSE_TIMEOUT_WORKER;
    Send(parent, (char *)&msg, sizeof(SensorMsg), (char *)NULL, 0);
    Delay(7, timeServer);
  }
}