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
4 changes: 2 additions & 2 deletions refloat/.github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ runs:
authToken: '${{ inputs.cache-auth-token }}'
- uses: rrbutani/use-nix-shell-action@v1
with:
flakes: nixpkgs/nixos-24.11#gcc-arm-embedded-7, nixpkgs#gnumake, github:lukash/vesc_tool-flake/release_6_05
flakes: nixpkgs/nixos-24.11#gcc-arm-embedded-7, nixpkgs#gnumake, github:lukash/vesc_tool-flake/release_6_06

- name: Build
shell: bash
run: make -j OLDVT=1
run: make -j
4 changes: 2 additions & 2 deletions refloat/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
- uses: cachix/install-nix-action@v25
- uses: rrbutani/use-nix-shell-action@v1
with:
flakes: nixpkgs#clang-tools_18, nixpkgs#lefthook
flakes: nixpkgs#llvmPackages_18.clang-tools, nixpkgs#pre-commit

- name: Run clang-format
id: clang-format
run: lefthook run clang-format-check
run: pre-commit run --all-files --show-diff-on-failure --color always

- name: Build Package
if: success() || (failure() && steps.clang-format.conclusion == 'failure')
Expand Down
6 changes: 4 additions & 2 deletions refloat/.github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ jobs:
run: cat src/conf/confparser.h | sed -n 's/^#define .\+_SIGNATURE\W\+\([0-9]*\)/\1/p' > config_signature.txt

- name: Rename Package File
run: mv refloat.vescpkg refloat-${{env.VERSION}}.vescpkg
run: |
mv refloat.vescpkg refloat-${{env.VERSION}}.vescpkg
mv src/package_lib.elf refloat-${{env.VERSION}}.elf

- name: Install Changelog Generation Dependencies
run: sudo apt-get install python3-git
Expand All @@ -74,7 +76,7 @@ jobs:
tag: ${{github.ref}}
name: Refloat ${{env.VERSION}}
draft: true
artifacts: "refloat-${{env.VERSION}}.vescpkg,config_signature.txt"
artifacts: "refloat-${{env.VERSION}}.vescpkg,refloat-${{env.VERSION}}.elf,config_signature.txt"
bodyFile: "release_notes.md"
prerelease: ${{env.PRERELEASE}}
allowUpdates: true
27 changes: 0 additions & 27 deletions refloat/.lefthook.yml

This file was deleted.

9 changes: 9 additions & 0 deletions refloat/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: local
hooks:
- id: clang-format
name: clang-format
entry: clang-format -i
language: system
types: [c]
exclude: ^vesc_pkg_lib/
11 changes: 3 additions & 8 deletions refloat/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,12 @@ clang-format -i src/*.{h,c}
But, it's better to use git hooks.

## Git Hooks
Refloat uses `lefthook` for managing git hooks. Again, you need to install this dependency in your development environment. Then run this to install the commit hook in the repo:
Refloat uses `pre-commit` for managing git hooks. Again, you need to install this dependency in your development environment. Then run this to install the commit hook in the repo:
```sh
lefthook install
pre-commit install
```

After this, `lefthook` will automatically run clang-format on every commit you make and check your formatting.

To auto-fix all formatting of all files in your working tree, run:
```sh
lefthook run clang-format-fix
```
After this, `pre-commit` will automatically run clang-format on every commit you make, check and automatically fix your formatting.

## Naming Conventions
- Type names are in `PascalCase`.
Expand Down
4 changes: 2 additions & 2 deletions refloat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ OLDVT ?= 0

all: refloat.vescpkg

refloat.vescpkg: src package.lisp package_README-gen.md ui.qml
refloat.vescpkg: src lisp/package.lisp package_README-gen.md ui.qml
ifeq ($(OLDVT), 1)
$(VESC_TOOL) --buildPkg "refloat.vescpkg:package.lisp:ui.qml:0:package_README-gen.md:Refloat"
$(VESC_TOOL) --buildPkg "refloat.vescpkg:lisp/package.lisp:ui.qml:0:package_README-gen.md:Refloat"
else
$(VESC_TOOL) --buildPkgFromDesc pkgdesc.qml
endif
Expand Down
11 changes: 11 additions & 0 deletions refloat/doc/commands/ALERTS_CONTROL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Command: ALERTS_CONTROL

**ID**: 36

**Status**: **unstable**

The alerts control command.

| Offset | Size | Name | Mandatory | Description |
|--------|------|-----------|-----------|---------------|
| 0 | 1 | `command` | Yes | `1`: Clear Fatal Error<br> |
34 changes: 34 additions & 0 deletions refloat/doc/commands/ALERTS_LIST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Command: ALERTS_LIST

**ID**: 35

**Status**: **unstable**

Returns a list of active alerts and a log of alert history. The package maintains a number of last occurred alerts in a circular buffer. This command can return all of them, or, optionally provide a starting timestamp in ticks in the `since` argument. In such case only alerts which occurred after the timestamp are returned (note: the caller needs to take into account the possibility of the ticks overflowing, which occurs once every ~5 days).

The response is limited to 511B in size, in case the alerts wouldn't fit in the message, the alert list will be trucncated (hence it's recommended to use the `since` argument to deal with this eventuality).

## Request

| Offset | Size | Name | Mandatory | Description |
|--------|------|---------|-----------|---------------|
| 0 | 4 | `since` | No | Timestamp in ticks from which to list alerts in the log as `uint32`. |

## Response

| Offset | Size | Name | Description |
|--------|------|-----------------------|---------------|
| 0 | 4 | `active_alert_mask_1` | Bits 0..31 of the `active_alert_mask`, indicating which [alert_id](alert_id.md)s are active. |
| 4 | 8 | `active_alert_mask_2` | Bits 32..63 of the `active_alert_mask`, indicating which [alert_id](alert_id.md)s are active. |
| 8 | 1 | `firmware_fault_code` | In case `ALERT_FW_FAULT` is active, the VESC firmware fault code, otherwise 0. |
| 9 | ? | `firmware_fault_name` | Iff `firmware_fault_code` is non-zero, a [string](string.md) containing the firmware fault name.
| ? | ? | `alert_log` | A sequence of `alert_record`s containing the alert history stored in the package. |

**`alert_record`**:
| Offset | Size | Name | Description |
|--------|------|----------|---------------|
| 0 | 4 | `time` | Timestamp of the alert in ticks, as `uint32`. |
| 4 | 1 | `id` | The ID of the alert, see [alert_id](alert_id.md). |
| 5 | 1 | `active` | `1` if the event represents the alert becoming active, `0` if the event marks the end of the alert. |
| 6 | 1 | `code` | If the Alert ID is `ALERT_FW_FAULT`, the code of the fault from the firmware, otherwise 0. |
| 7 | ? | `firmware_fault_name` | Iff Alert ID is `ALERT_FW_FAULT` and `firmware_fault_code` is non-zero, a [string](string.md) containing the firmware fault name.
10 changes: 2 additions & 8 deletions refloat/doc/commands/DATA_RECORD.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,13 @@ The client is responsible to request all the chunks of data by repeatedly callin

**ID**: 42

Response with the metadata for the recorded data. Sends the total number of samples and then a list of string IDs for the values in each sample, same as in [REALTIME_DATA](REALTIME_DATA.md).
Response with the metadata for the recorded data. Sends the total number of samples and then a list of [string](string.md) IDs for the values in each sample, same as in [REALTIME_DATA](REALTIME_DATA.md).

| Offset | Size | Name | Description |
|--------|------|--------------------------|---------------|
| 0 | 4 | `size` | Size of the buffer in number of samples. The client is expected to fetch up to this number of samples. |
| 4 | 1 | `recorded_data_id_count` | Number of the recorded items per sample (sample size). |
| 5 | ? | `recorded_data_ids` | A `string` sequence repeated `recorded_data_id_count` times. |

**`string`**:
| Offset | Size | Name | Description |
|--------|------|----------|---------------|
| 0 | 1 | `length` | Length of the string. |
| 1 | ? | `string` | `length` number of characters of the string (not null-terminated). |
| 5 | ? | `recorded_data_ids` | A [string](string.md) sequence repeated `recorded_data_id_count` times. |

## DATA_RECORD_DATA (Response)

Expand Down
26 changes: 26 additions & 0 deletions refloat/doc/commands/LIGHTS_CONTROL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Command: LIGHTS_CONTROL

**ID**: 20

Controls the lights and returns current lighting state values.

## Request

| Offset | Size | Name | Mandatory | Description |
|--------|------|-----------|-----------|---------------|
| 0 | 4 | `mask` | No | Mask determining which values are being set in the command. Bits 0..7 correspond to the `flags` bits. Bits 8..31 are unused. |
| 4 | 1 | `flags` | No | Values of lighting flags to set. |

## Response

| Offset | Size | Name | Description |
|--------|------|---------|---------------|
| 0 | 1 | `flags` | Current values of lighting flags. |

## Common Structures

#### flags

| 7-2 | 1 | 0 |
|-----|-----------------|-----------|
| 0 | `headlights_on` | `leds_on` |
9 changes: 8 additions & 1 deletion refloat/doc/commands/REALTIME_DATA.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ In case the following bits are set in the `mask`, the listed data follow in the
| 0 | 2 | `charging_current` | The charging current encoded as [float16](float16.md). |
| 2 | 2 | `charging_voltage` | The charging voltage encoded as [float16](float16.md). |

**`0x4`: Alerts**
| Offset | Size | Name | Description |
|--------|------|-----------------------|---------------|
| 0 | 4 | `active_alert_mask_1` | Bits 0..31 of the `active_alert_mask`, indicating which [alert_id](alert_id.md)s are active. |
| 4 | 8 | `active_alert_mask_2` | Bits 32..63 of the `active_alert_mask`, indicating which [alert_id](alert_id.md)s are active. |
| 8 | 1 | `firmware_fault_code` | In case `ALERT_FW_FAULT` is active, the VESC firmware fault code, otherwise 0. |

#### extra_flags

| 7-5 | 2 | 1 | 0 |
| 7-3 | 2 | 1 | 0 |
|-----|------------------------|-------------------------|-------------------------|
| 0 | `data_record_autostop` | `data_record_autostart` | `data_record_recording` |

Expand Down
10 changes: 2 additions & 8 deletions refloat/doc/commands/REALTIME_DATA_IDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ The actual list of IDs that are sent is in [rt_data.h](/src/rt_data.h). See [Rea
| Offset | Size | Name | Description |
|--------|------|----------------------------------|---------------|
| 0 | 1 | `realtime_data_id_count` | Number of IDs of the `REALTIME_DATA` items which are always sent. |
| 1 | ? | `realtime_data_ids` | A `string` sequence repeated `realtime_data_id_count` times. |
| 1 | ? | `realtime_data_ids` | A [string](string.md) sequence repeated `realtime_data_id_count` times. |
| ? | 1 | `realtime_runtime_data_id_count` | Number of IDs of the `REALTIME_DATA` items which are sent only when the package is running. |
| ? | ? | `realtime_runtime_data_ids` | A `string` sequence repeated `realtime_runtime_data_id_count` times. |

**`string`**:
| Offset | Size | Name | Description |
|--------|------|----------|---------------|
| 0 | 1 | `length` | Length of the string. |
| 1 | ? | `string` | `length` number of characters of the string (not null-terminated). |
| ? | ? | `realtime_runtime_data_ids` | A [string](string.md) sequence repeated `realtime_runtime_data_id_count` times. |
4 changes: 4 additions & 0 deletions refloat/doc/commands/alert_id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `alert_id`

- `1: ALERT_FW_FAULT`

3 changes: 3 additions & 0 deletions refloat/doc/commands/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ All commands on the VESC bus are checksummed (so they shouldn't get mangled). In
In the commands' documentation, the first two bytes with `package_interface_id` and `command_id` are omitted, so while their offsets start at 0, in the full message their data are always preceded by them.

- [INFO](INFO.md)
- [LIGHTS_CONTROL](LIGHTS_CONTROL.md)
- [REALTIME_DATA](REALTIME_DATA.md)
- [REALTIME_DATA_IDS](REALTIME_DATA_IDS.md)
- [DATA_RECORD](DATA_RECORD.md)
- [ALERTS_LIST](ALERTS_LIST.md)
- [ALERTS_CONTROL](ALERTS_CONTROL.md)
7 changes: 7 additions & 0 deletions refloat/doc/commands/string.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# `string`

| Offset | Size | Name | Description |
|--------|------|----------|---------------|
| 0 | 1 | `length` | Length of the string. |
| 1 | ? | `string` | `length` number of characters of the string (not null-terminated). |

37 changes: 37 additions & 0 deletions refloat/lisp/bms.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(defun bms-loop () {
(var v-cell-support (eq (first (trap (get-bms-val 'bms-v-cell-min))) 'exit-ok))
(var v-min 0)
(var v-max 0)
(var temp-min 0)
(var temp-max 0)
(var temp-fet -281)
(loopwhile t {
(if (and (>= (get-bms-val 'bms-can-id) 0) (ext-bms)) {
(var msg-age (get-bms-val 'bms-msg-age))
(setq temp-max (get-bms-val 'bms-temp-cell-max))
(setq temp-min temp-max)

(if v-cell-support {
(if (= (get-bms-val 'bms-data-version) 1) {
(setq temp-min (get-bms-val 'bms-temps-adc 1))
(setq temp-fet (get-bms-val 'bms-temps-adc 3))
})
(setq v-min (get-bms-val 'bms-v-cell-min))
(setq v-max (get-bms-val 'bms-v-cell-max))
} {
(var num-cells (get-bms-val 'bms-cell-num))
(if (> num-cells 0) {
(setq v-min (get-bms-val 'bms-v-cell 0))
(setq v-max v-min)
(looprange i 1 num-cells {
(var cell-v (get-bms-val 'bms-v-cell i))
(if (< cell-v v-min) (setq v-min cell-v))
(if (> cell-v v-max) (setq v-max cell-v))
})
})
})
(ext-bms v-min v-max temp-min temp-max temp-fet msg-age)
})
(sleep 0.2)
})
})
17 changes: 17 additions & 0 deletions refloat/lisp/package.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(import "src/package_lib.bin" 'package-lib)
(load-native-lib package-lib)

(define fw-ver (sysinfo 'fw-ver))
(apply ext-set-fw-version fw-ver)

; Start the BMS polling loop in a thread if enabled
(if (ext-bms)
(if (or (>= (first fw-ver) 7) (and (= (first fw-ver) 6) (>= (second fw-ver) 5)))
(progn
(import "bms.lisp" 'bms)
(read-eval-program bms)
(spawn "Refloat BMS" 50 bms-loop)
)
(print "[refloat] BMS Integration: Unsupported firmware version, 6.05+ required.")
)
)
27 changes: 0 additions & 27 deletions refloat/package.lisp

This file was deleted.

Loading