This commit is contained in:
cfif 2025-05-26 14:41:45 +03:00
commit 74048a481a
3 changed files with 770 additions and 0 deletions

109
Inc/json_func.h Normal file
View File

@ -0,0 +1,109 @@
//
// Created by cfif on 04.10.2022.
//
#ifndef JSONFUNC_H
#define JSONFUNC_H
#include "tiny-json.h"
#include "mtojson.h"
#include "ModemMain.h"
// Ответ статуса обновления WEB
size_t json_generate_webup_answer(char *buf, size_t len_buf, uint32_t webup);
// Ответ stat
size_t json_generate_stat_answer(char *buf, size_t len_buf, uint32_t NumFileOutBox, uint32_t NumFileInbox,
uint32_t CntMsgsOutBox, uint32_t stn1, uint32_t stn2, uint32_t stn3);
// Ответ с событием
size_t json_generate_event(char *buf, size_t len_buf, tEventWebState *eventWebState, uint32_t timestampWriteLog, uint32_t timestampWriteLog2);
// Ответ спутника ЗВР
size_t json_generate_getalma(char *buf, size_t len_buf, uint32_t sec, uint32_t number);
size_t json_generate_answer_get_ex_elem_fs(char *buf, size_t len_buf, uint32_t err, uint32_t count, const char *dir);
// Ответ состояния кнопок
size_t json_generate_state_answer(char *buf, size_t len_buf, uint32_t alma);
// Ответ с состоянием альманаха
size_t json_generate_alma_state_answer(char *buf, size_t len_buf, uint32_t state);
// Ответ с ошибкой
size_t json_generate_err_answer(char *buf, size_t len_buf, uint32_t err);
// Ответ с ошибкой и id
size_t
json_generate_err_id_end_myid_answer(char *buf, size_t len_buf, uint32_t err, uint32_t id, uint32_t end, uint32_t myid);
size_t json_generate_err_id_end_answer(char *buf, size_t len_buf, uint32_t err, uint32_t id, uint32_t end);
// Формирование элемента структуры файловой системы
size_t
json_generate_get_elem_fs(char *buf, size_t len_buf, const char *nam, uint8_t tpf, uint32_t fsz, const char *fdt);
// Ответ квитанция
size_t json_generate_answer_get_elem_fs(char *buf, size_t len_buf, uint32_t err, const char *dir);
// Ответ квитанция
size_t
json_generate_answer_get_elem_file_fs(char *buf, size_t len_buf, uint32_t err, const char *file_name, uint32_t pos,
uint32_t len);
// Текущий уровень аторизации
size_t json_generate_auth_send_answer(char *buf, size_t len_buf, uint32_t auth);
// Ответ timestamp
size_t json_generate_timestamp_answer(char *buf, size_t len_buf, uint32_t timestamp_gnss, uint32_t timestamp_block,
uint32_t timestamp_work);
// Ответ координат
size_t json_generate_coordinates_answer(char *buf, size_t len_buf, uint32_t valid, float latitude, float longitude,
uint32_t routing, uint32_t angle, uint32_t timeZoneInSat);
// Ответ vars
size_t json_generate_vars_send_answer(char *buf, size_t len_buf, uint32_t at, const char *username, uint32_t diskall, uint32_t diskfree);
// Ответ АДЦ
size_t json_generate_adc_answer(char *buf, size_t len_buf, uint32_t vcc);
// Ответ rssi
size_t json_generate_rssi_answer(char *buf, size_t len_buf, int32_t rssi);
// Ответ версии
size_t json_generate_version_answer(char *buf, size_t len_buf, char *versionModem, char *versionCrypto);
// Ответ с размером файла
size_t json_generate_fileinfo_answer(char *buf, size_t len_buf, uint32_t size);
// Ответ процент передачи
//size_t json_generate_proc_send_answer(char *buf, size_t len_buf, tFileSendInfoForJson *fileSendInfo);
size_t json_generate_get_data(char *buf, size_t len_buf,
uint32_t timestamp_gnss,
uint32_t timestamp_block,
uint32_t timestamp_rtc,
uint32_t timestamp_work,
uint32_t vcc,
int32_t temp,
int32_t *rssi,
uint32_t tracert,
uint32_t valid,
float latitude,
float longitude,
tEventWebState *eventWebState,
uint32_t timestampWriteLog,
uint32_t timestampWriteLog2
);
#endif //JSONFUNC_H

643
Src/json_func.c Normal file
View File

@ -0,0 +1,643 @@
//
// Created by cfif on 04.10.2022.
//
#include "json_func.h"
#include "time.h"
#include "string.h"
#include "FirmwareMetadataSection.h"
// Ответ с размером файла
size_t json_generate_fileinfo_answer(char *buf, size_t len_buf, uint32_t size) {
struct to_json jsonResponse_Post[] = {
{.name = "size", .value = &size, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ с событием
size_t json_generate_event(char *buf, size_t len_buf, tEventWebState *eventWebState, uint32_t timestampWriteLog,
uint32_t timestampWriteLog2) {
struct to_json jsonResponse_Post[] = {
{.name = "outbox", .value = &eventWebState->EVENT_OUTBOX, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "sentbox", .value = &eventWebState->EVENT_SENTBOX, .vtype = t_to_uint32_t},
{.name = "inbox", .value = &eventWebState->EVENT_INBOX, .vtype = t_to_uint32_t},
{.name = "alma", .value = &eventWebState->EVENT_ALMA, .vtype = t_to_uint32_t},
{.name = "log", .value = &timestampWriteLog, .vtype = t_to_uint32_t},
{.name = "log2", .value = &timestampWriteLog2, .vtype = t_to_uint32_t},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ состояния кнопок
size_t json_generate_state_answer(char *buf, size_t len_buf, uint32_t alma) {
struct to_json jsonResponse_Post[] = {
{.name = "alma", .value = &alma, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ с состоянием альманаха
size_t json_generate_alma_state_answer(char *buf, size_t len_buf, uint32_t state) {
struct to_json jsonResponse_Post[] = {
{.name = "almastate", .value = &state, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ спутника ЗВР
size_t json_generate_getalma(char *buf, size_t len_buf, uint32_t sec, uint32_t number) {
uint32_t num = 100;
uint32_t grp = 15;
struct to_json jsonResponse_Post1[] = {
{.name = "num", .value = &num, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "grp", .value = &grp, .vtype = t_to_uint32_t},
{.name = "typ", .value = "dec", .vtype = t_to_string},
{.name = "val", .value = &sec, .vtype = t_to_uint32_t},
{.name = "hlp", .value = "AlmhSecToSAT", .vtype = t_to_string},
{NULL}
};
struct to_json jsonResponse_Post2[] = {
{.name = "num", .value = &num, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "grp", .value = &grp, .vtype = t_to_uint32_t},
{.name = "typ", .value = "dec", .vtype = t_to_string},
{.name = "val", .value = &number, .vtype = t_to_uint32_t},
{.name = "hlp", .value = "AlmhNumSAT", .vtype = t_to_string},
{NULL}
};
buf[0] = '[';
size_t len1_json = json_generate(&buf[1], jsonResponse_Post1, len_buf - 1);
buf[len1_json + 1] = ',';
num = 101;
size_t len2_json = json_generate(&buf[len1_json + 2], jsonResponse_Post2, len_buf - 1);
buf[len1_json + len2_json + 2] = ']';
return len1_json + len2_json + 3;
}
// Ответ статуса обновления WEB
size_t json_generate_webup_answer(char *buf, size_t len_buf, uint32_t webup) {
struct to_json jsonResponse_Post[] = {
{.name = "status", .value = &webup, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ с ошибкой
size_t json_generate_err_answer(char *buf, size_t len_buf, uint32_t err) {
struct to_json jsonResponse_Post[] = {
{.name = "err", .value = &err, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ с ошибкой и id end myid
size_t json_generate_err_id_end_myid_answer(char *buf, size_t len_buf, uint32_t err, uint32_t id, uint32_t end,
uint32_t myid) {
struct to_json jsonResponse_Post[] = {
{.name = "err", .value = &err, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "id", .value = &id, .vtype = t_to_uint32_t},
{.name = "end", .value = &end, .vtype = t_to_uint32_t},
{.name = "myid", .value = &myid, .vtype = t_to_uint32_t},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ с ошибкой и id end
size_t json_generate_err_id_end_answer(char *buf, size_t len_buf, uint32_t err, uint32_t id, uint32_t end) {
struct to_json jsonResponse_Post[] = {
{.name = "err", .value = &err, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "id", .value = &id, .vtype = t_to_uint32_t},
{.name = "end", .value = &end, .vtype = t_to_uint32_t},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ квитанция
size_t json_generate_answer_get_ex_elem_fs(char *buf, size_t len_buf, uint32_t err, uint32_t count, const char *dir) {
struct to_json jsonResponse_Post[] = {
{.name = "err", .value = &err, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "dir", .value = dir, .vtype = t_to_string, .stype = t_to_object},
{.name = "count_all", .value = &count, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
size_t len_json = json_generate(&buf[0], jsonResponse_Post, len_buf);
return len_json;
}
// Ответ квитанция
size_t json_generate_answer_get_elem_fs(char *buf, size_t len_buf, uint32_t err, const char *dir) {
struct to_json jsonResponse_Post[] = {
{.name = "err", .value = &err, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "dir", .value = dir, .vtype = t_to_string, .stype = t_to_object},
{NULL}
};
size_t len_json = json_generate(&buf[0], jsonResponse_Post, len_buf);
return len_json;
}
// Ответ квитанция
size_t
json_generate_answer_get_elem_file_fs(char *buf, size_t len_buf, uint32_t err, const char *file_name, uint32_t pos,
uint32_t len) {
struct to_json jsonResponse_Post[] = {
{.name = "err", .value = &err, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "file", .value = file_name, .vtype = t_to_string, .stype = t_to_object},
{.name = "pos", .value = &pos, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "len", .value = &len, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
size_t len_json = json_generate(&buf[0], jsonResponse_Post, len_buf);
return len_json;
}
// Формирование элемента структуры файловой системы
size_t
json_generate_get_elem_fs(char *buf, size_t len_buf, const char *nam, uint8_t tpf, uint32_t fsz, const char *fdt) {
struct to_json jsonResponse_Post[] = {
{.name = "nam", .value = nam, .vtype = t_to_string, .stype = t_to_object},
{.name = "tpf", .value = &tpf, .vtype = t_to_uint8_t},
{.name = "fsz", .value = &fsz, .vtype = t_to_uint32_t},
{.name = "fdt", .value = fdt, .vtype = t_to_string},
{NULL}
};
size_t len_json = json_generate(&buf[0], jsonResponse_Post, len_buf);
return len_json;
}
size_t json_generate_get_data(char *buf, size_t len_buf,
uint32_t timestamp_gnss,
uint32_t timestamp_block,
uint32_t timestamp_rtc,
uint32_t timestamp_work,
uint32_t vcc,
int32_t temp,
int32_t *rssi,
uint32_t tracert,
uint32_t valid,
float latitude,
float longitude,
tEventWebState *eventWebState,
uint32_t timestampWriteLog,
uint32_t timestampWriteLog2
) {
const struct to_json json_ArrayRssi[] = {
{.value = &rssi[0], .vtype = t_to_int32_t},
{.value = &rssi[1], .vtype = t_to_int32_t},
{.value = &rssi[2], .vtype = t_to_int32_t},
{.value = &rssi[3], .vtype = t_to_int32_t},
{.value = &rssi[4], .vtype = t_to_int32_t},
{.value = &rssi[5], .vtype = t_to_int32_t},
{.value = &rssi[6], .vtype = t_to_int32_t},
{.value = &rssi[7], .vtype = t_to_int32_t},
{.value = &rssi[8], .vtype = t_to_int32_t},
{.value = &rssi[9], .vtype = t_to_int32_t},
{NULL}
};
struct to_json jsonResponse_Post[] = {
{.name = "timestamp_gnss", .value = &timestamp_gnss, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "timestamp_block", .value = &timestamp_block, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "timestamp_rtc", .value = &timestamp_rtc, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "timestamp_work", .value = &timestamp_work, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "vcc", .value = &vcc, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "temp", .value = &temp, .vtype = t_to_int32_t, .stype = t_to_object},
{.name = "rssi", .value = &json_ArrayRssi, .vtype = t_to_array, .stype = t_to_object},
{.name = "tracert_view", .value = &tracert, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "valid_gnss", .value = &valid, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "latitude", .value = &latitude, .vtype = t_to_float, .stype = t_to_object},
{.name = "longitude", .value = &longitude, .vtype = t_to_float},
{.name = "outbox", .value = &eventWebState->EVENT_OUTBOX, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "sentbox", .value = &eventWebState->EVENT_SENTBOX, .vtype = t_to_uint32_t},
{.name = "inbox", .value = &eventWebState->EVENT_INBOX, .vtype = t_to_uint32_t},
{.name = "tracert", .value = &eventWebState->EVENT_TRACERT, .vtype = t_to_uint32_t},
{.name = "alma", .value = &eventWebState->EVENT_ALMA, .vtype = t_to_uint32_t},
{.name = "log", .value = &timestampWriteLog, .vtype = t_to_uint32_t},
{.name = "log2", .value = &timestampWriteLog2, .vtype = t_to_uint32_t},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ timestamp
size_t json_generate_timestamp_answer(char *buf, size_t len_buf, uint32_t timestamp_gnss, uint32_t timestamp_block,
uint32_t timestamp_work) {
struct to_json jsonResponse_Post[] = {
{.name = "timestamp_gnss", .value = &timestamp_gnss, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "timestamp_block", .value = &timestamp_block, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "timestamp_work", .value = &timestamp_work, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ координат
size_t json_generate_coordinates_answer(char *buf, size_t len_buf, uint32_t valid, float latitude, float longitude,
uint32_t routing, uint32_t angle, uint32_t timeZoneInSat) {
struct to_json jsonResponse_Post[] = {
// {.name = "valid_gnss", .value = &valid, .vtype = t_to_uint32_t, .stype = t_to_object},
// {.name = "latitude", .value = &latitude, .vtype = t_to_float, .stype = t_to_object},
// {.name = "longitude", .value = &longitude, .vtype = t_to_float},
{.name = "routing", .value = &routing, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "time", .value = &timeZoneInSat, .vtype = t_to_uint32_t},
{.name = "dist", .value = &angle, .vtype = t_to_uint32_t},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ АДЦ
size_t json_generate_adc_answer(char *buf, size_t len_buf, uint32_t vcc) {
struct to_json jsonResponse_Post[] = {
{.name = "vcc", .value = &vcc, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ stat
size_t json_generate_stat_answer(char *buf, size_t len_buf, uint32_t NumFileOutBox, uint32_t NumFileInbox,
uint32_t CntMsgsOutBox, uint32_t stn1, uint32_t stn2, uint32_t stn3) {
if (stn1)
stn1 = 1;
if (stn2)
stn2 = 2;
if (stn3)
stn3 = 3;
const struct to_json jsonResponse_Post1[] = {
{.name = "stn", .value = &stn1, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "typ", .value = "dec", .vtype = t_to_string},
{.name = "val", .value = &NumFileOutBox, .vtype = t_to_uint32_t},
{.name = "hlp", .value = "NumFileOutBox", .vtype = t_to_string},
{NULL}
};
const struct to_json jsonResponse_Post2[] = {
{.name = "stn", .value = &stn2, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "typ", .value = "dec", .vtype = t_to_string},
{.name = "val", .value = &NumFileInbox, .vtype = t_to_uint32_t},
{.name = "hlp", .value = "NumFileInbox", .vtype = t_to_string},
{NULL}
};
const struct to_json jsonResponse_Post3[] = {
{.name = "stn", .value = &stn3, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "typ", .value = "dec", .vtype = t_to_string},
{.name = "val", .value = &CntMsgsOutBox, .vtype = t_to_uint32_t},
{.name = "hlp", .value = "CntMsgsOutBox", .vtype = t_to_string},
{NULL}
};
buf[0] = '[';
buf[1] = '\0';
char bufTmp[255];
if (stn1) {
json_generate(bufTmp, jsonResponse_Post1, sizeof(bufTmp));
if ((stn2) || (stn3))
strcat(bufTmp, ",");
strcat(buf, bufTmp);
}
if (stn2) {
json_generate(bufTmp, jsonResponse_Post2, sizeof(bufTmp));
if (stn3)
strcat(bufTmp, ",");
strcat(buf, bufTmp);
}
if (stn3) {
json_generate(bufTmp, jsonResponse_Post3, sizeof(bufTmp));
strcat(buf, bufTmp);
}
strcat(buf, "]");
return strlen(buf);
}
// Ответ rssi
size_t json_generate_rssi_answer(char *buf, size_t len_buf, int32_t rssi) {
struct to_json jsonResponse_Post[] = {
{.name = "rssi", .value = &rssi, .vtype = t_to_int32_t, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Текущий уровень авторизации
size_t json_generate_auth_send_answer(char *buf, size_t len_buf, uint32_t auth) {
uint32_t num = 103;
uint32_t grp = 15;
// AUTH_NONE = 0,
// AUTH_USER = 1,
// AUTH_INTEG = 2,
// AUTH_ADMIN = 3
uint32_t val = 0;
if (auth == 1)
val = 103;
if (auth == 2)
val = 131;
if (auth == 3)
val = 133;
struct to_json jsonResponse_Post[] = {
{.name = "num", .value = &num, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "grp", .value = &grp, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "typ", .value = "dec", .vtype = t_to_string, .stype = t_to_object},
{.name = "val", .value = &val, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "typ", .value = "IsAuthorizedNow", .vtype = t_to_string, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ vars
size_t json_generate_vars_send_answer(char *buf, size_t len_buf, uint32_t at, const char *username, uint32_t diskall,
uint32_t diskfree) {
struct to_json jsonResponse_Post[] = {
{.name = "numat", .value = &at, .vtype = t_to_int32_t, .stype = t_to_object},
{.name = "username", .value = username, .vtype = t_to_string, .stype = t_to_object},
{.name = "disksize", .value = &diskall, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "diskfree", .value = &diskfree, .vtype = t_to_uint32_t, .stype = t_to_object},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
}
// Ответ версии
size_t json_generate_version_answer(char *buf, size_t len_buf, char *versionModem, char *versionCrypto) {
char META_HW_NAME_BUF[32];
memset(META_HW_NAME_BUF, 0, sizeof(META_HW_NAME_BUF));
//memcpy(&META_HW_NAME_BUF, META_HW_NAME, META_HW_NAME_SIZE);
strcat(META_HW_NAME_BUF, "MAIN_APP");
char META_FW_NAME_BUF[32];
memset(META_FW_NAME_BUF, 0, sizeof(META_FW_NAME_BUF));
memcpy(&META_FW_NAME_BUF, META_FW_NAME, META_FW_NAME_SIZE);
char *firmwareModemBoot = "null\0";
firmwareModemBoot = (char *) strchr(versionModem, ',');
if (firmwareModemBoot != NULL) {
*firmwareModemBoot = '\0';
firmwareModemBoot++;
}
char *firmwareModemBootEnd = (char *) strchr(firmwareModemBoot, '\r');
if (firmwareModemBootEnd != NULL) {
*firmwareModemBootEnd = '\0';
firmwareModemBootEnd++;
}
char *firmwareCryptoBoot = "null\0";
firmwareCryptoBoot = (char *) strchr(versionCrypto, ',');
if (firmwareCryptoBoot != NULL) {
*firmwareCryptoBoot = '\0';
firmwareCryptoBoot++;
}
char *firmwareCryptoBootEnd = (char *) strchr(firmwareCryptoBoot, '\r');
if (firmwareCryptoBootEnd != NULL) {
*firmwareCryptoBootEnd = '\0';
firmwareCryptoBootEnd++;
}
struct to_json jsonResponse_Post[] = {
{.name = "hardwareMain", .value = META_HW_NAME_BUF, .vtype = t_to_string, .stype = t_to_object},
{.name = "firmwareMain", .value = META_FW_NAME_BUF, .vtype = t_to_string},
{.name = "hardwareModem", .value = versionModem, .vtype = t_to_string},
{.name = "firmwareModem", .value = firmwareModemBoot, .vtype = t_to_string},
{.name = "hardwareCrypto", .value = versionCrypto, .vtype = t_to_string},
{.name = "firmwareCrypto", .value = firmwareCryptoBoot, .vtype = t_to_string},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
/*
char META_FW_NAME_BUF[32];
memset(META_FW_NAME_BUF, 0, sizeof(META_FW_NAME_BUF));
memcpy(META_FW_NAME_BUF, META_FW_NAME, META_FW_NAME_SIZE);
struct to_json jsonResponse_Post[] = {
{.name = "hardware", .value = "ГОНЕЦ PRO", .vtype = t_to_string, .stype = t_to_object},
{.name = "firmware", .value = META_FW_NAME_BUF, .vtype = t_to_string},
{.name = "ATnum", .value = &ATnum, .vtype = t_to_uint32_t},
{NULL}
};
buf[0] = '[';
size_t len_json = json_generate(&buf[1], jsonResponse_Post, len_buf - 1);
buf[len_json + 1] = ']';
return len_json + 2;
*/
}
/*
typedef struct {
struct to_json objJson[6];
} tObjJson;
tObjJson jsonResponse_States[maxFilesOutBox];
struct to_json objsMesJsonLinks[maxFilesOutBox + 1];
// Ответ процент передачи
size_t json_generate_proc_send_answer(char *buf, size_t len_buf, tFileSendInfoForJson *fileSendInfo) {
int j = 0;
for (int i = 0; i < maxFilesOutBox; ++i) {
if (fileSendInfo[i].valid) {
struct to_json jsonResponse_State[] = {
{.name = "mnum", .value = &fileSendInfo[i].mnum, .vtype = t_to_uint32_t, .stype = t_to_object},
{.name = "kvs", .value = &fileSendInfo[i].kvs, .vtype = t_to_uint8_t},
{.name = "isSendAll", .value = &fileSendInfo[i].isSendAll, .vtype = t_to_uint8_t},
{.name = "bytes_sending", .value = &fileSendInfo[i].bytes_sending, .vtype = t_to_uint32_t},
{.name = "bytes_no_sending", .value = &fileSendInfo[i].bytes_no_sending, .vtype = t_to_uint32_t},
{NULL}
};
jsonResponse_States[j].objJson[0] = jsonResponse_State[0];
jsonResponse_States[j].objJson[1] = jsonResponse_State[1];
jsonResponse_States[j].objJson[2] = jsonResponse_State[2];
jsonResponse_States[j].objJson[3] = jsonResponse_State[3];
jsonResponse_States[j].objJson[4] = jsonResponse_State[4];
jsonResponse_States[j].objJson[5] = jsonResponse_State[5];
const struct to_json objJsonLink[] = {
{.value = &jsonResponse_States[j].objJson, .vtype = t_to_object},
{NULL}
};
objsMesJsonLinks[j] = objJsonLink[0];
objsMesJsonLinks[j + 1] = objJsonLink[1];
++j;
}
}
struct to_json jsonResponse_Post[] = {
{.name = "InfoSend", .value = &objsMesJsonLinks, .vtype = t_to_array, .stype = t_to_object},
{NULL}
};
if (j == 0) {
buf[0] = '[';
buf[1] = ']';
buf[2] = '\0';
return 2;
} else {
size_t len_json = json_generate(buf, jsonResponse_Post, len_buf);
return len_json;
}
}
*/

18
modular.json Normal file
View File

@ -0,0 +1,18 @@
{
"dep": [
{
"type": "git",
"provider": "GONEC_NEW",
"repo": "JSON"
}
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}