void routeFinder( ) { track_node track[TRACK_MAX]; init_tracka(track); RegisterAs( "route" ); // int printer = MyParentTid(); ComReqStruct reply; int sender; FOREVER { Receive( &sender, (char *)&reply, sizeof(ComReqStruct) ); int src = reply.data1; // No offset right now int dest = reply.data2; // Begin finding the shortest path from the src to the dest Path shortest; route( track, &shortest, src, dest ); ComReqStruct fus, roh; fus.type = UPDATE_STAT; fus.data1 = (int *)&shortest; Send( MyParentTid(), (char *)&fus, sizeof(ComReqStruct), (char *)&roh, sizeof(ComReqStruct) ); Reply( sender, (char *)&shortest, sizeof(Path) ); } }
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); } }
void loadTrackStructure(char track) { // draw track drawTrackLayoutGraph(track); if(track == 'a') { init_tracka(g_track); setTurnout(5, 'c'); } else { init_trackb(g_track); } }
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 routeFinder( ) { track_node track[TRACK_MAX]; init_tracka(track); RegisterAs( "route" ); int myAdmin = MyParentTid(); int monitor = WhoIs( "monitor" ); // int printer = MyParentTid(); ComReqStruct reply, reservation,send; int sender; int trains[2]; // first train use the first Path structure, second train use the second path trains[0] = 0; trains[1] = 0; Path paths[2]; FOREVER { Receive( &sender, (char *)&reply, sizeof(ComReqStruct) ); int src = reply.data1; // No offset right now int dest = reply.data2; // Begin finding the shortest path from the src to the dest int i; if ( trains[0] == 0 || sender == trains[0] ) { trains[0] = sender; i = 0; } else if ( trains[1] == 0 || sender == trains[1] ) { trains[1] = sender; i = 1; } route( track, &paths[i], src, dest ); // ComReqStruct fus, roh; // fus.type = UPDATE_STAT; // fus.data1 = (int *)&paths[i]; // Send( MyParentTid(), (char *)&fus, sizeof(ComReqStruct), (char *)&roh, sizeof(ComReqStruct) ); Reply( sender, (char *)&paths[i], sizeof(Path) ); } }
// Initialize track data structures static void track_init() { #if TRACK_TYPE == TRACK_TYPE_A init_tracka(track); #else init_trackb(track); #endif // Initialize the switch table int switch_tid = WhoIs(SWITCH_SERVER); int i; for (i = 1; i <= 18; i++) { switch_table[i] = (char)SwitchGetDirection(i, switch_tid); } switch_table[0x99] = (char)SwitchGetDirection(0x99, switch_tid); switch_table[0x9A] = (char)SwitchGetDirection(0x9A, switch_tid); switch_table[0x9B] = (char)SwitchGetDirection(0x9B, switch_tid); switch_table[0x9C] = (char)SwitchGetDirection(0x9C, switch_tid); }
void init(void) { #ifdef TRACKA init_tracka(track); #else init_trackb(track); #endif start_servers(); #if CALIBRATE calibratesrv_start(); #else tracksrv_start(); displaysrv_start(); commandsrv_start(); trains_start(); routesrv_start(); heartbeat_start(); #endif sensorsrv_start(); }