Исправлена ошибка линковки из-за hla-pause, добавлено переключение паузы и ночного режима. добавлена трассировка кода роботов на "панель"
This commit is contained in:
51
emulator.cpp
51
emulator.cpp
@@ -5,6 +5,7 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <libc.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include "emulator.h"
|
||||
#include "robot.h"
|
||||
|
||||
@@ -48,6 +49,7 @@ char one_robot_mode = (char)(hla_robot1_en ^ hla_robot2_en);
|
||||
char scheduler_en = 1;
|
||||
char scheduler_start_signal = 1;
|
||||
char auto_mode_pause = 0;
|
||||
char hla_night_mode = 0;
|
||||
|
||||
|
||||
short etching_zone = 0, galvanizing_zone = 0;
|
||||
@@ -154,7 +156,7 @@ static void showAll() {
|
||||
image_init();
|
||||
image_draw_borders();
|
||||
char tmp[64];
|
||||
sprintf(tmp, "Lock1=%02d Lock2=%02d", robot1_lock_zone, robot2_lock_zone);
|
||||
sprintf(tmp, "Lock1=%2d Lock2=%2d", robot1_lock_zone, robot2_lock_zone);
|
||||
image_insert_sprite(0, 2, tmp);
|
||||
|
||||
int barrels_count = 0, barrels_time = 0;
|
||||
@@ -176,9 +178,12 @@ static void showAll() {
|
||||
max_time = barrels_time;
|
||||
}
|
||||
|
||||
sprintf(tmp, "barrels=%02d time=%04d max_time=%04d", barrels_count, barrels_time, max_time);
|
||||
sprintf(tmp, "barrels=%2d time=%d max_time=%d", barrels_count, barrels_time, max_time);
|
||||
image_insert_sprite(0, 25, tmp);
|
||||
|
||||
sprintf(tmp, "MODE: night=%d pause=%d", hla_night_mode, auto_mode_pause);
|
||||
image_insert_sprite(0, 70, tmp);
|
||||
|
||||
// рисование бочек
|
||||
for (int i = 0; i < BARRELS_COUNT; i++) {
|
||||
const auto& b = barrels[i];
|
||||
@@ -220,26 +225,36 @@ static void open_socket() {
|
||||
|
||||
sock_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock_fd < 0) {
|
||||
printf("\n Socket creation error \n");
|
||||
printf("Socket creation error\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// setting socket options
|
||||
int flag = 1;
|
||||
|
||||
if(setsockopt(sock_fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)) == -1){
|
||||
printf("setsockopt TCP_NODELAY failed for server socket on address 127.0.0.1\n");
|
||||
}
|
||||
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_port = htons(40000);
|
||||
|
||||
// Convert IPv4 and IPv6 addresses from text to binary form
|
||||
if (inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr) <= 0) {
|
||||
printf("\nInvalid address/ Address not supported \n");
|
||||
printf("Invalid address/ Address not supported\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (connect(sock_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
|
||||
printf("Connection Failed \n");
|
||||
printf("Connection Failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
robot1.mx.correct_sensor = true;
|
||||
robot2.mx.correct_sensor = true;
|
||||
|
||||
open_socket();
|
||||
|
||||
current_tic = 0;
|
||||
@@ -253,12 +268,31 @@ int main() {
|
||||
scheduler_main();
|
||||
send_str("\033c");
|
||||
showAll();
|
||||
|
||||
if (message) {
|
||||
std::cout << message << std::endl;
|
||||
send_str(message);
|
||||
send_str("\n");
|
||||
}
|
||||
|
||||
if (!one_robot_mode) {
|
||||
if (!robot2.mx.correct_sensor) {
|
||||
if (robot2.dx.current_zone + 1 >= robot1.dx.current_zone) {
|
||||
printf("ASSERTION FAILED: FOUND ROBOTS CORRUPTION\n");
|
||||
if (robot1_code.PC >= 0)
|
||||
debug_print_robot_code(&robot1_code, 1, 0);
|
||||
if (robot2_code.PC >= 0)
|
||||
debug_print_robot_code(&robot2_code, 2, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (robot1_code.PC >= 0)
|
||||
debug_print_robot_code(&robot1_code, 1, sock_fd);
|
||||
if (robot2_code.PC >= 0)
|
||||
debug_print_robot_code(&robot2_code, 2, sock_fd);
|
||||
|
||||
send_str("cmd >> ");
|
||||
std::string in;
|
||||
while (true) {
|
||||
@@ -292,6 +326,12 @@ int main() {
|
||||
} else if (in == "2") {
|
||||
button_load = 1;
|
||||
message = "Нажата кнопка загрузки 2";
|
||||
} else if (in == "n") {
|
||||
hla_night_mode = !hla_night_mode;
|
||||
message = "Переключен ночной режим";
|
||||
} else if (in == "p") {
|
||||
auto_mode_pause = !auto_mode_pause;
|
||||
message = "Переключен режим паузы";
|
||||
} else {
|
||||
message = "Неизвестная команда. q - выход, u - выгрузка, 1 - загрузка 1, 2 - загрузка 2";
|
||||
}
|
||||
@@ -299,6 +339,7 @@ int main() {
|
||||
current_tic++;
|
||||
}
|
||||
|
||||
fsync(sock_fd);
|
||||
close(sock_fd);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user