v1.1 reprint button

main
Evgeniy Mashtarо́v 2025-07-29 13:19:47 +07:00
parent 1ee9c67179
commit 48cfcbeae9
14 changed files with 638 additions and 619 deletions

View File

@ -11,4 +11,4 @@
#define PIN_Speaker 26
#define SerialDevice "/dev/ttyUSB0"
#define API_URL "http://192.168.122.120:3000/api/"
#define API_URL "http://192.168.122.161:8000/api/"

View File

@ -1,5 +1,5 @@
#include "../Inc/Godex500.h"
const int OFFSET = 131;
const int OFFSET = 0;
int GODEX500_setup_serial(const char* device) {
int serial_port = open(device, O_RDWR);
if (serial_port < 0) {
@ -49,7 +49,8 @@ void GODEX500_print_label(int serial_port, const char* id, const char* model) {
snprintf(buffer, sizeof(buffer),
"^Q10,2\n"
"^W25^H14\n"
"^W25\n"
"^H14\n"
"^P1\n"
"^S2\n"
"^AT\n"

View File

@ -118,6 +118,13 @@ void set_etalonSensor_data(){
log_trace("Обновлены данные эталонного датчика: Давление = %u", etalonSensor.pressure);
}
char* lastModelName = "";
void reprintSticker(){
if(testSensor.id_sensor > 0){
GODEX500_print_label(serial_port, NumToHexString(testSensor.id_sensor), lastModelName);
}
}
void* stend_logic() {
log_set_level(LOG_DEBUG);
@ -349,28 +356,33 @@ void* stend_logic() {
case ACTION_PRINT_RESULTS:
log_trace("Состояние: ACTION_PRINT_RESULTS");
static uint8_t* id_sensor_str;
uint8_t error_code = *(uint8_t*)&error_data;
memset(&jsonDataBuffer, 0, sizeof(jsonDataBuffer));
CURL_GET_Request(concat_strings(API_URL, concat_strings("get-serial-data/", NumToHexString(testSensor.id_sensor))), &jsonDataBuffer);
cJSON *json = cJSON_Parse(jsonDataBuffer);
log_debug("result: %s", jsonDataBuffer);
cJSON *dataJSON = cJSON_GetObject(json, "data");
log_debug("Model id: %s\n", cJSON_GetObject(dataJSON, "model_id")->valuestring);
id_sensor_str = cJSON_GetObject(dataJSON, "serial_num")->valuestring;
cJSON *json;
static char* id_sensor_str;
id_sensor_str = NumToHexString(testSensor.id_sensor);
log_info("%s", id_sensor_str);
uint8_t error_code = *(uint8_t*)&error_data;
log_info("Код ошибки: %u", error_code);
uint32_t device_id;
if (error_code == 0) {
log_info("Тест пройден, датчик соответствует спецификациям");
char url[256];
snprintf(url, sizeof(url), "%sdevice_model/%d/device_serial_number/", API_URL, testSensor.id_sensor);
memset(&jsonDataBuffer, 0, sizeof(jsonDataBuffer));
CURL_GET_Request(concat_strings(API_URL, concat_strings("get-data/device_model/", cJSON_GetObject(dataJSON, "model_id")->valuestring)), &jsonDataBuffer);
CURL_GET_Request((uint8_t *)url, &jsonDataBuffer);
json = cJSON_Parse(jsonDataBuffer);
dataJSON = cJSON_GetObject(json, "data");
log_debug("Model name: %s\n", cJSON_GetObject(dataJSON, "name")->valuestring);
log_debug("Model name: %s\n", cJSON_GetObject(json, "name")->valuestring);
lastModelName = cJSON_GetObject(json, "name")->valuestring;
GODEX500_print_label(serial_port, NumToHexString(testSensor.id_sensor), lastModelName);
snprintf(url, sizeof(url), "%sdevice/%d/serial_number/", API_URL, testSensor.id_sensor);
memset(&jsonDataBuffer, 0, sizeof(jsonDataBuffer));
CURL_GET_Request((uint8_t *)url, &jsonDataBuffer);
json = cJSON_Parse(jsonDataBuffer);
device_id = cJSON_GetObject(json, "id")->valueint;
GODEX500_print_label(serial_port, NumToHexString(testSensor.id_sensor), cJSON_GetObject(dataJSON, "name")->valuestring);
Set_Color_ButtonMain_green();
} else {
log_error("Тест не пройден, датчик не прошёл все проверки");
@ -380,9 +392,11 @@ void* stend_logic() {
Update_Error_Table(error_code);
}
get_current_time(datetime);
char url[256];
snprintf(url, sizeof(url), "%sinsert-log/", API_URL);
snprintf(post_data, sizeof(post_data),
"{\"device_serial_num\": \"%s\", \"type\": \"calibrate\", \"date\": \"%s\", \"json_data\": {\"code\": %d}}", id_sensor_str, datetime, error_code);
CURL_POST_Request(concat_strings(API_URL, "insert-data/log"), (uint8_t *)post_data);
"{\"device_id\": \"%d\", \"type\": \"calibrate\", \"date\": \"%s\", \"data\": {\"code\": %d}}", device_id, datetime, error_code);
CURL_POST_Request(url, (uint8_t *)post_data);
current_action = ACTION_WAIT_SENSOR_RELEASE;
break;

View File

@ -1,2 +1,3 @@
void _ResetPressure();
void _CloseSerial();
void _ReprintSticker();

View File

@ -7,4 +7,7 @@ void _ResetPressure(){
void _CloseSerial(){
close_Serial();
}
void _ReprintSticker(){
reprintSticker();
}

View File

@ -1,11 +1,11 @@
#include "../Inc/button_handlers.h"
#include "../../controllers/Inc/stend_controller.h"
// Функция для изменения цвета кнопки и отключения её
void ButtonMain_Handler(GtkButton *button) {
set_button_color_white(button);
}
void ButtonReprint_Handler(GtkButton *button){
g_print("Button Reprint Pressed\n");
_ReprintSticker();
}