Рефакторинг планировщика, вспомогательная логика теперь вынесена в utils.c

This commit is contained in:
2022-12-14 16:16:06 +03:00
parent 6195891e57
commit 7e1cf33d1f
7 changed files with 610 additions and 583 deletions

View File

@@ -48,6 +48,9 @@ char hla_robot2_en = 0;
char _scheduler_en = 1;
short etching_zone = 0, galvanizing_zone = 0;
static const int ROWS = 10;
static const int COLS = 23 * 5 + 1;
static char buffer[ROWS][COLS];
@@ -196,10 +199,10 @@ static void open_socket() {
}
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(40000);
serv_addr.sin_port = htons(40090);
// 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, "192.168.0.160", &serv_addr.sin_addr) <= 0) {
printf("\nInvalid address/ Address not supported \n");
exit(-1);
}
@@ -210,23 +213,29 @@ static void open_socket() {
}
}
extern "C" struct barrel makeBarrel(short flags, short zone, short timer);
static struct barrel make_barrel(short flags, short zone, short timer) {
barrel b;
b.flags.raw_word = flags;
b.zone = zone;
b.software_timer = timer;
b.time_degreasing = hla_time_degreasing;
b.time_washing_1a = hla_time_washing_1a;
b.time_washing_1b = hla_time_washing_1b;
b.time_etching = hla_time_etching;
b.time_washing_2a = hla_time_washing_2a;
b.time_washing_2b = hla_time_washing_2b;
b.time_galvanizing = hla_time_galvanizing;
b.time_washing_3a = hla_time_washing_3a;
b.time_washing_3b = hla_time_washing_3b;
b.time_passivation = hla_time_passivation;
b.time_washing_4a = hla_time_washing_4a;
b.time_washing_4b = hla_time_washing_4b;
return b;
}
int main() {
open_socket();
// for (auto & b : barrels) {
// b.barrel_flags.is_exist = 1;
// b.software_timer = (short)(random() % 50);
// b.zone = (short) abs(random() % 20);
// }
// barrels[5] = makeBarrel(1, 21, 3);
// barrels[6] = makeBarrel(1, 5, -6);
// barrels[7] = makeBarrel(1, 6, -7);
//
// barrels[8] = makeBarrel(1, 10, -8);
current_tic = 0;
const char* message = nullptr;
while (true) {
@@ -239,7 +248,6 @@ int main() {
std::cout << message << std::endl;
send_str(message);
send_str("\n");
message = nullptr;
}
send_str("cmd >> ");