Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ struct message {
31|0x1f|MainPowerFail||значение напряжения в вольтах
32|0x20|PowerGood||значение напряжения в вольтах
37|0x25|Report|1|если в позиции 0 значение "2", то значение текущей температуры в гр.Цельсия
57|0x39|SystemDisarm||значение в позиции "0" представляет снятые с охраны разделы в бинарной форме. Т.е. значение `ff` можно выразить как `1 1 1 1 1 1 1 1`.Т.е. все 8 разделов сняты с охраны
58|0x3a|SystemArm||значение в позиции "0" представляет поставленные на охрану разделы в бинарной форме. Т.е. значение `07` можно выразить как `0 0 0 0 0 1 1 1`.Т.е. первые 3 раздела поставлены на охрану
63|0x3f|RemoteCommandHandled|5|в позиции 0 - ИД команды, в позиции 5 - результат обработки

## Результаты обработки удаленных команд
Expand Down
11 changes: 7 additions & 4 deletions dozord/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ on_message_t socket_message_callback(CommandResponse * response, uint8_t * data,
for (index = 0; index < events->length; index++) {
pthread_t publishThread = 0;

snprintf(logMessage, sizeof(logMessage), "%s", events->items[index].event);
prettyLogger(LOG_LEVEL_INFO, clientIp, logMessage);

// skip keep alive updates to being logged
if (events->items[index].eventType != ENUM_EVENT_TYPE_KEEPALIVE) {
snprintf(logMessage, sizeof(logMessage), "%s", events->items[index].event);
prettyLogger(LOG_LEVEL_INFO, clientIp, logMessage);
}

strncpy(payload->deviceIp, clientIp, sizeof(char) * 16);
memcpy(payload->data, &events->items[0], sizeof(EventInfo));
memcpy(payload->data, &events->items[index], sizeof(EventInfo));

publishEvent(payload);
}
Expand Down
6 changes: 1 addition & 5 deletions dozord/nightshift-mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ struct mosquitto * mosq = NULL;

void publish(char * topic, char * message, bool retainFlag) {
int rc = 0;
char logMessage[256];
char logMessage[2048];

if (GlobalMQTTConnected) {
rc = mosquitto_publish(mosq, NULL, topic, strlen(message), message, 0, retainFlag);
if (rc != MOSQ_ERR_SUCCESS) {
snprintf(logMessage, sizeof(logMessage), "Failed to publish to topic \"%s\". Error code: %d", topic, rc);
prettyLogger(LOG_LEVEL_ERROR, "MQTT", logMessage);
} else {
// snprintf(logMessage, sizeof(logMessage), "\"%s\" published to \"%s\"", message, topic);
// @todo going to be LOG_LEVEL_DEBUG
// prettyLogger(LOG_LEVEL_INFO, "MQTT", logMessage);
}
} else {
// @todo build outgoing queue
Expand Down
55 changes: 44 additions & 11 deletions libdozor/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,14 @@ void convertDeviceEventToCommon(EventInfo* eventInfo, uint8_t site, DeviceEvent*

strcat(res, "}");

free(timestamp);
free(temp);

sprintf(eventInfo->event, "%s", res);
eventInfo->siteId = site;

if (deviceEvent->time != 0x00000000) {
free(timestamp);
}

free(temp);
free(res);
}

Expand Down Expand Up @@ -411,13 +414,18 @@ static char * getCommandEventData(uint8_t type, uint8_t * data, uint8_t len)

static char * getReportEventData(uint8_t type, uint8_t * data, uint8_t len)
{
char * template = ",\"temp\":%s,\"event\":\"%s\",\"scope\":\"Common\"";
char * res = malloc(sizeof(char) * (strlen(template) + MAX_EVENT_NAME_LENGTH + 2));
char * extractedData = getData(data, REPORT_TEMP_DATA_POSITION, len);

sprintf(res, template, extractedData, getEventNameByType(type));
char * temperatureReportTemplate = ",\"temp\":%s,\"event\":\"%s\",\"scope\":\"Common\"";
char * unknownReportTemplate = ",\"temp\":null,\"event\":\"%s\",\"scope\":\"Common\"";
char * res = malloc(sizeof(char) * (strlen(temperatureReportTemplate) + MAX_EVENT_NAME_LENGTH + 2));

free(extractedData);
if (data[0] == 2) {
char * extractedData = getData(data, REPORT_TEMP_DATA_POSITION, len);
sprintf(res, temperatureReportTemplate, extractedData, getEventNameByType(type));

free(extractedData);
} else {
sprintf(res, unknownReportTemplate, getEventNameByType(type));
}

return res;
}
Expand All @@ -437,11 +445,15 @@ static char * getAuthEventData(uint8_t type, uint8_t * data, uint8_t len)

static char * getSecurityEventData(uint8_t type, uint8_t * data, uint8_t len)
{
char * template = ",\"user\":%s,\"event\":\"%s\",\"scope\":\"Security\"";
char * template = ",\"user\":%s,\"event\":\"%s\",\"scope\":\"Security\",\"sections\":%s";
char * res = malloc(sizeof(char) * (strlen(template) + MAX_EVENT_NAME_LENGTH + 2));
char * extractedData = getData(data, USER_DATA_POSITION, len);
uint8_t state_byte = data[0];
char affectedSections[50];

sprintf(res, template, extractedData, getEventNameByType(type));
get_affected_sections(state_byte, affectedSections);

sprintf(res, template, extractedData, getEventNameByType(type), affectedSections);

free(extractedData);
return res;
Expand Down Expand Up @@ -501,4 +513,25 @@ static char * getEventNameByType(uint8_t type)
return (char *) events[type];
}
return "null";
}

void get_affected_sections(uint8_t state_byte, char *result) {
char temp[4]; // Temporary buffer for individual port numbers
int first = 1; // Flag to track if it's the first port in the list

strcpy(result, "["); // Initialize the result with the opening bracket

// Iterate through each bit (8 ports)
for (int i = 0; i < 8; i++) {
if ((state_byte & (1 << i))) { // Check if the i-th bit is 1 (closed)
if (!first) {
strcat(result, ", "); // Add a comma and space for subsequent ports
}
snprintf(temp, sizeof(temp), "%d", i + 1); // Convert port number to string
strcat(result, temp); // Append the port number to the result
first = 0; // Clear the flag after the first port
}
}

strcat(result, "]"); // Append the closing bracket
}
Loading