Skip to content

open-simulation-platform/cosim-demo-app

Repository files navigation

Cosim Demo Application

cosim-demo-app CI

This repository contains a server-client demo application for libcosim. The server is written in Go and the client in clojurescript

Server

Required tools

  • Conan v1.59 (currently v2 is not supported)
  • Go dev tools: Golang >= 1.11
  • Compiler: MinGW-w64 (Windows), GCC >= 9 (Linux)
  • Package managers: Conan and Go Modules

Throughout this guide, we will use Conan to manage C++ dependencies. However, you can also install the C++ dependencies manually.

Note: About the installation of MinGW-w64 (Windows)

An easier way to install it is to download the Mingw-w64 automated installer from here and follow the steps in the wizard. It is essential that the installation path does not contain any spaces. Install a current version and specify win32 as thread when requested. Additionally, choose the architecture x86_64.

After installing it, you need to add it to the PATH environment variable (add the path where your MinGW-w64 has been installed to e.g., C:\mingw\mingw64\bin).

Alternatively, MinGW can also be installed via chocolatey. Once chocolatey is installed, simply run the following command (as admin) to install MinGW:

choco install mingw

Step 1: Configure Conan

First, add the OSP Conan repository as a remote and configure the username and password to access it:

conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local

Step 2: Build and run

You can do this in two ways:

Alternative 1: Using Conan

From the cosim-demo-app source directory, get C/C++ dependencies using Conan:

conan install . -u -s build_type=Release -g virtualrunenv
source activate_run.sh # or run activate_run.bat in windows
go build

To run the application on Windows:

activate_run.bat (activate_run.ps1 in PowerShell)
cosim-demo-app.exe
deactivate_run.bat when done (deactivate_run.ps1 in PowerShell)

To run the application on Linux:

source activate_run.sh
./cosim-demo-app
./deactivate_run.sh when done

Open a browser at http://localhost:8000/status to verify that it's running (you should see some JSON).

Alternative 2: Manually handle libcosimc dependencies

You will have to define CGO environment variables with arguments pointing to your libcosimc headers and libraries. An example for Windows can be:

set CGO_CFLAGS=-IC:\dev\libcosimc\include
set CGO_LDFLAGS=-LC:\dev\libcosimc\bin -lcosim -lcosimc
go build

To run the application on Windows you need to also update the path to point to your libraries:

set PATH=C:\dev\libcosimc\bin;%PATH%
cosim-demo-app.exe

To run the application on Linux you need to update the LD_LIBRARY_PATH:

LD_LIBRARY_PATH=~dev/libcosimc/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
./cosim-demo-app

Open a browser at http://localhost:8000/status to verify that it's running (you should see some JSON).

Client

Providing a web user interface.

Development mode

You now have a framework running for live reloading of client code.

Building the client

  • Run lein cljsbuild once min
  • The client application will be compiled to /resources/js/compiled

Create distribution with built-in client

To package the application with the client you can use packr. You can install packr and build distributable with:

go get -u github.com/gobuffalo/packr/packr
packr build