<div dir="ltr">Hello all -<br><div class="gmail_quote"><div dir="ltr"><br>Having a bit of trouble with fcall/fret.<br><br>I need to read a number in a string that indicates the number of bytes to follow. I do this correctly with a complete string, but also reach a final state with an incomplete string that includes some of the binary data. I'm using fcall into another <span style="padding: 0pt; background-color: yellow; color: black; display: inline; font-size: inherit;">machine</span> to read the binary data.<br>
<br>Have I missed something obvious?<br><br>Thanks,<br>Gordon<br><br>%%{<br> <span style="padding: 0pt; background-color: yellow; color: black; display: inline; font-size: inherit;">machine</span> TEST;<br>
alphtype char;<br><br> action binary_data_<span style="padding: 0pt; background-color: yellow; color: black; display: inline; font-size: inherit;">length</span>_check {<br> fsm.binary_data_count++;<br>
if ( fsm.binary_data_count >= fsm.byte_count ) {<br> //fhold;<br> fret;<br> }<br> }<br><br> action binary_data_init { fsm.binary_data_count = 0; }<br><br> binary_data_<span style="padding: 0pt; background-color: yellow; color: black; display: inline; font-size: inherit;">machine</span> := any+ $binary_data_<span style="padding: 0pt; background-color: yellow; color: black; display: inline; font-size: inherit;">length</span>_check >binary_data_init;<br>
<br> # We're trying to do this:<br> # any{fsm.byte_count}<br> action binary_data_action {<br> fcall binary_data_<span style="padding: 0pt; background-color: yellow; color: black; display: inline; font-size: inherit;">machine</span>;<br>
}<br><br> binary_payload = 'r.' @binary_data_action;<br><br> # b:<NumBytes>:<NumBytes of chars>:<CRC><CR><br> bridge_packet =<br> 'b:'<br> ( xdigit @{ AddXDigit( fsm.byte_count, * p ); } )+<br>
':'<br> binary_payload<br> ':'<br> xdigit+<br> '\r';<br><br> main := bridge_packet;<br>}%%<br><br>%% write data;<br><br>void init() {<br> %% write init;<br>
fsm.byte_count = 0;<br>}<br><br>void parse(char * payload, char * payloadEnd) {<br> const char * p = payload;<br> const char * pe = payloadEnd;<br><br> %% access fsm.;<br> %% write exec;<br><br> if ( fsm.cs == TEST_error ) {<br>
std::cout << "FINISH_ERROR\n";<br> } else if ( fsm.cs >= TEST_first_final ) {<br> std::cout << "FINISH_FINAL\n";<br> } else {<br> std::cout << "FINISH_NOT_FINAL\n";<br>
}<br>}<br><br>int main() {<br> init();<br> {<br> // Complete<br> char * t1 = "b:0004:r.abcd:a0\r";<br> parse(t1, t1 + strlen( t1 ) );<br> }<br> <br> init();<br> {<br> // Incomplete<br>
char * t1 = "b:0004:r.ab";<br> parse(t1, t1 + strlen( t1 ) );<br> }<br> <br> return 0;<br>}<br><br>----------<br>Output is:<br>{{{<br>FINISH_FINAL<br>FINISH_FINAL<br>}}}<br><br>and I expect<br>
{{{<br>FINISH_FINAL<br>
FINISH_NOT_FINAL<br>
}}}<br><br>AddXDigit( unsigned target, char c ) adds value of hexadecimal digit to target.<br><br></div>
</div><br></div>