@@ -301,6 +301,41 @@ def test_enip_TYPES_numeric():
301301 assert data .typed_data .data == [2 ** 63 ]
302302
303303
304+ def test_enip_TYPES_bool ():
305+ """Disappointingly, the struct '?' format in Python2 """
306+ pkt = b'\x00 \x01 \x02 \x04 \x08 \x10 \x20 \x40 \x80 \xff \x00 '
307+ pkt_truths = [ False , True , True , True , True , True , True , True , True , True , False ]
308+ data = cpppo .dotdict ()
309+ source = cpppo .chainable ( pkt )
310+ with enip .BOOL () as machine :
311+ for i ,(m ,s ) in enumerate ( machine .run ( source = source , data = data )):
312+ log .info ( "%s #%3d -> %10.10s; next byte %3d: %-10.10r: %r" , m .name_centered (),
313+ i , s , source .sent , source .peek (), data )
314+ assert i == 0
315+ assert data .BOOL == False
316+
317+ data = cpppo .dotdict ()
318+ with enip .BOOL () as machine :
319+ for i ,(m ,s ) in enumerate ( machine .run ( source = source , data = data )):
320+ log .info ( "%s #%3d -> %10.10s; next byte %3d: %-10.10r: %r" , m .name_centered (),
321+ i , s , source .sent , source .peek (), data )
322+ assert i == 0
323+ assert data .BOOL == True
324+
325+ data = cpppo .dotdict ()
326+ source = cpppo .chainable ( pkt )
327+ with enip .typed_data ( tag_type = enip .BOOL .tag_type , terminal = True ) as machine :
328+ for i ,(m ,s ) in enumerate ( machine .run ( source = source , data = data )):
329+ log .info ( "%s #%3d -> %10.10s; next byte %3d: %-10.10r: %r" , m .name_centered (),
330+ i , s , source .sent , source .peek (), data )
331+ assert i == 48
332+ assert data .typed_data .data == pkt_truths
333+
334+ pkt_produced = b'\x00 \xff \xff \xff \xff \xff \xff \xff \xff \x00 '
335+ enip .typed_data .produce ( {'data' : pkt_truths }, tag_type = enip .BOOL .tag_type ) == pkt_produced
336+
337+
338+
304339# pkt4
305340# "4","0.000863000","192.168.222.128","10.220.104.180","ENIP","82","Register Session (Req)"
306341rss_004_request = bytes (bytearray ([
0 commit comments