a œ™WW@#ã@s¨ddlZddlZddlZz ddlZWneyBddlmZYn0dd„Zdd„ZGdd„de ƒZ Gdd „d e ƒZ Gd d „d ej ƒZ e d kr¤e dƒZd e_eeƒdS)éNccs¬d}t |¡D]d}d t|ƒ¡d|kr2dkr@nn | d¡ndfV|d7}|dkr`d Vq|d krd Vd}q|dkr¨|d kr¢|d7}|dkršd Vd Vq|d Vd S)z• yield tuples of hex and ASCII display in multiples of 16. Includes a space after 8 bytes and (None, None) after 16 bytes and at the end. rz{:02X} ó óÚasciiÚ.éé)ú Úé)NN)z rN)ÚserialZ iterbytesÚformatÚordÚdecode)ÚdataÚnÚb©rúB/usr/lib/python3.9/site-packages/serial/urlhandler/protocol_spy.pyÚsixteen"s 6rccs|g}g}d}t|ƒD]b\}}|durb|d d |¡d |¡g¡fV|dd…=|dd…=|d7}q| |¡| |¡qdS)z yield lines with hexdump of datarNrr r )rÚjoinÚappend)rÚvaluesrÚoffsetÚhÚarrrÚhexdump9s     rc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) Ú FormatRawz&Forward only RX and TX data to output.cCs||_||_d|_d|_dS)Núú)ÚoutputÚcolorÚrx_colorÚtx_color©Úselfrr rrrÚ__init__LszFormatRaw.__init__cCs.|jr|j |j¡|j |¡|j ¡dS)zshow received dataN)r rÚwriter!Úflush©r$rrrrÚrxRs z FormatRaw.rxcCs.|jr|j |j¡|j |¡|j ¡dS)zshow transmitted dataN)r rr&r"r'r(rrrÚtxYs z FormatRaw.txcCsdS)z(do not) show control callsNr©r$ÚnameÚvaluerrrÚcontrol`szFormatRaw.controlN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r%r)r*r.rrrrrIs rc@s:eZdZdZdd„Zddd„Zdd„Zd d „Zd d „Zd S)Ú FormatHexdumpax Create a hex dump of RX ad TX data, show when control lines are read or written. output example:: 000000.000 Q-RX flushInput 000002.469 RTS inactive 000002.773 RTS active 000003.001 TX 48 45 4C 4C 4F HELLO 000003.102 RX 48 45 4C 4C 4F HELLO cCs,t ¡|_||_||_d|_d|_d|_dS)Nrrz)ÚtimeÚ start_timerr r!r"Ú control_colorr#rrrr%ts  zFormatHexdump.__init__r cCs&|j d ||||¡¡|j ¡dS)Nz{:010.3f} {:4} {}{} )rr&r r')r$Z timestampZlabelr-Zvalue2rrrÚ write_line|szFormatHexdump.write_linecCsh|jr|j |j¡|rLt|ƒD](\}}| t ¡|jdd |¡|¡q n| t ¡|jdd¡dS)zshow received data as hex dumpZRXú{:04X} zN) r rr&r!rr7r4r5r ©r$rrÚrowrrrr)€s $zFormatHexdump.rxcCsJ|jr|j |j¡t|ƒD](\}}| t ¡|jdd |¡|¡qdS)z!show transmitted data as hex dumpZTXr8N) r rr&r"rr7r4r5r r9rrrr*ŠszFormatHexdump.txcCs0|jr|j |j¡| t ¡|j||¡dS)zshow control callsN)r rr&r6r7r4r5r+rrrr.‘szFormatHexdump.controlN)r ) r/r0r1r2r%r7r)r*r.rrrrr3es   r3csTeZdZdZ‡fdd„Zejjjdd„ƒZdd„Z ‡fdd „Z d,‡fd d „ Z e ejd ƒrd‡fdd„Z e ejdƒr|‡fdd„Ze‡fdd„ƒZ‡fdd„Z‡fdd„Z‡fdd„Zd-‡fdd„ Zejjjdd„ƒZejjjd d!„ƒZejjjd"d#„ƒZejjj‡fd$d%„ƒZejjj‡fd&d'„ƒZejjj‡fd(d)„ƒZejjj‡fd*d+„ƒZ‡ZS).ÚSerialzc Inherit the native Serial port implementation and wrap all the methods and attributes. cs&tt|ƒj|i|¤Žd|_d|_dS)NF)Úsuperr;r%Ú formatterÚshow_all)r$ÚargsÚkwargs©Ú __class__rrr%ŸszSerial.__init__cCs"|durtjj || |¡¡dS©N)r r;ÚportÚ__set__Úfrom_url)r$r-rrrrD¤sz Serial.portc Csút |¡}|jdkr&t d |j¡¡‚t}d}tj}zrt  |j d¡  ¡D]Z\}}|dkrht |ddƒ}qH|dkrvd}qH|d kr„t }qH|d kr”d|_qHtd  |¡ƒ‚qHWn4tyÚ}zt d  |¡¡‚WYd }~n d }~00|||ƒ|_d |j|jg¡S)z(extract host and port from an URL stringZspyzmexpected a string in the form "spy://port[?option[=value][&option[=value]]]": not starting with spy:// ({!r})FTÚfilerÚwr ÚrawÚallzunknown option: {!r}zPexpected a string in the form "spy://port[?option[=value][&option[=value]]]": {}Nr )ÚurlparseÚurlsplitÚschemer ZSerialExceptionr r3ÚsysÚstderrÚparse_qsÚqueryÚitemsÚopenrr>Ú ValueErrorr=rÚnetlocÚpath) r$ÚurlÚpartsr=r rÚoptionrÚerrrrF©s:  þÿÿÿ zSerial.from_urlcs|j |¡tt|ƒ |¡SrC)r=r*r<r;r&)r$r*rArrr&Ès z Serial.writercs*tt|ƒ |¡}|s|jr&|j |¡|SrC)r<r;Úreadr>r=r))r$Úsizer)rArrr[Ìs  z Serial.readÚ cancel_readcs |j dd¡tt|ƒ ¡dS)NúQ-RXr])r=r.r<r;r]©r$rArrr]ÓszSerial.cancel_readÚ cancel_writecs |j dd¡tt|ƒ ¡dS)NúQ-TXr`)r=r.r<r;r`r_rArrr`ØszSerial.cancel_writecs*tt|ƒj}|jr&|j dd |¡¡|S)Nr^zin_waiting -> {})r<r;Ú in_waitingr>r=r.r )r$rrArrrbÜs zSerial.in_waitingcs |j dd¡tt|ƒ ¡dS)Nrar')r=r.r<r;r'r_rArrr'ãsz Serial.flushcs |j dd¡tt|ƒ ¡dS)Nr^Úreset_input_buffer)r=r.r<r;rcr_rArrrcçszSerial.reset_input_buffercs |j dd¡tt|ƒ ¡dS)NraÚreset_output_buffer)r=r.r<r;rdr_rArrrdëszSerial.reset_output_bufferçÐ?cs(|j dd |¡¡tt|ƒ |¡dS)NÚBRKzsend_break {}s)r=r.r r<r;Ú send_break)r$ZdurationrArrrgïszSerial.send_breakcCs*|j d|rdnd¡tjj ||¡dS)NrfÚactiveÚinactive)r=r.r r;Úbreak_conditionrE©r$ÚlevelrrrrjószSerial.break_conditioncCs*|j d|rdnd¡tjj ||¡dS)NZRTSrhri)r=r.r r;ÚrtsrErkrrrrmøsz Serial.rtscCs*|j d|rdnd¡tjj ||¡dS)NZDTRrhri)r=r.r r;ÚdtrrErkrrrrnýsz Serial.dtrcs&tt|ƒj}|j d|rdnd¡|S)NZCTSrhri)r<r;Úctsr=r.rkrArrros z Serial.ctscs&tt|ƒj}|j d|rdnd¡|S)NZDSRrhri)r<r;Údsrr=r.rkrArrrps z Serial.dsrcs&tt|ƒj}|j d|rdnd¡|S)NZRIrhri)r<r;Úrir=r.rkrArrrqs z Serial.rics&tt|ƒj}|j d|rdnd¡|S)NZCDrhri)r<r;Úcdr=r.rkrArrrrs z Serial.cd)r)re)r/r0r1r2r%r r;rDÚsetterrFr&r[Úhasattrr]r`Úpropertyrbr'rcrdrgrjrmrnroÚgetterrprqrrÚ __classcell__rrrArr;˜s>             r;Ú__main__zspy:///dev/ttyS0)rNr4r rKÚ ImportErrorÚ urllib.parseÚparserrÚobjectrr3r;r/ZserrDÚprintrrrrÚs   3