SmartPower3 keeps printing "Unknown command"

Post Reply
connorimes
Posts: 15
Joined: Tue May 13, 2014 6:47 am
languages_spoken: english
ODROIDs: XU+E
XU3
XU4
Smart Power
Smart Power 3
Has thanked: 0
Been thanked: 3 times
Contact:

SmartPower3 keeps printing "Unknown command"

Post by connorimes »

I'm using serial logging to capture results from my SmartPower3, but seems to be stuck in some kind of error state where it keeps printing ">>> Unknown command <<<" every 50 ms or so. Cycling the device power doesn't resolve the issue - it seems to remember its state after power is restored. I ran into the problem once before and used the opportunity to re-flash the firmware, but only because I hoped the newest firmware would resolve the issue. How can I reset the device without re-flashing it?

As a result of the the error message being printed to the serial port, I end up having difficulty parsing the interleaved log messages. I suspect the problem is because the normal logging ends its lines with "\r\n", but other messages use "\n\r", which throws off my strict parsing. Why the difference?

I'm using the latest 20230518-v2.2 firmware.

Thanks.

User avatar
mad_ady
Posts: 11988
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4 (HC1, HC2), C1+, C2, C4 (HC4), N1, N2, N2L, H2, H3+, Go, Go Advance, M1, M1S
Location: Bucharest, Romania
Has thanked: 662 times
Been thanked: 1280 times
Contact:

Re: SmartPower3 keeps printing "Unknown command"

Post by mad_ady »

Are you sending anything to the SP3? That might cause it to spit errors. Try connecting via screen (screen /dev/ttyUSB0 115200) with the correct baud and see if it happens.

User avatar
mctom
Posts: 3992
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polski
ODROIDs: XU4, M1, H3+, SP3, N2L, M1S, N2
Location: Gdańsk, Poland
Has thanked: 585 times
Been thanked: 783 times
Contact:

Re: SmartPower3 keeps printing "Unknown command"

Post by mctom »

Depending on your logging technique, perhaps you're echoing SP3's output back to it, maybe?
Punk ain't no religious cult, punk means thinking for yourself!
OpenUPS
PiStackMon

connorimes
Posts: 15
Joined: Tue May 13, 2014 6:47 am
languages_spoken: english
ODROIDs: XU+E
XU3
XU4
Smart Power
Smart Power 3
Has thanked: 0
Been thanked: 3 times
Contact:

Re: SmartPower3 keeps printing "Unknown command"

Post by connorimes »

Thanks for your responses. My application is written in C, and I don't ever write data to the device. I was opening the device file with O_RDWR, but I'll open with O_RDONLY going forward. As far as I can tell, the data I read from the SmartPower3 is different than usual. E.g., normally I get an output like:

Code: Select all

0007576805,15332,0037,00567,0,00000,0000,00000,0,00,00000,0000,00000,0,00,0c,14\r\n
But instead I was getting something like (note the absence of the `\r` character):

Code: Select all

0007309966,15329,0035,00536,0,00000,0000,00000,0,00,00001,0000,00000,0,00,09,13\n
Connecting with screen seems to have done something to stop the issue---for now at least---but I wouldn't be surprised if it reappears at some point.
This seems very strange. I can only speculate, but perhaps some kind of bug or dynamic configuration change in the serial driver on the SmartPower3 device (or even a problem with the cp210x Linux driver)?

It would be nice if there were a way to force the device to reboot in a clean configuration in case of runtime problems like these, e.g., by holding the main button for several seconds without the need to issue commands from a terminal.

User avatar
odroid
Site Admin
Posts: 42297
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 3648 times
Been thanked: 2016 times
Contact:

Re: SmartPower3 keeps printing "Unknown command"

Post by odroid »

It's been over two years since SmartPower3 was released, and this is the first report I've heard of.
Does this mean that if you run the screen program and your parsing program at the same time, both \r and \n after the data will always come in?
Which Linux distro and Kernel version do you use on your host PC?

connorimes
Posts: 15
Joined: Tue May 13, 2014 6:47 am
languages_spoken: english
ODROIDs: XU+E
XU3
XU4
Smart Power
Smart Power 3
Has thanked: 0
Been thanked: 3 times
Contact:

Re: SmartPower3 keeps printing "Unknown command"

Post by connorimes »

I can't really run both screen and my program at the same time -- my program will quickly encounter an EAGAIN ("Resource temporarily unavailable") error on read and then exit. This isn't surprising since both applications are trying to read from the device simultaneously, I'd assume that screen is just more forgiving of read errors.

The ODROID Smart Power 3 host-side code I've run across appears to all be Python, and I expect the serial package being used is somewhat more robust and may cleanly handle line endings / carriage returns for the user. However, I'm working in C and my parsing is pretty strict. I may be able to better detect and handle this error message at runtime if I enable raw mode (cfmakeraw), since it seems like maybe the host-side driver is trying to handle carriage returns for me, perhaps b/c it's in canonical mode by default. I'm not an expert on working with serial devices though, so I might be grasping.

I think the real problem here is less about line endings and more about why the device seemed to think it was receiving any commands at all. I don't make any explicit writes to the device. I also don't know how to reproduce the issue since the problem resolved when I first ran screen.

I'm running a Debian 12 (stable) host with kernel 6.1.0-17-amd64.

Thanks.

P.S. I'm also wondering why the latest firmware versions don't seem to be tagged on GitHub? The latest I see at https://github.com/hardkernel/smartpower3 is v2022/02/22. Cheers.

User avatar
mctom
Posts: 3992
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polski
ODROIDs: XU4, M1, H3+, SP3, N2L, M1S, N2
Location: Gdańsk, Poland
Has thanked: 585 times
Been thanked: 783 times
Contact:

Re: SmartPower3 keeps printing "Unknown command"

Post by mctom »

connorimes wrote:
Wed Apr 03, 2024 10:49 am
I think the real problem here is less about line endings and more about why the device seemed to think it was receiving any commands at all.
Probably because it did, and I think it's safe to assume that SP3's firmware is fine.

Your problems may return after reboot.

tty driver on Linux is more complicated than explicit reads and writes. stty utility can be used to read and write tty configuration.
screen probably applies its own settings to tty, as it assumes the given tty will be used as a terminal, and not a modem or a computer mouse.
using stty, you can determine what changes in tty configuration.

I would bet a modest sum on disabling echo. :)
viewtopic.php?p=355589#p355589
Punk ain't no religious cult, punk means thinking for yourself!
OpenUPS
PiStackMon

User avatar
odroid
Site Admin
Posts: 42297
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 3648 times
Been thanked: 2016 times
Contact:

Re: SmartPower3 keeps printing "Unknown command"

Post by odroid »

Once you can reproduce the issue, let us know how we can reproduce for debugging.
connorimes wrote:
Wed Apr 03, 2024 10:49 am
P.S. I'm also wondering why the latest firmware versions don't seem to be tagged on GitHub?
A new developer didn't know how to use GitHub, so he just compressed the entire changed source code and uploaded it to the WiKi page. :oops:

connorimes
Posts: 15
Joined: Tue May 13, 2014 6:47 am
languages_spoken: english
ODROIDs: XU+E
XU3
XU4
Smart Power
Smart Power 3
Has thanked: 0
Been thanked: 3 times
Contact:

Re: SmartPower3 keeps printing "Unknown command"

Post by connorimes »

mctom wrote:
Wed Apr 03, 2024 2:50 pm
connorimes wrote:
Wed Apr 03, 2024 10:49 am
I think the real problem here is less about line endings and more about why the device seemed to think it was receiving any commands at all.
Probably because it did, and I think it's safe to assume that SP3's firmware is fine.
I tend to agree. In my earlier post I only meant to speculate on a possible problem in the serial driver the firmware packages.
mctom wrote:
Wed Apr 03, 2024 2:50 pm
I would bet a modest sum on disabling echo. :)
viewtopic.php?p=355589#p355589
I am also leaning this direction, so IIUC using raw mode should avoid echoing. I initially (and I gather incorrectly) assumed that only the device side might echo, not the host system. The appearance and then disappearance of the problem suggests some inconsistency though, which is why I thought there might be a problem on either end, e.g., the device serial driver not ignoring echoed data if/when it should (if ever), but again, speculation without hard evidence....
odroid wrote:
Wed Apr 03, 2024 4:07 pm
Once you can reproduce the issue, let us know how we can reproduce for debugging.
If I can, I certainly will. My priority is to avoid it altogether though and finish my library development.

I'll also share my code here on the forums soon, in case anyone is interested in a C API for polling a SmartPower3.
odroid wrote:
Wed Apr 03, 2024 4:07 pm
connorimes wrote:
Wed Apr 03, 2024 10:49 am
P.S. I'm also wondering why the latest firmware versions don't seem to be tagged on GitHub?
A new developer didn't know how to use GitHub, so he just compressed the entire changed source code and uploaded it to the WiKi page. :oops:
LOL, well that's nice if you to accept it anyway. Were the changes later manually merged into the GitHub repository at least?

User avatar
mctom
Posts: 3992
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polski
ODROIDs: XU4, M1, H3+, SP3, N2L, M1S, N2
Location: Gdańsk, Poland
Has thanked: 585 times
Been thanked: 783 times
Contact:

Re: SmartPower3 keeps printing "Unknown command"

Post by mctom »

connorimes wrote:
Wed Apr 03, 2024 10:15 pm
I am also leaning this direction, so IIUC using raw mode should avoid echoing. I initially (and I gather incorrectly) assumed that only the device side might echo, not the host system. The appearance and then disappearance of the problem suggests some inconsistency though, which is why I thought there might be a problem on either end, e.g., the device serial driver not ignoring echoed data if/when it should (if ever), but again, speculation without hard evidence....
I think raw mode is the best for parsing data in your C program. It should pass everything faithfully, including control characters (0x00 - 0x0f) including newlines. By the way, that's why you may have seen newlines swallowed or added by the driver. By default it processes data in chunks separated by newlines and can manipulate newlines, and so on.
Raw mode is the closest to what you have expected.

The concept of "host and device" is not a part of UART specification, and the system designer might as well make two identical devices talking to each other via UART with no master. There is no difference in hardware implementation, and thus there's no basis to assume your programmable UART interface's capabilities. Every programmable UART port can echo data back, if the designer decides to do so.

tty driver's designer clearly thought that echo is an important feature, but it has more flags and configuration options. Part of the reason is support of legacy RS-232 ports and tons of vintage devices that used to be plugged into them. I have a RS-232 thermal printer right here that I use for printing quick notes. It took me a while to find a combination of flags that let me simply cat a file into tty and have it printed.
Just so you know why someone planted that bomb ~50 years ago. :)
Punk ain't no religious cult, punk means thinking for yourself!
OpenUPS
PiStackMon

Post Reply

Return to “Smart Power”

Who is online

Users browsing this forum: No registered users and 1 guest