Commit c26be7a7 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

stat mngmt added

parent 6cf62525
No preview for this file type
...@@ -161,11 +161,31 @@ int main (int argc, char **argv) { ...@@ -161,11 +161,31 @@ int main (int argc, char **argv) {
); );
//printf("%s\n", buf); //printf("%s\n", buf);
res = PQexec(conn, buf); res = PQexec(conn, buf);
if (PQresultStatus(res) != PGRES_COMMAND_OK) { if (PQresultStatus(res) == PGRES_COMMAND_OK) {
PQclear(res);
fprintf(stderr, "%s\n", PQerrorMessage(conn)); fprintf(stderr, "%s\n", PQerrorMessage(conn));
sprintf(buf, "SELECT * FROM pend_msgs WHERE dev_id = %d", dev_id);
res = PQexec(conn, buf);
if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res)) {
buf[2] = GATEWAY_PROTOCOL_STAT_ACK_PEND;
printf("ACK_PEND prepared\n");
} else {
buf[2] = GATEWAY_PROTOCOL_STAT_ACK;
printf("ACK prepared\n");
}
buf[0] = dev_id;
buf[1] = GATEWAY_PROTOCOL_PACKET_TYPE_STAT;
buf_len = 3;
} }
PQclear(res); PQclear(res);
} else { } else {
buf[0] = dev_id;
buf[1] = GATEWAY_PROTOCOL_PACKET_TYPE_STAT;
buf[2] = GATEWAY_PROTOCOL_STAT_NACK;
buf_len = 3;
printf("payload decode error\n"); printf("payload decode error\n");
} }
} else if (packet_type == GATEWAY_PROTOCOL_PACKET_TYPE_PEND_REQ) { } else if (packet_type == GATEWAY_PROTOCOL_PACKET_TYPE_PEND_REQ) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment