void process_command(char* command) { if (is_command(command, "ps")) { print_all_processes(&shell_wnd); return; } if (is_command(command, "clear")) { clear_window(&shell_wnd); return; } if (is_command(command, "pacman")) { run_pacman_app(&pacman_wnd); return; } if (is_command(command, "train")) { run_train_app(&train_wnd); return; } if (is_command(command, "macaddr")) { ne2k_print_mac(&ne2k_wnd, &ne2k_phy); return; } if (is_command(command, "go")) { set_train_speed("4"); return; } if (is_command(command, "stop")) { set_train_speed("0"); return; } if (is_command(command, "rev")) { set_train_speed("D"); return; } if (is_command(command, "help")) { wprintf(&shell_wnd, "Commands:\n"); wprintf(&shell_wnd, " - help show this help\n"); wprintf(&shell_wnd, " - clear clear window\n"); wprintf(&shell_wnd, " - ps show all processes\n"); wprintf(&shell_wnd, " - pacman start PacMan\n"); wprintf(&shell_wnd, " - go make the train go\n"); wprintf(&shell_wnd, " - stop make the train stop\n"); wprintf(&shell_wnd, " - rev reverse train direction\n"); wprintf(&shell_wnd, " - train start train application\n"); wprintf(&shell_wnd, " - macaddr get the MAC address of your NE2K\n\n"); return; } /* Room for more commands! */ wprintf(&shell_wnd, "Syntax error! Type 'help' for help.\n"); }
void runConfig1or2(int zamboniConfig) { // Set switches for wagon pickup train_set_switch('3', 'G'); train_set_switch('2', 'G'); wprintf(&train_wnd, "Waiting for Zamboni to pass wagon\n"); // wait for zamboni to go by wagon if(zamboniConfig) { while(!get_status_of_contact("3")); } set_train_speed("5"); // set switch so zamboni will be trapped in loop train_set_switch('8', 'R'); // set switch so train can get wagon train_set_switch('4', 'R'); wprintf(&train_wnd, "Trapping Zamboni in small loop\n"); // slow down train once it's close to the wagon while(!get_status_of_contact("6")); while(get_status_of_contact("6")); // Won't need this on actual train set set_train_speed("4"); // detect pickup of wagon while(!get_status_of_contact("1")); set_train_speed("0"); train_set_switch('4', 'G'); wprintf(&train_wnd, "Ensure Zamboni is trapped\n"); // make sure zamboni is in loop if(zamboniConfig) { while(!get_status_of_contact("12")); } wprintf(&train_wnd, "Heading home\n"); // send the train home train_switch_directions(); set_train_speed("5"); train_set_switch('5', 'R'); train_set_switch('6', 'R'); // wait for arrival and stop while(!get_status_of_contact("7")); while(get_status_of_contact("7")); set_train_speed("0"); wprintf(&train_wnd, "Home Safe!\n"); // restore outer track config train_set_switch('5', 'G'); }
// initialize the track, set switch positions void init_track() { // make sure train is immobile set_train_speed("0"); // Set switches so that Zamboni will not crash train_set_switch('5', 'G'); train_set_switch('8', 'G'); train_set_switch('9', 'R'); train_set_switch('4', 'G'); train_set_switch('1', 'G'); }
int trainCommand(char* param1, char* param2) { if(stringCompare(param1, "clear") == 0 && stringCompare(param2, "") == 0) { train_clear_mem_buffer(); return 0; } // train speed setting else if(stringCompare(param1, "speed") == 0) { if(param2[1] == 0 && param2[0] >= '0' && param2[0] <= '5') { set_train_speed(¶m2[0]); return 0; } else { wprintf(&shell_wnd, "Invalid Speed Selection\n"); return -1; } } else if(stringCompare(param1, "switch") == 0) { if(param2[2] != 0) { wprintf(&shell_wnd, "Invalid switch command format\n"); wprintf(&shell_wnd, "Must be of form train switch #C\n"); wprintf(&shell_wnd, "Where # is [1-9] and C is 'R' or 'G'\n"); return -1; } if(param2[0] < '1' || param2[0] > '9') { wprintf(&shell_wnd, "Invalid switch identifier\n"); return -1; } if(param2[1] != 'G' && param2[1] != 'R') { wprintf(&shell_wnd, "Invalid switch position\n"); return -1; } train_set_switch(param2[0], param2[1]); return 0; } else if(stringCompare(param1, "see") == 0) { // Only allow second parameter length of 2 if(strlen(param2) > 2 || param2[0] == 0) { wprintf(&shell_wnd, "Invalid parameter 2 length\n"); return -1; } else { if(get_status_of_contact(param2) == 0) { wprintf(&shell_wnd, "train not detected\n"); } else { wprintf(&shell_wnd, "train found on track "); wprintf(&shell_wnd, param2); wprintf(&shell_wnd, "\n"); } return 0; } } else if(stringCompare(param1, "rev") == 0) { wprintf(&shell_wnd, "Reversing train direction\n"); train_switch_directions(); //switch_train_direction(&train_wnd); return 0; } else if(stringCompare(param1, "run") == 0 && stringCompare(param2, "") == 0) { wprintf(&shell_wnd, "Train Executing\n"); trainRunning = 0; init_train(&train_wnd); return 0; } else { wprintf(&shell_wnd, "See 'help' for list of train commands\n"); return -1; } return 1; }
void runConfig4(int zamboniConfig) { int on13 = 0; // init switches train_set_switch('9', 'G'); // put train on outer loop, head for wagon wprintf(&train_wnd, "Turning around\n"); set_train_speed("5"); while(!get_status_of_contact("6")); set_train_speed("0"); train_switch_directions(); set_train_speed("5"); // redirect zamboni, wait at 3 if(zamboniConfig) { wprintf(&train_wnd, "Redirecting Zamboni\n"); while(get_status_of_contact("6")); train_set_switch('4', 'R'); train_set_switch('3', 'G'); wprintf(&train_wnd, "Waiting for Zamboni at track 3\n"); while(!get_status_of_contact("3")); set_train_speed("0"); while(!get_status_of_contact("14")); set_train_speed("5"); } // turn train around, connect to wagon wprintf(&train_wnd, "Getting the wagon\n"); while(!get_status_of_contact("14")); set_train_speed("0"); train_switch_directions(); // check to see that train is on track 13 // this determines how long the train should reverse on the spur if(get_status_of_contact("13")) { on13 = 1; wprintf(&train_wnd, "Stopped to reverse on track 13\n"); } else { wprintf(&train_wnd, "Stopped to reverse on track 14\n"); } set_train_speed("5"); while(get_status_of_contact("14")); // carriage is on a spur, so wait a bit before stopping // boolean will protect against inadvertent run-offs if(on13) { sleep(80); } else { sleep(5); } set_train_speed("0"); train_switch_directions(); // Wait for zamboni if(zamboniConfig) { wprintf(&train_wnd, "Waiting for Zamboni"); while(!get_status_of_contact("7")) { wprintf(&train_wnd, "."); } wprintf(&train_wnd, "\n"); } // Go home wprintf(&train_wnd, "Going home\n"); set_train_speed("5"); train_set_switch('4', 'G'); train_set_switch('3', 'R'); // wait for zamboni to pass before throwing switch if(zamboniConfig) { wprintf(&train_wnd, "Waiting for Zamboni to pass home plate\n"); while(!get_status_of_contact("4")); } train_set_switch('4', 'R'); while(!get_status_of_contact("6")); while(get_status_of_contact("6")); set_train_speed("0"); wprintf(&train_wnd, "Home Safe!\n"); train_set_switch('4', 'G'); }
void runConfig3(int zamboniConfig) { // init switches train_set_switch('7', 'G'); train_set_switch('3', 'R'); train_set_switch('2', 'R'); // Waiting for Zamboni if(zamboniConfig) { wprintf(&train_wnd, "Waiting for Zamboni\n"); while(!get_status_of_contact("4")); } // put train on outer loop, head for wagon wprintf(&train_wnd, "Turning around\n"); set_train_speed("5"); while(!get_status_of_contact("6")); set_train_speed("0"); train_switch_directions(); set_train_speed("5"); wprintf(&train_wnd, "Getting wagon\n"); // redirect zamboni, wait at 3 if(zamboniConfig) { wprintf(&train_wnd, "Redirecting Zamboni\n"); while(get_status_of_contact("6")); train_set_switch('4', 'R'); train_set_switch('3', 'G'); wprintf(&train_wnd, "Waiting for Zamboni at track 3\n"); while(!get_status_of_contact("3")); set_train_speed("0"); while(!get_status_of_contact("14")); sleep(75); set_train_speed("5"); } // Let Zamboni pass track segment 13 before setting switch if(zamboniConfig) { while(!get_status_of_contact("10")); } train_set_switch('8', 'R'); train_set_switch('4', 'G'); while(get_status_of_contact("11")); set_train_speed("0"); train_switch_directions(); train_set_switch('8', 'G'); // Waiting for Zamboni if(zamboniConfig) { wprintf(&train_wnd, "Waiting for Zamboni\n"); while(!get_status_of_contact("7")); } // train back to home wprintf(&train_wnd, "Going home\n"); set_train_speed("5"); // wait for zamboni to pass home, before setting outer loop switch if(zamboniConfig) { while(!get_status_of_contact("4")); } train_set_switch('4', 'R'); train_set_switch('3', 'R'); while(!get_status_of_contact("6")); while(get_status_of_contact("6")); set_train_speed("0"); wprintf(&train_wnd, "Home Safe!\n"); //Return outer loop continuity train_set_switch('4', 'G'); }