diff options
-rw-r--r-- | man/psmq-sub.1 | 52 | ||||
-rw-r--r-- | src/psmq-sub.c | 8 | ||||
-rwxr-xr-x | tst/psmq-progs.sh | 44 |
3 files changed, 61 insertions, 43 deletions
diff --git a/man/psmq-sub.1 b/man/psmq-sub.1 index 0298593..568ed03 100644 --- a/man/psmq-sub.1 +++ b/man/psmq-sub.1 @@ -100,29 +100,37 @@ charater. Rest of lines are printed in single line as a string. .PP .nf - p:0 /source data( 37): switch (psmqd_cfg_init(argc, argv)) - p:0 /source data( 3): { - p:0 /source data( 9): case 0: - p:0 /source data( 37): /* no errors in parsing arguments, - p:0 /source data( 32): * continue program execution - p:0 /source data(40) - 0x0000 09 09 20 2a 20 75 74 66 2d 38 20 61 74 74 61 63 .. * utf-8 attac - 0x0010 6b 2c 20 68 65 72 65 20 69 74 20 63 6f 6d 65 73 k, here it comes - 0x0020 21 20 c5 82 20 2a 2f 00 ! .. */. - p:0 /source data( 9): break; - p:0 /source data( 1): - p:0 /source data( 10): case -2: - p:0 /source data( 10): case -3: - p:0 /source data( 39): /* help or version was printed, exit - p:0 /source data( 30): * program without error */ - p:0 /source data( 12): return 0; - p:0 /source data( 1): - p:0 /source data( 10): default: - p:0 /source data( 32): /* error occured when parsing - p:0 /source data( 23): * arguments, die */ - p:0 /source data( 12): return 1; - p:0 /source data( 3): } +p:0 l: 37 /msg switch (psmqd_cfg_init(argc, argv)) +p:0 l: 3 /msg { +p:0 l: 9 /msg case 0: +p:0 l: 37 /msg /* no errors in parsing arguments, +p:0 l: 32 /msg * continue program execution +p:0 l: 40 /msg +0x0000 09 09 20 2a 20 75 74 66 2d 38 20 61 74 74 61 63 .. * utf-8 attac +0x0010 6b 2c 20 68 65 72 65 20 69 74 20 63 6f 6d 65 73 k, here it comes +0x0020 21 20 c5 82 20 2a 2f 00 ! .. */. +p:0 l: 9 /msg break; +p:0 l: 1 /msg +p:0 l: 10 /msg case -2: +p:0 l: 10 /msg case -3: +p:0 l: 39 /msg /* help or version was printed, exit +p:0 l: 30 /msg * program without error */ +p:0 l: 12 /msg return 0; +p:0 l: 1 /msg +p:0 l: 10 /msg default: +p:0 l: 32 /msg /* error occured when parsing +p:0 l: 23 /msg * arguments, die */ +p:0 l: 12 /msg return 1; +p:0 l: 3 /msg } fi +.PP +Log from different sensors may look like this +.PP +.nf +[2021-05-23 17:53:59] p:0 l: 3 /can/engine/rpm 50 +[2021-05-23 17:53:59] p:0 l: 3 /adc/volt 30 +[2021-05-23 17:53:59] p:0 l: 3 /can/room/10/temp 23 +.fi .SH EXAMPLES .TP Listen to single topic diff --git a/src/psmq-sub.c b/src/psmq-sub.c index 5171ba8..eba676c 100644 --- a/src/psmq-sub.c +++ b/src/psmq-sub.c @@ -174,14 +174,14 @@ static int on_receive case PSMQ_CTRL_CMD_PUBLISH: if (is_payload_binary(payload, paylen)) { - el_oprint(ELN, &psmqs_out, "p:%u %s data(%hu)", - prio, topic, paylen); + el_oprint(ELN, &psmqs_out, "p:%u l:%4hu %s", + prio, paylen, topic); el_opmemory(ELN, &psmqs_out, payload, paylen); } else { - el_oprint(ELN, &psmqs_out, "p:%u %s data(%4hu): %s", - prio, topic, paylen, payload); + el_oprint(ELN, &psmqs_out, "p:%u l:%4hu %s %s", + prio, paylen - 1, topic, payload); } return 0; diff --git a/tst/psmq-progs.sh b/tst/psmq-progs.sh index dec7980..f916d9f 100755 --- a/tst/psmq-progs.sh +++ b/tst/psmq-progs.sh @@ -397,7 +397,8 @@ psmq_pub_from_stdin() { start_psmqs echo "t" | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 - mt_fail "psmq_grep \"2): t\" \"${psmqs_stdout}\"" + psmq_grep "p:0 l: 1 /1" $psmqs_stdout + mt_fail "[ $? -eq 0 ]" stop_psmqs } psmq_pub_from_stdin_max_line() @@ -463,8 +464,8 @@ psmq_pub_with_prio() start_psmqs msg="m" ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -m${msg} -p2 - mt_fail "psmq_grep \"p:2 /1 data(\" \"${psmqs_stdout}\"" - mt_fail "psmq_grep \"2): m\" \"${psmqs_stdout}\"" + psmq_grep "p:2 l: 1 /1 m" $psmqs_stdout + mt_fail "[ $? -eq 0 ]" stop_psmqs } psmq_pub_with_invalid_prio() @@ -480,16 +481,16 @@ psmq_pub_from_stdin_with_prio() { start_psmqs echo t | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p2 - mt_fail "psmq_grep \"p:2 /1 data(\" \"${psmqs_stdout}\"" - mt_fail "psmq_grep \"2): t\" \"${psmqs_stdout}\"" + psmq_grep "p:2 l: 1 /1 t" $psmqs_stdout + mt_fail "[ $? -eq 0 ]" stop_psmqs } psmq_pub_empty_message() { start_psmqs ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p2 -e - mt_fail "psmq_grep \"p:2 /1 data(0)\" \ - \"${psmqs_stdout}\"" + psmq_grep "p:2 l: 0 /1" $psmqs_stdout + mt_fail "[ $? -eq 0 ]" stop_psmqs } psmq_pub_binary_single() @@ -497,9 +498,11 @@ psmq_pub_binary_single() start_psmqs msg=$(mktemp) count=$((psmq_msg_max - 1 - 3)) - dd if=/dev/urandom of=$msg bs=1 count=${count} 2>/dev/null + dd if=/dev/zero of=$msg bs=1 count=${count} 2>/dev/null cat $msg | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p2 -B - mt_fail "psmq_grep \"p:2 /1 data($count)\" \"${psmqs_stdout}\"" + cnt=$(printf "%4d" $count) + psmq_grep "p:2 l:$cnt /1" $psmqs_stdout + mt_fail "[ $? -eq 0 ]" rm $msg stop_psmqs } @@ -508,9 +511,11 @@ psmq_pub_binary_max() start_psmqs msg=$(mktemp) count=$((psmq_msg_max - 3)) - dd if=/dev/urandom of=$msg bs=1 count=${count} 2>/dev/null + dd if=/dev/zero of=$msg bs=1 count=${count} 2>/dev/null cat $msg | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p2 -B - mt_fail "psmq_grep \"p:2 /1 data($count)\" \"${psmqs_stdout}\"" + cnt=$(printf "%4d" $count) + psmq_grep "p:2 l:$cnt /1" $psmqs_stdout + mt_fail "[ $? -eq 0 ]" rm $msg stop_psmqs } @@ -520,10 +525,13 @@ psmq_pub_binary_split() msg=$(mktemp) count=$((psmq_msg_max - 3 + 1)) splt_count=$((count - 1)) - dd if=/dev/urandom of=$msg bs=1 count=${count} 2>/dev/null + dd if=/dev/zero of=$msg bs=1 count=${count} 2>/dev/null cat $msg | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p2 -B - mt_fail "psmq_grep \"p:2 /1 data($splt_count)\" \"${psmqs_stdout}\"" - mt_fail "psmq_grep \"p:2 /1 data(1)\" \"${psmqs_stdout}\"" + cnt=$(printf "%4d" $splt_count) + psmq_grep "p:2 l:$cnt /1" $psmqs_stdout + mt_fail "[ $? -eq 0 ]" + psmq_grep "p:2 l: 1 /1" $psmqs_stdout + mt_fail "[ $? -eq 0 ]" rm $msg stop_psmqs } @@ -534,13 +542,15 @@ psmq_pub_binary_many_split() # 4 full messages + one splitted byte count=$((4 * (psmq_msg_max - 3) + 1)) splt_count=$((psmq_msg_max - 3)) - dd if=/dev/urandom of=$msg bs=1 count=${count} 2>/dev/null + dd if=/dev/zero of=$msg bs=1 count=${count} 2>/dev/null cat $msg | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p2 -B # first check for last split, this will make sure that previous # splits are in a log file as well - mt_fail "psmq_grep \"p:2 /1 data(1)\" \"${psmqs_stdout}\"" + psmq_grep "p:2 l: 1 /1" $psmqs_stdout + mt_fail "[ $? -eq 0 ]" # now do custom grep and check if we have 4 full splits - split_count=$(grep "p:2 /1 data($splt_count)" $psmqs_stdout | wc -l) + cnt=$(printf "%4d" $splt_count) + split_count=$(grep "p:2 l:$cnt /1" $psmqs_stdout | wc -l) mt_fail "[ $split_count -eq 4 ]" rm $msg stop_psmqs |