Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read with timeout feature #165

Merged
merged 9 commits into from
Mar 30, 2024
Merged

Add read with timeout feature #165

merged 9 commits into from
Mar 30, 2024

Conversation

Baldanos
Copy link
Collaborator

Based on #164 this PR adds a read with timeout feature.

  1. Add a timeout keyword to set timeout in miliseconds on all relevant modes (UART, LIN, Smartcard)
  2. Change read and hd commands behavior. They now display read bytes and show an message if not every byte requested could be read
  3. Some cleanup of now unused functions

Example with UART in loopback mode:

> uart 
Device: UART1
Speed: 9600 bps
Parity: none
Stop bits: 1
Timeout: 10000 msec
uart1> timeout 1000
uart1> show 
Device: UART1
Speed: 9600 bps
Parity: none
Stop bits: 1
Timeout: 1000 msec
uart1> 0x41 r:8
WRITE: 0x41
! TIMEOUT: read 1 out of 8
READ: 0x41
uart1> 0x41 hd:8
WRITE: 0x41
41                                                |  A 
! TIMEOUT: read 1 out of 8
uart1>

This might need to be further tested before being included. Maybe @bvernoux and @0xDRRB could do some tests ?

@Baldanos Baldanos self-assigned this Feb 23, 2024
@0xDRRB
Copy link
Contributor

0xDRRB commented Feb 23, 2024

I've just tested it with a smartcard and it works like a charm:

> smartcard 
Device: SMARTCARD1
Speed: 9408 bps
Parity: even
Stop bits: 1.5
Convention: normal
Prescaler: 12 / 3.50mhz
Timeout: 10000 msec

smartcard1> timeout 2000

smartcard1> ]%%[read:33 
RST DOWN
DELAY: 1 ms
DELAY: 1 ms
RST UP
! TIMEOUT: read 18 out of 33
READ: 0x3B 0xF8 0x13 0x00 0x00 0x81 0x31 0xFE 0x45 0x4A 0x43 0x4F 0x50 0x76 0x32 0x34 0x31 0xB7 
smartcard1> 0x00 0x00 0x0f 0x00 0xa4 0x04 0x00 0x0a 0xf2 0x76 0xa2 0x88 0xbc 0xde 0xad 0xbe 0xef 0x01 0x94 % read:18 
WRITE: 0x00 0x00 0x0F 0x00 0xA4 0x04 0x00 0x0A 0xF2 0x76 0xA2 0x88 0xBC 0xDE 0xAD 0xBE 0xEF 0x01 0x94 
DELAY: 1 ms
! TIMEOUT: read 6 out of 18
READ: 0x00 0x00 0x02 0x90 0x00 0x92 

The fact that using the atr command resets the timeout to the default value (10000ms) is annoying but, as @bvernoux pointed out in #164, 10000ms is huge and could be reduced to 1000 or 2000, which would mitigate the problem.

Having said that, the atr command isn't really useful now that a ]%%[read:33 does the job without a hitch.

(It would be great to be able to define aliases for certain recurring commands, like "alias atr = ]%%[read:33" or something like that. Maybe loaded from the MMC as a text file like smartcard.aliases, uart.aliases, spi.aliases)

I'll do some more tests over the weekend and let you know if I come across any problems.

@bvernoux
Copy link
Member

I've just tested it with a smartcard and it works like a charm:

> smartcard 
Device: SMARTCARD1
Speed: 9408 bps
Parity: even
Stop bits: 1.5
Convention: normal
Prescaler: 12 / 3.50mhz
Timeout: 10000 msec

smartcard1> timeout 2000

smartcard1> ]%%[read:33 
RST DOWN
DELAY: 1 ms
DELAY: 1 ms
RST UP
! TIMEOUT: read 18 out of 33
READ: 0x3B 0xF8 0x13 0x00 0x00 0x81 0x31 0xFE 0x45 0x4A 0x43 0x4F 0x50 0x76 0x32 0x34 0x31 0xB7 
smartcard1> 0x00 0x00 0x0f 0x00 0xa4 0x04 0x00 0x0a 0xf2 0x76 0xa2 0x88 0xbc 0xde 0xad 0xbe 0xef 0x01 0x94 % read:18 
WRITE: 0x00 0x00 0x0F 0x00 0xA4 0x04 0x00 0x0A 0xF2 0x76 0xA2 0x88 0xBC 0xDE 0xAD 0xBE 0xEF 0x01 0x94 
DELAY: 1 ms
! TIMEOUT: read 6 out of 18
READ: 0x00 0x00 0x02 0x90 0x00 0x92 

The fact that using the atr command resets the timeout to the default value (10000ms) is annoying but, as @bvernoux pointed out in #164, 10000ms is huge and could be reduced to 1000 or 2000, which would mitigate the problem.

Thanks for the fast feedback

Yes we shall clearly change that default timeout to something smaller more realistic (even on big command with big answer which shall in theory take less than 2s in majority of cases)

Having said that, the atr command isn't really useful now that a ]%%[read:33 does the job without a hitch.

(It would be great to be able to define aliases for certain recurring commands, like "alias atr = ]%%[read:33" or something like that. Maybe loaded from the MMC as a text file like smartcard.aliases, uart.aliases, spi.aliases)

Could you create an issue about the alias (as new feature) ?

I'll do some more tests over the weekend and let you know if I come across any problems.

@Baldanos
Copy link
Collaborator Author

Thank you both for testing ;)

We can totally lower the default timeout values.

Regarding the atr command, the fact that it parses and displays the timing information is a good reason to keep it. I'll push a fix in this PR so it reuses the current timeout.

@bvernoux
Copy link
Member

Maybe add that feature on Wiegand also (I have tested uart with success)

@Baldanos
Copy link
Collaborator Author

Maybe add that feature on Wiegand also (I have tested uart with success)

I did a quick check, and Wiegand could use a full rewrite.
Unfortunately I do not have access to a Wiegand interface so I would not attempt such rewrite without tests.

@bvernoux
Copy link
Member

Maybe add that feature on Wiegand also (I have tested uart with success)

I did a quick check, and Wiegand could use a full rewrite. Unfortunately I do not have access to a Wiegand interface so I would not attempt such rewrite without tests.

Wiegand is clearly not a priority, I have nothing to test it too (so far) so keep that for future potential improvement

@Baldanos Baldanos merged commit 80e8bb7 into hydrabus:master Mar 30, 2024
@Baldanos Baldanos deleted the timeout branch April 12, 2024 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants