diff --git a/README.md b/README.md index d5ca214..384a8e3 100644 --- a/README.md +++ b/README.md @@ -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 - результат обработки ## Результаты обработки удаленных команд diff --git a/dozord/main.c b/dozord/main.c index 54f5e98..98374d9 100644 --- a/dozord/main.c +++ b/dozord/main.c @@ -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); } diff --git a/dozord/nightshift-mqtt.c b/dozord/nightshift-mqtt.c index 619d5bb..438c94a 100644 --- a/dozord/nightshift-mqtt.c +++ b/dozord/nightshift-mqtt.c @@ -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 diff --git a/libdozor/event.c b/libdozor/event.c index 28e6aff..ec75d80 100644 --- a/libdozor/event.c +++ b/libdozor/event.c @@ -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); } @@ -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; } @@ -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; @@ -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 } \ No newline at end of file