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:
Eric F
2026-06-08 00:38:27 -04:00
parent 468cfeaa50
commit d398a6ced2
7326 changed files with 1177561 additions and 7 deletions

View File

@@ -0,0 +1,7 @@
# Chargebridge Protocol
Contains the header definitions for the raw C structs that will be used for comms between the Linux system and the
development board. Will also include various assertions and size/bounds checks to determine the that the client
systems are compatible and have the same memory layout.
The headers are C compliant for both C and C++ user code.

View File

@@ -0,0 +1,87 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#pragma once
#include "cb_platform.h"
#include <stdint.h>
/* Enum definitions */
typedef enum _CanErrorState {
CanErrorState_Error_Active = 0,
CanErrorState_Error_Passive = 1,
CanErrorState_ForceSize = 0xFFFFFFFF,
} CanErrorState;
typedef enum _CanBitrate {
CanBitrate_125kbps = 0,
CanBitrate_250kbps = 1,
CanBitrate_500kbps = 2,
CanBitrate_1000kbps = 3,
CanBitrate_ForceSize = 0xFFFFFFFF,
} CanBitrate;
typedef enum _CanFDBitrate {
CanFDBitrate_1MBps = 0,
CanFDBitrate_2MBps = 1,
CanFDBitrate_3MBps = 2,
CanFDBitrate_4MBps = 3,
CanFDBitrate_5MBps = 4,
CanFDBitrate_6MBps = 5,
CanFDBitrate_7MBps = 6,
CanFDBitrate_8MBps = 7,
CanFDBitrate_ForceSize = 0xFFFFFFFF,
} CanFDBitrate;
typedef enum _CanFlags {
CanFlags_EFF = 1,
CanFlags_RTR = 1 << 1,
CanFlags_ERR = 1 << 2,
} CanFlags;
typedef struct CB_COMPILER_ATTR_PACK _CanStatistics {
// tx: direction is from host to bus
// rx: direction is from bus to host
uint32_t frames_tx;
uint32_t frames_rx;
uint32_t event_rx_buf_full;
uint32_t event_tx_buf_full;
} CanStatistics;
typedef enum _CanPacketType : uint8_t{
CanPacketType_Regular = 0,
CanPacketType_Keep_Alive = 1,
} CanPacketType;
struct CB_COMPILER_ATTR_PACK cb_can_message {
uint8_t version;
CanPacketType packet_type; // 0: regular CAN packet, 1: dummy keep-alive packet
CanErrorState error_state;
CanStatistics statistics;
CanBitrate bitrate;
CanFDBitrate fd_bitrate; /* integer in MBit (1-8) */
uint8_t can_flags; // EFF, RTR, ERR
uint32_t can_id;
/* dlc 0..8: standard CAN frame with up to 8 bytes
* FDCAN dlc:
* 9: 12 bytes
* 10: 16 bytes
* 11: 20 bytes
* 12: 24 bytes
* 13: 32 bytes
* 14: 48 bytes
* 15: 64 bytes
*/
uint8_t dlc;
// Note: in UDP transmission, data bytes at the end may be omitted in the message.
// Always check dlc first before accessing the data
uint8_t data[64];
};
#define cb_can_message_set_zero \
{0, CanPacketType_Regular, CanErrorState_Error_Active, {0, 0, 0, 0}, CanBitrate_125kbps, CanFDBitrate_1MBps, 0, 0, \
0, {0, 0, 0, 0, 0, 0, 0, 0}};
#include "test/cb_can_message_test.h"

View File

@@ -0,0 +1,44 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#pragma once
#include "cb_platform.h"
#include <stdint.h>
// Structs
typedef union _SafetyErrorFlags {
struct _flags {
uint32_t cp_not_state_c : 1;
uint32_t pwm_not_enabled : 1;
uint32_t pp_invalid : 1;
uint32_t plug_temperature_too_high : 1;
uint32_t internal_temperature_too_high : 1;
uint32_t emergency_input_latched : 1;
uint32_t relay_health_latched : 1;
uint32_t vdd_3v3_out_of_range : 1;
uint32_t vdd_core_out_of_range : 1;
uint32_t vdd_12V_out_of_range : 1;
uint32_t vdd_N12V_out_of_range : 1;
uint32_t vdd_refint_out_of_range : 1;
uint32_t external_allow_power_on : 1;
uint32_t config_mem_error : 1;
uint32_t dc_hv_ov_emergency : 1;
uint32_t dc_hv_ov_error : 1;
uint32_t reserved : 17;
} flags;
uint32_t raw;
} SafetyErrorFlags;
typedef enum _CpState : uint8_t {
CpState_A,
CpState_B,
CpState_C,
CpState_D,
CpState_E,
CpState_F,
CpState_DF,
CpState_INVALID
} CpState;

View File

@@ -0,0 +1,127 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#pragma once
#include "cb_platform.h"
#include <stdint.h>
#define CB_NUMBER_OF_GPIOS 10
#define CB_NUMBER_OF_UARTS 3
// enums
typedef enum _CbGpioMode : uint8_t {
CBG_Input = 0x00,
CBG_Output = 0x01,
CBG_Pwm_Input = 0x02,
CBG_Pwm_Output = 0x03,
CBG_RS485_2_DE = 0x04,
CBG_Rcd_Selftest_Output = 0x05,
CBG_Rcd_Error_Input= 0x06,
CBG_Rcd_PWM_Input= 0x07,
CBG_MotorLock_1 = 0x08,
CBG_MotorLock_2 = 0x09,
} CbGpioMode;
typedef enum _CbRelayMode : uint8_t {
CBR_PowerRelay = 0x00, CBR_UserRelay = 0x01,
} CbRelayMode;
typedef enum _CbGpioPulls : uint8_t {
CBGP_NoPull = 0x00, CBGP_PullUp = 0x01, CBGP_PullDown = 0x02,
} CbGpioPulls;
typedef enum _CbUartBaudrate : uint8_t {
CBUBR_9600 = 0x00,
CBUBR_19200 = 0x01,
CBUBR_38400 = 0x02,
CBUBR_57600 = 0x03,
CBUBR_115200 = 0x04,
CBUBR_230400 = 0x05,
CBUBR_250000 = 0x06,
CBUBR_460800 = 0x07,
CBUBR_500000 = 0x08,
CBUBR_1000000 = 0x09,
CBUBR_2000000 = 0x0A,
CBUBR_3000000 = 0x0B,
CBUBR_4000000 = 0x0C,
CBUBR_6000000 = 0x0D,
CBUBR_8000000 = 0x0E,
CBUBR_10000000 = 0x0F,
} CbUartBaudrate;
typedef enum _CbUartStopbits : uint8_t {
CBUS_OneStopBit = 0x00, CBUS_TwoStopBits = 0x01,
} CbUartStopbits;
typedef enum _CbUartParity : uint8_t {
CBUP_None = 0x00, CBUP_Odd = 0x01, CBUP_Even = 0x02,
} CbUartParity;
typedef enum _CbCanBaudrate : uint8_t {
CBCBR_125000 = 0x00,
CBCBR_250000 = 0x01,
CBCBR_500000 = 0x02,
CBCBR_1000000 = 0x03,
} CbCanBaudrate;
typedef enum _CbSafetyMode : uint8_t {
CBSM_disabled = 0x00, CBSM_US = 0x01, CBSM_EU = 0x02,
} CbSafetyMode;
// Structs
typedef struct CB_COMPILER_ATTR_PACK _relay_config {
CbRelayMode relay_mode;
uint8_t feedback_enabled; // 0: feedback unused, 1: feedback expected
uint16_t feedback_delay_ms; // After switching, wait for this delay before evaluating feedback pin
uint8_t feedback_inverted; // 0: feedback normal (mirror contact, high when relay is off), 1: inverted
uint8_t pwm_dc; // 100: Do not use PWM. 1-99: Set PWM Duty cycle after delay
uint16_t pwm_delay_ms; // Delay in ms after which the PWM starts
uint16_t switchoff_delay_ms; // Delay before switching relay off. Can be used to set a small delay between EMG_OUT
// and relays off [SR-SL-2]
} RelayConfig;
typedef struct CB_COMPILER_ATTR_PACK _safety_config {
CbSafetyMode pp_mode; // set to 0: disabled 1: US type 1, 2: EU type 2
uint8_t cp_avg_ms; // default is 10ms / pulses
RelayConfig relays[3]; // Config for the 3 relay I/Os
uint8_t inverted_emergency_input; // 0: normal operation, 1: emergency input is inverted
uint8_t temperature_limit_pt1000_C; // Temperature limit for the PT1000 inputs. Relays will switch off if temperature is above the limit. Setting this to 0 will disable the feature.
} SafetyConfig;
typedef struct CB_COMPILER_ATTR_PACK _CbGpioConfig {
CbGpioMode mode;
CbGpioPulls pulls;
uint8_t strap_option_mdns_naming; // sample as bit for mdns id;
uint16_t mode_config; // Config value for the mode, e.g. frequency of PWM
} CbGpioConfig;
typedef struct CB_COMPILER_ATTR_PACK _CbUartConfig {
CbUartBaudrate baudrate;
CbUartStopbits stopbits;
CbUartParity parity;
} CbUartConfig;
typedef struct CB_COMPILER_ATTR_PACK _CbCanConfig {
CbCanBaudrate baudrate;
} CbCanConfig;
typedef struct CB_COMPILER_ATTR_PACK _CbNetworkConfig {
char mdns_name[20]; // custom MDNS name
} CbNetworkConfig;
// Final complete config struct
#define CB_CONFIG_VERSION 0
typedef struct CB_COMPILER_ATTR_PACK _cb_config {
uint32_t config_version;
SafetyConfig safety;
CbGpioConfig gpios[CB_NUMBER_OF_GPIOS];
CbUartConfig uarts[CB_NUMBER_OF_UARTS];
CbCanConfig can;
CbNetworkConfig network;
uint8_t plc_powersaving_mode;
} CbConfig;

View File

@@ -0,0 +1,151 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
/**
* \file Common structs used between linux and the STM32 dev board. Data
* will be sent raw over the UDP socket, with the sender using
* \ref send(struct, sizeof(CbStruct))
* and the receiver using
* \ref receive(raw_bytes, sizeof(CbStruct))
* CbStruct *struct = reinterpret_cast<CbStruct *>(raw_bytes);
*
* Notes:
* 1) After V1 structs will not be able to remove fields, only add fields
* after the existing fields
* 2) There can be problems with variable length structs, for example
* CbFirmwarePacket that can have a payload with lengths 0-1024
*
* Test files are added at the end that check the sizes of the structs
* at compile time, to determine the fact that they are consistent
* across platforms.
*/
#pragma once
#include <stdint.h>
#include "cb_config.h"
#ifndef __cplusplus
#error "This header is C++ only"
#endif
enum class AppUDPResponse : uint32_t {
AUR_Ok = 0x500D500D, AUR_Bad = 0xBADBAD00,
};
enum class CbType : uint8_t {
CCS_EVSE = 0, CCS_EV = 1,
};
/*
* What type of message is on the socket
*/
enum class CbStructType : uint16_t {
// track IP with timeout and port
// Housekeepig, heartbeat/config (safety_config, serial port(fixed)/CAN bitrate, gpio config, mdns module name), fw version, softreset,
CST_HostToCb_Heartbeat = 1,
CST_CbToHost_Heartbeat = 2,
// track IP with timeout and port
// GPIO client
CST_HostToCb_Gpio = 3,
CST_CbToHost_Gpio = 4,
// FW update
CST_CbFirmwareReply = 0xFFF9,
CST_CbFirmwareStart = 0xFFFA,
CST_CbFirmwarePacket = 0xFFFB,
CST_CbFirmwareFinish = 0xFFFC,
CST_CbFirmwareUpdateCancel = 0xFFFD,
CST_CbFirmwarePing = 0xFFFE,
CST_CbFirmwareGetVersion = 0xFFFF,
};
/*
This container message is used for all generic module management packets
*/
template<typename T>
struct CB_COMPILER_ATTR_PACK CbManagementPacket {
CbStructType type;
T data;
};
template<> struct CB_COMPILER_ATTR_PACK CbManagementPacket<void> {
CbStructType type;
};
struct CB_COMPILER_ATTR_PACK CbGpioPacket {
uint8_t number_of_gpios; // Just to check compatibility
uint16_t gpio_values[CB_NUMBER_OF_GPIOS]; // Actual value, 0: low, 1: high, or duty cycle for PWM
};
struct CB_COMPILER_ATTR_PACK CbHeartbeatPacket {
CbConfig module_config;
};
struct CB_COMPILER_ATTR_PACK CbHeartbeatReplyPacket {
int32_t cp_hi_mV;
int32_t cp_lo_mV;
int32_t vdd_core;
int32_t vdd_3v3;
int32_t vdd_refint;
int32_t vdd_12V;
int32_t vdd_N12V;
int32_t pp_mOhm;
int32_t pp_voltage_mV;
uint8_t relay_state_feedback[3];
int16_t temperature_mcu_C;
int16_t temperature_pcb_C;
int16_t temperature_modem_C;
int16_t temperature_PT1000_C[2];
int32_t uptime_ms;
};
struct CB_COMPILER_ATTR_PACK CbFirmwareStart {
uint8_t is_secure_fw :1;
uint8_t requires_crc_verification :1;
uint8_t requires_sha256_verification :1;
uint8_t requires_signature_verification :1;
uint8_t requires_decryption :1;
// IV in case we require decryption
uint8_t iv[16];
};
struct CB_COMPILER_ATTR_PACK CbFirmwarePacket {
// If it is the last packet sent, used when we need to take care of
// the padding bytes in case of decryption or other operations
uint8_t last_packet :1;
uint16_t sector;
uint16_t data_len;
uint8_t data[1024];
};
struct CB_COMPILER_ATTR_PACK CbFirmwareEnd {
uint32_t firmware_len;
// Signature for the firmware in the faw format
uint8_t fw_signature[128];
uint8_t fw_signature_len;
uint8_t watermark_secure_end;
};
struct CB_COMPILER_ATTR_PACK CbFirmwareUpdateCancel {
uint8_t dummy;
};
struct CB_COMPILER_ATTR_PACK CbFirmwarePing {
uint8_t dummy;
};
struct CB_COMPILER_ATTR_PACK CbFirmwareGetVersion {
uint8_t dummy;
};
#include "test/cb_management_test.h"

View File

@@ -0,0 +1,25 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
/**
* \file compiler utilities and Pionix defines for
* cross-compiling
*/
#pragma once
#if defined(__cplusplus)
#define CB_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
#else
#define CB_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
#endif
#define CB_COMPILER_ATTR_PACK __attribute__((packed))
// Should be < MTU (defined as #define NX_DRIVER_ETHERNET_MTU 1514)
#define CB_MAX_UDP_PACKET_SIZE (1024 + 256)
// -128 since we might want some non-struct metadata
#define CB_MAX_CB_STRUCT_SIZE (CB_MAX_UDP_PACKET_SIZE - 128)
#define CB_MAX_STRING_SIZE 64
#define cb_string(name) int8_t name[CB_MAX_STRING_SIZE]

View File

@@ -0,0 +1,62 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EVSE_BSP_CB_TO_HOST_H
#define EVSE_BSP_CB_TO_HOST_H
#include <stdint.h>
#include "cb_platform.h"
#include "cb_common.h"
struct CB_COMPILER_ATTR_PACK evse_bsp_cb_to_host {
// add version number as first uint16 ????
// potentially unused, ignore for now
uint8_t reset_reason;
CpState cp_state;
uint8_t relay_state;
SafetyErrorFlags error_flags;
uint8_t pp_state_type1;
uint8_t pp_state_type2;
uint8_t lock_state;
uint32_t hv_mV;
// still define handling set for
uint8_t stop_charging;
uint16_t cp_duty_cycle;
};
/* Enum definitions */
typedef enum _RelayState {
RelayState_Open = 0,
RelayState_Closed = 1
} RelaiseState;
typedef enum _ResetReason {
ResetReason_USER = 0,
ResetReason_WATCHDOG = 1
} ResetReason;
typedef enum _PpState_Type2 {
PpState_Type2_STATE_NC = 0,
PpState_Type2_STATE_13A = 1,
PpState_Type2_STATE_20A = 2,
PpState_Type2_STATE_32A = 3,
PpState_Type2_STATE_70A = 4,
PpState_Type2_STATE_FAULT = 5
} PpState_Type2;
typedef enum _PpState_Type1 {
PpState_Type1_STATE_NotConnected,
PpState_Type1_STATE_Connected_Button_Pressed,
PpState_Type1_STATE_Connected,
PpState_Type1_STATE_Invalid
} PpState_Type1;
typedef enum _LockState {
LockState_UNDEFINED = 0,
LockState_UNLOCKED = 1,
LockState_LOCKED = 2
} LockState;
#include "test/evse_bsp_cb_to_host_test.h"
#endif // EVSE_BSP_CB_TO_HOST_H

View File

@@ -0,0 +1,25 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EVSE_BSP_HOST_TO_CB_H
#define EVSE_BSP_HOST_TO_CB_H
#include <stdint.h>
#include "cb_platform.h"
struct CB_COMPILER_ATTR_PACK evse_bsp_host_to_cb {
uint8_t connector_lock; /* 0: unlock, otherwise: lock */
uint32_t pwm_duty_cycle; /* in 0.01 %, 0 = State F, 10000 = X1 */
uint8_t allow_power_on; /* 0 false, true otherwise */
uint8_t reset; /* 0 false, true otherwise */
uint8_t ovm_enable; /* 0 disabled, 1: enabled */
uint8_t ovm_reset_errors; /* 0 leave errors untouched, 1: clear error bits for OVM */
uint32_t ovm_limit_emergency_mV; /* 9ms limit in mV */
uint32_t ovm_limit_error_mV; /* 400ms limit in mV */
CpState ev_set_cp_state; /* Set CP state (EV side only) */
uint8_t ev_set_diodefault; /* Set/Clear DF state (EV side only) */
};
#include "test/evse_bsp_host_to_cb_test.h"
#endif // EVSE_BSP_H

View File

@@ -0,0 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#pragma once
#include "protocol/cb_can_message.h"
#include "protocol/cb_platform.h"
CB_STATIC_ASSERT(sizeof(CanErrorState) == 4, "CanErrorState data size!!");
CB_STATIC_ASSERT(sizeof(CanBitrate) == 4, "CanBitrate data size!!");
CB_STATIC_ASSERT(sizeof(CanFDBitrate) == 4, "CanFDBitrate data size!!");
CB_STATIC_ASSERT(sizeof(CanStatistics) == 4+4+4+4, "CanStatistics data size!!");
CB_STATIC_ASSERT(sizeof(struct cb_can_message) == 1+4+16+4+4+1+4+1+64+1, "cb_can_message type size!!");

View File

@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
/**
* \file Test utilities used to determine that the used types
* have the same sizes independent of the platforms that we
* are using. Added to make sure that reinterpret_cast or other
* types of cast will yield the same types across platform
*/
#pragma once
CB_STATIC_ASSERT(sizeof(AppUDPResponse) == 4, "Wrong AppUDPReponse type size!");
CB_STATIC_ASSERT(sizeof(CbType) == 1, "Wrong CB type size!");
CB_STATIC_ASSERT(sizeof(CbStructType) == 2, "Wrong CB type size!");
CB_STATIC_ASSERT((sizeof(CbFirmwareStart) == 16 + 1 && sizeof(CbFirmwareStart) <= CB_MAX_CB_STRUCT_SIZE),
"Wrong CB type size!");
CB_STATIC_ASSERT((sizeof(CbFirmwarePacket) == 1 + 2 + 2 + 1024 && sizeof(CbFirmwarePacket) <= CB_MAX_CB_STRUCT_SIZE),
"Wrong CB type size!");
CB_STATIC_ASSERT((sizeof(CbFirmwareEnd) == 4 + 1 + (128 + 1) && sizeof(CbFirmwareEnd) <= CB_MAX_CB_STRUCT_SIZE),
"Wrong CB type size!");
CB_STATIC_ASSERT((sizeof(CbHeartbeatPacket) == 119 && sizeof(CbHeartbeatPacket) <= CB_MAX_CB_STRUCT_SIZE),
"Wrong CB type size!");

View File

@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#pragma once
CB_STATIC_ASSERT(sizeof(struct evse_bsp_cb_to_host)== 11+4+4+2, "Wrong evse_bsp_cb_to_host size!!!");

View File

@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#pragma once
CB_STATIC_ASSERT (sizeof(struct evse_bsp_host_to_cb) == 7+9+1+1+1, "Wrong evse_bsp_host_to_cb size!");