Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ if(NO_PYTHON)
add_compile_definitions(NO_PYTHON)
list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/src/drivers/PythonController.cpp)
else()
include_directories(/usr/include/python3.10)
find_package(Python3 COMPONENTS Development REQUIRED)
include_directories(${Python3_INCLUDE_DIRS})
endif()

add_executable(${PROJECT_NAME} ${sources})
Expand All @@ -31,6 +32,10 @@ if(NO_CANLIB)
add_compile_definitions(NO_CANLIB)
endif()

if(NO_INFLUX)
MESSAGE(STATUS "InfluxDB is not used")
add_compile_definitions(NO_INFLUX)
endif()

if(UNIX AND NOT APPLE)
set(LINUX TRUE)
Expand All @@ -43,7 +48,7 @@ if(LINUX)
target_link_libraries(${PROJECT_NAME} PRIVATE -lcanlib)
endif()
if(NOT NO_PYTHON)
target_link_libraries(${PROJECT_NAME} PRIVATE -lpython3.10)
target_link_libraries(${PROJECT_NAME} PRIVATE ${Python3_LIBRARIES})
endif()
else()
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
Expand Down
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Installation](#installation)
- [Build options](#build-options)
- [Supported CAN Drivers](#supported-can-drivers)
- [Development Setup](#development-setup)
- [CAN Protocol](#can-protocol)
- [The importance of States](#the-importance-of-states)
- [Events](#events)
Expand Down Expand Up @@ -109,6 +110,98 @@ Currently two drivers are supported namely
the preferred driver can be selected inside the [config.json](#configjson).
The Dockerfile also installs all required kvaser canlib library files automatically.

## Development Setup
The LLServer is meant to be used in conjuction with a can-bus and an influxdb logging server.
For local development the following setup is recommended:

### can interface
The LLServer still requires a can interface to be present on the system to function.
You can create a dummy can interface with the following commands:
```bash
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
```

### Building the LLServer
Use the following cmake variables to run the LLServer in Dev Mode:
```bash
mkdir build && cd build
cmake -D NO_PYTHON=true -D NO_CANLIB=true -D NO_INFLUX=true .. -o ./
make -j
```
This disables the python bindings, the canbus interface and the influxdb logging.

### Running the LLServer
The LLServer requires a `config.json` and a `mapping.json` file to run. You can find examples in the `config` folder.

To run the LLServer with the example config files, use the following command:
```bash
ECUI_CONFIG_PATH=$(dirname "$PWD")/sample_config ./llserver_ecui_houbolt
```

Please note that without the CAN Bus none of the commands will work. You can crudely some for testing like this in the LLInterface::init:

```c++
auto doStuff = [](std::vector<double> &data, bool flag) {
std::string str = [&data] {
std::ostringstream oss;
std::copy(data.begin(), data.end(), std::ostream_iterator<double>(oss, " "));
return oss.str();
}();
Debug::print("doStuff flag: %d values: %s", flag, str.c_str());
};

eventManager->AddCommands({{"doStuff", {doStuff, {}}}});

```



### Emulating the ECUI
The LLServer communicates over a TCP-Socket with the [ECUI](https://github.com/SpaceTeam/web_ecui_houbolt).
To emulate this one can use the [ECUIEmulator.py](scripts/ECUIEmulator.py) script.
You have to set the message `type` and `data` and it will send it to the LLServer.
Responses are logged to the console.

Eg. Starting a sequence:
```bash
python3 scripts/ECUIEmulator.py
Starting JSON socket server.
Enter your message type(one of sequence-start, send-postseq-comment, abort, auto-abort-change, states-load, states-get, states-set, states-start, states-stop, gui-mapping-load, commands-load, commands-set):
sequence-start
Enter your JSON message (send with `END` in a new line):
{
"globals": {
"endTime": 10,
"interpolation": {
"doStuff": "none"
},
"interval": 0.01,
"startTime": -3
},
"data": [
{
"timestamp": "START",
"name": "start",
"desc": "start",
"actions": [
{
"timestamp": 0.0,
"doStuff": [
2
]
}
]
}

]
}
END
Message sent.

```

## CAN Protocol
As many terms from the [CAN Protocol](https://github.com/SpaceTeam/can_houbolt)
are also used to describe many functionalities
Expand Down
2 changes: 1 addition & 1 deletion include/can/CANMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef LLSERVER_ECUI_HOUBOLT_CANMAPPING_H
#define LLSERVER_ECUI_HOUBOLT_CANMAPPING_H

#include "utility/JSONMapping.h"
#include "../utility/JSONMapping.h"

class CANMappingObj
{
Expand Down
12 changes: 7 additions & 5 deletions include/can/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <mutex>
#include <atomic>

#include "common.h"
#include "../common.h"

typedef struct
{
Expand All @@ -23,12 +23,12 @@ typedef struct __attribute__((__packed__))
uint8_t channel_data[60];
} SensorMsg_t;

#include "can/Channel.h"
#include "channels/Channel.h"
#include "CANDriverKvaser.h"
#include "can_houbolt/channels/generic_channel_def.h"
#include "logging/InfluxDbLogger.h"
#include "../can_houbolt/channels/generic_channel_def.h"
#include "../logging/InfluxDbLogger.h"

#include "utility/Config.h"
#include "../utility/Config.h"

class Node : public Channel
{
Expand Down Expand Up @@ -57,6 +57,8 @@ class Node : public Channel
SensorData_t *latestSensorBuffer;
size_t latestSensorBufferLength = 0;
std::mutex bufferMtx;
std::vector<std::pair<std::string,double>> nameValueMap;


void InitChannels(NodeInfoMsg_t &nodeInfo, std::map<uint8_t, std::tuple<std::string, std::vector<double>>> &channelInfo);

Expand Down
2 changes: 1 addition & 1 deletion include/can/ADC16.h → include/can/channels/ADC16.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "common.h"

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/adc16_channel_def.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "common.h"

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/adc16_single_channel_def.h"

Expand Down
2 changes: 1 addition & 1 deletion include/can/ADC24.h → include/can/channels/ADC24.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "common.h"

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/adc24_channel_def.h"

Expand Down
42 changes: 42 additions & 0 deletions include/can/channels/CANMonitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Created by raffael on 31.03.25.
//

#ifndef CANMONITOR_H
#define CANMONITOR_H


#include "can/channels/Channel.h"
#include "../Node.h"
#include "channels/can_monitor_channel_def.hpp"

class CANMonitor : public Channel, public NonNodeChannel
{
static const std::vector<std::string> states;
static const std::map<std::string, std::vector<double>> scalingMap;
static const std::map<CAN_MONITOR_VARIABLES , std::string> variableMap;

public:
CANMonitor(uint8_t channelID, std::string channelName, Node *parent);

void GetSensorValue(uint8_t *valuePtr, uint8_t &valueLength, std::vector<std::pair<std::string, double>> &nameValueMap) override;

//-------------------------------RECEIVE Functions-------------------------------//

void ProcessCANCommand(Can_MessageData_t *canMsg, uint32_t &canMsgLength, uint64_t &timestamp) override;
std::vector<std::string> GetStates() override;

//-------------------------------SEND Functions-------------------------------//

void SetRefreshDivider(std::vector<double> &params, bool testOnly);
void GetRefreshDivider(std::vector<double> &params, bool testOnly);

//-------------------------------Utility Functions-------------------------------//

void RequestCurrentState() override;

};



#endif //CANMONITOR_H
4 changes: 2 additions & 2 deletions include/can/Channel.h → include/can/channels/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "StateController.h"
#include "can_houbolt/cmds.h"
#include "CANDriver.h"
#include "../CANDriver.h"
#include "EventManager.h"

class Channel
Expand Down Expand Up @@ -172,7 +172,7 @@ class Channel

virtual const std::string GetChannelTypeName();

virtual void GetSensorValue(uint8_t *valuePtr, uint8_t &valueLength, double &value);
virtual void GetSensorValue(uint8_t *valuePtr, uint8_t &valueLength, std::vector<std::pair<std::string, double>> &nameValueMap);

virtual uint8_t GetChannelID()
{ return this->channelID; };
Expand Down
2 changes: 1 addition & 1 deletion include/can/Control.h → include/can/channels/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef LLSERVER_ECUI_HOUBOLT_CONTROL_H
#define LLSERVER_ECUI_HOUBOLT_CONTROL_H

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/control_channel_def.h"

Expand Down
2 changes: 1 addition & 1 deletion include/can/DATA32.h → include/can/channels/DATA32.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "common.h"

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/data32_channel_def.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <utility>

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/digital_out_channel_def.h"

Expand Down
2 changes: 1 addition & 1 deletion include/can/IMU.h → include/can/channels/IMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "common.h"

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/imu_channel_def.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef LLSERVER_ECUI_HOUBOLT_PI_CONTROL_H
#define LLSERVER_ECUI_HOUBOLT_PI_CONTROL_H

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/pi_control_channel_def.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef LLSERVER_ECUI_HOUBOLT_PNEUMATIC_VALVE_H
#define LLSERVER_ECUI_HOUBOLT_PNEUMATIC_VALVE_H

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/pneumatic_valve_channel_def.h"

Expand Down
2 changes: 1 addition & 1 deletion include/can/Rocket.h → include/can/channels/Rocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef LLSERVER_ECUI_HOUBOLT_ROCKET_H
#define LLSERVER_ECUI_HOUBOLT_ROCKET_H

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/rocket_channel_def.h"

Expand Down
2 changes: 1 addition & 1 deletion include/can/Servo.h → include/can/channels/Servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef LLSERVER_ECUI_HOUBOLT_SERVO_H
#define LLSERVER_ECUI_HOUBOLT_SERVO_H

#include "can/Channel.h"
#include "can/channels/Channel.h"
#include "can/Node.h"
#include "can_houbolt/channels/servo_channel_def.h"

Expand Down
2 changes: 1 addition & 1 deletion include/can_houbolt
Loading