diff --git a/emulator.cpp b/emulator.cpp index ac56728..0664b20 100644 --- a/emulator.cpp +++ b/emulator.cpp @@ -9,6 +9,11 @@ #include "emulator.h" #include "robot.h" + +// закомментить когда надо будет отключить +//#define DEBUG_CORRECTION + + struct barrel barrels[BARRELS_COUNT]; struct robot_regs robot1; @@ -51,8 +56,14 @@ char scheduler_start_signal = 1; char auto_mode_pause = 0; char hla_night_mode = 0; +short hla_exchange_zone = ZONE_GALVANIZING_1; -short etching_zone = 0, galvanizing_zone = 0; +short hla_disabled_zones = 0; + + +short etching_zone = -2, galvanizing_zone = -2; + +char hla_correct_command = 0; static const int ROWS = 10; @@ -132,7 +143,42 @@ static void image_draw_borders() { // рамки ванн char tmp[24]; for (int i = 0, zone = 0; i < COLS; i += 5, zone++) { - sprintf(tmp, "|\n|\n+----+\n|\n|Z-%02d|", zone); + const char* label = nullptr; + const char* disabled_label = "+XXXX+"; + const char* selected_label = "+####+"; + + if (zone == ZONE_ETCHING_1) { + if (hla_disabled_zones & DISABLED_ETCH_1) { + label = disabled_label; + } + if (etching_zone == 0) { + label = selected_label; + } + } + + if (zone == ZONE_ETCHING_2) { + if (hla_disabled_zones & DISABLED_ETCH_2) { + label = disabled_label; + } + if (etching_zone == 1) { + label = selected_label; + } + } + + if (zone >= ZONE_GALVANIZING_1 && zone <= ZONE_GALVANIZING_8) { + const auto zone_id = zone - ZONE_GALVANIZING_1; + if (hla_disabled_zones & (DISABLED_GAL_1 << zone_id)) { + label = disabled_label; + } + if (galvanizing_zone == zone_id) { + label = selected_label; + } + } + + if (label == nullptr) { + label = "+----+"; + } + sprintf(tmp, "|\n|\n%s\n|\n|Z-%02d|", label, zone); image_insert_sprite(5, i, tmp, false); } @@ -181,12 +227,12 @@ static void showAll() { image_init(); image_draw_borders(); char tmp[64]; - sprintf(tmp, "Lock1=%2d Lock2=%2d", robot1_lock_zone, robot2_lock_zone); + sprintf(tmp, "Lock1=%2d Lock2=%2d E=%d G=%d", robot1_lock_zone, robot2_lock_zone, etching_zone, galvanizing_zone); image_insert_sprite(0, 2, tmp); collectBarrelsStatistic(); sprintf(tmp, "barrels=%2d time=%d max_time=%d", barrels_count, barrels_time, max_time); - image_insert_sprite(0, 25, tmp); + image_insert_sprite(0, 30, tmp); sprintf(tmp, "MODE: night=%d pause=%d", hla_night_mode, auto_mode_pause); image_insert_sprite(0, 70, tmp); @@ -272,8 +318,15 @@ static void open_socket() { } int main() { +#ifdef DEBUG_CORRECTION + robot1.mx.correct_sensor = false; + robot1.dx.current_zone = 5; + robot2.mx.correct_sensor = false; + robot2.dx.current_zone = 3; +#else robot1.mx.correct_sensor = true; robot2.mx.correct_sensor = true; +#endif open_socket(); @@ -291,7 +344,9 @@ int main() { } robot_main(); - scheduler_main(); +// scheduler_main(); + increment_zone(ROBOT_ZONE_GAL); + increment_zone(ROBOT_ZONE_ETCH); send_str("\033c"); showAll(); @@ -319,6 +374,10 @@ int main() { if (robot2_code.PC >= 0) debug_print_robot_code(&robot2_code, 2, sock_fd); +#ifdef DEBUG_CORRECTION + +#endif + send_str("cmd >> "); std::string in; while (true) { diff --git a/scheduler.c b/scheduler.c index 48316b3..544f3d5 100644 --- a/scheduler.c +++ b/scheduler.c @@ -126,28 +126,32 @@ void scheduler_main() // кнопка загрузки барабана if (button_load) { - if (!zone_is_busy(1)) { - for (int i = 0; i < BARRELS_COUNT; i++) { - if (!barrels[i].flags.is_exist) { - barrels[i].flags.raw_word = 1; // только is_exist - barrels[i].zone = 1; - barrels[i].software_timer = -1; - barrels[i].time_degreasing = hla_time_degreasing; - barrels[i].time_washing_1a = hla_time_washing_1a; - barrels[i].time_washing_1b = hla_time_washing_1b; - barrels[i].time_etching = hla_time_etching; - barrels[i].time_washing_2a = hla_time_washing_2a; - barrels[i].time_washing_2b = hla_time_washing_2b; - barrels[i].time_galvanizing = hla_time_galvanizing; - barrels[i].time_washing_3a = hla_time_washing_3a; - barrels[i].time_washing_3b = hla_time_washing_3b; - barrels[i].time_passivation = hla_time_passivation; - barrels[i].time_washing_4a = hla_time_washing_4a; - barrels[i].time_washing_4b = hla_time_washing_4b; - button_load = 0; - break; + if (!hla_night_mode) { + if (!zone_is_busy(1)) { + for (int i = 0; i < BARRELS_COUNT; i++) { + if (!barrels[i].flags.is_exist) { + barrels[i].flags.raw_word = 1; // только is_exist + barrels[i].zone = 1; + barrels[i].software_timer = -1; + barrels[i].time_degreasing = hla_time_degreasing; + barrels[i].time_washing_1a = hla_time_washing_1a; + barrels[i].time_washing_1b = hla_time_washing_1b; + barrels[i].time_etching = hla_time_etching; + barrels[i].time_washing_2a = hla_time_washing_2a; + barrels[i].time_washing_2b = hla_time_washing_2b; + barrels[i].time_galvanizing = hla_time_galvanizing; + barrels[i].time_washing_3a = hla_time_washing_3a; + barrels[i].time_washing_3b = hla_time_washing_3b; + barrels[i].time_passivation = hla_time_passivation; + barrels[i].time_washing_4a = hla_time_washing_4a; + barrels[i].time_washing_4b = hla_time_washing_4b; + button_load = 0; + break; + } } } + } else { + button_load = 0; } } @@ -217,51 +221,30 @@ void scheduler_main() // а вот для режима двух роботов все интересно // для каждого робота нужно получить свой список задач // и надо еще сделать так, чтобы роботы не столкнулись - char cmd_en = 0; - // добавляем ночной режим: в режиме двух роботов требуется чтобы во время ночного режима робот 2 стоял на парковке - if (hla_night_mode) { - if (!robot2.mx.correct_sensor) { - // уводим робота в парковку - if (robot2_code.PC < 0) { - robot2_code.barrel_id = -1; - robot2_code.code[0] = ROBOT_CMD_DOWN(); - robot2_code.code[1] = ROBOT_CMD_MOVE_TO_PARKING(); - robot2_code.code[2] = ROBOT_CMD_END(); - robot2_code.PC = 0; - } - } else { - cmd_en = 1; + // логика для того, чтобы роботы не столкнулись в начале + if (robot1.dx.current_zone < ZONE_GALVANIZING_1) { + // начальная позиция робота 1 - промывка 3Б + robot2_lock_zone = -1; + robot1_lock_zone = ZONE_WASHING_3B; + if (robot1_code.PC < 0) { + robot1_code.barrel_id = -1; + robot1_code.code[0] = ROBOT_CMD_DOWN(); + robot1_code.code[1] = ROBOT_CMD_MOVE_TO_ZONE(ZONE_WASHING_3B); + robot1_code.code[2] = ROBOT_CMD_END(); + robot1_code.PC = 0; + } + } else if (robot2.dx.current_zone < ZONE_DEGREASING) { + // начальная позиция робота 1 - обезжир + robot2_lock_zone = ZONE_WASHING_2A; + if (robot2_code.PC < 0) { + robot2_code.barrel_id = -1; + robot2_code.code[0] = ROBOT_CMD_DOWN(); + robot2_code.code[1] = ROBOT_CMD_MOVE_TO_ZONE(ZONE_DEGREASING); + robot2_code.code[2] = ROBOT_CMD_END(); + robot2_code.PC = 0; } } else { - // логика для того, чтобы роботы не столкнулись в начале - if (robot1.dx.current_zone < ZONE_GALVANIZING_1) { - // начальная позиция робота 1 - промывка 3Б - robot2_lock_zone = -1; - robot1_lock_zone = ZONE_WASHING_3B; - if (robot1_code.PC < 0) { - robot1_code.barrel_id = -1; - robot1_code.code[0] = ROBOT_CMD_DOWN(); - robot1_code.code[1] = ROBOT_CMD_MOVE_TO_ZONE(ZONE_WASHING_3B); - robot1_code.code[2] = ROBOT_CMD_END(); - robot1_code.PC = 0; - } - } else if (robot2.dx.current_zone < ZONE_DEGREASING) { - // начальная позиция робота 1 - обезжир - robot2_lock_zone = ZONE_WASHING_2A; - if (robot2_code.PC < 0) { - robot2_code.barrel_id = -1; - robot2_code.code[0] = ROBOT_CMD_DOWN(); - robot2_code.code[1] = ROBOT_CMD_MOVE_TO_ZONE(ZONE_DEGREASING); - robot2_code.code[2] = ROBOT_CMD_END(); - robot2_code.PC = 0; - } - } else { - cmd_en = 1; - } - } - - if (cmd_en) { // отдельно просчитаем все для первого робота if (robot1_code.PC < 0) { for (short i = 0; i < BARRELS_COUNT; i++) {