Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter
- CitrineOS core extracted (CSMS OCPP 2.0.1) - OpenOCPP extracted (firmware OCPP 1.6J/2.0.1) - ShapeShifter library installed (pip install -e) - ShapeShifter specification extracted - EVerest extracted TODO updated with progress
This commit is contained in:
138
tools/EVerest-main/lib/everest/ieee2030_1_1/.clang-format
Normal file
138
tools/EVerest-main/lib/everest/ieee2030_1_1/.clang-format
Normal file
@@ -0,0 +1,138 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: true
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: AfterColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Left
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
...
|
||||
|
||||
1
tools/EVerest-main/lib/everest/ieee2030_1_1/.github/CODEOWNERS
vendored
Normal file
1
tools/EVerest-main/lib/everest/ieee2030_1_1/.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* @SebaLukas
|
||||
3
tools/EVerest-main/lib/everest/ieee2030_1_1/.gitignore
vendored
Normal file
3
tools/EVerest-main/lib/everest/ieee2030_1_1/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
*build
|
||||
.vscode
|
||||
.cache
|
||||
84
tools/EVerest-main/lib/everest/ieee2030_1_1/CMakeLists.txt
Normal file
84
tools/EVerest-main/lib/everest/ieee2030_1_1/CMakeLists.txt
Normal file
@@ -0,0 +1,84 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(iee2030
|
||||
VERSION 0.1
|
||||
DESCRIPTION "Simple IEEE2030.1.1 library"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
find_package(everest-cmake 0.5
|
||||
PATHS ../everest-cmake
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
find_package(everest-cmake 0.5)
|
||||
|
||||
if (NOT everest-cmake_FOUND)
|
||||
message(STATUS "Retrieving everest-cmake using FetchContent")
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
everest-cmake
|
||||
GIT_REPOSITORY https://github.com/EVerest/everest-cmake.git
|
||||
GIT_TAG v0.5.4
|
||||
)
|
||||
FetchContent_MakeAvailable(everest-cmake)
|
||||
set(everest-cmake_DIR "${everest-cmake_SOURCE_DIR}")
|
||||
include("${everest-cmake_SOURCE_DIR}/everest-cmake-config.cmake")
|
||||
endif()
|
||||
|
||||
# options
|
||||
option(${PROJECT_NAME}_BUILD_TESTING "Build unit tests, used if included as dependency" OFF)
|
||||
option(BUILD_TESTING "Build unit tests, used if standalone project" OFF)
|
||||
|
||||
option(IEEE2030_INSTALL "Enable install target" ${EVC_MAIN_PROJECT})
|
||||
option(DISABLE_IEEE2030_LOCAL_DEPENDENCIES "Disable local dependency lookup for libieee2030_1_1" OFF)
|
||||
option(IEEE2030_USE_EXPORTED_BUILD "Use (experimental) exported build of libieee2030_1_1" OFF)
|
||||
|
||||
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
|
||||
if(IEEE2030_USE_EXPORTED_BUILD)
|
||||
include(cmake/exported-build.cmake)
|
||||
else()
|
||||
include(cmake/local-build.cmake)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# list of compile options
|
||||
set(IEEE2030_COMPILE_OPTIONS_WARNING "-Wall;-Wextra;-Wno-unused-function;-Werror" CACHE STRING "A list of compile options used")
|
||||
message(STATUS "Building libieee2030_1_1 with the following compile options: ${IEEE2030_COMPILE_OPTIONS_WARNING}")
|
||||
|
||||
if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
|
||||
set(IEEE2030_BUILD_TESTING ON)
|
||||
endif()
|
||||
|
||||
# dependencies
|
||||
if (NOT DISABLE_EDM)
|
||||
evc_setup_edm()
|
||||
# In EDM mode, we can't install exports (because the dependencies usually do not install their exports)
|
||||
set(IEEE2030_INSTALL OFF)
|
||||
endif()
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
if (IEEE2030_BUILD_TESTING)
|
||||
include(CTest)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
if (IEEE2030_INSTALL)
|
||||
install(
|
||||
TARGETS
|
||||
ieee2030
|
||||
EXPORT ieee2030-targets
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY include/
|
||||
TYPE INCLUDE
|
||||
PATTERN "detail" EXCLUDE
|
||||
)
|
||||
|
||||
evc_setup_package(
|
||||
NAME ieee2030
|
||||
EXPORT ieee2030-targets
|
||||
NAMESPACE ieee2030
|
||||
)
|
||||
endif()
|
||||
201
tools/EVerest-main/lib/everest/ieee2030_1_1/LICENSE
Normal file
201
tools/EVerest-main/lib/everest/ieee2030_1_1/LICENSE
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
78
tools/EVerest-main/lib/everest/ieee2030_1_1/README.md
Normal file
78
tools/EVerest-main/lib/everest/ieee2030_1_1/README.md
Normal file
@@ -0,0 +1,78 @@
|
||||
# C++ implementation of IEEE Std 2030.1.1-2021
|
||||
|
||||
This is a C++ open source implementation of the IEEE Std 2030.1.1-2021 communication protocol.
|
||||
|
||||
> **Note:** This is a "rump library" (Work In Progress). It currently implements a subset of the full protocol stack and is not production-ready.
|
||||
|
||||
## Overview
|
||||
|
||||
`libIEEE2030.1.1` implements the digital communication parameters for DC Quick and Bidirectional Chargers as defined in **IEEE Std 2030.1.1-2021**. This standard specifies the interface for rapid energy transfer between Electric Vehicles (EVs) and DC chargers.
|
||||
|
||||
## Relationship to CHAdeMO
|
||||
|
||||
The IEEE 2030.1.1 standard is technically derived from CHAdeMO specifications with the permission of the CHAdeMO Association. Consequently, this library serves as a foundation for systems intended to interoperate with vehicles using the CHAdeMO protocol.
|
||||
|
||||
## Supported Versions
|
||||
|
||||
The library targets the following protocol definitions:
|
||||
* **1.1 / 1.2**
|
||||
* **2.0.1**
|
||||
|
||||
## Compliance and Certification
|
||||
|
||||
Implementation of this library does not grant compliance with CHAdeMO requirements. While the IEEE standard and CHAdeMO share core specifications, commercial chargers require official certification and adherence to CHAdeMO Association governance.
|
||||
|
||||
## Features
|
||||
|
||||
* **CAN Communication:** Handling of standard ID allocation (Vehicle: H'100-H'102, Charger: H'108-H'109).
|
||||
* **Sequence Control:** Basic state machine for charge control sequences (Start, Charging, Stop).
|
||||
* **Error Handling:** Definitions for standard error flags.
|
||||
|
||||
## Integration with EVerest
|
||||
|
||||
This library will be (but is not yet) integrated within the `IEEE2030.1.1` module within [EVerest](https://github.com/EVerest/EVerest) — the complete software stack for your charging station. It is recommended to use EVerest together with this IEEE 2030.1.1 implementation.
|
||||
|
||||
## Dependencies
|
||||
|
||||
To build this library you need [everest-cmake](https://github.com/EVerest/everest-cmake) checkout in the same directory as `libIEEE2030.1.1`. If no `everest-cmake` is available, it is retrieved via FetchContent.
|
||||
|
||||
For Debian GNU/Linux 12 you will need the following dependencies:
|
||||
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install build-essential cmake
|
||||
```
|
||||
|
||||
For Fedora 42+ you will need the following dependencies:
|
||||
|
||||
```bash
|
||||
sudo dnf update
|
||||
sudo dnf install gcc gcc-c++ git make cmake
|
||||
```
|
||||
|
||||
The build system `ninja` is optional.
|
||||
|
||||
## Getting started
|
||||
|
||||
```
|
||||
# Run cmake (BUILD_TESTING to enable/disable unit tests)
|
||||
cmake -S . -B build -G Ninja -DBUILD_TESTING=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
|
||||
# Run cmake with disabled compiler warnings
|
||||
cmake -S . -B build -G Ninja -DBUILD_TESTING=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DIEEE2030_COMPILE_OPTIONS_WARNING=""
|
||||
|
||||
# Build
|
||||
ninja -C build
|
||||
|
||||
# Running tests
|
||||
ninja -C build test
|
||||
```
|
||||
|
||||
## Get Involved
|
||||
|
||||
See the [Contribution Guideline](https://everest.github.io/nightly/project/contributing.html) of the EVerest project to get involved.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the Apache License 2.0. See the [LICENSE](./LICENSE) file for details.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
_Use this file to list out any third-party dependencies used by this project. You may choose to point to a Gemfile or other language specific packaging file for details._
|
||||
@@ -0,0 +1,25 @@
|
||||
# download everest-core (source of util)
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(
|
||||
everest-core-src
|
||||
DOWNLOAD_DIR "everest-core/src"
|
||||
GIT_REPOSITORY "https://github.com/EVerest/everest-core.git"
|
||||
GIT_TAG "main"
|
||||
TIMEOUT 30
|
||||
LOG_DOWNLOAD ON
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
|
||||
# util is header-only
|
||||
ExternalProject_Get_Property(everest-core-src SOURCE_DIR)
|
||||
set(UTIL_INCLUDE_DIR "${SOURCE_DIR}/lib/everest/util/include")
|
||||
|
||||
# workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/15052
|
||||
file(MAKE_DIRECTORY ${UTIL_INCLUDE_DIR})
|
||||
|
||||
add_library(everest_util INTERFACE IMPORTED GLOBAL)
|
||||
add_library(everest::util ALIAS everest_util)
|
||||
set_property(TARGET everest_util PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${UTIL_INCLUDE_DIR})
|
||||
add_dependencies(everest_util everest-core-src)
|
||||
@@ -0,0 +1,28 @@
|
||||
# detect if we try to build inside everest-core and local dependencies are available
|
||||
message(STATUS "Attempting build with autodetected local dependencies")
|
||||
|
||||
get_filename_component(EVC_EVEREST_LIB_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
|
||||
|
||||
function(ev_register_library_target NAME)
|
||||
endfunction()
|
||||
|
||||
set(EVC_UTIL_DIR "${EVC_EVEREST_LIB_DIR}/util")
|
||||
if (EVC_UTIL_DIR AND NOT DISABLE_IEEE2030_LOCAL_DEPENDENCIES)
|
||||
message(STATUS "Detected util in ${EVC_UTIL_DIR}, if you do not want this set -DDISABLE_IEEE2030_LOCAL_DEPENDENCIES=ON")
|
||||
if (BUILD_TESTING)
|
||||
message(STATUS "Setting BUILD_TESTING temporary to false")
|
||||
set(CACHE_BUILD_TESTING ON)
|
||||
set(BUILD_TESTING OFF)
|
||||
endif()
|
||||
add_subdirectory("${EVC_UTIL_DIR}" util)
|
||||
if (CACHE_BUILD_TESTING)
|
||||
set(BUILD_TESTING ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
get_filename_component(EVC_LIB_DIR ${EVC_EVEREST_LIB_DIR} DIRECTORY)
|
||||
get_filename_component(EVC_DIR ${EVC_LIB_DIR} DIRECTORY)
|
||||
set(EVC_EDM_DIR "${EVC_DIR}/applications/dependency_manager")
|
||||
|
||||
# use edm from everest-core
|
||||
add_subdirectory("${EVC_EDM_DIR}" edm_tool)
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
catch2:
|
||||
git: https://github.com/catchorg/Catch2.git
|
||||
git_tag: v3.12.0
|
||||
cmake_condition: "IEEE2030_BUILD_TESTING"
|
||||
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <ieee2030/charger/session/callback.hpp>
|
||||
#include <ieee2030/charger/session/session.hpp>
|
||||
#include <ieee2030/charger/v20/control_event.hpp>
|
||||
#include <ieee2030/common/v20/event_queue.hpp>
|
||||
|
||||
namespace ieee2030::charger {
|
||||
|
||||
enum class HwSignal {
|
||||
CS1,
|
||||
CS2,
|
||||
CHARGE_PERMISSION,
|
||||
PROX,
|
||||
};
|
||||
|
||||
class Controller {
|
||||
public:
|
||||
Controller(std::string, callback::Callbacks);
|
||||
~Controller(); // Todo: Adding destructor
|
||||
|
||||
// Collection of api ideas
|
||||
|
||||
// Call only if the charging session is authorized and the ev is connected
|
||||
void start_session(bool, float, float, float, defs::ProtocolNumber);
|
||||
|
||||
// HW Signals
|
||||
void update_hw_signal(HwSignal, bool);
|
||||
|
||||
// Update physical values
|
||||
void update_present_voltage_current(float, float);
|
||||
void update_available_voltage_current(float, float);
|
||||
void update_isolation_status(events::IsolationStatus);
|
||||
|
||||
// Events
|
||||
void cable_check_finished();
|
||||
void stop();
|
||||
|
||||
// Error handling
|
||||
void send_error(); // Todo: define error enums
|
||||
void reset_errors();
|
||||
|
||||
private:
|
||||
std::string can_interface;
|
||||
|
||||
ieee2030::events::EventQueue<events::Event> event_queue;
|
||||
|
||||
// HW Signals: Enable/disable CS1 & CS2 done
|
||||
// EV Target voltage & current done
|
||||
// EV min & max battery voltage
|
||||
// Debug infos (protocol, soc)
|
||||
// Fault
|
||||
// Lock enable/disable?
|
||||
//
|
||||
const callback::Callbacks callbacks;
|
||||
};
|
||||
|
||||
} // namespace ieee2030::charger
|
||||
@@ -0,0 +1,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
namespace ieee2030::charger::v20::state {
|
||||
|
||||
bool state_c_1(const messages::EV100&, const messages::EV101&, const messages::EV102&);
|
||||
bool state_c_2(const messages::EV102&);
|
||||
|
||||
} // namespace ieee2030::charger::v20::state
|
||||
@@ -0,0 +1,124 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
namespace ieee2030::charger::io {
|
||||
|
||||
enum class CanEvent {
|
||||
ACTIVE,
|
||||
NEW_DATA,
|
||||
INACTIVE,
|
||||
};
|
||||
|
||||
using CanEventCallback = std::function<void(CanEvent)>;
|
||||
|
||||
class CanBrokerCharger {
|
||||
|
||||
enum class SendState {
|
||||
ID_108,
|
||||
ID_109,
|
||||
};
|
||||
|
||||
public:
|
||||
CanBrokerCharger();
|
||||
CanBrokerCharger(const std::string&);
|
||||
~CanBrokerCharger();
|
||||
|
||||
void set_event_callback(const CanEventCallback&);
|
||||
|
||||
void enable_tx_can() {
|
||||
tx_active = true;
|
||||
};
|
||||
void disable_tx_can() {
|
||||
tx_active = false;
|
||||
};
|
||||
|
||||
bool rx_can_enabled() {
|
||||
return rx_active;
|
||||
}
|
||||
|
||||
const messages::EV100& get_can_100_message() const {
|
||||
return message_100;
|
||||
}
|
||||
|
||||
const messages::EV101& get_can_101_message() const {
|
||||
return message_101;
|
||||
}
|
||||
|
||||
const messages::EV102& get_can_102_message() const {
|
||||
return message_102;
|
||||
}
|
||||
|
||||
void init_charger_messages(bool welding_detection, float available_voltage, float available_current,
|
||||
float threshold_voltage, defs::ProtocolNumber protocol) {
|
||||
message_108 = messages::Charger108(welding_detection, available_voltage, available_current, threshold_voltage);
|
||||
message_109 = messages::Charger109(protocol);
|
||||
};
|
||||
|
||||
void update_present_voltage(float voltage) {
|
||||
message_109.present_voltage = voltage;
|
||||
}
|
||||
|
||||
void update_present_current(float current) {
|
||||
message_109.present_current = current;
|
||||
}
|
||||
|
||||
void update_available_voltage(float voltage) {
|
||||
message_108.available_voltage = voltage;
|
||||
}
|
||||
|
||||
void update_available_current(float current) {
|
||||
message_108.available_current = current;
|
||||
}
|
||||
|
||||
void update_threshold_voltage(float voltage) {
|
||||
message_108.threshold_voltage = voltage;
|
||||
}
|
||||
|
||||
void update_status_error_flag(defs::ChargerStatusError, bool);
|
||||
void update_reamining_time_10s(uint16_t);
|
||||
|
||||
private:
|
||||
std::atomic_bool exit_rx_loop{false};
|
||||
std::atomic_bool rx_active{false};
|
||||
void rx_loop();
|
||||
std::thread rx_loop_thread;
|
||||
void handle_can_input(uint32_t, const std::vector<uint8_t>&);
|
||||
|
||||
std::atomic_bool exit_tx_loop{false};
|
||||
std::atomic_bool tx_active{false};
|
||||
void tx_loop();
|
||||
std::thread tx_loop_thread;
|
||||
void send(uint32_t, const std::vector<uint8_t>&);
|
||||
|
||||
int can_fd{-1};
|
||||
|
||||
CanEventCallback event_callback{nullptr};
|
||||
|
||||
void publish_event(CanEvent event) {
|
||||
if (!event_callback) {
|
||||
return;
|
||||
}
|
||||
event_callback(event);
|
||||
}
|
||||
|
||||
messages::EV100 message_100;
|
||||
messages::EV101 message_101;
|
||||
messages::EV102 message_102;
|
||||
|
||||
messages::Charger108 message_108;
|
||||
messages::Charger109 message_109;
|
||||
|
||||
SendState tx_state{SendState::ID_108};
|
||||
};
|
||||
|
||||
} // namespace ieee2030::charger::io
|
||||
@@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace ieee2030::charger {
|
||||
|
||||
namespace callback {
|
||||
|
||||
enum class Signal {
|
||||
START_CABLE_CHECK,
|
||||
CHARGE_LOOP_STARTED,
|
||||
CHARGE_LOOP_FINISHED,
|
||||
};
|
||||
|
||||
enum class ChargerSequence {
|
||||
CS1,
|
||||
CS2,
|
||||
};
|
||||
|
||||
enum class Status : bool {
|
||||
OFF = false,
|
||||
ON = true
|
||||
};
|
||||
|
||||
struct HwSignal {
|
||||
ChargerSequence signal;
|
||||
Status status;
|
||||
};
|
||||
|
||||
struct Callbacks {
|
||||
std::function<void(Signal)> signal;
|
||||
std::function<void(const HwSignal&)> hw_signal;
|
||||
};
|
||||
|
||||
} // namespace callback
|
||||
|
||||
class Callback {
|
||||
public:
|
||||
Callback(callback::Callbacks);
|
||||
|
||||
void signal(callback::Signal) const;
|
||||
void hw_signal(const callback::HwSignal&) const;
|
||||
|
||||
private:
|
||||
callback::Callbacks callbacks;
|
||||
};
|
||||
|
||||
} // namespace ieee2030::charger
|
||||
@@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <ieee2030/charger/io/can_broker_charger.hpp>
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
#include <everest/util/fsm/fsm.hpp>
|
||||
#include <ieee2030/charger/v20/context.hpp>
|
||||
#include <ieee2030/charger/v20/control_event.hpp>
|
||||
#include <ieee2030/charger/v20/states.hpp>
|
||||
|
||||
namespace ieee2030::charger {
|
||||
|
||||
struct SessionState {
|
||||
bool can_active{false};
|
||||
bool new_data{false};
|
||||
};
|
||||
|
||||
class Session {
|
||||
public:
|
||||
Session(std::unique_ptr<io::CanBrokerCharger>, const callback::Callbacks&);
|
||||
~Session();
|
||||
|
||||
void update(const std::vector<events::Event>&);
|
||||
|
||||
bool is_session_active() const {
|
||||
return session_is_active;
|
||||
}
|
||||
|
||||
// void end_session() {
|
||||
// session_is_active = false;
|
||||
// }
|
||||
|
||||
private:
|
||||
std::unique_ptr<io::CanBrokerCharger> can_broker;
|
||||
|
||||
std::optional<events::Event> active_event{std::nullopt};
|
||||
|
||||
SessionState state;
|
||||
|
||||
v20::Context ctx;
|
||||
|
||||
fsm::v2::FSM<ieee2030::charger::v20::StateBase> fsm;
|
||||
|
||||
bool session_is_active;
|
||||
|
||||
void handle_can_event(io::CanEvent);
|
||||
|
||||
messages::EV100 message_100;
|
||||
messages::EV101 message_101;
|
||||
messages::EV102 message_102;
|
||||
};
|
||||
|
||||
} // namespace ieee2030::charger
|
||||
@@ -0,0 +1,85 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include <ieee2030/charger/session/callback.hpp>
|
||||
#include <ieee2030/charger/v20/control_event.hpp>
|
||||
#include <ieee2030/common/io/time.hpp>
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
namespace ieee2030::charger::v20 {
|
||||
|
||||
struct CanBrokerContext {
|
||||
std::function<void()> enable_can;
|
||||
std::function<void()> disable_can;
|
||||
std::function<void(defs::ChargerStatusError, bool)> update_status_error;
|
||||
std::function<void(uint16_t)> update_reamining_time;
|
||||
};
|
||||
|
||||
class StateBase;
|
||||
using BasePointerType = std::unique_ptr<StateBase>;
|
||||
|
||||
class Context {
|
||||
public:
|
||||
Context(const std::optional<events::Event>&, callback::Callbacks, const messages::EV100&, const messages::EV101&,
|
||||
const messages::EV102&);
|
||||
|
||||
template <typename StateType, typename... Args> BasePointerType create_state(Args&&... args) {
|
||||
return std::make_unique<StateType>(*this, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
const auto& get_event() {
|
||||
return current_event;
|
||||
}
|
||||
|
||||
template <typename T> T const* get_event() {
|
||||
if (not current_event.has_value()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (not std::holds_alternative<T>(*current_event)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &std::get<T>(*current_event);
|
||||
}
|
||||
|
||||
const messages::EV100& message_100;
|
||||
const messages::EV101& message_101;
|
||||
const messages::EV102& message_102;
|
||||
|
||||
void set_can_broker_callback(const CanBrokerContext& callbacks_) {
|
||||
can_broker_callbacks = callbacks_;
|
||||
}
|
||||
|
||||
void enable_can() {
|
||||
can_broker_callbacks.enable_can();
|
||||
}
|
||||
void disable_can() {
|
||||
can_broker_callbacks.disable_can();
|
||||
}
|
||||
|
||||
void update_status_error(defs::ChargerStatusError status, bool active) {
|
||||
can_broker_callbacks.update_status_error(status, active);
|
||||
}
|
||||
void update_reaminig_time_s(uint16_t seconds) {
|
||||
can_broker_callbacks.update_reamining_time(seconds);
|
||||
}
|
||||
|
||||
const Callback callbacks;
|
||||
|
||||
// bool& log; // Todo: Adding log file logic and write to log file
|
||||
|
||||
ieee2030::io::Timeout timeout;
|
||||
|
||||
private:
|
||||
const std::optional<events::Event>& current_event;
|
||||
|
||||
CanBrokerContext can_broker_callbacks;
|
||||
};
|
||||
|
||||
} // namespace ieee2030::charger::v20
|
||||
@@ -0,0 +1,109 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
namespace ieee2030::charger::events {
|
||||
|
||||
class CS1 {
|
||||
public:
|
||||
explicit CS1(bool status_) : status(status_) {
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
private:
|
||||
bool status;
|
||||
};
|
||||
|
||||
class CS2 {
|
||||
public:
|
||||
explicit CS2(bool status_) : status(status_) {
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
private:
|
||||
bool status;
|
||||
};
|
||||
|
||||
class ProximityDetection {
|
||||
public:
|
||||
explicit ProximityDetection(bool status_) : status(status_) {
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
private:
|
||||
bool status;
|
||||
};
|
||||
|
||||
class ChargePermission {
|
||||
public:
|
||||
explicit ChargePermission(bool status_) : status(status_) {
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
private:
|
||||
bool status;
|
||||
};
|
||||
|
||||
class CableCheckFinished {
|
||||
public:
|
||||
explicit CableCheckFinished(bool success_) : success(success_) {
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return success;
|
||||
}
|
||||
|
||||
private:
|
||||
bool success;
|
||||
};
|
||||
|
||||
class StopCharging {
|
||||
public:
|
||||
explicit StopCharging(bool stop_) : stop(stop_) {
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return stop;
|
||||
}
|
||||
|
||||
private:
|
||||
bool stop;
|
||||
};
|
||||
|
||||
struct PresentVoltageCurrent {
|
||||
float voltage;
|
||||
float current;
|
||||
};
|
||||
|
||||
struct AvailableVoltageCurrent {
|
||||
float voltage;
|
||||
float current;
|
||||
};
|
||||
|
||||
enum class IsolationStatus {
|
||||
Invalid,
|
||||
Valid,
|
||||
Fault,
|
||||
};
|
||||
|
||||
enum class Error {
|
||||
Test,
|
||||
};
|
||||
|
||||
using Event = std::variant<CS1, CS2, ProximityDetection, ChargePermission, CableCheckFinished, StopCharging,
|
||||
PresentVoltageCurrent, AvailableVoltageCurrent, IsolationStatus, Error>;
|
||||
} // namespace ieee2030::charger::events
|
||||
@@ -0,0 +1,22 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include "../states.hpp"
|
||||
|
||||
namespace ieee2030::charger::v20::state {
|
||||
|
||||
struct StateB : public StateBase {
|
||||
public:
|
||||
StateB(Context& ctx) : StateBase(ctx, StateID::StateB) {
|
||||
}
|
||||
|
||||
void enter() final;
|
||||
|
||||
Result feed(Event) final;
|
||||
|
||||
private:
|
||||
bool stop{false};
|
||||
};
|
||||
|
||||
} // namespace ieee2030::charger::v20::state
|
||||
@@ -0,0 +1,37 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include "../states.hpp"
|
||||
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
namespace ieee2030::charger::v20::state {
|
||||
|
||||
namespace state_c {
|
||||
enum class InternalStates {
|
||||
C_1,
|
||||
C_2,
|
||||
};
|
||||
|
||||
} // namespace state_c
|
||||
struct StateC : public StateBase {
|
||||
public:
|
||||
StateC(Context& ctx) : StateBase(ctx, StateID::StateC) {
|
||||
}
|
||||
|
||||
void enter() final;
|
||||
|
||||
Result feed(Event) final;
|
||||
|
||||
private:
|
||||
bool stop{false};
|
||||
|
||||
state_c::InternalStates states{state_c::InternalStates::C_1};
|
||||
|
||||
messages::EV100 ev_100;
|
||||
messages::EV101 ev_101;
|
||||
messages::EV102 ev_102;
|
||||
};
|
||||
|
||||
} // namespace ieee2030::charger::v20::state
|
||||
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
|
||||
namespace ieee2030::charger::v20 {
|
||||
|
||||
class Context;
|
||||
|
||||
enum class Event {
|
||||
CAN_MESSAGE,
|
||||
HW_SIGNAL,
|
||||
EVENT,
|
||||
TIMEOUT,
|
||||
};
|
||||
|
||||
enum class StateID {
|
||||
StateB,
|
||||
StateC
|
||||
};
|
||||
|
||||
struct Result {
|
||||
constexpr Result() = default;
|
||||
Result(BasePointerType result_state) : unhandled(false), new_state(std::move(result_state)) {
|
||||
}
|
||||
|
||||
bool unhandled{true};
|
||||
BasePointerType new_state{nullptr};
|
||||
};
|
||||
|
||||
struct StateBase {
|
||||
using ContainerType = BasePointerType;
|
||||
using EventType = Event;
|
||||
|
||||
StateBase(Context& ctx, StateID id) : m_ctx(ctx), m_id(id){};
|
||||
|
||||
virtual ~StateBase() = default;
|
||||
|
||||
StateID get_id() const {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
virtual void enter(){};
|
||||
virtual Result feed(Event) = 0;
|
||||
virtual void leave(){};
|
||||
|
||||
protected:
|
||||
Context& m_ctx;
|
||||
|
||||
private:
|
||||
StateID m_id;
|
||||
};
|
||||
|
||||
} // namespace ieee2030::charger::v20
|
||||
@@ -0,0 +1,88 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2022 - 2026 Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include <endian.h>
|
||||
|
||||
template <class T> typename std::enable_if_t<sizeof(T) == 1, T> from_raw(const std::vector<uint8_t>& raw, int idx) {
|
||||
T ret = raw[idx];
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class T> typename std::enable_if_t<sizeof(T) == 2, T> from_raw(const std::vector<uint8_t>& raw, int idx) {
|
||||
if (idx + sizeof(T) > raw.size()) {
|
||||
throw std::out_of_range("from_raw: buffer access out of bounds");
|
||||
}
|
||||
uint16_t tmp{};
|
||||
memcpy(&tmp, raw.data() + idx, sizeof(uint16_t)); // Safe copy from buffer
|
||||
tmp = be16toh(tmp); // Convert endianness
|
||||
|
||||
T ret;
|
||||
memcpy(&ret, &tmp, 2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class T> typename std::enable_if_t<sizeof(T) == 4, T> from_raw(const std::vector<uint8_t>& raw, int idx) {
|
||||
if (idx + sizeof(T) > raw.size()) {
|
||||
throw std::out_of_range("from_raw: buffer access out of bounds");
|
||||
}
|
||||
uint32_t tmp{};
|
||||
memcpy(&tmp, raw.data() + idx, sizeof(uint32_t)); // Safe copy from buffer
|
||||
tmp = be32toh(tmp); // Convert endianness
|
||||
|
||||
T ret;
|
||||
memcpy(&ret, &tmp, 4);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class T> typename std::enable_if_t<sizeof(T) == 8, T> from_raw(const std::vector<uint8_t>& raw, int idx) {
|
||||
if (idx + sizeof(T) > raw.size()) {
|
||||
throw std::out_of_range("from_raw: buffer access out of bounds");
|
||||
}
|
||||
uint64_t tmp{};
|
||||
memcpy(&tmp, raw.data() + idx, sizeof(uint64_t)); // Safe copy from buffer
|
||||
tmp = be64toh(tmp); // Convert endianness
|
||||
T ret;
|
||||
memcpy(&ret, &tmp, 8);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class T> typename std::enable_if_t<sizeof(T) == 1> to_raw(T src, std::vector<uint8_t>& dest) {
|
||||
uint8_t tmp{};
|
||||
memcpy(&tmp, &src, 1);
|
||||
dest.push_back(tmp);
|
||||
}
|
||||
|
||||
// FIXME (aw): these conversions should be optimized!
|
||||
template <class T> typename std::enable_if_t<sizeof(T) == 2> to_raw(T src, std::vector<uint8_t>& dest) {
|
||||
uint16_t tmp{};
|
||||
memcpy(&tmp, &src, 2);
|
||||
tmp = htobe16(tmp);
|
||||
uint8_t ret[2];
|
||||
memcpy(ret, &tmp, 2);
|
||||
dest.insert(dest.end(), {ret[0], ret[1]});
|
||||
}
|
||||
|
||||
template <class T> typename std::enable_if_t<sizeof(T) == 4> to_raw(T src, std::vector<uint8_t>& dest) {
|
||||
uint32_t tmp{};
|
||||
memcpy(&tmp, &src, 4);
|
||||
tmp = htobe32(tmp);
|
||||
uint8_t ret[4];
|
||||
memcpy(ret, &tmp, 4);
|
||||
dest.insert(dest.end(), {ret[0], ret[1], ret[2], ret[3]});
|
||||
}
|
||||
|
||||
template <class T> typename std::enable_if_t<sizeof(T) == 8> to_raw(T src, std::vector<uint8_t>& dest) {
|
||||
uint64_t tmp{};
|
||||
memcpy(&tmp, &src, 8);
|
||||
tmp = htobe64(tmp);
|
||||
uint8_t ret[8];
|
||||
memcpy(ret, &tmp, 8);
|
||||
dest.insert(dest.end(), {ret[0], ret[1], ret[2], ret[3], ret[4], ret[5], ret[6], ret[7]});
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <cstdarg>
|
||||
#include <string>
|
||||
|
||||
namespace ieee2030 {
|
||||
|
||||
void logf(const char* fmt, ...);
|
||||
|
||||
void vlogf(const char* fmt, va_list ap);
|
||||
|
||||
void log(const std::string&);
|
||||
|
||||
template <typename CallbackType, typename... Args> bool call_if_available(const CallbackType& callback, Args... args) {
|
||||
if (not callback) {
|
||||
false;
|
||||
}
|
||||
|
||||
callback(std::forward<Args>(args)...);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ieee2030
|
||||
@@ -0,0 +1,11 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace ieee2030::io {
|
||||
void set_logging_callback(const std::function<void(std::string)>&);
|
||||
|
||||
} // namespace ieee2030::io
|
||||
@@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
|
||||
namespace ieee2030::io {
|
||||
|
||||
using TimePoint = std::chrono::steady_clock::time_point;
|
||||
|
||||
inline TimePoint get_current_time_point() {
|
||||
return std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
inline TimePoint offset_time_point_by_ms(const TimePoint& time_point, int32_t offset) {
|
||||
return time_point + std::chrono::milliseconds(offset);
|
||||
}
|
||||
|
||||
// Todo: How to handle parallel timeouts?
|
||||
class Timeout {
|
||||
public:
|
||||
Timeout(){};
|
||||
|
||||
void start(float timeout_s); // Todo: Perhaps change that chrono::seconds
|
||||
void reset();
|
||||
|
||||
std::optional<bool> timeout_reached();
|
||||
|
||||
private:
|
||||
std::optional<TimePoint> timeout_point;
|
||||
};
|
||||
|
||||
} // namespace ieee2030::io
|
||||
@@ -0,0 +1,150 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2022 - 2026 Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
// #include <linux/can.h>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
namespace ieee2030 {
|
||||
|
||||
namespace defs {
|
||||
|
||||
static constexpr auto CHARGED_RATE_REFERENCE = 100;
|
||||
|
||||
enum class ProtocolNumber : uint8_t {
|
||||
VERSION_0_9_1 = 0,
|
||||
VERSION_1_X_X = 1,
|
||||
VERSION_2_0 = 2,
|
||||
};
|
||||
|
||||
enum class EVStatusFault : uint8_t {
|
||||
FAULT_BATTERY_OVER_VOLTAGE,
|
||||
FAULT_BATTERY_UNDER_VOTLAGE,
|
||||
FAULT_BATTER_CURRENT_DEVIATION_ERROR,
|
||||
FAULT_HIGH_BATTERY_TEMPERATURE,
|
||||
FAULT_BATTERY_VOLTAGE_DEVIATION_ERROR,
|
||||
STATUS_CHARGING_ENABLED,
|
||||
STATUS_SHIFT_POSITION,
|
||||
STATUS_SYSTEM_FAULT,
|
||||
STATUS_VEHICLE_STATUS,
|
||||
STATUS_STOP_REQUEST,
|
||||
};
|
||||
enum class ChargerStatusError : uint8_t {
|
||||
CHARGER_STATUS,
|
||||
CHARGER_MALFUNCTION,
|
||||
CONNECTOR_LOCK,
|
||||
BATTERY_INCOMPATIBILITY,
|
||||
SYSTEM_MALFUNCTION,
|
||||
STOP_CONTROL,
|
||||
};
|
||||
} // namespace defs
|
||||
|
||||
namespace messages {
|
||||
|
||||
static constexpr auto EV_ID_100 = 0x100;
|
||||
static constexpr auto EV_ID_101 = 0x101;
|
||||
static constexpr auto EV_ID_102 = 0x102;
|
||||
|
||||
struct EV100 {
|
||||
EV100(){};
|
||||
EV100(const std::vector<uint8_t> raw);
|
||||
friend std::ostream& operator<<(std::ostream&, const EV100&);
|
||||
operator std::vector<uint8_t>();
|
||||
|
||||
float max_battery_voltage;
|
||||
uint8_t charged_rate{defs::CHARGED_RATE_REFERENCE};
|
||||
};
|
||||
|
||||
struct EV101 {
|
||||
EV101(){};
|
||||
EV101(const std::vector<uint8_t> raw);
|
||||
friend std::ostream& operator<<(std::ostream&, const EV101&);
|
||||
operator std::vector<uint8_t>();
|
||||
|
||||
uint8_t max_charging_time_10s; // 0xFF -> use of time_1min
|
||||
uint8_t max_charging_time_1min;
|
||||
uint8_t estimated_charging_time_1min;
|
||||
std::optional<float> total_capacity; // 0.1kWh/bit
|
||||
};
|
||||
|
||||
struct EV102 {
|
||||
EV102(){};
|
||||
EV102(const std::vector<uint8_t> raw);
|
||||
friend std::ostream& operator<<(std::ostream&, const EV102&);
|
||||
operator std::vector<uint8_t>();
|
||||
|
||||
defs::ProtocolNumber protocol;
|
||||
float target_voltage;
|
||||
float target_current;
|
||||
|
||||
bool fault_battery_over_voltage;
|
||||
bool fault_battery_under_voltage;
|
||||
bool fault_battery_current_deviation_error;
|
||||
bool fault_high_battery_temperature;
|
||||
bool fault_battery_voltage_deviation_error;
|
||||
|
||||
bool status_charging_enabled;
|
||||
bool status_shift_position;
|
||||
bool status_system_fault;
|
||||
bool status_vehicle_status;
|
||||
bool status_stop_request;
|
||||
|
||||
uint8_t soc; // 0% - 100%
|
||||
};
|
||||
|
||||
namespace v1_2 {} // namespace v1_2
|
||||
|
||||
namespace v2_0 {} // namespace v2_0
|
||||
|
||||
static constexpr auto CHARGER_ID_108 = 0x108;
|
||||
static constexpr auto CHARGER_ID_109 = 0x109;
|
||||
|
||||
struct Charger108 {
|
||||
Charger108(){};
|
||||
Charger108(const std::vector<uint8_t> raw);
|
||||
Charger108(bool welding_detection_, float voltage_, float current_, float threshold_voltage_) :
|
||||
identifier_welding_detection(welding_detection_),
|
||||
available_voltage(voltage_),
|
||||
available_current(current_),
|
||||
threshold_voltage(threshold_voltage_){};
|
||||
friend std::ostream& operator<<(std::ostream&, const Charger108&);
|
||||
operator std::vector<uint8_t>();
|
||||
|
||||
uint8_t identifier_welding_detection; // 0: not supported, 1-255: supported
|
||||
float available_voltage;
|
||||
float available_current;
|
||||
float threshold_voltage;
|
||||
};
|
||||
|
||||
struct Charger109 {
|
||||
Charger109(){};
|
||||
Charger109(const std::vector<uint8_t> raw);
|
||||
Charger109(defs::ProtocolNumber protocol_) : protocol(protocol_){};
|
||||
friend std::ostream& operator<<(std::ostream&, const Charger109&);
|
||||
operator std::vector<uint8_t>();
|
||||
|
||||
defs::ProtocolNumber protocol;
|
||||
float present_voltage;
|
||||
float present_current;
|
||||
|
||||
bool charger_status;
|
||||
bool charger_malfunction;
|
||||
bool connector_lock;
|
||||
bool battery_incompatibility;
|
||||
bool system_malfunction;
|
||||
bool stop_control{true};
|
||||
|
||||
uint8_t reamining_time_10s; // 0xFF -> use of time_1min
|
||||
uint8_t reamining_time_1min;
|
||||
};
|
||||
|
||||
namespace v1_2 {} // namespace v1_2
|
||||
|
||||
namespace v2_0 {} // namespace v2_0
|
||||
|
||||
} // namespace messages
|
||||
|
||||
} // namespace ieee2030
|
||||
@@ -0,0 +1,37 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
|
||||
namespace ieee2030::events {
|
||||
|
||||
template <class T> class EventQueue {
|
||||
public:
|
||||
std::optional<T> pop() {
|
||||
std::lock_guard<std::mutex> lck(mutex);
|
||||
|
||||
if (queue.empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto event = std::make_optional<T>(std::move(queue.front()));
|
||||
queue.pop();
|
||||
|
||||
return event;
|
||||
};
|
||||
|
||||
void push(T event) {
|
||||
std::lock_guard<std::mutex> lck(mutex);
|
||||
|
||||
queue.push(std::move(event));
|
||||
};
|
||||
|
||||
private:
|
||||
std::queue<T> queue;
|
||||
std::mutex mutex;
|
||||
};
|
||||
|
||||
} // namespace ieee2030::events
|
||||
@@ -0,0 +1,92 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
namespace ieee2030::ev::io {
|
||||
|
||||
enum class CanEvent {
|
||||
ACTIVE,
|
||||
NEW_DATA,
|
||||
INACTIVE,
|
||||
};
|
||||
|
||||
using CanEventCallback = std::function<void(CanEvent)>;
|
||||
|
||||
// Todo(sl): Check if refactoring with CanBrokerCharger is possible
|
||||
class CanBrokerEv {
|
||||
|
||||
enum class SendState {
|
||||
ID_100,
|
||||
ID_101,
|
||||
ID_102,
|
||||
};
|
||||
|
||||
public:
|
||||
CanBrokerEv(){}; // Todo(sl): Check if needed
|
||||
CanBrokerEv(const std::string&);
|
||||
~CanBrokerEv();
|
||||
|
||||
void set_event_callback(const CanEventCallback&);
|
||||
|
||||
void enable_tx_can() {
|
||||
tx_active = true;
|
||||
};
|
||||
void disable_tx_can() {
|
||||
tx_active = false;
|
||||
};
|
||||
|
||||
const messages::Charger108& get_can_108_message() const {
|
||||
return message_108;
|
||||
};
|
||||
const messages::Charger109& get_can_109_message() const {
|
||||
return message_109;
|
||||
}
|
||||
|
||||
void init_messages(); // Todo(sl): Define init arguments
|
||||
|
||||
// Todo(sl): define update functions
|
||||
|
||||
private:
|
||||
std::atomic_bool exit_rx_loop{false};
|
||||
std::atomic_bool rx_active{false};
|
||||
void rx_loop();
|
||||
std::thread rx_loop_thread;
|
||||
void handle_can_input(uint32_t, const std::vector<uint8_t>&);
|
||||
|
||||
std::atomic_bool exit_tx_loop{false};
|
||||
std::atomic_bool tx_active{false};
|
||||
void tx_loop();
|
||||
std::thread tx_loop_thread;
|
||||
void send(uint32_t, const std::vector<uint8_t>&);
|
||||
|
||||
int can_fd{-1};
|
||||
|
||||
CanEventCallback event_callback{nullptr};
|
||||
|
||||
void publish_event(CanEvent event) {
|
||||
if (!event_callback) {
|
||||
return;
|
||||
}
|
||||
event_callback(event);
|
||||
}
|
||||
|
||||
messages::EV100 message_100;
|
||||
messages::EV101 message_101;
|
||||
messages::EV102 message_102;
|
||||
|
||||
messages::Charger108 message_108;
|
||||
messages::Charger109 message_109;
|
||||
|
||||
SendState tx_state{SendState::ID_100};
|
||||
};
|
||||
|
||||
} // namespace ieee2030::ev::io
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(ieee2030)
|
||||
@@ -0,0 +1,43 @@
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
add_library(ieee2030)
|
||||
add_library(ieee2030::ieee2030 ALIAS ieee2030)
|
||||
|
||||
target_sources(ieee2030
|
||||
PRIVATE
|
||||
|
||||
# Common
|
||||
common/io/logging.cpp
|
||||
common/io/time.cpp
|
||||
common/messages/messages.cpp
|
||||
|
||||
# Charger
|
||||
charger/charger_controller.cpp
|
||||
|
||||
charger/session/callback.cpp
|
||||
charger/session/session.cpp
|
||||
|
||||
charger/v20/context.cpp
|
||||
|
||||
charger/v20/state/state_b.cpp
|
||||
charger/v20/state/state_c.cpp
|
||||
|
||||
charger/io/can_broker_charger.cpp
|
||||
|
||||
# EV
|
||||
ev/io/can_broker_ev.cpp
|
||||
)
|
||||
|
||||
target_include_directories(ieee2030
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
)
|
||||
|
||||
target_link_libraries(ieee2030
|
||||
PUBLIC
|
||||
everest::util
|
||||
PRIVATE
|
||||
Threads::Threads
|
||||
)
|
||||
|
||||
target_compile_features(ieee2030 PUBLIC cxx_std_17)
|
||||
@@ -0,0 +1,87 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/charger/charger_controller.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
#include <ieee2030/charger/io/can_broker_charger.hpp>
|
||||
|
||||
namespace ieee2030::charger {
|
||||
Controller::Controller(std::string can_interface_, callback::Callbacks callbacks_) :
|
||||
can_interface(can_interface_), callbacks(std::move(callbacks_)) {
|
||||
}
|
||||
|
||||
void Controller::start_session(bool welding_detection, float available_voltage, float available_current,
|
||||
float threshold_voltage, defs::ProtocolNumber protocol) {
|
||||
|
||||
static constexpr auto SESSION_UPDATE_TIMEOUT_MS = 25;
|
||||
|
||||
auto can_broker = std::make_unique<io::CanBrokerCharger>(can_interface);
|
||||
can_broker->init_charger_messages(welding_detection, available_voltage, available_current, threshold_voltage,
|
||||
protocol);
|
||||
auto session = Session(std::move(can_broker), callbacks);
|
||||
|
||||
while (session.is_session_active()) {
|
||||
|
||||
std::vector<events::Event> current_events;
|
||||
while (auto event = event_queue.pop()) {
|
||||
current_events.push_back(event.value());
|
||||
}
|
||||
|
||||
session.update(current_events);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SESSION_UPDATE_TIMEOUT_MS));
|
||||
}
|
||||
}
|
||||
|
||||
// Hardware signals
|
||||
void Controller::update_hw_signal(HwSignal signal, bool status) {
|
||||
|
||||
switch (signal) {
|
||||
case HwSignal::CS1:
|
||||
event_queue.push(events::CS1{status});
|
||||
break;
|
||||
case HwSignal::CS2:
|
||||
event_queue.push(events::CS2{status});
|
||||
break;
|
||||
case HwSignal::PROX:
|
||||
event_queue.push(events::ProximityDetection{status});
|
||||
break;
|
||||
case HwSignal::CHARGE_PERMISSION:
|
||||
event_queue.push(events::ChargePermission{status});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Update physical values
|
||||
|
||||
void Controller::update_isolation_status(events::IsolationStatus status) {
|
||||
event_queue.push(status);
|
||||
}
|
||||
|
||||
void Controller::update_present_voltage_current(float voltage, float current) {
|
||||
event_queue.push(events::PresentVoltageCurrent{voltage, current});
|
||||
}
|
||||
|
||||
void Controller::update_available_voltage_current(float voltage, float current) {
|
||||
event_queue.push(events::AvailableVoltageCurrent{voltage, current});
|
||||
}
|
||||
|
||||
// Events
|
||||
void Controller::cable_check_finished() {
|
||||
event_queue.push(events::CableCheckFinished{true});
|
||||
}
|
||||
|
||||
void Controller::stop() {
|
||||
event_queue.push(events::StopCharging{true});
|
||||
}
|
||||
|
||||
// Errors
|
||||
void Controller::send_error() {
|
||||
}
|
||||
void Controller::reset_errors() {
|
||||
}
|
||||
|
||||
} // namespace ieee2030::charger
|
||||
@@ -0,0 +1,211 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/charger/io/can_broker_charger.hpp>
|
||||
#include <ieee2030/common/io/time.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <linux/can.h>
|
||||
#include <net/if.h>
|
||||
#include <poll.h>
|
||||
#include <stdexcept>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Todo: should be in a helper file
|
||||
static void throw_with_error(const std::string& msg) {
|
||||
throw std::runtime_error(msg + ": (" + std::string(strerror(errno)) + ")");
|
||||
}
|
||||
|
||||
namespace ieee2030::charger::io {
|
||||
|
||||
CanBrokerCharger::CanBrokerCharger() {
|
||||
}
|
||||
|
||||
CanBrokerCharger::CanBrokerCharger(const std::string& interface_name) : tx_active(false), rx_active{false} {
|
||||
can_fd = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||
|
||||
if (can_fd == -1) {
|
||||
throw_with_error("Failed to open socket");
|
||||
}
|
||||
|
||||
// retrieve interface index from interface name
|
||||
struct ifreq ifr;
|
||||
|
||||
if (interface_name.size() >= sizeof(ifr.ifr_name)) {
|
||||
throw_with_error("Interface name too long: " + interface_name);
|
||||
} else {
|
||||
strcpy(ifr.ifr_name, interface_name.c_str());
|
||||
}
|
||||
|
||||
if (ioctl(can_fd, SIOCGIFINDEX, &ifr) == -1) {
|
||||
throw_with_error("Failed with ioctl/SIOCGIFINDEX on interface " + interface_name);
|
||||
}
|
||||
|
||||
// bind to the interface
|
||||
struct sockaddr_can addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.can_family = AF_CAN;
|
||||
addr.can_ifindex = ifr.ifr_ifindex;
|
||||
|
||||
if (bind(can_fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) == -1) {
|
||||
throw_with_error("Failed with bind");
|
||||
}
|
||||
|
||||
rx_loop_thread = std::thread(&CanBrokerCharger::rx_loop, this);
|
||||
tx_loop_thread = std::thread(&CanBrokerCharger::tx_loop, this);
|
||||
}
|
||||
|
||||
CanBrokerCharger::~CanBrokerCharger() {
|
||||
|
||||
tx_active = false;
|
||||
rx_active = false;
|
||||
exit_rx_loop = true;
|
||||
exit_tx_loop = true;
|
||||
|
||||
rx_loop_thread.join();
|
||||
tx_loop_thread.join();
|
||||
|
||||
close(can_fd);
|
||||
}
|
||||
|
||||
void CanBrokerCharger::set_event_callback(const CanEventCallback& callback) {
|
||||
event_callback = callback;
|
||||
}
|
||||
|
||||
void CanBrokerCharger::rx_loop() {
|
||||
|
||||
struct pollfd pfds = {can_fd, POLLIN, 0};
|
||||
|
||||
while (!exit_rx_loop) {
|
||||
|
||||
const auto poll_result = poll(&pfds, 1, 1);
|
||||
|
||||
if (poll_result == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pfds.revents & POLLIN) {
|
||||
struct can_frame frame;
|
||||
read(can_fd, &frame, sizeof(frame));
|
||||
|
||||
std::vector<uint8_t> payload;
|
||||
payload.assign(frame.data, frame.data + frame.can_dlc);
|
||||
handle_can_input(frame.can_id, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CanBrokerCharger::handle_can_input(uint32_t can_id, const std::vector<uint8_t>& payload) {
|
||||
|
||||
if (!(can_id == messages::EV_ID_100 || can_id == messages::EV_ID_101 || can_id == messages::EV_ID_102)) {
|
||||
// Todo: Check standard if a error is provided
|
||||
return;
|
||||
}
|
||||
|
||||
// Todo: How to detect ev can is active -> Active means the first 100, 101, 102 are received?
|
||||
// Todo: How to detect ev can is not active? -> Receiving nothing over a certain time?
|
||||
|
||||
// Todo: Check if correct sequence 100 -> 101 -> 102 -> 100 ...
|
||||
// Todo: Check Timer for message 100, 101, 102
|
||||
|
||||
if (can_id == messages::EV_ID_100) {
|
||||
message_100 = messages::EV100(payload);
|
||||
} else if (can_id == messages::EV_ID_101) {
|
||||
message_101 = messages::EV101(payload);
|
||||
} else if (can_id == messages::EV_ID_102) {
|
||||
message_102 = messages::EV102(payload);
|
||||
}
|
||||
|
||||
publish_event(CanEvent::NEW_DATA);
|
||||
}
|
||||
|
||||
void CanBrokerCharger::tx_loop() {
|
||||
|
||||
static constexpr auto SEND_CAN_TIMEOUT_MS = 100;
|
||||
auto actual_time_108 = ieee2030::io::get_current_time_point();
|
||||
auto actual_time_109 = ieee2030::io::get_current_time_point();
|
||||
|
||||
while (!exit_tx_loop) {
|
||||
|
||||
if (tx_active) {
|
||||
switch (tx_state) {
|
||||
case SendState::ID_108:
|
||||
if (ieee2030::io::get_current_time_point() >=
|
||||
ieee2030::io::offset_time_point_by_ms(actual_time_108, SEND_CAN_TIMEOUT_MS)) {
|
||||
send(messages::CHARGER_ID_108, message_108);
|
||||
actual_time_108 = ieee2030::io::get_current_time_point();
|
||||
tx_state = SendState::ID_109;
|
||||
}
|
||||
break;
|
||||
|
||||
case SendState::ID_109:
|
||||
if (ieee2030::io::get_current_time_point() >=
|
||||
ieee2030::io::offset_time_point_by_ms(actual_time_109, SEND_CAN_TIMEOUT_MS)) {
|
||||
send(messages::CHARGER_ID_109, message_109);
|
||||
actual_time_109 = ieee2030::io::get_current_time_point();
|
||||
tx_state = SendState::ID_108;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
|
||||
void CanBrokerCharger::send(uint32_t id, const std::vector<uint8_t>& payload) {
|
||||
|
||||
struct can_frame frame;
|
||||
|
||||
// Check payload length
|
||||
if (payload.size() > sizeof(frame.data)) {
|
||||
throw_with_error("Payload data length is too large");
|
||||
}
|
||||
|
||||
frame.can_id = id;
|
||||
frame.can_dlc = payload.size();
|
||||
|
||||
memcpy(frame.data, payload.data(), payload.size());
|
||||
|
||||
const auto wrote_bytes = write(can_fd, &frame, sizeof(frame));
|
||||
|
||||
if (wrote_bytes != sizeof(frame)) {
|
||||
throw_with_error("Failed to send can packet!");
|
||||
}
|
||||
}
|
||||
|
||||
void CanBrokerCharger::update_status_error_flag(defs::ChargerStatusError status, bool active) {
|
||||
switch (status) {
|
||||
case defs::ChargerStatusError::CHARGER_STATUS:
|
||||
message_109.charger_status = active;
|
||||
break;
|
||||
case defs::ChargerStatusError::CHARGER_MALFUNCTION:
|
||||
message_109.charger_malfunction = active;
|
||||
break;
|
||||
case defs::ChargerStatusError::CONNECTOR_LOCK:
|
||||
message_109.connector_lock = active;
|
||||
break;
|
||||
case defs::ChargerStatusError::BATTERY_INCOMPATIBILITY:
|
||||
message_109.battery_incompatibility = active;
|
||||
break;
|
||||
case defs::ChargerStatusError::SYSTEM_MALFUNCTION:
|
||||
message_109.system_malfunction = active;
|
||||
break;
|
||||
case defs::ChargerStatusError::STOP_CONTROL:
|
||||
message_109.stop_control = active;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CanBrokerCharger::update_reamining_time_10s(uint16_t time_10s) {
|
||||
if (time_10s < 0xFF) {
|
||||
message_109.reamining_time_10s = (uint8_t)time_10s;
|
||||
message_109.reamining_time_1min = 0;
|
||||
} else {
|
||||
message_109.reamining_time_10s = 0xFF;
|
||||
message_109.reamining_time_1min = (uint8_t)(time_10s / 6);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ieee2030::charger::io
|
||||
@@ -0,0 +1,21 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include <ieee2030/charger/session/callback.hpp>
|
||||
|
||||
#include <ieee2030/common/detail/helper.hpp>
|
||||
|
||||
namespace ieee2030::charger {
|
||||
|
||||
Callback::Callback(callback::Callbacks callbacks_) : callbacks(std::move(callbacks_)) {
|
||||
}
|
||||
|
||||
void Callback::signal(callback::Signal signal) const {
|
||||
call_if_available(callbacks.signal, signal);
|
||||
}
|
||||
|
||||
void Callback::hw_signal(const callback::HwSignal& hw_signal) const {
|
||||
call_if_available(callbacks.hw_signal, hw_signal);
|
||||
}
|
||||
|
||||
} // namespace ieee2030::charger
|
||||
@@ -0,0 +1,94 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2023 - 2026 Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/charger/session/session.hpp>
|
||||
|
||||
#include <ieee2030/charger/v20/state/state_b.hpp>
|
||||
|
||||
namespace ieee2030::charger {
|
||||
|
||||
Session::Session(std::unique_ptr<io::CanBrokerCharger> can_broker_, const callback::Callbacks& callbacks) :
|
||||
can_broker(std::move(can_broker_)),
|
||||
session_is_active(true),
|
||||
ctx(active_event, callbacks, message_100, message_101, message_102),
|
||||
fsm(ctx.create_state<v20::state::StateB>()) {
|
||||
|
||||
can_broker->set_event_callback([this](io::CanEvent event) { this->handle_can_event(event); });
|
||||
|
||||
v20::CanBrokerContext can_broker_callbacks;
|
||||
can_broker_callbacks.enable_can = [this] { can_broker->enable_tx_can(); };
|
||||
can_broker_callbacks.disable_can = [this] { can_broker->disable_tx_can(); };
|
||||
can_broker_callbacks.update_status_error = [this](defs::ChargerStatusError status, bool active) {
|
||||
can_broker->update_status_error_flag(status, active);
|
||||
};
|
||||
can_broker_callbacks.update_reamining_time = [this](uint16_t seconds) {
|
||||
const auto time_10s = static_cast<uint16_t>(seconds / 10);
|
||||
can_broker->update_reamining_time_10s(time_10s);
|
||||
};
|
||||
|
||||
ctx.set_can_broker_callback(can_broker_callbacks);
|
||||
}
|
||||
|
||||
Session::~Session() = default;
|
||||
|
||||
void Session::update(const std::vector<events::Event>& current_events) {
|
||||
|
||||
// Handle all events before state machine
|
||||
if (!current_events.empty()) {
|
||||
for (auto event : current_events) {
|
||||
if (std::holds_alternative<events::PresentVoltageCurrent>(event)) {
|
||||
const auto& present_values = std::get<events::PresentVoltageCurrent>(event);
|
||||
can_broker->update_present_voltage(present_values.voltage);
|
||||
can_broker->update_present_current(present_values.current);
|
||||
} else if (std::holds_alternative<events::AvailableVoltageCurrent>(event)) {
|
||||
const auto& available_values = std::get<events::AvailableVoltageCurrent>(event);
|
||||
can_broker->update_available_voltage(available_values.voltage);
|
||||
can_broker->update_available_current(available_values.current);
|
||||
} else {
|
||||
active_event = event;
|
||||
|
||||
if (std::holds_alternative<events::CS1>(event) || std::holds_alternative<events::CS2>(event) ||
|
||||
std::holds_alternative<events::ProximityDetection>(event) ||
|
||||
std::holds_alternative<events::ChargePermission>(event)) {
|
||||
// Todo(sl): check result!
|
||||
[[maybe_unused]] const auto res = fsm.feed(v20::Event::HW_SIGNAL);
|
||||
} else {
|
||||
// Todo(sl): check result!
|
||||
[[maybe_unused]] const auto res = fsm.feed(v20::Event::EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (auto timeout_reached = ctx.timeout.timeout_reached()) {
|
||||
if (*timeout_reached) {
|
||||
// Todo(sl): check result!
|
||||
[[maybe_unused]] const auto res = fsm.feed(v20::Event::TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
if (state.new_data) {
|
||||
message_100 = can_broker->get_can_100_message();
|
||||
message_101 = can_broker->get_can_101_message();
|
||||
message_102 = can_broker->get_can_102_message();
|
||||
// Todo(sl): Check return value
|
||||
[[maybe_unused]] const auto res = fsm.feed(v20::Event::CAN_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
void Session::handle_can_event(io::CanEvent event) {
|
||||
using Event = io::CanEvent;
|
||||
|
||||
switch (event) {
|
||||
case Event::ACTIVE:
|
||||
state.can_active = true;
|
||||
break;
|
||||
case Event::INACTIVE:
|
||||
state.can_active = false;
|
||||
break;
|
||||
case Event::NEW_DATA:
|
||||
state.new_data = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ieee2030::charger
|
||||
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/charger/v20/context.hpp>
|
||||
|
||||
namespace ieee2030::charger::v20 {
|
||||
|
||||
Context::Context(const std::optional<events::Event>& current_event_, callback::Callbacks callbacks_,
|
||||
const messages::EV100& message_100_, const messages::EV101& message_101_,
|
||||
const messages::EV102& message_102_) :
|
||||
current_event{current_event_},
|
||||
callbacks(std::move(callbacks_)),
|
||||
message_100(message_100_),
|
||||
message_101(message_101_),
|
||||
message_102(message_102_) {
|
||||
}
|
||||
|
||||
} // namespace ieee2030::charger::v20
|
||||
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/charger/v20/state/state_b.hpp>
|
||||
#include <ieee2030/charger/v20/state/state_c.hpp>
|
||||
|
||||
namespace ieee2030::charger::v20::state {
|
||||
|
||||
void StateB::enter() {
|
||||
// ctx.log.enter_state("State B");
|
||||
m_ctx.callbacks.hw_signal({callback::ChargerSequence::CS1, callback::Status::ON});
|
||||
m_ctx.timeout.start(6);
|
||||
// Todo: Start second timeout
|
||||
}
|
||||
|
||||
Result StateB::feed(Event ev) {
|
||||
|
||||
if (ev == Event::CAN_MESSAGE) {
|
||||
return m_ctx.create_state<StateC>();
|
||||
} else if (ev == Event::TIMEOUT) {
|
||||
// Todo: Adding Log -> Timeout error
|
||||
stop = true;
|
||||
} else if (ev == Event::EVENT) {
|
||||
if (const auto event = m_ctx.get_event<events::StopCharging>()) {
|
||||
if (*event) {
|
||||
// Todo: Adding Log -> Stop button is pressed
|
||||
stop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stop) {
|
||||
m_ctx.callbacks.hw_signal({callback::ChargerSequence::CS1, callback::Status::OFF});
|
||||
// Todo: Stop the session
|
||||
return {};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace ieee2030::charger::v20::state
|
||||
@@ -0,0 +1,83 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/charger/detail/v20/state/state_c.hpp>
|
||||
#include <ieee2030/charger/v20/state/state_c.hpp>
|
||||
|
||||
namespace ieee2030::charger::v20::state {
|
||||
|
||||
bool state_c_1(const messages::EV100& ev_100, const messages::EV101& ev_101, const messages::EV102& ev_102) {
|
||||
|
||||
// Check ev messages if sended
|
||||
// If yes, check Battery comp check, calculate output current
|
||||
|
||||
// If yes, start charger can
|
||||
// Start Timeout after starting charger can (From cs1 = on)
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
bool state_c_2(const messages::EV102& ev_102) {
|
||||
|
||||
// Start Reaming Time Check task
|
||||
|
||||
// Check HW Charge Permission Signal
|
||||
// Check 102.5.0 == 1
|
||||
return false;
|
||||
};
|
||||
|
||||
void StateC::enter() {
|
||||
// ctx.log.enter_state("State C");
|
||||
}
|
||||
|
||||
Result StateC::feed(Event ev) {
|
||||
|
||||
if (ev == Event::CAN_MESSAGE) {
|
||||
ev_100 = m_ctx.message_100;
|
||||
ev_101 = m_ctx.message_101;
|
||||
ev_102 = m_ctx.message_102;
|
||||
} else if (ev == Event::TIMEOUT) {
|
||||
// Todo: Adding Log -> Timeout error
|
||||
stop = true;
|
||||
} else if (ev == Event::EVENT) {
|
||||
if (const auto event = m_ctx.get_event<events::StopCharging>()) {
|
||||
if (*event) {
|
||||
// Todo: Adding Log -> Stop button is pressed
|
||||
stop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Todo: Define in a separat file tasks.cpp in state
|
||||
// tasks::monitoring(); -> Check ev can errors
|
||||
// tasks::battery_compability_check();
|
||||
// tasks::calculation_remaming_time();
|
||||
|
||||
// Todo: Adding Monitoring for every main state
|
||||
// Todo: Start Battery Compability Check until 102.3 > 0
|
||||
// Todo: Start Calculation remaming charging time untule 102.3 > 0
|
||||
|
||||
switch (states) {
|
||||
case state_c::InternalStates::C_1:
|
||||
if (state_c_1(ev_100, ev_101, ev_102)) {
|
||||
states = state_c::InternalStates::C_2;
|
||||
}
|
||||
break;
|
||||
|
||||
case state_c::InternalStates::C_2:
|
||||
if (state_c_2(ev_102)) {
|
||||
// return sa.create_simple<StateD>(m_ctx); // Todo: Adding state D
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (stop) {
|
||||
// Todo(sl): How to stop in state C
|
||||
m_ctx.callbacks.hw_signal({callback::ChargerSequence::CS1, callback::Status::OFF});
|
||||
// Todo(sl): Stopping the session
|
||||
return {};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace ieee2030::charger::v20::state
|
||||
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/common/io/logging.hpp>
|
||||
|
||||
#include <cstdarg>
|
||||
#include <iostream>
|
||||
|
||||
static std::function<void(std::string)> logging_callback = [](const std::string& msg) { std::cout << msg; };
|
||||
|
||||
namespace ieee2030 {
|
||||
|
||||
void log(const std::string& msg) {
|
||||
logging_callback(msg);
|
||||
}
|
||||
|
||||
void vlogf(const char* fmt, va_list ap) {
|
||||
static constexpr auto MAX_FMT_LOG_BUFSIZE = 1024;
|
||||
char msg_buf[MAX_FMT_LOG_BUFSIZE];
|
||||
|
||||
vsnprintf(msg_buf, MAX_FMT_LOG_BUFSIZE, fmt, ap);
|
||||
|
||||
log(msg_buf);
|
||||
}
|
||||
|
||||
void logf(const char* fmt, ...) {
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
vlogf(fmt, args);
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
namespace io {
|
||||
void set_logging_callback(const std::function<void(std::string)>& callback) {
|
||||
logging_callback = callback;
|
||||
}
|
||||
} // namespace io
|
||||
|
||||
} // namespace ieee2030
|
||||
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/common/io/time.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace ieee2030::io {
|
||||
|
||||
void Timeout::start(float timeout_s) {
|
||||
timeout_point =
|
||||
std::chrono::steady_clock::now() + std::chrono::seconds(static_cast<int64_t>(std::round(timeout_s)));
|
||||
}
|
||||
|
||||
void Timeout::reset() {
|
||||
timeout_point.reset();
|
||||
}
|
||||
|
||||
std::optional<bool> Timeout::timeout_reached() {
|
||||
|
||||
if (!timeout_point.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (get_current_time_point() >= timeout_point.value()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace ieee2030::io
|
||||
@@ -0,0 +1,191 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2022 - 2026 Pionix GmbH and Contributors to EVerest
|
||||
#include <iostream>
|
||||
|
||||
#include <ieee2030/common/detail/conversions.hpp>
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
namespace ieee2030::messages {
|
||||
EV100::EV100(const std::vector<uint8_t> raw) {
|
||||
max_battery_voltage = static_cast<float>(from_raw<uint16_t>(raw, 4));
|
||||
charged_rate = from_raw<uint8_t>(raw, 6);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const EV100& self) {
|
||||
out << "Maximum Battery Voltage: " << self.max_battery_voltage << "Charged Rate: " << self.charged_rate;
|
||||
return out;
|
||||
}
|
||||
|
||||
EV100::operator std::vector<uint8_t>() {
|
||||
std::vector<uint8_t> data;
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
to_raw(static_cast<uint16_t>(max_battery_voltage), data);
|
||||
to_raw(static_cast<uint8_t>(charged_rate), data);
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
EV101::EV101(const std::vector<uint8_t> raw) {
|
||||
max_charging_time_10s = from_raw<uint8_t>(raw, 1);
|
||||
max_charging_time_1min = from_raw<uint8_t>(raw, 2);
|
||||
estimated_charging_time_1min = from_raw<uint8_t>(raw, 3);
|
||||
float capacity = static_cast<float>(from_raw<uint16_t>(raw, 5));
|
||||
if (capacity > 0) {
|
||||
total_capacity = capacity;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const EV101& self) {
|
||||
out << "EV Msg 101: Maximum Charging Time (10s): " << self.max_charging_time_10s
|
||||
<< "Maximum Charging Time (1min): " << self.max_charging_time_1min
|
||||
<< "Estimated Charging Time: " << self.estimated_charging_time_1min
|
||||
<< "Total Capacity: " << self.total_capacity.value_or(0);
|
||||
return out;
|
||||
}
|
||||
|
||||
EV101::operator std::vector<uint8_t>() {
|
||||
std::vector<uint8_t> data;
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
to_raw(static_cast<uint8_t>(max_charging_time_10s), data);
|
||||
to_raw(static_cast<uint8_t>(max_charging_time_1min), data);
|
||||
to_raw(static_cast<uint8_t>(estimated_charging_time_1min), data);
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
to_raw(static_cast<uint16_t>(total_capacity.value_or(0)), data);
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
EV102::EV102(const std::vector<uint8_t> raw) {
|
||||
protocol = static_cast<defs::ProtocolNumber>(from_raw<uint8_t>(raw, 0));
|
||||
target_voltage = static_cast<float>(from_raw<uint16_t>(raw, 1));
|
||||
target_current = static_cast<float>(from_raw<uint8_t>(raw, 3));
|
||||
|
||||
uint8_t fault = from_raw<uint8_t>(raw, 4);
|
||||
fault_battery_over_voltage = fault & (1 << 0);
|
||||
fault_battery_under_voltage = fault & (1 << 1);
|
||||
fault_battery_current_deviation_error = fault & (1 << 2);
|
||||
fault_high_battery_temperature = fault & (1 << 3);
|
||||
fault_battery_voltage_deviation_error = fault & (1 << 4);
|
||||
|
||||
uint8_t status = from_raw<uint8_t>(raw, 5);
|
||||
status_charging_enabled = status & (1 << 0);
|
||||
status_shift_position = status & (1 << 1);
|
||||
status_system_fault = status & (1 << 2);
|
||||
status_vehicle_status = status & (1 << 3);
|
||||
status_stop_request = status & (1 << 4);
|
||||
|
||||
soc = from_raw<uint8_t>(raw, 6);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const EV102& self) {
|
||||
out << "EV Msg 102: Protocol: " << static_cast<uint8_t>(self.protocol)
|
||||
<< "Target Voltage [V]: " << self.target_voltage << "Target Current [A]: " << self.target_current
|
||||
<< "SoC [%]: " << self.soc << "Fault battery over voltage: " << self.fault_battery_under_voltage
|
||||
<< "Fault battery under voltage: " << self.fault_battery_under_voltage
|
||||
<< "Fault battery current deviation error: " << self.fault_battery_current_deviation_error
|
||||
<< "Fault high battery temp: " << self.fault_high_battery_temperature
|
||||
<< "Fault battery voltage deviation error: " << self.fault_battery_voltage_deviation_error
|
||||
<< "Status charging enabled: " << self.status_charging_enabled
|
||||
<< "Status shift position: " << self.status_shift_position
|
||||
<< "Status system fault: " << self.status_system_fault
|
||||
<< "Status vehicle status: " << self.status_vehicle_status
|
||||
<< "Status stop request: " << self.status_stop_request;
|
||||
return out;
|
||||
}
|
||||
|
||||
EV102::operator std::vector<uint8_t, std::allocator<uint8_t>>() {
|
||||
std::vector<uint8_t> data;
|
||||
to_raw(static_cast<uint8_t>(protocol), data);
|
||||
to_raw(static_cast<uint16_t>(target_voltage), data);
|
||||
to_raw(static_cast<uint8_t>(target_current), data);
|
||||
|
||||
uint8_t fault = fault_battery_voltage_deviation_error << 4 | fault_high_battery_temperature << 3 |
|
||||
fault_battery_current_deviation_error << 2 | fault_battery_under_voltage << 1 |
|
||||
fault_battery_over_voltage;
|
||||
|
||||
to_raw(static_cast<uint8_t>(fault), data);
|
||||
|
||||
uint8_t status = status_stop_request << 4 | status_vehicle_status << 3 | status_system_fault << 2 |
|
||||
status_shift_position << 1 | status_charging_enabled;
|
||||
|
||||
to_raw(static_cast<uint8_t>(status), data);
|
||||
to_raw(static_cast<uint8_t>(soc), data);
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Charger108::Charger108(const std::vector<uint8_t> raw) {
|
||||
identifier_welding_detection = from_raw<uint8_t>(raw, 0);
|
||||
available_voltage = static_cast<float>(from_raw<uint16_t>(raw, 1));
|
||||
available_current = static_cast<float>(from_raw<uint8_t>(raw, 3));
|
||||
threshold_voltage = static_cast<float>(from_raw<uint16_t>(raw, 4));
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const Charger108& self) {
|
||||
out << "Charger Msg 108: Identifier welding detection: " << self.identifier_welding_detection
|
||||
<< "Available Voltage [V]: " << self.available_voltage << "Available Current [A]: " << self.available_current
|
||||
<< "Threshold voltage [V]: " << self.threshold_voltage;
|
||||
return out;
|
||||
}
|
||||
|
||||
Charger108::operator std::vector<uint8_t>() {
|
||||
std::vector<uint8_t> data;
|
||||
to_raw(static_cast<uint8_t>(identifier_welding_detection), data);
|
||||
to_raw(static_cast<uint16_t>(available_voltage), data);
|
||||
to_raw(static_cast<uint8_t>(available_current), data);
|
||||
to_raw(static_cast<uint16_t>(threshold_voltage), data);
|
||||
to_raw(static_cast<uint16_t>(0), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
Charger109::Charger109(const std::vector<uint8_t> raw) {
|
||||
protocol = static_cast<defs::ProtocolNumber>(from_raw<uint8_t>(raw, 0));
|
||||
present_voltage = static_cast<float>(from_raw<uint16_t>(raw, 1));
|
||||
present_current = static_cast<float>(from_raw<uint8_t>(raw, 3));
|
||||
|
||||
uint8_t status = from_raw<uint8_t>(raw, 5);
|
||||
charger_status = status & (1 << 0);
|
||||
charger_malfunction = status & (1 << 1);
|
||||
connector_lock = status & (1 << 2);
|
||||
battery_incompatibility = status & (1 << 3);
|
||||
system_malfunction = status & (1 << 4);
|
||||
stop_control = status & (1 << 5);
|
||||
|
||||
reamining_time_10s = from_raw<uint8_t>(raw, 6);
|
||||
reamining_time_1min = from_raw<uint8_t>(raw, 7);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const Charger109& self) {
|
||||
out << "Charger Msg 109: Protocol: " << static_cast<uint8_t>(self.protocol)
|
||||
<< "Present Voltage [V]: " << self.present_voltage << "Present Current [A]: " << self.present_current
|
||||
<< "Reamining time [10s]: " << self.reamining_time_10s << "Reamining time [1min]: " << self.reamining_time_1min
|
||||
<< "Charger status: " << self.charger_status << "Charger malfunction: " << self.charger_malfunction
|
||||
<< "Connector lock: " << self.connector_lock << "Battery incompatibility: " << self.battery_incompatibility
|
||||
<< "System malfunction: " << self.system_malfunction << "Stop control: " << self.stop_control;
|
||||
return out;
|
||||
}
|
||||
|
||||
Charger109::operator std::vector<uint8_t>() {
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
to_raw(static_cast<uint8_t>(protocol), data);
|
||||
to_raw(static_cast<uint16_t>(present_voltage), data);
|
||||
to_raw(static_cast<uint8_t>(present_current), data);
|
||||
to_raw(static_cast<uint8_t>(0), data);
|
||||
|
||||
uint8_t status = stop_control << 5 | system_malfunction << 4 | battery_incompatibility << 3 | connector_lock << 2 |
|
||||
charger_malfunction << 1 | charger_status;
|
||||
|
||||
to_raw(static_cast<uint8_t>(status), data);
|
||||
to_raw(static_cast<uint8_t>(reamining_time_10s), data);
|
||||
to_raw(static_cast<uint8_t>(reamining_time_1min), data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
} // namespace ieee2030::messages
|
||||
@@ -0,0 +1,184 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/common/io/time.hpp>
|
||||
#include <ieee2030/ev/io/can_broker_ev.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <linux/can.h>
|
||||
#include <net/if.h>
|
||||
#include <poll.h>
|
||||
#include <stdexcept>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Todo(sl): should be in a helper file
|
||||
static void throw_with_error(const std::string& msg) {
|
||||
throw std::runtime_error(msg + ": (" + std::string(strerror(errno)) + ")");
|
||||
}
|
||||
|
||||
namespace ieee2030::ev::io {
|
||||
|
||||
CanBrokerEv::CanBrokerEv(const std::string& interface_name) : tx_active(false), rx_active{false} {
|
||||
can_fd = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||
|
||||
if (can_fd == -1) {
|
||||
throw_with_error("Failed to open socket");
|
||||
}
|
||||
|
||||
// retrieve interface index from interface name
|
||||
struct ifreq ifr;
|
||||
|
||||
if (interface_name.size() >= sizeof(ifr.ifr_name)) {
|
||||
throw_with_error("Interface name too long: " + interface_name);
|
||||
} else {
|
||||
strcpy(ifr.ifr_name, interface_name.c_str());
|
||||
}
|
||||
|
||||
if (ioctl(can_fd, SIOCGIFINDEX, &ifr) == -1) {
|
||||
throw_with_error("Failed with ioctl/SIOCGIFINDEX on interface " + interface_name);
|
||||
}
|
||||
|
||||
// bind to the interface
|
||||
struct sockaddr_can addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.can_family = AF_CAN;
|
||||
addr.can_ifindex = ifr.ifr_ifindex;
|
||||
|
||||
if (bind(can_fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) == -1) {
|
||||
throw_with_error("Failed with bind");
|
||||
}
|
||||
|
||||
rx_loop_thread = std::thread(&CanBrokerEv::rx_loop, this);
|
||||
tx_loop_thread = std::thread(&CanBrokerEv::tx_loop, this);
|
||||
}
|
||||
|
||||
CanBrokerEv::~CanBrokerEv() {
|
||||
|
||||
tx_active = false;
|
||||
rx_active = false;
|
||||
exit_rx_loop = true;
|
||||
exit_tx_loop = true;
|
||||
|
||||
rx_loop_thread.join();
|
||||
tx_loop_thread.join();
|
||||
|
||||
close(can_fd);
|
||||
}
|
||||
|
||||
void CanBrokerEv::set_event_callback(const CanEventCallback& callback) {
|
||||
event_callback = callback;
|
||||
}
|
||||
|
||||
void CanBrokerEv::rx_loop() {
|
||||
|
||||
struct pollfd pfds = {can_fd, POLLIN, 0};
|
||||
|
||||
while (!exit_rx_loop) {
|
||||
|
||||
const auto poll_result = poll(&pfds, 1, 1);
|
||||
|
||||
if (poll_result == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pfds.revents & POLLIN) {
|
||||
struct can_frame frame;
|
||||
read(can_fd, &frame, sizeof(frame));
|
||||
|
||||
std::vector<uint8_t> payload;
|
||||
payload.assign(frame.data, frame.data + frame.can_dlc);
|
||||
handle_can_input(frame.can_id, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CanBrokerEv::handle_can_input(uint32_t can_id, const std::vector<uint8_t>& payload) {
|
||||
|
||||
if (!(can_id == messages::CHARGER_ID_108 || can_id == messages::CHARGER_ID_109)) {
|
||||
// Todo(sl): Check standard if a error is provided
|
||||
// Todo(sl): What is with the extended can ids (v1.2, 2.0, 3,1 and V2H)?
|
||||
return;
|
||||
}
|
||||
|
||||
// Todo(sl): send can charger is active event -> Active means the first 108, 109 are received?
|
||||
// Todo(sl): How to detect charger can is shutdown? -> Receiving nothing over a certain time?
|
||||
|
||||
// Todo(sl): Check if correct sequence 108 -> 109 -> 108 ...
|
||||
// Todo(sl): Check Timer for message 108, 109
|
||||
|
||||
if (can_id == messages::CHARGER_ID_108) {
|
||||
message_108 = messages::Charger108(payload);
|
||||
} else if (can_id == messages::CHARGER_ID_109) {
|
||||
message_109 = messages::Charger109(payload);
|
||||
}
|
||||
|
||||
publish_event(CanEvent::NEW_DATA);
|
||||
}
|
||||
|
||||
void CanBrokerEv::tx_loop() {
|
||||
|
||||
static constexpr auto SEND_CAN_TIMEOUT_MS = 100;
|
||||
auto actual_time_100 = ieee2030::io::get_current_time_point();
|
||||
auto actual_time_101 = ieee2030::io::get_current_time_point();
|
||||
auto actual_time_102 = ieee2030::io::get_current_time_point();
|
||||
|
||||
while (!exit_tx_loop) {
|
||||
|
||||
if (tx_active) {
|
||||
switch (tx_state) {
|
||||
case SendState::ID_100:
|
||||
if (ieee2030::io::get_current_time_point() >=
|
||||
ieee2030::io::offset_time_point_by_ms(actual_time_100, SEND_CAN_TIMEOUT_MS)) {
|
||||
send(messages::EV_ID_100, message_100);
|
||||
actual_time_100 = ieee2030::io::get_current_time_point();
|
||||
tx_state = SendState::ID_101;
|
||||
}
|
||||
break;
|
||||
|
||||
case SendState::ID_101:
|
||||
if (ieee2030::io::get_current_time_point() >=
|
||||
ieee2030::io::offset_time_point_by_ms(actual_time_101, SEND_CAN_TIMEOUT_MS)) {
|
||||
send(messages::EV_ID_101, message_101);
|
||||
actual_time_101 = ieee2030::io::get_current_time_point();
|
||||
tx_state = SendState::ID_101;
|
||||
}
|
||||
break;
|
||||
|
||||
case SendState::ID_102:
|
||||
if (ieee2030::io::get_current_time_point() >=
|
||||
ieee2030::io::offset_time_point_by_ms(actual_time_102, SEND_CAN_TIMEOUT_MS)) {
|
||||
send(messages::EV_ID_100, message_102);
|
||||
actual_time_102 = ieee2030::io::get_current_time_point();
|
||||
tx_state = SendState::ID_102;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
|
||||
void CanBrokerEv::send(uint32_t id, const std::vector<uint8_t>& payload) {
|
||||
|
||||
struct can_frame frame;
|
||||
|
||||
// Check payload length
|
||||
if (payload.size() > sizeof(frame.data)) {
|
||||
throw_with_error("Payload data length is too large");
|
||||
}
|
||||
|
||||
frame.can_id = id;
|
||||
frame.can_dlc = payload.size();
|
||||
|
||||
memcpy(frame.data, payload.data(), payload.size());
|
||||
|
||||
const auto wrote_bytes = write(can_fd, &frame, sizeof(frame));
|
||||
|
||||
if (wrote_bytes != sizeof(frame)) {
|
||||
throw_with_error("Failed to send can packet!");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ieee2030::ev::io
|
||||
@@ -0,0 +1,6 @@
|
||||
add_compile_options(${IEEE2030_COMPILE_OPTIONS_WARNING})
|
||||
list(APPEND CMAKE_MODULE_PATH ${CPM_PACKAGE_catch2_SOURCE_DIR}/extras)
|
||||
|
||||
add_subdirectory(ieee2030)
|
||||
add_subdirectory(charger)
|
||||
add_subdirectory(common)
|
||||
@@ -0,0 +1,2 @@
|
||||
add_subdirectory(session)
|
||||
add_subdirectory(fsm)
|
||||
@@ -0,0 +1,21 @@
|
||||
include(Catch)
|
||||
|
||||
add_executable(test_fsm_state_b state_b.cpp)
|
||||
|
||||
target_sources(test_fsm_state_b
|
||||
PRIVATE
|
||||
helper.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_fsm_state_b
|
||||
PRIVATE
|
||||
ieee2030::ieee2030
|
||||
Catch2::Catch2WithMain
|
||||
)
|
||||
|
||||
target_compile_options(test_fsm_state_b
|
||||
PRIVATE
|
||||
"-Wno-error=maybe-uninitialized"
|
||||
)
|
||||
|
||||
catch_discover_tests(test_fsm_state_b)
|
||||
@@ -0,0 +1,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include "helper.hpp"
|
||||
|
||||
v20::Context& FsmStateHelper::get_context() {
|
||||
return ctx;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
|
||||
#include <everest/util/fsm/fsm.hpp>
|
||||
#include <ieee2030/charger/session/callback.hpp>
|
||||
#include <ieee2030/charger/v20/context.hpp>
|
||||
#include <ieee2030/charger/v20/control_event.hpp>
|
||||
#include <ieee2030/charger/v20/states.hpp>
|
||||
#include <ieee2030/common/io/logging.hpp>
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
using namespace ieee2030::charger;
|
||||
|
||||
class FsmStateHelper {
|
||||
public:
|
||||
FsmStateHelper(const callback::Callbacks& callbacks) :
|
||||
ctx(active_event, callbacks, message_100, message_101, message_102) {
|
||||
|
||||
ieee2030::io::set_logging_callback([](std::string message) { std::cout << message; });
|
||||
}
|
||||
|
||||
v20::Context& get_context();
|
||||
|
||||
void handle_can_message(const ieee2030::messages::EV100& message_100_,
|
||||
const ieee2030::messages::EV101& message_101_,
|
||||
const ieee2030::messages::EV102& message_102_) {
|
||||
|
||||
this->message_100 = message_100_;
|
||||
this->message_101 = message_101_;
|
||||
this->message_102 = message_102_;
|
||||
}
|
||||
|
||||
void handle_event(const events::Event& event) {
|
||||
active_event = event;
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<events::Event> active_event;
|
||||
|
||||
v20::Context ctx;
|
||||
|
||||
ieee2030::messages::EV100 message_100;
|
||||
ieee2030::messages::EV101 message_101;
|
||||
ieee2030::messages::EV102 message_102;
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
#include <ieee2030/charger/v20/state/state_b.hpp>
|
||||
#include <ieee2030/charger/v20/state/state_c.hpp>
|
||||
|
||||
using namespace ieee2030;
|
||||
|
||||
callback::Callbacks callbacks;
|
||||
|
||||
callback::HwSignal hw_signal;
|
||||
|
||||
SCENARIO("StateB state transitions") {
|
||||
|
||||
callbacks.signal = []([[maybe_unused]] callback::Signal signal_) {};
|
||||
callbacks.hw_signal = [](callback::HwSignal hw_signal_) { hw_signal = hw_signal_; };
|
||||
|
||||
hw_signal = callback::HwSignal();
|
||||
auto state_helper = FsmStateHelper(callbacks);
|
||||
auto ctx = state_helper.get_context();
|
||||
|
||||
GIVEN("Handle Timeout") {
|
||||
fsm::v2::FSM<charger::v20::StateBase> fsm{ctx.create_state<charger::v20::state::StateB>()};
|
||||
const auto result = fsm.feed(v20::Event::TIMEOUT);
|
||||
|
||||
THEN("Check state transititon") {
|
||||
REQUIRE(result.transitioned() == false);
|
||||
REQUIRE(fsm.get_current_state_id() == v20::StateID::StateB);
|
||||
|
||||
REQUIRE(hw_signal.signal == callback::ChargerSequence::CS1);
|
||||
REQUIRE(hw_signal.status == callback::Status::OFF);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Handle stop event") {
|
||||
fsm::v2::FSM<charger::v20::StateBase> fsm{ctx.create_state<charger::v20::state::StateB>()};
|
||||
state_helper.handle_event(events::StopCharging{true});
|
||||
const auto result = fsm.feed(v20::Event::EVENT);
|
||||
|
||||
THEN("Check state transititon") {
|
||||
REQUIRE(result.transitioned() == false);
|
||||
REQUIRE(fsm.get_current_state_id() == v20::StateID::StateB);
|
||||
|
||||
REQUIRE(hw_signal.signal == callback::ChargerSequence::CS1);
|
||||
REQUIRE(hw_signal.status == callback::Status::OFF);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Handle stop event - false alarm") {
|
||||
fsm::v2::FSM<charger::v20::StateBase> fsm{ctx.create_state<charger::v20::state::StateB>()};
|
||||
state_helper.handle_event(events::StopCharging{false});
|
||||
const auto result = fsm.feed(v20::Event::EVENT);
|
||||
|
||||
THEN("Check state transititon") {
|
||||
REQUIRE(result.transitioned() == false);
|
||||
REQUIRE(fsm.get_current_state_id() == v20::StateID::StateB);
|
||||
|
||||
REQUIRE(hw_signal.signal == callback::ChargerSequence::CS1);
|
||||
REQUIRE(hw_signal.status == callback::Status::ON);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Handle first can message") {
|
||||
const auto message_100 = ieee2030::messages::EV100();
|
||||
const auto message_101 = ieee2030::messages::EV101();
|
||||
const auto message_102 = ieee2030::messages::EV102();
|
||||
fsm::v2::FSM<charger::v20::StateBase> fsm{ctx.create_state<charger::v20::state::StateB>()};
|
||||
state_helper.handle_can_message(message_100, message_101, message_102);
|
||||
const auto result = fsm.feed(v20::Event::CAN_MESSAGE);
|
||||
|
||||
THEN("Check state transititon") {
|
||||
REQUIRE(result.transitioned() == true);
|
||||
REQUIRE(fsm.get_current_state_id() == v20::StateID::StateC);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Handle random HW Signal") {
|
||||
fsm::v2::FSM<charger::v20::StateBase> fsm{ctx.create_state<charger::v20::state::StateB>()};
|
||||
state_helper.handle_event(events::ChargePermission{true});
|
||||
const auto result = fsm.feed(v20::Event::EVENT);
|
||||
|
||||
THEN("Check state transititon") {
|
||||
REQUIRE(result.transitioned() == false);
|
||||
REQUIRE(fsm.get_current_state_id() == v20::StateID::StateB);
|
||||
|
||||
REQUIRE(hw_signal.signal == callback::ChargerSequence::CS1);
|
||||
REQUIRE(hw_signal.status == callback::Status::ON);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Handle random event") {
|
||||
fsm::v2::FSM<charger::v20::StateBase> fsm{ctx.create_state<charger::v20::state::StateB>()};
|
||||
state_helper.handle_event(events::CableCheckFinished{true});
|
||||
const auto result = fsm.feed(v20::Event::EVENT);
|
||||
|
||||
THEN("Check state transititon") {
|
||||
REQUIRE(result.transitioned() == false);
|
||||
REQUIRE(fsm.get_current_state_id() == v20::StateID::StateB);
|
||||
|
||||
REQUIRE(hw_signal.signal == callback::ChargerSequence::CS1);
|
||||
REQUIRE(hw_signal.status == callback::Status::ON);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
include(Catch)
|
||||
|
||||
add_executable(test_callback test_callback.cpp)
|
||||
|
||||
target_link_libraries(test_callback
|
||||
PRIVATE
|
||||
ieee2030::ieee2030
|
||||
Catch2::Catch2WithMain
|
||||
)
|
||||
|
||||
catch_discover_tests(test_callback)
|
||||
@@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ieee2030/charger/session/callback.hpp>
|
||||
|
||||
using namespace ieee2030::charger;
|
||||
|
||||
callback::Signal signal;
|
||||
callback::HwSignal hw_signal;
|
||||
|
||||
SCENARIO("Testing callback") {
|
||||
GIVEN("Signal") {
|
||||
|
||||
callback::Callbacks callbacks_functions;
|
||||
|
||||
callbacks_functions.signal = [](callback::Signal signal_) { signal = signal_; };
|
||||
|
||||
auto callback = Callback(callbacks_functions);
|
||||
|
||||
callback.signal(callback::Signal::CHARGE_LOOP_STARTED);
|
||||
|
||||
THEN("Signal should be CHARGE_LOOP_STARTED") {
|
||||
REQUIRE(signal == callback::Signal::CHARGE_LOOP_STARTED);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("HwSignal") {
|
||||
|
||||
callback::Callbacks callbacks_functions;
|
||||
|
||||
callbacks_functions.hw_signal = [](callback::HwSignal hw_signal_) { hw_signal = hw_signal_; };
|
||||
|
||||
auto callback = Callback(callbacks_functions);
|
||||
|
||||
callback.hw_signal({callback::ChargerSequence::CS1, callback::Status::ON});
|
||||
|
||||
THEN("Hw Signal should be enabled CS1") {
|
||||
REQUIRE(hw_signal.signal == callback::ChargerSequence::CS1);
|
||||
REQUIRE(hw_signal.status == callback::Status::ON);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
add_subdirectory(messages)
|
||||
add_subdirectory(io)
|
||||
add_subdirectory(v20)
|
||||
@@ -0,0 +1,11 @@
|
||||
include(Catch)
|
||||
|
||||
add_executable(test_timeout test_timeout.cpp)
|
||||
|
||||
target_link_libraries(test_timeout
|
||||
PRIVATE
|
||||
ieee2030::ieee2030
|
||||
Catch2::Catch2WithMain
|
||||
)
|
||||
|
||||
catch_discover_tests(test_timeout)
|
||||
@@ -0,0 +1,54 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include <ieee2030/common/io/time.hpp>
|
||||
|
||||
using namespace ieee2030;
|
||||
|
||||
SCENARIO("Testing timeout") {
|
||||
GIVEN("Timeout not started") {
|
||||
io::Timeout timeout;
|
||||
|
||||
WHEN("Check if timeout has not started") {
|
||||
REQUIRE(timeout.timeout_reached() == std::nullopt);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Timeout 4 second started") {
|
||||
io::Timeout timeout;
|
||||
|
||||
timeout.start(4);
|
||||
|
||||
WHEN("Check if timeout has started, but not reached") {
|
||||
REQUIRE(timeout.timeout_reached() == false);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Timeout 1 second started") {
|
||||
io::Timeout timeout;
|
||||
|
||||
timeout.start(1);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
||||
WHEN("Check if timeout has started and reached") {
|
||||
REQUIRE(timeout.timeout_reached() == true);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Timeout 1 second started") {
|
||||
io::Timeout timeout;
|
||||
|
||||
timeout.start(1);
|
||||
|
||||
WHEN("Check if reset is working") {
|
||||
REQUIRE(timeout.timeout_reached() == false);
|
||||
|
||||
timeout.reset();
|
||||
|
||||
REQUIRE(timeout.timeout_reached() == std::nullopt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
include(Catch)
|
||||
|
||||
add_executable(test_charger_messages charger_messages.cpp)
|
||||
|
||||
target_link_libraries(test_charger_messages
|
||||
PRIVATE
|
||||
ieee2030::ieee2030
|
||||
Catch2::Catch2WithMain
|
||||
)
|
||||
|
||||
catch_discover_tests(test_charger_messages)
|
||||
|
||||
add_executable(test_ev_messages ev_messages.cpp)
|
||||
|
||||
target_link_libraries(test_ev_messages
|
||||
PRIVATE
|
||||
ieee2030::ieee2030
|
||||
Catch2::Catch2WithMain
|
||||
)
|
||||
|
||||
catch_discover_tests(test_ev_messages)
|
||||
@@ -0,0 +1,98 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
using namespace ieee2030;
|
||||
|
||||
SCENARIO("Charger 108 message") {
|
||||
|
||||
GIVEN("Create from payload") {
|
||||
std::vector<uint8_t> payload = {1, 0x03, 0x20, 30, 0x03, 0x20, 0, 0};
|
||||
auto charger_108 = messages::Charger108(payload);
|
||||
|
||||
THEN("Charger 108 should set correct!") {
|
||||
REQUIRE(charger_108.identifier_welding_detection == 1);
|
||||
REQUIRE(charger_108.available_voltage == 800.0);
|
||||
REQUIRE(charger_108.available_current == 30.0);
|
||||
REQUIRE(charger_108.threshold_voltage == 800.0);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Set payload with operator overload") {
|
||||
auto charger_108 = messages::Charger108();
|
||||
charger_108.identifier_welding_detection = 1;
|
||||
charger_108.available_voltage = 400;
|
||||
charger_108.available_current = 20;
|
||||
charger_108.threshold_voltage = 250;
|
||||
|
||||
std::vector<uint8_t> payload = charger_108;
|
||||
|
||||
THEN("Charger108 payload should set correct!") {
|
||||
REQUIRE(payload[0] == 0x01);
|
||||
REQUIRE(payload[1] == 0x01);
|
||||
REQUIRE(payload[2] == 0x90);
|
||||
REQUIRE(payload[3] == 0x14);
|
||||
REQUIRE(payload[4] == 0x00);
|
||||
REQUIRE(payload[5] == 0xFA);
|
||||
REQUIRE(payload[6] == 0x00);
|
||||
REQUIRE(payload[7] == 0x00);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("Charger 109 message") {
|
||||
|
||||
GIVEN("Create from payload") {
|
||||
std::vector<uint8_t> payload = {1, 0x01, 0xC2, 0xC8, 0, 0x05, 0xFF, 0x1E};
|
||||
auto charger_109 = messages::Charger109(payload);
|
||||
|
||||
THEN("Charger 109 should set correct!") {
|
||||
REQUIRE(charger_109.protocol == defs::ProtocolNumber::VERSION_1_X_X);
|
||||
REQUIRE(charger_109.present_voltage == 450);
|
||||
REQUIRE(charger_109.present_current == 200);
|
||||
|
||||
REQUIRE(charger_109.charger_status == true);
|
||||
REQUIRE(charger_109.charger_malfunction == false);
|
||||
REQUIRE(charger_109.connector_lock == true);
|
||||
REQUIRE(charger_109.battery_incompatibility == false);
|
||||
REQUIRE(charger_109.system_malfunction == false);
|
||||
REQUIRE(charger_109.stop_control == false);
|
||||
|
||||
REQUIRE(charger_109.reamining_time_10s == 0xFF);
|
||||
REQUIRE(charger_109.reamining_time_1min == 30);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Set payload with operator overload") {
|
||||
auto charger_109 = messages::Charger109();
|
||||
|
||||
charger_109.protocol = defs::ProtocolNumber::VERSION_2_0;
|
||||
charger_109.present_voltage = 450;
|
||||
charger_109.present_current = 200;
|
||||
|
||||
charger_109.charger_status = true;
|
||||
charger_109.charger_malfunction = false;
|
||||
charger_109.connector_lock = true;
|
||||
charger_109.battery_incompatibility = false;
|
||||
charger_109.system_malfunction = false;
|
||||
charger_109.stop_control = false;
|
||||
|
||||
charger_109.reamining_time_10s = 0xFF;
|
||||
charger_109.reamining_time_1min = 30;
|
||||
|
||||
std::vector<uint8_t> payload = charger_109;
|
||||
|
||||
THEN("Charger109 payload should set correct!") {
|
||||
REQUIRE(payload[0] == 0x02);
|
||||
REQUIRE(payload[1] == 0x01);
|
||||
REQUIRE(payload[2] == 0xC2);
|
||||
REQUIRE(payload[3] == 0xC8);
|
||||
REQUIRE(payload[4] == 0x00);
|
||||
REQUIRE(payload[5] == 0x05);
|
||||
REQUIRE(payload[6] == 0xFF);
|
||||
REQUIRE(payload[7] == 0x1E);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ieee2030/common/messages/messages.hpp>
|
||||
|
||||
using namespace ieee2030;
|
||||
|
||||
SCENARIO("EV 100 message") {
|
||||
GIVEN("Create from payload") {
|
||||
std::vector<uint8_t> payload = {0x00, 0x00, 0x00, 0x00, 0x02, 0x26, 0x64, 0x00};
|
||||
auto ev_100 = messages::EV100(payload);
|
||||
|
||||
THEN("EV 100 should set correct!") {
|
||||
REQUIRE(ev_100.max_battery_voltage == 550);
|
||||
REQUIRE(ev_100.charged_rate == 100);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Set payload with operator overload") {
|
||||
auto ev_100 = messages::EV100();
|
||||
ev_100.max_battery_voltage = 550;
|
||||
|
||||
std::vector<uint8_t> payload = ev_100;
|
||||
|
||||
THEN("EV 100 payload should set correct!") {
|
||||
REQUIRE(payload[0] == 0x00);
|
||||
REQUIRE(payload[1] == 0x00);
|
||||
REQUIRE(payload[2] == 0x00);
|
||||
REQUIRE(payload[3] == 0x00);
|
||||
REQUIRE(payload[4] == 0x02);
|
||||
REQUIRE(payload[5] == 0x26);
|
||||
REQUIRE(payload[6] == 0x64);
|
||||
REQUIRE(payload[7] == 0x00);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("EV 101 message") {
|
||||
GIVEN("Create from payload") {
|
||||
std::vector<uint8_t> payload = {0x00, 0x3C, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00};
|
||||
auto ev_101 = messages::EV101(payload);
|
||||
|
||||
THEN("EV 101 should set correct!") {
|
||||
REQUIRE(ev_101.max_charging_time_10s == 60);
|
||||
REQUIRE(ev_101.max_charging_time_1min == 0x00);
|
||||
REQUIRE(ev_101.estimated_charging_time_1min == 9);
|
||||
|
||||
REQUIRE(ev_101.total_capacity.has_value() == false);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Set payload with operator overload") {
|
||||
auto ev_101 = messages::EV101();
|
||||
ev_101.max_charging_time_10s = 60;
|
||||
ev_101.max_charging_time_1min = 0x00;
|
||||
ev_101.estimated_charging_time_1min = 9;
|
||||
ev_101.total_capacity = 800;
|
||||
|
||||
std::vector<uint8_t> payload = ev_101;
|
||||
|
||||
THEN("EV 101 payload should set correct!") {
|
||||
REQUIRE(payload[0] == 0x00);
|
||||
REQUIRE(payload[1] == 0x3C);
|
||||
REQUIRE(payload[2] == 0x00);
|
||||
REQUIRE(payload[3] == 0x09);
|
||||
REQUIRE(payload[4] == 0x00);
|
||||
REQUIRE(payload[5] == 0x03);
|
||||
REQUIRE(payload[6] == 0x20);
|
||||
REQUIRE(payload[7] == 0x00);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("EV 102 message") {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
include(Catch)
|
||||
|
||||
add_executable(test_event_queue test_event_queue.cpp)
|
||||
|
||||
target_link_libraries(test_event_queue
|
||||
PRIVATE
|
||||
ieee2030::ieee2030
|
||||
Catch2::Catch2WithMain
|
||||
)
|
||||
|
||||
catch_discover_tests(test_event_queue)
|
||||
@@ -0,0 +1,68 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ieee2030/charger/v20/control_event.hpp>
|
||||
#include <ieee2030/common/v20/event_queue.hpp>
|
||||
|
||||
using namespace ieee2030;
|
||||
|
||||
SCENARIO("Testing event queue") {
|
||||
GIVEN("Create event queue and check if queue is empty") {
|
||||
events::EventQueue<charger::events::Event> queue;
|
||||
|
||||
THEN("Queue should be empty") {
|
||||
REQUIRE(queue.pop() == std::nullopt);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Queue pop one element") {
|
||||
events::EventQueue<charger::events::Event> queue;
|
||||
|
||||
queue.push(charger::events::StopCharging{true});
|
||||
|
||||
THEN("Queue should have one element") {
|
||||
auto event = queue.pop();
|
||||
REQUIRE(event.has_value());
|
||||
REQUIRE(std::holds_alternative<charger::events::StopCharging>(event.value()) == true);
|
||||
REQUIRE(queue.pop() == std::nullopt);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Queue pop 4 element") {
|
||||
events::EventQueue<charger::events::Event> queue;
|
||||
|
||||
queue.push(charger::events::StopCharging{true});
|
||||
queue.push(charger::events::CS1{false});
|
||||
queue.push(charger::events::CS1{true});
|
||||
queue.push(charger::events::ChargePermission{true});
|
||||
|
||||
THEN("Queue should have 4 elements in the correct order") {
|
||||
auto event = queue.pop();
|
||||
REQUIRE(event.has_value());
|
||||
REQUIRE(std::holds_alternative<charger::events::StopCharging>(event.value()) == true);
|
||||
const auto stop_charging = std::get<charger::events::StopCharging>(event.value());
|
||||
REQUIRE(stop_charging == charger::events::StopCharging{true});
|
||||
|
||||
event = queue.pop();
|
||||
REQUIRE(event.has_value());
|
||||
REQUIRE(std::holds_alternative<charger::events::CS1>(event.value()) == true);
|
||||
auto cs1 = std::get<charger::events::CS1>(event.value());
|
||||
REQUIRE(cs1 == charger::events::CS1{false});
|
||||
|
||||
event = queue.pop();
|
||||
REQUIRE(event.has_value());
|
||||
REQUIRE(std::holds_alternative<charger::events::CS1>(event.value()) == true);
|
||||
cs1 = std::get<charger::events::CS1>(event.value());
|
||||
REQUIRE(cs1 == charger::events::CS1{true});
|
||||
|
||||
event = queue.pop();
|
||||
REQUIRE(event.has_value());
|
||||
REQUIRE(std::holds_alternative<charger::events::ChargePermission>(event.value()) == true);
|
||||
const auto permission = std::get<charger::events::ChargePermission>(event.value());
|
||||
REQUIRE(permission == charger::events::ChargePermission{true});
|
||||
|
||||
REQUIRE(queue.pop() == std::nullopt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
include(Catch)
|
||||
|
||||
add_executable(can_charger)
|
||||
|
||||
target_sources(can_charger
|
||||
PRIVATE
|
||||
can_charger.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(can_charger
|
||||
PRIVATE
|
||||
ieee2030::ieee2030
|
||||
)
|
||||
@@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2022 - 2026 Pionix GmbH and Contributors to EVerest
|
||||
#include <ieee2030/charger/io/can_broker_charger.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace ieee2030::charger::io;
|
||||
|
||||
int main() {
|
||||
|
||||
std::cout << "Start CanBroker Charger\n";
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
|
||||
auto broker = CanBrokerCharger("vcan0");
|
||||
|
||||
std::cout << "Wait 2 seconds!\n";
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
|
||||
broker.enable_tx_can();
|
||||
|
||||
std::cout << "Send can message for 10 seconds!\n";
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
|
||||
broker.disable_tx_can();
|
||||
|
||||
std::cout << "Stop CanBroker Charger\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user