Function failure

Post here first, or if you can't find a relevant section!
Post Reply
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Function failure

Post by mebab »

This might not be specific to STM32 based platforms for codes written in Arduino IDE. But, you may have an idea that can help me a lot.
I provide an array of compressed data to be decompressed by a function. There might be wrong data in that array that is not detectable in advance. If that function fails, the application will halt. Is there any way to prevent this other than manipulating the function itself? Something like on error or so?
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Function failure

Post by mrburnette »

The topic is too complex for a simple forum answer:
But, here are some resources which may prove useful:
https://www.google.com/search?q=arduino ... r+recovery
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Function failure

Post by mebab »

Thank you mrburnette! Still looking for an appropriate solution.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Function failure

Post by mrburnette »

mebab wrote: Fri Nov 19, 2021 4:51 pm Thank you mrburnette! Still looking for an appropriate solution.
Just remember that a multitude of OS hacks rely upon function bad-behavior, such as buffer overflow. Without an OS or thread manager, essentially the return from any failed function can leave SRAM or the processor stack is a trashed condition.

But since Arduino is C++, you can review the best practice guidelines:

https://isocpp.org/wiki/faq/exceptions

Exception handling on a uC can be very resource impacting.

Ray
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Function failure

Post by ag123 »

On tiny mcus (including stm32), it may be pretty expensive to do all that, e.g. c++ exception handling, it will bloat your binaries so much it may not even fit on the mcu.
what would be more appropriate is to make well behaved functions, e.g. c functions can return an int as a status.

I remembered somewhere (old forum) where simply making a new object say
ptr = new MyClass;
it bloat memory so much, it hard faults - out of memory. We forgot things like stm32f103c8 has 20k sram, not 2 GB ram.
ideally, if you can use things like new to make new objects, and with dynamic memory management, we can do pretty fancy things.
those probably works on mcus with more sram or external memory.

we're just 'borderline' above 'bare metal', literally
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Function failure

Post by mebab »

Thanks for both comments of mrburnette and ag123!
and
...functions can return an int as a status
The above hints might help. I will work around those directions and will give feedback as soon as I get an answer. Maybe I have to deep dive into the function to see where it is failed with the wrong data array.

Thanks again,
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Function failure

Post by mrburnette »

mebab wrote: Fri Nov 19, 2021 8:59 pm ...
Maybe I have to deep dive into the function to see where it is failed with the wrong data array.
This brings up the testing methodology around "know good data" and the need to have a dataset (file, function generator, or other source) for providing you "good test data.: The real-world is cruel.

When writing the Magic Morse algorithm, I used training recordings posted by ARRL for various test speeds.

When writing my GPS NMEA decoder for a clock/calendar, I took GPS serial data, ran it through 2 GPS libraries to verify and then programmed that into my QBF (Quick Brown Fox) ASCII generator. Then I had a known input set with a known output solution.

Libraries and black-boxes are the bane of every programmer! Unfortunately, IMO, Arduino teaches too many people how to plagiarize with cut & pasts and fails generally in driving a deep understanding of C/C++ programming.

QBF:
https://forum.arduino.cc/t/the-qbf-the- ... ags/229468

You can store any outgoing message in QBF, even binary, and use it as a serial input.

Ray
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Function failure

Post by mebab »

...Libraries and black-boxes are the bane of every programmer!
Great and informative words!
Just wanted to add more descriptions on the source of the failure:
I almost can control everything in my star-based networked application except for a very little probability of concurrency of receiving compressed data from one sensor node together with other data from other nodes.
Having a CSMA protocol cannot prevent congestion issues as much as 100 %. For example, when the channel is free for all nodes and by chance, two nodes start to transmit simultaneously, in very rare situations, the received mixed signal of two nodes can be read like a normal one. This corrupts the original compressed data and causes failure while decompression.

This source of failure may happen once a day in a very busy network of many active nodes where all try to communicate with the center and send data. This might not happen in the reality but I have to consider the worst-case scenarios.

Thanks again,
Mehrdad
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Function failure

Post by mrburnette »

mebab wrote: Sat Nov 20, 2021 4:17 am ...
Having a CSMA protocol cannot prevent congestion issues as much as 100 %. For example, when the channel is free for all nodes and by chance, two nodes start to transmit simultaneously, in very rare situations, the received mixed signal of two nodes can be read like a normal one. This corrupts the original compressed data and causes failure while decompression.
...
I'm old and out-of-touch with many "modern colloquial expressions", but in my time I would have said simply, bummer!
CSMA Enh.JPG
CSMA Enh.JPG (74.37 KiB) Viewed 2548 times
I'm a TCP kind of guy and I need never worry about such issues.

Ray
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Function failure

Post by mebab »

Thanks Ray! I am really learning from you and appreciate that.

This is my experience using Carrier-sense multiple access (CSMA) in a Lora node-to-node communication:
Having a LoRa node in a single RX mode (not continuous) needs us to activate RX mode to check the channel to see if it is free. Then change the mode to TX for a transmission. Every mode change (RX-->TX) needs a short transition time before being able to transmit. In addition, nodes are located at different distances and we consider different times on air for each node. Then, in crowded networks, there is a rare chance that one or even more sensor node/s see also the same channel free and start to transmit during the mentioned variable periods.
My experiments show that: the received signal in the central LoRa node may be corrupted which is detectable with no extra effort. However, there is another very little probability where the center receives for example numeric data simultaneously from different sources (nodes) and mixes them. This was a root cause of a rare failure in my system when communicating without Acknowledgement (ACK).

Thanks again for your time and responsibility!
Mehrdad
Post Reply

Return to “General discussion”