Исправлена ошибка линковки из-за hla-pause, добавлено переключение паузы и ночного режима. добавлена трассировка кода роботов на "панель"
This commit is contained in:
parent
ec7f508931
commit
bbc73b4e31
49
emulator.cpp
49
emulator.cpp
@ -5,6 +5,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
#include "emulator.h"
|
#include "emulator.h"
|
||||||
#include "robot.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_en = 1;
|
||||||
char scheduler_start_signal = 1;
|
char scheduler_start_signal = 1;
|
||||||
char auto_mode_pause = 0;
|
char auto_mode_pause = 0;
|
||||||
|
char hla_night_mode = 0;
|
||||||
|
|
||||||
|
|
||||||
short etching_zone = 0, galvanizing_zone = 0;
|
short etching_zone = 0, galvanizing_zone = 0;
|
||||||
@ -154,7 +156,7 @@ static void showAll() {
|
|||||||
image_init();
|
image_init();
|
||||||
image_draw_borders();
|
image_draw_borders();
|
||||||
char tmp[64];
|
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);
|
image_insert_sprite(0, 2, tmp);
|
||||||
|
|
||||||
int barrels_count = 0, barrels_time = 0;
|
int barrels_count = 0, barrels_time = 0;
|
||||||
@ -176,9 +178,12 @@ static void showAll() {
|
|||||||
max_time = barrels_time;
|
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);
|
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++) {
|
for (int i = 0; i < BARRELS_COUNT; i++) {
|
||||||
const auto& b = barrels[i];
|
const auto& b = barrels[i];
|
||||||
@ -220,16 +225,23 @@ static void open_socket() {
|
|||||||
|
|
||||||
sock_fd = socket(AF_INET, SOCK_STREAM, 0);
|
sock_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (sock_fd < 0) {
|
if (sock_fd < 0) {
|
||||||
printf("\n Socket creation error \n");
|
printf("Socket creation error\n");
|
||||||
exit(-1);
|
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_family = AF_INET;
|
||||||
serv_addr.sin_port = htons(40000);
|
serv_addr.sin_port = htons(40000);
|
||||||
|
|
||||||
// Convert IPv4 and IPv6 addresses from text to binary form
|
// Convert IPv4 and IPv6 addresses from text to binary form
|
||||||
if (inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr) <= 0) {
|
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);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,6 +252,9 @@ static void open_socket() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
robot1.mx.correct_sensor = true;
|
||||||
|
robot2.mx.correct_sensor = true;
|
||||||
|
|
||||||
open_socket();
|
open_socket();
|
||||||
|
|
||||||
current_tic = 0;
|
current_tic = 0;
|
||||||
@ -253,12 +268,31 @@ int main() {
|
|||||||
scheduler_main();
|
scheduler_main();
|
||||||
send_str("\033c");
|
send_str("\033c");
|
||||||
showAll();
|
showAll();
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
std::cout << message << std::endl;
|
std::cout << message << std::endl;
|
||||||
send_str(message);
|
send_str(message);
|
||||||
send_str("\n");
|
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 >> ");
|
send_str("cmd >> ");
|
||||||
std::string in;
|
std::string in;
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -292,6 +326,12 @@ int main() {
|
|||||||
} else if (in == "2") {
|
} else if (in == "2") {
|
||||||
button_load = 1;
|
button_load = 1;
|
||||||
message = "Нажата кнопка загрузки 2";
|
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 {
|
} else {
|
||||||
message = "Неизвестная команда. q - выход, u - выгрузка, 1 - загрузка 1, 2 - загрузка 2";
|
message = "Неизвестная команда. q - выход, u - выгрузка, 1 - загрузка 1, 2 - загрузка 2";
|
||||||
}
|
}
|
||||||
@ -299,6 +339,7 @@ int main() {
|
|||||||
current_tic++;
|
current_tic++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fsync(sock_fd);
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -20,7 +20,6 @@ void scheduler_main();
|
|||||||
// Кнопки с панели
|
// Кнопки с панели
|
||||||
extern char hla_auto_mode;
|
extern char hla_auto_mode;
|
||||||
extern char hla_night_mode;
|
extern char hla_night_mode;
|
||||||
extern char hla_pause;
|
|
||||||
extern char hla_correct_command;
|
extern char hla_correct_command;
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ void schedule_one_robot(const struct scheduler_task* tasks, const struct robot_r
|
|||||||
r->dx.current_zone, robot_id);
|
r->dx.current_zone, robot_id);
|
||||||
|
|
||||||
#ifdef EMULATOR
|
#ifdef EMULATOR
|
||||||
debug_print_robot_code(code, robot_id);
|
debug_print_robot_code(code, robot_id, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
44
utils.c
44
utils.c
@ -285,75 +285,79 @@ char remove_barrel_from_zone(short zone) {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef EMULATOR
|
#ifdef EMULATOR
|
||||||
void debug_print_robot_code(const struct robot_code* code, const short robot_id) {
|
void debug_print_robot_code(const struct robot_code *code, const short robot_id, int fd) {
|
||||||
// printf("INFO: code length is %d\n", cmd_index);
|
// dprintf(fd, "INFO: code length is %d\n", cmd_index);
|
||||||
printf("Code for R%d, B%d:\n", robot_id, code->barrel_id);
|
dprintf(fd, "Code for R%d, B%d:\n", robot_id, code->barrel_id);
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
const short cmd_arg = (short)(code->code[i] & (short)(~ROBOT_CMD_MASK));
|
const short cmd_arg = (short)(code->code[i] & (short)(~ROBOT_CMD_MASK));
|
||||||
|
|
||||||
printf("%5d 0x%04X", i, code->code[i] & 0xFFFF);
|
if (code->PC == i) {
|
||||||
|
dprintf(fd, "==>%2d 0x%04X", i, code->code[i] & 0xFFFF);
|
||||||
|
} else {
|
||||||
|
dprintf(fd, " %2d 0x%04X", i, code->code[i] & 0xFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
if ((code->code[i] & ROBOT_CMD_MASK) == ROBOT_CMD_END_code) {
|
if ((code->code[i] & ROBOT_CMD_MASK) == ROBOT_CMD_END_code) {
|
||||||
printf(" END\n");
|
dprintf(fd, " END\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ((short)(code->code[i] & (short)ROBOT_CMD_MASK)) {
|
switch ((short)(code->code[i] & (short)ROBOT_CMD_MASK)) {
|
||||||
case ROBOT_CMD_MOVE_TO_ZONE_code:
|
case ROBOT_CMD_MOVE_TO_ZONE_code:
|
||||||
printf(" move to zone %d (with barrel: %d)\n", cmd_arg & (~ROBOT_WITH_BARREL), (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
dprintf(fd, " move to zone %d (with barrel: %d)\n", cmd_arg & (~ROBOT_WITH_BARREL), (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROBOT_CMD_MOVE_OFF_code:
|
case ROBOT_CMD_MOVE_OFF_code:
|
||||||
printf(" move to offset pos\n");
|
dprintf(fd, " move to offset pos\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROBOT_CMD_MOVE_ACCURATE_code:
|
case ROBOT_CMD_MOVE_ACCURATE_code:
|
||||||
printf(" move to accurate pos\n");
|
dprintf(fd, " move to accurate pos\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROBOT_CMD_UP_code:
|
case ROBOT_CMD_UP_code:
|
||||||
printf(" up (with barrel: %d)\n", (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
dprintf(fd, " up (with barrel: %d)\n", (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// в эмуляторе не важно где я, поэтому тут обе команды вниз обрабатываются одинаково
|
// в эмуляторе не важно где я, поэтому тут обе команды вниз обрабатываются одинаково
|
||||||
case ROBOT_CMD_DOWN_code:
|
case ROBOT_CMD_DOWN_code:
|
||||||
printf(" down (with barrel: %d)\n", (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
dprintf(fd, " down (with barrel: %d)\n", (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROBOT_CMD_WAIT_code:
|
case ROBOT_CMD_WAIT_code:
|
||||||
printf(" wait %d secs\n", cmd_arg);
|
dprintf(fd, " wait %d secs\n", cmd_arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROBOT_CMD_TMR_SET_code:
|
case ROBOT_CMD_TMR_SET_code:
|
||||||
printf(" set barrel timer %d secs\n", cmd_arg);
|
dprintf(fd, " set barrel timer %d secs\n", cmd_arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROBOT_CMD_SET_LOCK_ZONE_code:
|
case ROBOT_CMD_SET_LOCK_ZONE_code:
|
||||||
printf(" set lock zone %d\n", cmd_arg);
|
dprintf(fd, " set lock zone %d\n", cmd_arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROBOT_CMD_CORRECT_AXIS_code:
|
case ROBOT_CMD_CORRECT_AXIS_code:
|
||||||
if (cmd_arg == ROBOT_AXIS_X) {
|
if (cmd_arg == ROBOT_AXIS_X) {
|
||||||
printf(" correct axis: X\n");
|
dprintf(fd, " correct axis: X\n");
|
||||||
} else if (cmd_arg == ROBOT_AXIS_Z) {
|
} else if (cmd_arg == ROBOT_AXIS_Z) {
|
||||||
printf(" correct axis: Z\n");
|
dprintf(fd, " correct axis: Z\n");
|
||||||
} else {
|
} else {
|
||||||
printf(" correct axis: INVALID (%d)\n", cmd_arg);
|
dprintf(fd, " correct axis: INVALID (%d)\n", cmd_arg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROBOT_CMD_INC_ZONE_code:
|
case ROBOT_CMD_INC_ZONE_code:
|
||||||
if (cmd_arg == ROBOT_ZONE_GAL) {
|
if (cmd_arg == ROBOT_ZONE_GAL) {
|
||||||
printf(" increment zone: galvanic\n");
|
dprintf(fd, " increment zone: galvanic\n");
|
||||||
} else if (cmd_arg == ROBOT_ZONE_ETCH) {
|
} else if (cmd_arg == ROBOT_ZONE_ETCH) {
|
||||||
printf(" increment zone: etching\n");
|
dprintf(fd, " increment zone: etching\n");
|
||||||
} else {
|
} else {
|
||||||
printf(" increment zone: INVALID (0x%4X)\n", cmd_arg);
|
dprintf(fd, " increment zone: INVALID (0x%4X)\n", cmd_arg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf(" UNKNOWN: 0x%04X\n", code->code[i] & 0xFFFF);
|
dprintf(fd, " UNKNOWN: 0x%04X\n", code->code[i] & 0xFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
utils.h
2
utils.h
@ -347,7 +347,7 @@ void create_operation(struct robot_code *code, const short barrel_id, const shor
|
|||||||
const short current_zone, const short robot_id);
|
const short current_zone, const short robot_id);
|
||||||
|
|
||||||
#ifdef EMULATOR
|
#ifdef EMULATOR
|
||||||
void debug_print_robot_code(const struct robot_code* code, const short robot_id);
|
void debug_print_robot_code(const struct robot_code *code, const short robot_id, int fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Reference in New Issue
Block a user