Skip to main content

29 posts tagged with "embedded"

View All Tags

· 3 min read
Nicolas Rabault

A try-catch block is a language construct used in programming that allows a programmer to handle errors or exceptions in their code. The try block contains code that may throw an exception, and the catch block catches and handles that exception if it is thrown.

try
do_something_risky()
catch
print "The risky thing just failed."

Many modern programming languages, including JS, Python, and C++, have built-in support for try-catch blocks. However, the C programming language does not provide this functionality out of the box.

Why should you use try-catch?

The ability to handle exceptions in code is extremely useful for a number of reasons. First and foremost, it allows a program to gracefully handle errors or exceptional situations that may arise during execution. This can prevent the program from crashing or behaving unpredictably. In the case of embedded code, try-catch statements are particularly useful for writing your unit tests.

In embedded code, you probably use an assert function to handle errors, allowing you to check some conditions and manage critical situations. Most of the time, those assert functions display a log or traces and stop the program.

Let’s take a simple function as a reference:

void assert(bool statement)
{
if (!statement)
{
printf("This is bad\n");
while(1);
}
}

int freq(int period){
assert(period != 0);
return 1/period;
}

int main() {
freq(0); // divide by zero to assert
}

In this example, the main function will properly assert in the freq function if the value is 0.

When you create your unit test to validate the freq functions, you will have to check all possible values of period, but you don’t want your test to stop its execution by testings the limits. This is where you need a try-catch block.

How to create a try-catch bloc in C?

C does not have built-in support for try-catch blocks, but it is possible to create a similar construct using macros and the standards setjmp.h lib. Here's an example of how to create a simple try-catch macro in C following our previous example:

#include <setjmp.h>

jmp_buf ex_buf;

#define TRY if (setjmp(ex_buf) == 0)
#define CATCH else
#define THROW longjmp(ex_buf, 1)

void assert(bool statement)
{
if (!statement)
{
printf("This is bad\n");
THROW;
while(1);
}
}

int freq(int period){
assert(period!=0);
return 1/period;
}

int main() {
TRY {
// Code that may throw an exception
freq(0); // Divide by zero to throw an exception
}
CATCH {
// Handle the exception
printf("An exception occurred, the test just failed\n");
}

return 0;
}

This macro defines a TRY block, using a jmp_buf variable to check if an exception has been thrown and to save the current context. If no exception has been thrown, the code in the TRY block is executed.

If the THROW macro is called, the code will jump back to the setjmp function of the TRY block and restore the saved context. Then the setjmp function will return the integer passed to the longjmp(in this case, 1). So if an exception is thrown, the if statement of the second execution of the TRY macro will be false and the CATCH block will be executed instead.

In the example above, the code in the TRY block attempts to divide by zero, which will throw an exception. This will jump back on the TRY macro and make the if statement fail. The CATCH block catches the exception and prints a message into the console.

While this macro is a simplified version of a try-catch block, it demonstrates how a similar construct can be implemented in C.

caution

Please note that the following try-catch code is not suitable for use in a production environment. While it was designed for a specific, well-controlled unit test environment, it may cause issues with nested calls or multi-process situations. Therefore, we cannot guarantee its safety or reliability.

Please use this code at your own risk.

If you want a practical example of try catch usage, you can check out the Luos unit tests and try-catch macro.

In conclusion, try-catch blocks are a powerful tool for handling errors and exceptions in code. While the C programming language does not provide built-in support for this functionality, it is possible to create a close behavior using macros. By using try-catch blocks, programmers can make their unit-test simpler.

We advise that you thoroughly consider the risks associated with using this before proceeding.

Get started with Luos

· 4 min read
Nicolas Rabault

This article was originally for Techcrunch (available with a Techcrunch+ subscription).

The complexity associated with the development of embedded systems is increasing rapidly. For instance, it is estimated that the average complexity of software projects in the automotive industry has grown 300% over the past decade.

Today, every piece of hardware is driven by software, and most hardware is composed of multiple electronic boards running synchronized applications. Devices have more and more features, but adding features means increasing development and debugging complexity. A University of Cambridge report found that developers spend up to 50% of their programming time debugging. But there are practical ways to reduce the complex debugging of embedded systems. Let’s explore those.

· 4 min read
Nicolas Rabault

Getting started with Luos is quick and easy, however until now you were obligated to have the compatible hardware to do so.

In order to resolve this issue and make Luos accessible to anyone, we have been working on an alternative to get started without a physical board, the Luos Native.

This new feature allows you to compile and run Luos directly on your computer, eliminating the need for hardware at the beginning.

As a result, you can develop and test your Luos projects in a computer environment.

· 2 min read
Nicolas Lorenzi

While microservices are often used for building large and complex software applications, cyber-physical systems are typically used for building software systems embedded in physical devices and with a direct impact on the physical world. Let's discover the benefits and challenges of using philosophies such as microservices to develop cyber-physical systems.

· 3 min read
Nicolas Lorenzi

As we mentioned on our previous article, cyber-physical systems (CPS) are a type of systems that integrates computational and physical elements to perform tasks that involve both the physical world and the digital world. These systems are used in various applications, from manufacturing and transportation to healthcare and energy production. We are surrounded by them.

· 8 min read
Alexis Gorlier

Create an amateur space rocket using Luos by Alexgorl#3053

First, let me introduce myself. My name is Alexis Gorlier; I am a student in aerospace engineering at ESTACA (a French school specializing in mobilities). I'm very invested in an association named ESO (Estaca Space Odyssey), which is part of my school and allows students to work on real space projects. This article will present a project I am working on in my association, and show the issues linked to this project.

· 8 min read
Nicolas Rabault

A few days ago, we held our first live Q&A session on Discord, and it was a pleasure to exchange with all of you. This session was organized on August 10, 2022.

If you missed it or want to discover it again, we have concatenated all your questions in this article and completed them with precise answers.

If you have other questions concerning Luos, our open source project, or the embedded world, feel free to join our Discord community. We are +4000 community as of right now and keep in touch with our members daily to create a strong community and an inspiring place for everyone.

· 5 min read
Nicolas Lorenzi

At Luos, we often talk about embedded systems and edge, but a term often resurfaces in our everyday vocabulary: Cyber-physical systems (CPS).

This is the term that best describes the type of smart system Luos can manage since it is totally designed as a network of MCU that interact with each other through physical inputs and outputs. CPSs are, therefore, somewhat different from embedded and edge systems, which are autonomous interacting devices.

· 5 min read
Nicolas Rabault

What is the problem here?

At Luos, we deal with distributed (multi-MCU) critical and real-time environments. Everything in our technology has been thought to be fast and lightweight. The Robus protocol (our basic protocol) has been designed to have the minimal latency possible, but we still have some!

· 4 min read
James Langbridge

Let's talk about Embedded Services.

A family photo shared on a social network. An interesting news article. A funny video of a cat. It all starts with a website. A website needs a few things, notably a database. You ask for the website for your link, and the website gets data from different services, formats it into something pretty, and then returns that to you. The World Wide Web is literally that, a web of services. Websites fetching data from other websites, from databases, from authentification services, from data storage servers... And you don't need to know where those services are. They might be located on the same server, or they might be in the same building, or they might even be on the other side of the planet. Everything just works.

· 3 min read
James Langbridge

Imagine the liberty of being on a sailboat, alone, in the middle of the ocean. What skills would you require for that? First of all, basic (or even advanced) knowledge of sailing, you are all alone, with only the wind to help you move. Secondly, navigation, the art of knowing where you are, where you want to go, and how. Cooking, there are no delivery services possible, and you need to survive for over a month. Medical skills, if something goes wrong and you hurt yourself, you are the only first responder. Maintenance, fixing things that break down? And this is only part of a very long list.

· 3 min read
Emanuel Allely

The issue. To talk about Edge and Embedded systems, let’s consider the place where related issues are their climax: Robotics. For a long time now, there has been talks of a robotic revolution that seems to be continually pushed back to the next day. Robot vacuum cleaners, IOT, the autonomous cars are the beginnings of this change. But why is it so slow?

· 10 min read
Simon Baudry

This article is about the path taken during a couple years to explain what Luos is. Although Luos is a name for the company and the technology behind it, it’s the technology in particular I will mostly talk about, and how we sometimes struggled to explain it. Regarding the company in general, we will see why Luos is not a robotics company.