Init
This commit is contained in:
parent
2d32752feb
commit
b7ea3b3113
21
APP/blf.c
21
APP/blf.c
|
|
@ -150,9 +150,14 @@ static void systemtime_add_ms(SYSTEMTIME *st, uint64_t ms) {
|
||||||
* Реализация API-функций
|
* Реализация API-функций
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int blf_open(BLFContext *ctx, const char *filename) {
|
int blf_open(BLFContext *ctx, const char *filename, const SYSTEMTIME *startTime) {
|
||||||
memset(ctx, 0, sizeof(*ctx));
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
|
|
||||||
|
if (startTime == NULL) {
|
||||||
|
BLF_ERROR_PRINTF("ERROR: startTime must not be NULL\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (blf_file_open(ctx, filename) != 0) {
|
if (blf_file_open(ctx, filename) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -171,17 +176,11 @@ int blf_open(BLFContext *ctx, const char *filename) {
|
||||||
ctx->header.objectCount = 0;
|
ctx->header.objectCount = 0;
|
||||||
ctx->header.restorePointsOffset = 0;
|
ctx->header.restorePointsOffset = 0;
|
||||||
|
|
||||||
/* Время начала измерения */
|
/* Копируем переданное время начала */
|
||||||
ctx->header.measurementStartTime.year = 2026;
|
ctx->header.measurementStartTime = *startTime;
|
||||||
ctx->header.measurementStartTime.month = 3;
|
|
||||||
ctx->header.measurementStartTime.dayOfWeek = 3;
|
|
||||||
ctx->header.measurementStartTime.day = 18;
|
|
||||||
ctx->header.measurementStartTime.hour = 12;
|
|
||||||
ctx->header.measurementStartTime.minute = 0;
|
|
||||||
ctx->header.measurementStartTime.second = 0;
|
|
||||||
ctx->header.measurementStartTime.milliseconds = 0;
|
|
||||||
|
|
||||||
memset(&ctx->header.lastObjectTime, 0, sizeof(SYSTEMTIME));
|
/* Инициализируем lastObjectTime тем же временем (будет скорректировано при закрытии) */
|
||||||
|
ctx->header.lastObjectTime = *startTime;
|
||||||
|
|
||||||
/* Запись заголовка в начало файла */
|
/* Запись заголовка в начало файла */
|
||||||
ctx->headerPos = blf_file_tell(ctx);
|
ctx->headerPos = blf_file_tell(ctx);
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,7 @@ typedef struct {
|
||||||
* @param filename Имя файла.
|
* @param filename Имя файла.
|
||||||
* @return 0 при успехе, -1 при ошибке.
|
* @return 0 при успехе, -1 при ошибке.
|
||||||
*/
|
*/
|
||||||
int blf_open(BLFContext *ctx, const char *filename);
|
int blf_open(BLFContext *ctx, const char *filename, const SYSTEMTIME *startTime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Начинает новый контейнер (объект типа LOG_CONTAINER).
|
* @brief Начинает новый контейнер (объект типа LOG_CONTAINER).
|
||||||
|
|
|
||||||
88
APP/main.c
88
APP/main.c
|
|
@ -25,28 +25,39 @@ typedef struct {
|
||||||
} AdcSample;
|
} AdcSample;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
BLFContext ctx; /* контекст на стеке – без malloc */
|
BLFContext ctx;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* 1. Открываем файл (создаём новый) */
|
// Задаём время начала измерения (1 января 2025 года, 00:00:00.000)
|
||||||
ret = blf_open(&ctx, "log.blf");
|
SYSTEMTIME startTime = {
|
||||||
|
.year = 2025,
|
||||||
|
.month = 1,
|
||||||
|
.dayOfWeek = 3, // не критично
|
||||||
|
.day = 1,
|
||||||
|
.hour = 0,
|
||||||
|
.minute = 0,
|
||||||
|
.second = 0,
|
||||||
|
.milliseconds = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
ret = blf_open(&ctx, "log.blf", &startTime);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
BLF_ERROR_PRINTF("Failed to open file, exiting.\n");
|
BLF_ERROR_PRINTF("Failed to open file, exiting.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 2. Начинаем контейнер с временной меткой 1 секунда (1e9 нс) */
|
// 2. Начинаем контейнер с временной меткой 0 секунда (1e9 нс)
|
||||||
if (blf_start_container(&ctx, 1000000000ULL) != 0) {
|
if (blf_start_container(&ctx, 0000000000ULL) != 0) {
|
||||||
BLF_ERROR_PRINTF("Failed to start container\n");
|
BLF_ERROR_PRINTF("Failed to start container\n");
|
||||||
blf_close(&ctx);
|
blf_close(&ctx);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 3. Добавляем CAN-сообщение */
|
// 3. Добавляем CAN-сообщение
|
||||||
CanMessageStruct canMsg = {
|
CanMessageStruct canMsg = {
|
||||||
.channel = 2,
|
.channel = 1,
|
||||||
.id = 0x789,
|
.id = 0x538,
|
||||||
.flags = CAN_MSG_FLAGS(CAN_DIR_TX, 0),
|
.flags = CAN_MSG_FLAGS(CAN_DIR_RX, 0),
|
||||||
.dlc = 8,
|
.dlc = 8,
|
||||||
.data = {0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22},
|
.data = {0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22},
|
||||||
.timestamp = 9000 /* 9 секунд (миллисекунды) */
|
.timestamp = 9000 /* 9 секунд (миллисекунды) */
|
||||||
|
|
@ -57,7 +68,55 @@ int main() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 4. Добавляем LIN-сообщение */
|
CanMessageStruct canMsg2 = {
|
||||||
|
.channel = 1,
|
||||||
|
.id = 0x538,
|
||||||
|
.flags = CAN_MSG_FLAGS(CAN_DIR_RX, 0),
|
||||||
|
.dlc = 8,
|
||||||
|
.data = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88},
|
||||||
|
.timestamp = 10000 /* 10 секунд (миллисекунды) */
|
||||||
|
};
|
||||||
|
|
||||||
|
if (blf_add_can_message_struct(&ctx, &canMsg2) != 0) {
|
||||||
|
BLF_ERROR_PRINTF("Failed to add CAN message\n");
|
||||||
|
blf_close(&ctx);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CanMessageStruct canMsg3 = {
|
||||||
|
.channel = 1,
|
||||||
|
.id = 0x538,
|
||||||
|
.flags = CAN_MSG_FLAGS(CAN_DIR_RX, 0),
|
||||||
|
.dlc = 8,
|
||||||
|
.data = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88},
|
||||||
|
.timestamp = 11000 /* 11 секунд (миллисекунды) */
|
||||||
|
};
|
||||||
|
|
||||||
|
if (blf_add_can_message_struct(&ctx, &canMsg3) != 0) {
|
||||||
|
BLF_ERROR_PRINTF("Failed to add CAN message\n");
|
||||||
|
blf_close(&ctx);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CanMessageStruct canMsg4 = {
|
||||||
|
.channel = 1,
|
||||||
|
.id = 0x538,
|
||||||
|
.flags = CAN_MSG_FLAGS(CAN_DIR_RX, 0),
|
||||||
|
.dlc = 8,
|
||||||
|
.data = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88},
|
||||||
|
.timestamp = 12000 /* 12 секунд (миллисекунды) */
|
||||||
|
};
|
||||||
|
|
||||||
|
if (blf_add_can_message_struct(&ctx, &canMsg4) != 0) {
|
||||||
|
BLF_ERROR_PRINTF("Failed to add CAN message\n");
|
||||||
|
blf_close(&ctx);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// 4. Добавляем LIN-сообщение
|
||||||
LinMessageStruct linMsg = {
|
LinMessageStruct linMsg = {
|
||||||
.channel = 1,
|
.channel = 1,
|
||||||
.id = 0x45,
|
.id = 0x45,
|
||||||
|
|
@ -73,7 +132,7 @@ int main() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 5. Добавляем LIN-ошибку отсутствия ответа */
|
// 5. Добавляем LIN-ошибку отсутствия ответа
|
||||||
LinSendErrorStruct sendErr = {
|
LinSendErrorStruct sendErr = {
|
||||||
.channel = 1,
|
.channel = 1,
|
||||||
.id = 0x12,
|
.id = 0x12,
|
||||||
|
|
@ -86,7 +145,7 @@ int main() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 6. Добавляем данные окружения (АЦП) */
|
// 6. Добавляем данные окружения (АЦП)
|
||||||
AdcSample samples;
|
AdcSample samples;
|
||||||
samples.channel1 = (uint16_t) (1);
|
samples.channel1 = (uint16_t) (1);
|
||||||
samples.channel2 = (uint16_t) (2);
|
samples.channel2 = (uint16_t) (2);
|
||||||
|
|
@ -105,15 +164,16 @@ int main() {
|
||||||
blf_close(&ctx);
|
blf_close(&ctx);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/* 7. Завершаем контейнер */
|
// 7. Завершаем контейнер
|
||||||
if (blf_end_container(&ctx) != 0) {
|
if (blf_end_container(&ctx) != 0) {
|
||||||
BLF_ERROR_PRINTF("Failed to end container\n");
|
BLF_ERROR_PRINTF("Failed to end container\n");
|
||||||
blf_close(&ctx);
|
blf_close(&ctx);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 8. Закрываем файл (заголовок обновляется автоматически) */
|
// 8. Закрываем файл (заголовок обновляется автоматически)
|
||||||
ret = blf_close(&ctx);
|
ret = blf_close(&ctx);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
BLF_ERROR_PRINTF("Failed to close file\n");
|
BLF_ERROR_PRINTF("Failed to close file\n");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue