-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
157 changed files
with
9,578 additions
and
6,835 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
[![CI](https://github.com/lf-lang/examples-lingua-franca/actions/workflows/ci.yml/badge.svg)](https://github.com/lf-lang/examples-lingua-franca/actions/workflows/ci.yml) | ||
|
||
## 🛝 Lingua Franca Playground | ||
Get to know the language and tinker with some example Lingua Franca programs! | ||
Get to know the [Lingua Franca coordination language](https://lf-lang.org) and browse [example programs](examples/README.md). | ||
To view, edit, and run the programs, you can either run locally on your computer or run in the cloud using either GitHub Codespaces or Gitpod. | ||
|
||
### :rocket: Cloud-based dev environment | ||
## 💻 Running Locally | ||
Quick start: | ||
|
||
1. Clone this repo (`git clone [email protected]:lf-lang/playground-lingua-franca.git`) | ||
2. Open with [VS Code](https://code.visualstudio.com) (`code playground-lingua-franca`) | ||
3. Install the [Lingua Franca extension](https://github.com/lf-lang/vscode-lingua-franca) (<kbd>Ctrl</kbd>+<kbd>P</kbd> and enter `ext install lf-lang.vscode-lingua-franca`). | ||
|
||
Once in VSCode, navigate to [./examples](./examples) and click on any of the `.lf` files to open them into your editor. To build and run, use <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> and select `Lingua Franca: Build and Run`. Note: You might need not install additional dependencies in order to successfully build some of the code you find in this repository. For more information, see the [setup-env.bash](./utils/scripts/setup-env.bash) script that we use to configure our Docker-based environments. | ||
|
||
|
||
## :rocket: Running in the Cloud | ||
Spin up a fully configured dev environment in the cloud that start in seconds. | ||
Any dependencies required for building or running any of the examples are preinstalled. | ||
A web-based VS Code editor, preloaded with the Lingua Franca extension, is accessible through either **GitHub Codespaces** or **GitPod**. Simply click on either of the links below to get started. | ||
|
||
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&repo=477928779&ref=main&skip_quickstart=true&devcontainer_path=.devcontainer%2Fnightly%2Fdevcontainer.json) | ||
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&repo=477928779&ref=main&skip_quickstart=true&devcontainer_path=.devcontainer%2Fnightly%2Fdevcontainer.json) (NOTE: This can be quite slow to start.) | ||
|
||
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/new#https://github.com/lf-lang/playground-lingua-franca/tree/main) | ||
|
||
|
@@ -32,9 +43,3 @@ bash ./utils/scripts/setup-lf.bash dev | |
|
||
Please note that running these commands will remove the current lingua-franca directory. | ||
|
||
## 💻 Local dev environment | ||
1. Clone this repo (`git clone [email protected]:lf-lang/playground-lingua-franca.git`) | ||
2. Open with VS Code (`code playground-lingua-franca`) | ||
3. Install the [Lingua Franca extension](https://github.com/lf-lang/vscode-lingua-franca) (<kbd>Ctrl</kbd>+<kbd>P</kbd> and enter `ext install lf-lang.vscode-lingua-franca`). | ||
|
||
Once in VSCode, navigate to [./examples](./examples) and click on any of the `.lf` files to open them into your editor. To build and run, use <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> and select `Lingua Franca: Build and Run`. Note: You might need not install additional dependencies in order to successfully build some of the code you find in this repository. For more information, see the [setup-env.bash](./utils/scripts/setup-env.bash) script that we use to configure our Docker-based environments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
# C Examples | ||
* [Patterns](src/patterns/README.md): Common communication patterns. | ||
|
||
(in alphabetical order) | ||
|
||
* [Browser UIs](src/browser-ui/README.md): How to create a browser-based UI for an LF program. | ||
* [Car Brake](src/car-brake/README.md): Sketch of ADAS system illustrating the CAL theorem. | ||
* [Deadlines](src/deadlines/README.md): Uses of deadlines in Lingua Franca. | ||
* [Car Brake](src/car-brake/README.md): Sketch of ADAS system illustrating CAL theorem. | ||
* [Rosace](src/rosace/README.md): Aircraft controller illustrating periodic systems with multiple periods. | ||
* [Simulation](src/simulation/README.md): Using Lingua Franca for simulation. | ||
* [Distributed](src/distributed/README.md): Basic federated hello-world examples. | ||
* [Furuta Pendulum](src/modal_models/FurutaPendulum/README.md): A controller and simulation illustrating a modal reactor. | ||
* [Keyboard](src/keyboard/README.md): Responding to keyboard input using ncurses. | ||
* [Leader Election](src/leader-election/README.md): Federated fault-tolerant system with leader election. | ||
* [MQTT](src/mqtt/README.md): Interacting with MQTT-based services. | ||
* [Furuta Pendulum](src/modal_models/FurutaPendulum/README.md): A controller and simulation illustrating a modal reactor. | ||
* [Patterns](src/patterns/README.md): Common communication patterns. | ||
* [Rhythm](src/rhythm/README.md): Sound generation and terminal user interface demos. | ||
* [Rosace](src/rosace/README.md): Aircraft controller illustrating periodic systems with multiple periods. | ||
* [SDV](src/sdv/README.md): Software defined vehicle sketch integrating user input, a web display, and sound. | ||
* [Shared Memory](src/shared-memory/README.md): Using shared memory to exchange large data objects between federates. | ||
* [Simulation](src/simulation/README.md): Using Lingua Franca for simulation. | ||
* [Train Door](src/train-door/README.md): Train door controller from a verification paper. | ||
* [Distributed](src/distributed/README.md): Basic federated hello-world examples. | ||
* [Watchdog](src/watchdog/README.md): Federated illustration of watchdogs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Browser UI | ||
|
||
These examples show how to create user interfaces for a Lingua Franca program. | ||
The UI runs in the browser and connects to the program via either HTTP or via a web socket. | ||
|
||
<table> | ||
<tr> | ||
<td> <img src="img/BrowserUI.png" alt="BrowserUI" width="400"> | ||
<td> <a href="BrowserUI.lf">BrowserUI.lf</a>: This version starts a web server that serves a specified web page and enables implementing an HTTP-based API to control your LF program. When the program is running, you can point your browser to <a href="http://localhost:8080">http://localhost:8080</a> to get a page. Adding a path to the URL, as in for example, http://localhost:8080/count, will cause the ServerUI reactor to produce an output that your LF program can react to and send a (text) response.</td> | ||
</tr> | ||
<tr> | ||
<td> <img src="img/WebSocket.png" alt="WebSocket" width="400"> | ||
<td> <a href="WebSocket.lf">WebSocket.lf</a>: This example uses the much more versatile WebSocketServer reactor. When the program is running, you can open an HTML page that includes JavaScript that connects to the server. Messages can be sent in both directions over the web socket, from the LF program to the browser and vice versa.</td> | ||
</tr> | ||
<tr> | ||
<td> <img src="img/WebSocketString.png" alt="WebSocketString" width="400"> | ||
<td> <a href="WebSocketString.lf">WebSocketString.lf</a>: This version uses the simpler WebSocketServerString reactor, which is simpler in that it restricts the messages transported over the web socket to be of string types and it allows only one client to connect.</td> | ||
</tr> | ||
<tr> | ||
<td> <img src="img/Uptime.png" alt="Uptime" width="400"> | ||
<td> <a href="Uptime.lf"> Uptime.lf</a>: This version combines ServerUI with WebSocketServer to serve a web page and then feed it data continuously through a web socket. The application displays the total time that application has been running and updates this time once per second.</td> | ||
</tr> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* This example combines `ServerUI` with `WebSocketServer`. The former starts a web server that | ||
* listens for HTTP requests on port 8080 and serves the web page defined in `uptime.html`. That web | ||
* page includes JavaScript that connects to a web socket on port 8080 that is provided by the | ||
* `WebSocketServer` reactor. The resulting web page simply reports the total time that this program | ||
* has been running. That time is updated on the web page once per second. | ||
* | ||
* This uses the <a href="https://libwebsockets.org">libwebsockets</a> (see <a | ||
* href="https://libwebsockets.org/lws-api-doc-main/html/index.html">API documentation</a> and <a | ||
* href="https://libwebsockets.org/lws-api-doc-main/html/md_READMEs_README_build.html">installation | ||
* instructions</a>). To install on MacOS, we recommending using brew: | ||
* <pre> brew install libwebsockets | ||
* </pre> This puts the compiled libraries in {@code /usr/local/lib}, and these libraries can be | ||
* linked to using the {@code -lwebsockets} compile option or the {@code WebSocketCmake.txt} Cmake | ||
* include file. | ||
* | ||
* @author Edward A. Lee | ||
*/ | ||
target C { | ||
build-type: debug, | ||
keepalive: true | ||
} | ||
|
||
import WebSocketServer from "../lib/WebSocketServer.lf" | ||
|
||
main reactor { | ||
timer seconds(0, 1 s) | ||
|
||
w = new WebSocketServer( | ||
hostport=8080, | ||
initial_file = {= LF_SOURCE_DIRECTORY LF_FILE_SEPARATOR "Uptime.html" =}) | ||
|
||
reaction(startup) {= | ||
lf_print("Point your browser to http://localhost:8080"); | ||
=} | ||
|
||
reaction(seconds) -> w.send {= | ||
instant_t uptime = lf_time_logical_elapsed(); | ||
// Truncate to the nearest second. | ||
uptime = (uptime / SEC(1)) * SEC(1); | ||
char* message = (char*)malloc(LF_TIME_BUFFER_LENGTH * sizeof(char)); | ||
size_t length = lf_readable_time(message, uptime) + 1; // +1 to add a null character. | ||
message[length] = '\0'; | ||
|
||
// Broadcast to all connected sockets. This is accomplished by providing a NULL wsi. | ||
web_socket_message_t* to_send = (web_socket_message_t*)malloc(sizeof(web_socket_message_t)); | ||
to_send->wsi = NULL; | ||
to_send->length = length; | ||
to_send->message = message; | ||
to_send->binary = false; | ||
lf_set(w.send, to_send); | ||
=} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.