私の問題を言うのは難しいですが、私は試みます。
ネットワーク内のいくつかのセンサーからの応答を読み取るモジュール ztc_config があります。この応答を読むために、C クラス query.c を作成しました。これは次のとおりです。
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include "data.h"
#include "modules.h"
void query(hash_t* params) {
record_t* rec;
timestamp_t ts;
timestamp_t rec_ts;
uint32_t sec;
uint32_t usec;
timestamp_t now;
timestamp_t start;
timestamp_t end;
char* startime;
char* endtime;
// Coordinator, opgroup and Opcode specified by the client
uint64_t netid = 0;
uint8_t opcode_group = 0;
uint8_t opcode = 0;
char* par;
now = mdl_now();
/* set the start and end time based on query parameters */
startime = hash_get(params, "start");
if(startime != NULL)
start = mdl_parse_timestr(startime, now);
else
start = now;
endtime = hash_get(params, "end");
if(endtime != NULL)
end = mdl_parse_timestr(endtime, now);
else
end = ~0;
// Network id is required
par = hash_get(params, "netid");
if(par == NULL) {
mdl_print("netid required\n");
exit(1);
}
netid = strtoull(par, NULL, 10);
par = hash_get(params, "opcode_group");
if(par == NULL) {
mdl_print("opcode_group required\n");
exit(1);
}
opcode_group = strtoul(par, NULL, 10);
par = hash_get(params, "opcode");
if(par == NULL) {
mdl_print("opcode required\n");
exit(1);
}
opcode = strtoul(par, NULL, 10);
/* seek in the bytestream */
mdl_seek(start);
while((rec = (record_t* ) mdl_next(&ts)) != NULL) {
uint64_t val;
//float fval;
/* reached end time ? */
if(ts > end) break;
rec_ts = NTOHLL(rec->ts);
sec = TS2SEC(rec_ts);
usec = TS2USEC(rec_ts);
// Only print records with the wanted net and opcodes
if((netid != 0) && (netid != NTOHLL(rec->net_id)))
continue;
if((opcode_group != 0) && (opcode_group != ntohl(rec->opcode_group)))
continue;
if((opcode != 0) && (opcode != ntohl(rec->opcode)))
continue;
val = NTOHLL(rec->payload);
mdl_print("%u %llu %u %u %u %d\n", sec, NTOHLL(rec->net_id), rec->op_code_group, rec->op_code, rec->payloadlength, val);
}
}
たとえば、このリンクにアクセスすると、次のようになります。
http://localhost:44444/ztc_config?netid=2459546910990453036&opcode_group=164&opcode=224&start=-5m&end=-1s
このページには、過去 5 分間に opcode_group 164 (16 進数の A4) と opcode 224 (16 進数の E0) を持つ netid 2459546910990453036 からのレコードのみが表示されます。
しかし、私の query.c クラスには何か問題があります。このリンクにアクセスすると
http://localhost:44444/ztc_config?netid=0&opcode_group=0&opcode=0&start=-5m&end=-1s
過去 5 分間のすべての記録があります。
しかし、opcode_group または opcode の値を変更しても、何も得られませんでした...
助言がありますか?エラーはどこにありますか?
どうもありがとうございました。
編集
2 つの変数 opcode_group と opcode の名前を次のように変更しようとしました。
....
uint8_t op_code_group =0;
uint8_t op_code =0;
....
....
op_code_group = strtoul(par, NULL, 10);
....
op_code = strtoul(par, NULL, 10);
このように、私は次のように書いています。
if ((op_code_group != 0) && (op_code_group != ntohl(rec->opcode_group))) continue;
if ((op_code != 0) && (op_code != ntohl(rec->opcode))) continue;
これはフィルターである必要があります。別のケースでは、変数名が同じで、条件は true でしたが、値は常に初期値 = 0 でした。それともそうではありませんか?
とにかく、この解決策は機能しません... :(助けてください!