Compare commits
2 Commits
main
...
debug/flic
| Author | SHA1 | Date | |
|---|---|---|---|
| 993920fb1c | |||
| b09121b876 |
@@ -4,16 +4,15 @@ on: [push]
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Build-Release:
|
Build-Release:
|
||||||
runs-on: cls-build
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
#- name: Install dependencies
|
- name: Install dependencies
|
||||||
# run: apt-get update && apt-get install -y gcc-arm-none-eabi binutils-arm-none-eabi ninja-build cmake protobuf-compiler python3 python3-grpcio python3-protobuf python3-pkg-resources python3-requests
|
run: apt-get update && apt-get install -y gcc-arm-none-eabi binutils-arm-none-eabi ninja-build cmake protobuf-compiler python3 python3-grpcio python3-protobuf python3-pkg-resources python3-requests
|
||||||
# run: pip install setuptools
|
# run: pip install setuptools
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.TOKEN }}
|
|
||||||
submodules: true
|
submodules: true
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
|
|||||||
12
.gitmodules
vendored
12
.gitmodules
vendored
@@ -9,19 +9,13 @@
|
|||||||
url = https://github.com/ThrowTheSwitch/Unity
|
url = https://github.com/ThrowTheSwitch/Unity
|
||||||
[submodule "Application/CLS"]
|
[submodule "Application/CLS"]
|
||||||
path = Application/CLS
|
path = Application/CLS
|
||||||
url = https://git.revwal.de/oliver/libCLS.git
|
url = git@git.lan:oliver/libCLS.git
|
||||||
[submodule "lib/ulog"]
|
[submodule "lib/ulog"]
|
||||||
path = lib/ulog
|
path = lib/ulog
|
||||||
url = https://github.com/rdpoor/ulog.git
|
url = https://github.com/rdpoor/ulog.git
|
||||||
[submodule "lib/ee24"]
|
[submodule "lib/ee24"]
|
||||||
path = lib/ee24
|
path = lib/ee24
|
||||||
url = https://git.revwal.de/oliver/ee24.git
|
url = git@git.lan:oliver/ee24.git
|
||||||
[submodule "proto"]
|
[submodule "proto"]
|
||||||
path = proto
|
path = proto
|
||||||
url = https://git.revwal.de/oliver/cls-proto.git
|
url = git@git.lan:oliver/cls-proto.git
|
||||||
[submodule "lib/TinyFrame"]
|
|
||||||
path = lib/TinyFrame
|
|
||||||
url = https://github.com/MightyPork/TinyFrame.git
|
|
||||||
[submodule "Application/MLZR_Comm"]
|
|
||||||
path = Application/MLZR_Comm
|
|
||||||
url = https://git.revwal.de/ODDIY/MLZR_Comm.git
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ void BSP_SDLogger_Init(int log_number) {
|
|||||||
ULOG_ERROR("Failed to open file %s", file_name);
|
ULOG_ERROR("Failed to open file %s", file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ULOG_SUBSCRIBE(BSP_SDLogger_ULOG, ULOG_DEBUG_LEVEL);
|
ULOG_SUBSCRIBE(BSP_SDLogger_ULOG, ULOG_DEBUG_LEVEL);
|
||||||
|
|
||||||
// close the file
|
// close the file
|
||||||
f_close(&file);
|
f_close(&file);
|
||||||
|
|||||||
Submodule Application/CLS updated: 58b50b2fb3...7080707f9d
@@ -1,5 +1,4 @@
|
|||||||
#include "CLS_BSP.h"
|
#include "CLS_BSP.h"
|
||||||
#include "CLSAddress.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CLS_BSP_FDCAN
|
#ifdef CLS_BSP_FDCAN
|
||||||
@@ -68,9 +67,4 @@ CLS_Position_t CLS_BSP_GetPosition(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CLS_BSP_SetPosition(CLS_Position_t position) {
|
void CLS_BSP_SetPosition(CLS_Position_t position) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "BSP_GPIO.h"
|
|
||||||
|
|
||||||
@@ -12,4 +12,4 @@ target_sources(${PROJECT_NAME}
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE CLS BSP Vehicle)
|
target_link_libraries(${PROJECT_NAME} PRIVATE CLS)
|
||||||
@@ -2,6 +2,4 @@ add_subdirectory(Tasks)
|
|||||||
add_subdirectory(CLS)
|
add_subdirectory(CLS)
|
||||||
add_subdirectory(CLS_BSP)
|
add_subdirectory(CLS_BSP)
|
||||||
add_subdirectory(BSP)
|
add_subdirectory(BSP)
|
||||||
add_subdirectory(ram_loader)
|
add_subdirectory(ram_loader)
|
||||||
add_subdirectory(MLZR_Comm)
|
|
||||||
add_subdirectory(Vehicle)
|
|
||||||
Submodule Application/MLZR_Comm deleted from 48a98f4c82
@@ -12,8 +12,6 @@ target_sources(${PROJECT_NAME}
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/FirmwareUpdate.c
|
${CMAKE_CURRENT_LIST_DIR}/FirmwareUpdate.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/LightTask.c
|
${CMAKE_CURRENT_LIST_DIR}/LightTask.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/LightState.c
|
${CMAKE_CURRENT_LIST_DIR}/LightState.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/Headlight_can.c
|
|
||||||
|
|
||||||
INTERFACE
|
INTERFACE
|
||||||
${CMAKE_CURRENT_LIST_DIR}/UsbDataHandler.h
|
${CMAKE_CURRENT_LIST_DIR}/UsbDataHandler.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/CanDataTask.h
|
${CMAKE_CURRENT_LIST_DIR}/CanDataTask.h
|
||||||
@@ -24,4 +22,4 @@ target_sources(${PROJECT_NAME}
|
|||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC PROTOS CLS)
|
target_link_libraries(${PROJECT_NAME} PUBLIC PROTOS CLS)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE Revision CLS_BSP BSP ulog Vehicle ram_loader)
|
target_link_libraries(${PROJECT_NAME} PRIVATE Revision CLS_BSP BSP ulog ram_loader)
|
||||||
@@ -11,7 +11,6 @@
|
|||||||
#include "ulog.h"
|
#include "ulog.h"
|
||||||
#include "BSP_POWER.h"
|
#include "BSP_POWER.h"
|
||||||
#include "BSP_GPIO.h"
|
#include "BSP_GPIO.h"
|
||||||
#include "Vehicle.h"
|
|
||||||
// Define thread flags
|
// Define thread flags
|
||||||
#define FLAG_FDCAN_RX_FIFO0 (1<<0)
|
#define FLAG_FDCAN_RX_FIFO0 (1<<0)
|
||||||
#define FLAG_FDCAN_RX_FIFO1 (1<<1)
|
#define FLAG_FDCAN_RX_FIFO1 (1<<1)
|
||||||
@@ -47,7 +46,7 @@ const osThreadAttr_t CarCanTask_attr = {
|
|||||||
.priority = osPriorityNormal,
|
.priority = osPriorityNormal,
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint64_t last_car_message_time = 0;
|
|
||||||
|
|
||||||
uint32_t dlcDecode(uint32_t dlcCode) {
|
uint32_t dlcDecode(uint32_t dlcCode) {
|
||||||
switch(dlcCode) {
|
switch(dlcCode) {
|
||||||
@@ -131,6 +130,11 @@ void CanDataTask_func(void *argument) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint64_t last_unlock_message_time = UINT64_MAX;
|
||||||
|
static uint64_t last_car_message_time = 0;
|
||||||
|
static uint8_t car_can_brightness = 255;
|
||||||
|
static float car_can_speed = 0;
|
||||||
|
static int car_can_direction = 0;
|
||||||
|
|
||||||
// convert byte to 2 hex characters
|
// convert byte to 2 hex characters
|
||||||
void byteToHex(uint8_t byte, char * hex) {
|
void byteToHex(uint8_t byte, char * hex) {
|
||||||
@@ -139,10 +143,6 @@ void byteToHex(uint8_t byte, char * hex) {
|
|||||||
hex[1] = hexLookup[byte & 0x0F];
|
hex[1] = hexLookup[byte & 0x0F];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static FDCAN_RxHeaderTypeDef RxHeader = {0};
|
|
||||||
static uint8_t RxData[8] = {0};
|
|
||||||
|
|
||||||
void CarCanTask_func(void *argument) {
|
void CarCanTask_func(void *argument) {
|
||||||
|
|
||||||
// for testing accept all messages from the car can bus
|
// for testing accept all messages from the car can bus
|
||||||
@@ -152,8 +152,20 @@ void CarCanTask_func(void *argument) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vehicle_Setup_CAN();
|
|
||||||
|
FDCAN_FilterTypeDef sFilterConfig;
|
||||||
|
sFilterConfig.IdType = FDCAN_STANDARD_ID;
|
||||||
|
sFilterConfig.FilterIndex = 0;
|
||||||
|
sFilterConfig.FilterType = CLS_BSP_CAN_FILTER_LIST;
|
||||||
|
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
|
||||||
|
sFilterConfig.FilterID1 = 0x391;
|
||||||
|
sFilterConfig.FilterID2 = 0x395;
|
||||||
|
HAL_FDCAN_ConfigFilter(&hfdcan2, &sFilterConfig);
|
||||||
|
|
||||||
|
sFilterConfig.FilterIndex = 1;
|
||||||
|
sFilterConfig.FilterID1 = 0x351;
|
||||||
|
sFilterConfig.FilterID2 = 0x635;
|
||||||
|
HAL_FDCAN_ConfigFilter(&hfdcan2, &sFilterConfig);
|
||||||
|
|
||||||
/* Start the FDCAN module */
|
/* Start the FDCAN module */
|
||||||
if (HAL_FDCAN_Start(&hfdcan2) != HAL_OK){
|
if (HAL_FDCAN_Start(&hfdcan2) != HAL_OK){
|
||||||
@@ -164,7 +176,8 @@ void CarCanTask_func(void *argument) {
|
|||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FDCAN_RxHeaderTypeDef RxHeader;
|
||||||
|
uint8_t RxData[8];
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
// wait for interrupt event on any fifo
|
// wait for interrupt event on any fifo
|
||||||
@@ -248,8 +261,71 @@ void CarCanTask_func(void *argument) {
|
|||||||
if (HAL_FDCAN_GetRxMessage(&hfdcan2, FDCAN_RX_FIFO1, &RxHeader, RxData) != HAL_OK) {
|
if (HAL_FDCAN_GetRxMessage(&hfdcan2, FDCAN_RX_FIFO1, &RxHeader, RxData) != HAL_OK) {
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
} else {
|
} else {
|
||||||
|
char msg[17] = {0};
|
||||||
|
|
||||||
Vehicle_Receive_CAN(RxHeader, RxData);
|
|
||||||
|
// do something with the can data
|
||||||
|
|
||||||
|
|
||||||
|
if(RxHeader.Identifier == 0x391) {
|
||||||
|
byteToHex(RxData[0], &msg[0]);
|
||||||
|
byteToHex(RxData[1], &msg[2]);
|
||||||
|
byteToHex(RxData[2], &msg[4]);
|
||||||
|
if (RxData[1] == 0x04)
|
||||||
|
{
|
||||||
|
// car was unlocked
|
||||||
|
last_unlock_message_time = osKernelGetTickCount();
|
||||||
|
}
|
||||||
|
else if (RxData[1] ==0x80)
|
||||||
|
{
|
||||||
|
// car was locked
|
||||||
|
if (!BSP_GPIO_K15isSet()) {
|
||||||
|
NVIC_SystemReset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RxHeader.Identifier == 0x395) {
|
||||||
|
byteToHex(RxData[0], &msg[0]);
|
||||||
|
|
||||||
|
// send the unlock message to the car
|
||||||
|
if ((RxData[0] & 0x0F) == 0x01) {
|
||||||
|
// car was unlocked
|
||||||
|
last_unlock_message_time = osKernelGetTickCount();
|
||||||
|
ULOG_DEBUG("Unlock message received");
|
||||||
|
|
||||||
|
} else if ((RxData[0] & 0x0F) == 0x02) {
|
||||||
|
// car was locked
|
||||||
|
if (!BSP_GPIO_K15isSet()) {
|
||||||
|
NVIC_SystemReset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// speed signal
|
||||||
|
// AA BB XX YY 00 00 00 00
|
||||||
|
// Speed (XX*(2^8)+(YY-1))/190
|
||||||
|
// direction AA = 0x00 forward, 0x02 backward
|
||||||
|
if (RxHeader.Identifier == 0x351) {
|
||||||
|
|
||||||
|
uint16_t speed = (RxData[2] << 8) + RxData[3];
|
||||||
|
float speed_kmh = (speed - 1) / 190.0;
|
||||||
|
car_can_speed = speed_kmh;
|
||||||
|
car_can_direction = RxData[0];
|
||||||
|
ULOG_DEBUG("Speed: %f, Direction: %d", car_can_speed, car_can_direction);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// brightness knob in 0 - 100
|
||||||
|
if (RxHeader.Identifier == 0x635) {
|
||||||
|
// scale the brightness to 0 - 255 only using integer math
|
||||||
|
car_can_brightness = ((uint32_t)RxData[0] * 255) / 100;
|
||||||
|
ULOG_DEBUG("Brightness: %d", car_can_brightness);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//ULOG_DEBUG("Used Car MSG: %x, %d %s", RxHeader.Identifier, CLS_BSP_DLC_ToBytes(RxHeader.DataLength), msg );
|
//ULOG_DEBUG("Used Car MSG: %x, %d %s", RxHeader.Identifier, CLS_BSP_DLC_ToBytes(RxHeader.DataLength), msg );
|
||||||
}
|
}
|
||||||
@@ -263,6 +339,9 @@ void CarCanTask_func(void *argument) {
|
|||||||
* @return true if a car can message has been received
|
* @return true if a car can message has been received
|
||||||
* @return false if no car can message has been received
|
* @return false if no car can message has been received
|
||||||
*/
|
*/
|
||||||
|
bool CanDataTask_gotCarCanMessage() {
|
||||||
|
return last_unlock_message_time != UINT64_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CanDataTask_CarCanActive() {
|
bool CanDataTask_CarCanActive() {
|
||||||
@@ -271,9 +350,20 @@ bool CanDataTask_CarCanActive() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return osKernelGetTickCount() - last_car_message_time < 1000;
|
return osKernelGetTickCount() - last_car_message_time < 1000;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t CanDataTask_CarCanBrightness() {
|
||||||
|
return car_can_brightness;
|
||||||
|
}
|
||||||
|
|
||||||
|
float CanDataTask_CarCanSpeed() {
|
||||||
|
return car_can_speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CanDataTask_CarCanDirectionIsForward() {
|
||||||
|
return car_can_direction == 0;
|
||||||
|
}
|
||||||
|
|
||||||
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) {
|
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) {
|
||||||
// Notify the thread
|
// Notify the thread
|
||||||
|
|||||||
@@ -1,116 +0,0 @@
|
|||||||
|
|
||||||
#include "UsbDataHandler.h"
|
|
||||||
#include "headlight.pb.h"
|
|
||||||
#include "CanDataHandler.h"
|
|
||||||
#include "stdint.h"
|
|
||||||
#include "cmsis_os2.h"
|
|
||||||
#include "CLS.h"
|
|
||||||
#include "CLS_BSP.h"
|
|
||||||
#include "CLSAddress.h"
|
|
||||||
#include "ulog.h"
|
|
||||||
#include "Vehicle.h"
|
|
||||||
|
|
||||||
cls_headlight_RequestSettings msg_cls_headlight_RequestSettings;
|
|
||||||
cls_headlight_Settings msg_cls_headlight_Settings;
|
|
||||||
cls_headlight_SaveSettings msg_cls_headlight_SaveSettings;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct Headlight_Control_Setting {
|
|
||||||
float alpha;
|
|
||||||
uint16_t on_threshold;
|
|
||||||
uint16_t off_threshold;
|
|
||||||
} Headlight_Control_Setting_t;
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t headlight_amblight = 0;
|
|
||||||
|
|
||||||
void CanData_ambilight(CanDataId canid, uint8_t* data, uint8_t len) {
|
|
||||||
if(len == 2) {
|
|
||||||
headlight_amblight = (data[1] << 8) | data[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
ULOG_INFO("Ambilight: %d", headlight_amblight);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddHeadlightMessages() {
|
|
||||||
CanData_regEventMsg(GENERATE_CLS_ADDRESS(CLS_CODE_STATUS, 0, CLS_CH_STA_AMBIENTLIGHT), CanData_ambilight);
|
|
||||||
}
|
|
||||||
|
|
||||||
// whan a message is received, this function is called
|
|
||||||
void DataClbk_cls_headlight_Settings(void* msg, uint32_t length) {
|
|
||||||
DATA_CLBK_SETUP(cls_headlight_Settings);
|
|
||||||
uint8_t device = msg_cls_headlight_Settings.deviceId;
|
|
||||||
|
|
||||||
uint16_t msg_light_setting = GENERATE_CLS_ADDRESS(CLS_CODE_CONFIG, device, 0);
|
|
||||||
CLS_BSP_TxHeaderType can_header = CREATE_BSP_CAN_HEADER(msg_light_setting, CLS_BSP_DLC_BYTES_8);
|
|
||||||
|
|
||||||
|
|
||||||
Headlight_Control_Setting_t data = {0};
|
|
||||||
data.alpha = msg_cls_headlight_Settings.alpha;
|
|
||||||
data.on_threshold = msg_cls_headlight_Settings.on_threshold;
|
|
||||||
data.off_threshold = msg_cls_headlight_Settings.off_threshold;
|
|
||||||
|
|
||||||
CLS_BSP_CAN_AddMessageToSend(&can_header, (uint8_t*)&data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DataClbk_cls_headlight_SaveSettings(void* msg, uint32_t length) {
|
|
||||||
DATA_CLBK_SETUP(cls_headlight_SaveSettings);
|
|
||||||
|
|
||||||
uint8_t device = msg_cls_headlight_SaveSettings.deviceId;
|
|
||||||
uint16_t msg_light_setting = GENERATE_CLS_ADDRESS(CLS_CODE_CONFIG, device, 4);
|
|
||||||
CLS_BSP_TxHeaderType can_header = CREATE_BSP_CAN_HEADER(msg_light_setting, CLS_BSP_DLC_BYTES_1);
|
|
||||||
CLS_BSP_CAN_AddMessageToSend(&can_header, (uint8_t*)"X");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static Headlight_Control_Setting_t response_theme = {0};
|
|
||||||
static cls_headlight_Settings headligh_settings = {0};
|
|
||||||
void CanData_responseHeadlightSetting(CanDataId canid, uint8_t* data, uint8_t len) {
|
|
||||||
if(len == 8) {
|
|
||||||
memcpy(&response_theme, data, 8);
|
|
||||||
|
|
||||||
headligh_settings.alpha = response_theme.alpha;
|
|
||||||
headligh_settings.on_threshold = response_theme.on_threshold;
|
|
||||||
headligh_settings.off_threshold = response_theme.off_threshold;
|
|
||||||
headligh_settings.deviceId = (canid >> 3) & 0x1F;
|
|
||||||
|
|
||||||
|
|
||||||
USBDataResonse(&headligh_settings,cls_headlight_Settings_fields, cls_usb_PackageType_HEADLIGHT_SETTINGS);
|
|
||||||
}
|
|
||||||
|
|
||||||
CanData_removeEvent(canid);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DataClbk_cls_headlight_RequestSettings(void* msg, uint32_t length) {
|
|
||||||
DATA_CLBK_SETUP(cls_headlight_RequestSettings);
|
|
||||||
uint8_t device = msg_cls_headlight_RequestSettings.deviceId;
|
|
||||||
uint8_t data = 0;
|
|
||||||
|
|
||||||
uint16_t msg_light_setting = GENERATE_CLS_ADDRESS(CLS_CODE_CONFIG, device, 7);
|
|
||||||
CLS_BSP_TxHeaderType can_header = CREATE_BSP_CAN_HEADER(msg_light_setting, CLS_BSP_DLC_BYTES_1);
|
|
||||||
|
|
||||||
|
|
||||||
CanData_regEventMsg(msg_light_setting,CanData_responseHeadlightSetting);
|
|
||||||
|
|
||||||
|
|
||||||
CLS_BSP_CAN_AddMessageToSend(&can_header, (uint8_t*)&data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DataClbk_cls_headlight_RequestBrightness(void* msg, uint32_t length) {
|
|
||||||
|
|
||||||
cls_headlight_RequestBrightness msg_cls_headlight_RequestBrightness;
|
|
||||||
memcpy(&msg_cls_headlight_RequestBrightness, msg, sizeof(cls_headlight_RequestBrightness));
|
|
||||||
|
|
||||||
cls_headlight_Brightness msg_cls_headlight_Brightness;
|
|
||||||
msg_cls_headlight_Brightness.brightness = headlight_amblight;
|
|
||||||
USBDataResonse(&msg_cls_headlight_Brightness,cls_headlight_Brightness_fields, cls_usb_PackageType_HEADLIGHT_BRIGHTNESS);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "LightTask.h"
|
#include "LightTask.h"
|
||||||
#include "ulog.h"
|
#include "ulog.h"
|
||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
#include "Vehicle.h"
|
|
||||||
|
|
||||||
// Create the task with a specific priority and stack size
|
// Create the task with a specific priority and stack size
|
||||||
osThreadAttr_t task_attr = {
|
osThreadAttr_t task_attr = {
|
||||||
@@ -25,15 +24,89 @@ void LightStateTask_start(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Check if K15 is on for switching the light state
|
||||||
|
static bool isK15On()
|
||||||
|
{
|
||||||
|
return BSP_GPIO_K15isSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Define the threshold voltage for engine running
|
||||||
|
#define ENGINE_RUNNING_THRESHOLD 13.3 // 13.5V
|
||||||
|
|
||||||
|
// Define thresholds with hysteresis
|
||||||
|
#define ENGINE_RUNNING_THRESHOLD_HIGH (ENGINE_RUNNING_THRESHOLD + 0.125)
|
||||||
|
#define ENGINE_RUNNING_THRESHOLD_LOW (ENGINE_RUNNING_THRESHOLD - 0.125)
|
||||||
|
|
||||||
|
// Global variable to store the current engine state
|
||||||
|
static bool engineRunning = false;
|
||||||
|
|
||||||
|
// Function to initialize the engine state based on the initial voltage
|
||||||
|
static void initializeEngineState()
|
||||||
|
{
|
||||||
|
float initialVoltage = BSP_ADC_ReadBusValue();
|
||||||
|
if (initialVoltage > ENGINE_RUNNING_THRESHOLD)
|
||||||
|
{
|
||||||
|
engineRunning = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
engineRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the engine state is initialized once
|
||||||
|
static bool isEngineInitialized = false;
|
||||||
|
|
||||||
|
static bool isEngineRunning()
|
||||||
|
{
|
||||||
|
if (!isEngineInitialized)
|
||||||
|
{
|
||||||
|
initializeEngineState();
|
||||||
|
isEngineInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float voltage = BSP_ADC_ReadBusValue();
|
||||||
|
|
||||||
|
if (engineRunning)
|
||||||
|
{
|
||||||
|
// If engine is currently running, use the lower threshold to turn it off
|
||||||
|
if (voltage < ENGINE_RUNNING_THRESHOLD_LOW)
|
||||||
|
{
|
||||||
|
engineRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If engine is currently off, use the higher threshold to turn it on
|
||||||
|
if (voltage > ENGINE_RUNNING_THRESHOLD_HIGH)
|
||||||
|
{
|
||||||
|
engineRunning = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return engineRunning;
|
||||||
|
}
|
||||||
|
// check if the headlight is on and the engine is running to switch the light state
|
||||||
|
// we can check the headlight using the GPIO functions
|
||||||
|
static bool isHeadlightOn()
|
||||||
|
{
|
||||||
|
return BSP_GPIO_HeadLightIsSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Function to determine the next state of the light
|
// Function to determine the next state of the light
|
||||||
// return 1 as default state
|
// return 1 as default state
|
||||||
// return 2 if the engine is running
|
// return 2 if the engine is running
|
||||||
// return 3 if the headlight and engine is running
|
// return 3 if the headlight and engine is running
|
||||||
static int determineNextState()
|
static int determineNextState()
|
||||||
{
|
{
|
||||||
if (Vehicle_isHeadlightOn() && Vehicle_isEngineRunning()) {
|
if (isHeadlightOn() && isEngineRunning()) {
|
||||||
return 2;
|
return 2;
|
||||||
} else if (Vehicle_isEngineRunning()) {
|
} else if (isEngineRunning()) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include "BSP_GPIO.h"
|
#include "BSP_GPIO.h"
|
||||||
|
|
||||||
#include "CanDataTask.h"
|
#include "CanDataTask.h"
|
||||||
#include "Vehicle.h"
|
|
||||||
#include "BSP_ADC.h"
|
#include "BSP_ADC.h"
|
||||||
#define DIMM_DEADZONE_VOLTAGE 0.7
|
#define DIMM_DEADZONE_VOLTAGE 0.7
|
||||||
|
|
||||||
@@ -78,19 +77,19 @@ void LightTask_func(void *argument) {
|
|||||||
|
|
||||||
|
|
||||||
// calculate the brightness to send
|
// calculate the brightness to send
|
||||||
uint8_t brightness = lightSettings.brightness;
|
//uint8_t brightness = lightSettings.brightness;
|
||||||
// Read ADC battery voltage and dimmer voltage
|
// Read ADC battery voltage and dimmer voltage
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t dimm = 255;
|
//float dimmfactor = 1.0;
|
||||||
|
|
||||||
// currenlty not working
|
|
||||||
// only dimm if the headlight is on
|
// only dimm if the headlight is on
|
||||||
//if (Vehicle_isHeadlightOn()) {
|
//if (BSP_GPIO_HeadLightIsSet()) {
|
||||||
|
|
||||||
// new version over CAN
|
// new version over CAN
|
||||||
//dimm = Vehicle_Brightness();
|
//uint8_t precent = CanDataTask_CarCanBrightness();
|
||||||
|
//dimmfactor = (float)precent / 100.0;
|
||||||
|
|
||||||
// old version over ADC
|
// old version over ADC
|
||||||
// calculate the dimmfactor based on the battery voltage and the dimmer voltage
|
// calculate the dimmfactor based on the battery voltage and the dimmer voltage
|
||||||
@@ -105,15 +104,14 @@ void LightTask_func(void *argument) {
|
|||||||
//} else {
|
//} else {
|
||||||
// dimmfactor = (v_dimm - 4.0) / (v_bus - 4.0);
|
// dimmfactor = (v_dimm - 4.0) / (v_bus - 4.0);
|
||||||
//}
|
//}
|
||||||
|
// }
|
||||||
|
|
||||||
//}
|
//uint8_t adjustedBrightness = (uint8_t)(brightness * dimmfactor);
|
||||||
|
//lightSettings_dimmed.brightness = adjustedBrightness;
|
||||||
uint8_t adjustedBrightness = (brightness * dimm)/ 255;
|
//lightSettings_dimmed.theme = lightSettings.theme;
|
||||||
lightSettings_dimmed.brightness = adjustedBrightness;
|
|
||||||
lightSettings_dimmed.theme = lightSettings.theme;
|
|
||||||
|
|
||||||
|
lightSettings.brightness = 255;
|
||||||
CLS_BSP_CAN_AddMessageToSend(&can_header,(uint8_t*)&lightSettings_dimmed);
|
CLS_BSP_CAN_AddMessageToSend(&can_header,(uint8_t*)&lightSettings);
|
||||||
|
|
||||||
if( settingChangeTime !=0 && tick > settingChangeTime + settingSaveTimeout) {
|
if( settingChangeTime !=0 && tick > settingChangeTime + settingSaveTimeout) {
|
||||||
BSP_EE24_PartWrite(BSP_EE24_PART_GLOBAL_LIGHT, (uint8_t*) &lightSettings, sizeof(lightSettings));
|
BSP_EE24_PartWrite(BSP_EE24_PART_GLOBAL_LIGHT, (uint8_t*) &lightSettings, sizeof(lightSettings));
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "firmware.pb.h"
|
#include "firmware.pb.h"
|
||||||
#include "light.pb.h"
|
#include "light.pb.h"
|
||||||
#include "headlight.pb.h"
|
|
||||||
#include "usb_device.h"
|
#include "usb_device.h"
|
||||||
#include <pb_decode.h>
|
#include <pb_decode.h>
|
||||||
#include "cls_device.pb.h"
|
#include "cls_device.pb.h"
|
||||||
@@ -63,10 +62,7 @@ union {
|
|||||||
cls_light_SaveThemeSettings msg_cls_light_SaveThemeSettings;
|
cls_light_SaveThemeSettings msg_cls_light_SaveThemeSettings;
|
||||||
cls_light_RequestThemeSetting msg_cls_light_RequestThemeSetting;
|
cls_light_RequestThemeSetting msg_cls_light_RequestThemeSetting;
|
||||||
cls_usb_JumpToBootloader msg_cls_usb_JumpToBootloader;
|
cls_usb_JumpToBootloader msg_cls_usb_JumpToBootloader;
|
||||||
cls_headlight_Settings msg_cls_headlight_Settings;
|
|
||||||
cls_headlight_SaveSettings msg_cls_headlight_SaveSettings;
|
|
||||||
cls_headlight_RequestSettings msg_cls_headlight_RequestSettings;
|
|
||||||
cls_headlight_RequestBrightness msg_cls_headlight_RequestBrightness;
|
|
||||||
} mem_msg_decode;
|
} mem_msg_decode;
|
||||||
|
|
||||||
|
|
||||||
@@ -125,10 +121,6 @@ message_handler_t message_handlers[] = {
|
|||||||
MESSAGE_HANDLER(cls_usb_PackageType_LIGHT_SETTING_THEME_SAVE, cls_light_SaveThemeSettings),
|
MESSAGE_HANDLER(cls_usb_PackageType_LIGHT_SETTING_THEME_SAVE, cls_light_SaveThemeSettings),
|
||||||
MESSAGE_HANDLER(cls_usb_PackageType_LIGHT_REQUEST_THEME, cls_light_RequestThemeSetting),
|
MESSAGE_HANDLER(cls_usb_PackageType_LIGHT_REQUEST_THEME, cls_light_RequestThemeSetting),
|
||||||
MESSAGE_HANDLER(cls_usb_PackageType_JUMP_TO_BOOTLOADER, cls_usb_JumpToBootloader),
|
MESSAGE_HANDLER(cls_usb_PackageType_JUMP_TO_BOOTLOADER, cls_usb_JumpToBootloader),
|
||||||
MESSAGE_HANDLER(cls_usb_PackageType_HEADLIGHT_SETTINGS, cls_headlight_Settings),
|
|
||||||
MESSAGE_HANDLER(cls_usb_PackageType_HEADLIGHT_SAVE_SETTINGS, cls_headlight_SaveSettings),
|
|
||||||
MESSAGE_HANDLER(cls_usb_PackageType_HEADLIGHT_REQUEST_SETTINGS, cls_headlight_RequestSettings),
|
|
||||||
MESSAGE_HANDLER(cls_usb_PackageType_HEADLIGHT_REQUEST_BRIGHTNESS, cls_headlight_RequestBrightness),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -136,10 +136,6 @@ void DataClbk_cls_light_GlobalTheme(void* msg, uint32_t length);
|
|||||||
void DataClbk_cls_light_ThemeSettings(void* msg, uint32_t length);
|
void DataClbk_cls_light_ThemeSettings(void* msg, uint32_t length);
|
||||||
void DataClbk_cls_light_SaveThemeSettings(void* msg, uint32_t length);
|
void DataClbk_cls_light_SaveThemeSettings(void* msg, uint32_t length);
|
||||||
void DataClbk_cls_light_RequestThemeSetting(void* msg, uint32_t length);
|
void DataClbk_cls_light_RequestThemeSetting(void* msg, uint32_t length);
|
||||||
void DataClbk_cls_headlight_Settings(void* msg, uint32_t length);
|
|
||||||
void DataClbk_cls_headlight_SaveSettings(void* msg, uint32_t length);
|
|
||||||
void DataClbk_cls_headlight_RequestSettings(void* msg, uint32_t length);
|
|
||||||
void DataClbk_cls_headlight_RequestBrightness(void* msg, uint32_t length);
|
|
||||||
|
|
||||||
#include "usb.pb.h"
|
#include "usb.pb.h"
|
||||||
void USBDataResonse(void * msg, const pb_msgdesc_t *fields, cls_usb_PackageType typeid);
|
void USBDataResonse(void * msg, const pb_msgdesc_t *fields, cls_usb_PackageType typeid);
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
# Set the minimum required CMake version
|
|
||||||
cmake_minimum_required(VERSION 3.12)
|
|
||||||
|
|
||||||
# Set the project name
|
|
||||||
project(Vehicle)
|
|
||||||
|
|
||||||
# Add the source files for the library
|
|
||||||
set(SOURCES
|
|
||||||
Vehicle.c
|
|
||||||
Vehicle_can.c
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add the header files for the library
|
|
||||||
set(HEADERS
|
|
||||||
Vehicle.h
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create the library target
|
|
||||||
add_library(Vehicle ${SOURCES} ${HEADERS})
|
|
||||||
|
|
||||||
# Set the include directories for the library
|
|
||||||
target_include_directories(Vehicle PUBLIC ./)
|
|
||||||
|
|
||||||
# Set any additional compiler flags or options
|
|
||||||
# target_compile_options(Vehicle PRIVATE ...)
|
|
||||||
|
|
||||||
# Set any additional linker flags or options
|
|
||||||
# target_link_options(Vehicle PRIVATE ...)
|
|
||||||
|
|
||||||
# Specify any dependencies for the library
|
|
||||||
target_link_libraries(Vehicle BSP CLS CLS_BSP)
|
|
||||||
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
|
|
||||||
#include "Vehicle.h"
|
|
||||||
#include "BSP_GPIO.h"
|
|
||||||
#include "stdbool.h"
|
|
||||||
#include "BSP_ADC.h"
|
|
||||||
|
|
||||||
// Define the threshold voltage for engine running
|
|
||||||
#define ENGINE_RUNNING_THRESHOLD 13.0 // 13.5V
|
|
||||||
|
|
||||||
// Define thresholds with hysteresis
|
|
||||||
#define ENGINE_RUNNING_THRESHOLD_HIGH (ENGINE_RUNNING_THRESHOLD + 0.225)
|
|
||||||
#define ENGINE_RUNNING_THRESHOLD_LOW (ENGINE_RUNNING_THRESHOLD - 0.225)
|
|
||||||
|
|
||||||
// Global variable to store the current engine state
|
|
||||||
static bool engineRunning = false;
|
|
||||||
|
|
||||||
|
|
||||||
void Vehicle_Init() {
|
|
||||||
engineRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Vehicle_isHeadlightOn()
|
|
||||||
{
|
|
||||||
return BSP_GPIO_HeadLightIsSet();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Vehicle_isEngineRunning() {
|
|
||||||
|
|
||||||
|
|
||||||
float voltage = BSP_ADC_ReadBusValue();
|
|
||||||
|
|
||||||
if (engineRunning)
|
|
||||||
{
|
|
||||||
// If engine is currently running, use the lower threshold to turn it off
|
|
||||||
if (voltage < ENGINE_RUNNING_THRESHOLD_LOW)
|
|
||||||
{
|
|
||||||
engineRunning = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If engine is currently off, use the higher threshold to turn it on
|
|
||||||
if (voltage > ENGINE_RUNNING_THRESHOLD_HIGH)
|
|
||||||
{
|
|
||||||
engineRunning = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
return engineRunning;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Vehicle_isK15On() {
|
|
||||||
return BSP_GPIO_K15isSet();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "CLS.h"
|
|
||||||
#include "CLS_BSP.h"
|
|
||||||
#include "CLSAddress.h"
|
|
||||||
|
|
||||||
static CLS_VehicleStatus_t status = {0};
|
|
||||||
_Static_assert(sizeof(status) == 8, "CLS_HeatbeatData_t is not 8 bytes");
|
|
||||||
|
|
||||||
void CLS_VehicleHeatbeat(void *argument) {
|
|
||||||
CLS_BSP_TxHeaderType cls_vehicle_header = CREATE_BSP_CAN_HEADER(GENERATE_CLS_ADDRESS(CLS_CODE_STATUS,0,CLS_CH_STA_VEHICLE), CLS_BSP_DLC_BYTES_8);
|
|
||||||
|
|
||||||
|
|
||||||
status.k15 = Vehicle_isK15On();
|
|
||||||
status.headlight = Vehicle_isHeadlightOn();
|
|
||||||
status.engine = Vehicle_isEngineRunning();
|
|
||||||
status.speed = (uint8_t)Vehicle_Speed();
|
|
||||||
status.unlocked = Vehicle_UnlockedSignal();
|
|
||||||
|
|
||||||
CLS_BSP_CAN_AddMessageToSend(&cls_vehicle_header, (uint8_t*)&status);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
#include "fdcan.h"
|
|
||||||
#include "stdint.h"
|
|
||||||
#include "stdbool.h"
|
|
||||||
|
|
||||||
void Vehicle_Init();
|
|
||||||
|
|
||||||
bool Vehicle_isHeadlightOn();
|
|
||||||
|
|
||||||
bool Vehicle_isEngineRunning();
|
|
||||||
|
|
||||||
bool Vehicle_isK15On();
|
|
||||||
|
|
||||||
|
|
||||||
void Vehicle_Setup_CAN();
|
|
||||||
|
|
||||||
void Vehicle_Receive_CAN( FDCAN_RxHeaderTypeDef header, uint8_t* data);
|
|
||||||
|
|
||||||
|
|
||||||
bool Vehicle_gotUnlockMessage();
|
|
||||||
uint8_t Vehicle_Brightness();
|
|
||||||
float Vehicle_Speed();
|
|
||||||
int Vehicle_DirectionIsForward();
|
|
||||||
bool Vehicle_UnlockedSignal();
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
#include "Vehicle.h"
|
|
||||||
#include "fdcan.h"
|
|
||||||
#include "CLS.h"
|
|
||||||
#include "CLS_BSP.h"
|
|
||||||
#include "BSP_GPIO.h"
|
|
||||||
#include "cmsis_os2.h"
|
|
||||||
|
|
||||||
static uint64_t last_unlock_message_time = UINT64_MAX;
|
|
||||||
static uint8_t car_can_brightness = 255;
|
|
||||||
static float car_can_speed = 0;
|
|
||||||
static int car_can_direction = 0;
|
|
||||||
|
|
||||||
|
|
||||||
void Vehicle_Setup_CAN() {
|
|
||||||
|
|
||||||
|
|
||||||
FDCAN_FilterTypeDef sFilterConfig;
|
|
||||||
sFilterConfig.IdType = FDCAN_STANDARD_ID;
|
|
||||||
sFilterConfig.FilterIndex = 0;
|
|
||||||
sFilterConfig.FilterType = CLS_BSP_CAN_FILTER_LIST;
|
|
||||||
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
|
|
||||||
sFilterConfig.FilterID1 = 0x391;
|
|
||||||
sFilterConfig.FilterID2 = 0x395;
|
|
||||||
HAL_FDCAN_ConfigFilter(&hfdcan2, &sFilterConfig);
|
|
||||||
|
|
||||||
sFilterConfig.FilterIndex = 1;
|
|
||||||
sFilterConfig.FilterID1 = 0x351;
|
|
||||||
sFilterConfig.FilterID2 = 0x635;
|
|
||||||
HAL_FDCAN_ConfigFilter(&hfdcan2, &sFilterConfig);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void rx_unlock_key(uint8_t * RxData ) {
|
|
||||||
if (RxData[1] == 0x04)
|
|
||||||
{
|
|
||||||
// car was unlocked
|
|
||||||
last_unlock_message_time = osKernelGetTickCount();
|
|
||||||
}
|
|
||||||
else if (RxData[1] ==0x80)
|
|
||||||
{
|
|
||||||
// car was locked
|
|
||||||
if (!BSP_GPIO_K15isSet()) {
|
|
||||||
NVIC_SystemReset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rx_unlock_secure(uint8_t * RxData ) {
|
|
||||||
if ((RxData[0] & 0x0F) == 0x01) {
|
|
||||||
// car was unlocked
|
|
||||||
last_unlock_message_time = osKernelGetTickCount();
|
|
||||||
|
|
||||||
} else if ((RxData[0] & 0x0F) == 0x02) {
|
|
||||||
// car was locked
|
|
||||||
if (!BSP_GPIO_K15isSet()) {
|
|
||||||
NVIC_SystemReset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rx_speed(uint8_t * RxData) {
|
|
||||||
// speed signal
|
|
||||||
// AA BB XX YY 00 00 00 00
|
|
||||||
// Speed (XX*(2^8)+(YY-1))/190
|
|
||||||
// direction AA = 0x00 forward, 0x02 backward
|
|
||||||
uint16_t speed = (RxData[2] << 8) + RxData[3];
|
|
||||||
float speed_kmh = (speed - 1) / 190.0;
|
|
||||||
car_can_speed = speed_kmh;
|
|
||||||
car_can_direction = RxData[0];
|
|
||||||
//ULOG_DEBUG("Speed: %f, Direction: %d", car_can_speed, car_can_direction);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rx_brightness(uint8_t* RxData) {
|
|
||||||
// scale the brightness to 0 - 255 only using integer math
|
|
||||||
car_can_brightness = ((uint32_t)RxData[0] * 255) / 100;
|
|
||||||
//ULOG_DEBUG("Brightness: %d", car_can_brightness);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vehicle_Receive_CAN( FDCAN_RxHeaderTypeDef RxHeader, uint8_t* RxData) {
|
|
||||||
|
|
||||||
if(RxHeader.Identifier == 0x391) {
|
|
||||||
rx_unlock_key(RxData);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (RxHeader.Identifier == 0x395) {
|
|
||||||
rx_unlock_secure(RxData);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (RxHeader.Identifier == 0x351) {
|
|
||||||
rx_speed(RxData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// brightness knob in 0 - 100
|
|
||||||
if (RxHeader.Identifier == 0x635) {
|
|
||||||
rx_brightness(RxData);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Vehicle_gotUnlockMessage() {
|
|
||||||
return last_unlock_message_time != UINT64_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t Vehicle_Brightness() {
|
|
||||||
return car_can_brightness;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Vehicle_Speed() {
|
|
||||||
return car_can_speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Vehicle_DirectionIsForward() {
|
|
||||||
return car_can_direction == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static bool unlocked = false;
|
|
||||||
|
|
||||||
|
|
||||||
bool Vehicle_UnlockedSignal() {
|
|
||||||
|
|
||||||
if (unlocked) {
|
|
||||||
if(Vehicle_isK15On()) {
|
|
||||||
unlocked = false;
|
|
||||||
last_unlock_message_time = UINT64_MAX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!unlocked) {
|
|
||||||
if (Vehicle_gotUnlockMessage()) {
|
|
||||||
unlocked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return unlocked;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -124,7 +124,6 @@ nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS RELPATH proto
|
|||||||
proto/cls_device.proto
|
proto/cls_device.proto
|
||||||
proto/light.proto
|
proto/light.proto
|
||||||
proto/usb.proto
|
proto/usb.proto
|
||||||
proto/headlight.proto
|
|
||||||
)
|
)
|
||||||
add_library(PROTOS ${PROTO_SRCS} ${PROTO_HDRS})
|
add_library(PROTOS ${PROTO_SRCS} ${PROTO_HDRS})
|
||||||
target_include_directories(PROTOS PUBLIC ${NANOPB_INCLUDE_DIRS} ${PROJECT_BINARY_DIR})
|
target_include_directories(PROTOS PUBLIC ${NANOPB_INCLUDE_DIRS} ${PROJECT_BINARY_DIR})
|
||||||
@@ -141,9 +140,9 @@ add_subdirectory("Application")
|
|||||||
add_executable(${CMAKE_PROJECT_NAME})
|
add_executable(${CMAKE_PROJECT_NAME})
|
||||||
target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${sources_SRCS})
|
target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${sources_SRCS})
|
||||||
|
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC Tasks CLS CLS_BSP BSP EE24 INA219 ulog ram_loader Vehicle)
|
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC Tasks CLS CLS_BSP BSP EE24 INA219 ulog ram_loader)
|
||||||
#target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC PROTOS)
|
#target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC PROTOS)
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC mlzr_comm TinyFrame uart_driver)
|
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC uart_driver)
|
||||||
#target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC lwrb)
|
#target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC lwrb)
|
||||||
|
|
||||||
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
|
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
|
|||||||
@@ -40,8 +40,6 @@
|
|||||||
#include "BSP_GPIO.h"
|
#include "BSP_GPIO.h"
|
||||||
#include "BSP_ADC.h"
|
#include "BSP_ADC.h"
|
||||||
#include "BSP_SDLogger.h"
|
#include "BSP_SDLogger.h"
|
||||||
#include "Vehicle.h"
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
@@ -152,8 +150,6 @@ void MX_FREERTOS_Init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
void AddHeadlightMessages();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Function implementing the defaultTask thread.
|
* @brief Function implementing the defaultTask thread.
|
||||||
* @param argument: Not used
|
* @param argument: Not used
|
||||||
@@ -162,7 +158,6 @@ void AddHeadlightMessages();
|
|||||||
|
|
||||||
#include "CLS_BSP.h"
|
#include "CLS_BSP.h"
|
||||||
#include "CLSAddress.h"
|
#include "CLSAddress.h"
|
||||||
#include "mlzr_comm.h"
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
void StartDefaultTask(void *argument)
|
void StartDefaultTask(void *argument)
|
||||||
{
|
{
|
||||||
@@ -172,9 +167,6 @@ void StartDefaultTask(void *argument)
|
|||||||
BSP_EE24_Init();
|
BSP_EE24_Init();
|
||||||
BSP_INA_Init();
|
BSP_INA_Init();
|
||||||
|
|
||||||
MLZR_INIT();
|
|
||||||
|
|
||||||
|
|
||||||
retSD = f_mount(&SDFatFS,SDPath,0);
|
retSD = f_mount(&SDFatFS,SDPath,0);
|
||||||
retSD = f_open(&SDFile, "counter.bin", FA_READ);
|
retSD = f_open(&SDFile, "counter.bin", FA_READ);
|
||||||
|
|
||||||
@@ -196,7 +188,6 @@ void StartDefaultTask(void *argument)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BSP_SDLogger_Init(counter);
|
BSP_SDLogger_Init(counter);
|
||||||
AddHeadlightMessages();
|
|
||||||
|
|
||||||
char INA_LOG[72];
|
char INA_LOG[72];
|
||||||
|
|
||||||
@@ -245,7 +236,7 @@ void WaitForStartConfirm_Task(void *argument) {
|
|||||||
while(1) {
|
while(1) {
|
||||||
osDelayUntil(tick);
|
osDelayUntil(tick);
|
||||||
tick += delayTime;
|
tick += delayTime;
|
||||||
if(BSP_GPIO_K15isSet() || Vehicle_gotUnlockMessage()) {
|
if(BSP_GPIO_K15isSet() || CanDataTask_gotCarCanMessage()) {
|
||||||
BSP_POWER_FullPowerMode();
|
BSP_POWER_FullPowerMode();
|
||||||
ULOG_INFO("Power systems started");
|
ULOG_INFO("Power systems started");
|
||||||
osThreadExit();
|
osThreadExit();
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
#include "stm32h7xx_it.h"
|
#include "stm32h7xx_it.h"
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
#include "AsyncComm.h"
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
@@ -42,8 +41,7 @@
|
|||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
extern uart_desc_t uart_duplex;
|
|
||||||
extern uart_desc_t uart_half;
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@@ -235,7 +233,7 @@ void DMA1_Stream0_IRQHandler(void)
|
|||||||
/* USER CODE END DMA1_Stream0_IRQn 0 */
|
/* USER CODE END DMA1_Stream0_IRQn 0 */
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA1_Stream0_IRQn 1 */
|
/* USER CODE BEGIN DMA1_Stream0_IRQn 1 */
|
||||||
usart_dma_irq_handler(&uart_duplex);
|
|
||||||
/* USER CODE END DMA1_Stream0_IRQn 1 */
|
/* USER CODE END DMA1_Stream0_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +247,7 @@ void DMA1_Stream1_IRQHandler(void)
|
|||||||
/* USER CODE END DMA1_Stream1_IRQn 0 */
|
/* USER CODE END DMA1_Stream1_IRQn 0 */
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA1_Stream1_IRQn 1 */
|
/* USER CODE BEGIN DMA1_Stream1_IRQn 1 */
|
||||||
usart_dma_irq_handler_tx(&uart_duplex);
|
|
||||||
/* USER CODE END DMA1_Stream1_IRQn 1 */
|
/* USER CODE END DMA1_Stream1_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +261,7 @@ void DMA1_Stream2_IRQHandler(void)
|
|||||||
/* USER CODE END DMA1_Stream2_IRQn 0 */
|
/* USER CODE END DMA1_Stream2_IRQn 0 */
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA1_Stream2_IRQn 1 */
|
/* USER CODE BEGIN DMA1_Stream2_IRQn 1 */
|
||||||
usart_dma_irq_handler(&uart_half);
|
|
||||||
/* USER CODE END DMA1_Stream2_IRQn 1 */
|
/* USER CODE END DMA1_Stream2_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +275,7 @@ void DMA1_Stream3_IRQHandler(void)
|
|||||||
/* USER CODE END DMA1_Stream3_IRQn 0 */
|
/* USER CODE END DMA1_Stream3_IRQn 0 */
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA1_Stream3_IRQn 1 */
|
/* USER CODE BEGIN DMA1_Stream3_IRQn 1 */
|
||||||
usart_dma_irq_handler_tx(&uart_half);
|
|
||||||
/* USER CODE END DMA1_Stream3_IRQn 1 */
|
/* USER CODE END DMA1_Stream3_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +400,7 @@ void USART1_IRQHandler(void)
|
|||||||
|
|
||||||
/* USER CODE END USART1_IRQn 0 */
|
/* USER CODE END USART1_IRQn 0 */
|
||||||
/* USER CODE BEGIN USART1_IRQn 1 */
|
/* USER CODE BEGIN USART1_IRQn 1 */
|
||||||
usart_irq_handler(&uart_duplex);
|
|
||||||
/* USER CODE END USART1_IRQn 1 */
|
/* USER CODE END USART1_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,7 +413,7 @@ void USART3_IRQHandler(void)
|
|||||||
|
|
||||||
/* USER CODE END USART3_IRQn 0 */
|
/* USER CODE END USART3_IRQn 0 */
|
||||||
/* USER CODE BEGIN USART3_IRQn 1 */
|
/* USER CODE BEGIN USART3_IRQn 1 */
|
||||||
usart_irq_handler(&uart_half);
|
|
||||||
/* USER CODE END USART3_IRQn 1 */
|
/* USER CODE END USART3_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ void MX_USART1_UART_Init(void)
|
|||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
/* USER CODE END USART1_Init 1 */
|
||||||
USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
|
USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
|
||||||
USART_InitStruct.BaudRate = 2000000;
|
USART_InitStruct.BaudRate = 1000000;
|
||||||
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
|
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
|
||||||
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
|
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
|
||||||
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
|
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
|
||||||
@@ -273,7 +273,7 @@ void MX_USART3_UART_Init(void)
|
|||||||
|
|
||||||
/* USER CODE END USART3_Init 1 */
|
/* USER CODE END USART3_Init 1 */
|
||||||
USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
|
USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
|
||||||
USART_InitStruct.BaudRate = 2000000;
|
USART_InitStruct.BaudRate = 1000000;
|
||||||
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
|
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
|
||||||
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
|
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
|
||||||
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
|
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
|
||||||
|
|||||||
@@ -4,10 +4,5 @@ add_subdirectory(nanopb)
|
|||||||
add_subdirectory(ulog)
|
add_subdirectory(ulog)
|
||||||
add_subdirectory(ina219)
|
add_subdirectory(ina219)
|
||||||
|
|
||||||
|
|
||||||
add_library(EE24 STATIC "ee24/ee24.c")
|
add_library(EE24 STATIC "ee24/ee24.c")
|
||||||
target_include_directories(EE24 PUBLIC "ee24")
|
target_include_directories(EE24 PUBLIC "ee24")
|
||||||
|
|
||||||
|
|
||||||
add_library(TinyFrame STATIC "TinyFrame/TinyFrame.c")
|
|
||||||
target_include_directories(TinyFrame PUBLIC "./TinyFrame" "./TinyFrameConf")
|
|
||||||
Submodule lib/TinyFrame deleted from a29167a69f
@@ -1,81 +0,0 @@
|
|||||||
//
|
|
||||||
// TinyFrame configuration file.
|
|
||||||
//
|
|
||||||
// Rename to TF_Config.h
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef TF_CONFIG_H
|
|
||||||
#define TF_CONFIG_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h> // used by the TF_Error() macro defined below
|
|
||||||
//#include <esp8266.h> // when using with esphttpd
|
|
||||||
|
|
||||||
//----------------------------- FRAME FORMAT ---------------------------------
|
|
||||||
// The format can be adjusted to fit your particular application needs
|
|
||||||
|
|
||||||
// If the connection is reliable, you can disable the SOF byte and checksums.
|
|
||||||
// That can save up to 9 bytes of overhead.
|
|
||||||
|
|
||||||
// ,-----+-----+-----+------+------------+- - - -+-------------,
|
|
||||||
// | SOF | ID | LEN | TYPE | HEAD_CKSUM | DATA | DATA_CKSUM |
|
|
||||||
// | 0-1 | 1-4 | 1-4 | 1-4 | 0-4 | ... | 0-4 | <- size (bytes)
|
|
||||||
// '-----+-----+-----+------+------------+- - - -+-------------'
|
|
||||||
|
|
||||||
// !!! BOTH PEERS MUST USE THE SAME SETTINGS !!!
|
|
||||||
|
|
||||||
// Adjust sizes as desired (1,2,4)
|
|
||||||
#define TF_ID_BYTES 2
|
|
||||||
#define TF_LEN_BYTES 2
|
|
||||||
#define TF_TYPE_BYTES 2
|
|
||||||
|
|
||||||
// Checksum type. Options:
|
|
||||||
// TF_CKSUM_NONE, TF_CKSUM_XOR, TF_CKSUM_CRC8, TF_CKSUM_CRC16, TF_CKSUM_CRC32
|
|
||||||
// TF_CKSUM_CUSTOM8, TF_CKSUM_CUSTOM16, TF_CKSUM_CUSTOM32
|
|
||||||
// Custom checksums require you to implement checksum functions (see TinyFrame.h)
|
|
||||||
#define TF_CKSUM_TYPE TF_CKSUM_CRC16
|
|
||||||
|
|
||||||
// Use a SOF byte to mark the start of a frame
|
|
||||||
#define TF_USE_SOF_BYTE 1
|
|
||||||
// Value of the SOF byte (if TF_USE_SOF_BYTE == 1)
|
|
||||||
#define TF_SOF_BYTE 0x01
|
|
||||||
|
|
||||||
//----------------------- PLATFORM COMPATIBILITY ----------------------------
|
|
||||||
|
|
||||||
// used for timeout tick counters - should be large enough for all used timeouts
|
|
||||||
typedef uint16_t TF_TICKS;
|
|
||||||
|
|
||||||
// used in loops iterating over listeners
|
|
||||||
typedef uint8_t TF_COUNT;
|
|
||||||
|
|
||||||
//----------------------------- PARAMETERS ----------------------------------
|
|
||||||
|
|
||||||
// Maximum received payload size (static buffer)
|
|
||||||
// Larger payloads will be rejected.
|
|
||||||
#define TF_MAX_PAYLOAD_RX 1024
|
|
||||||
// Size of the sending buffer. Larger payloads will be split to pieces and sent
|
|
||||||
// in multiple calls to the write function. This can be lowered to reduce RAM usage.
|
|
||||||
#define TF_SENDBUF_LEN 1024
|
|
||||||
|
|
||||||
// --- Listener counts - determine sizes of the static slot tables ---
|
|
||||||
|
|
||||||
// Frame ID listeners (wait for response / multi-part message)
|
|
||||||
#define TF_MAX_ID_LST 50
|
|
||||||
// Frame Type listeners (wait for frame with a specific first payload byte)
|
|
||||||
#define TF_MAX_TYPE_LST 5
|
|
||||||
// Generic listeners (fallback if no other listener catches it)
|
|
||||||
#define TF_MAX_GEN_LST 5
|
|
||||||
|
|
||||||
// Timeout for receiving & parsing a frame
|
|
||||||
// ticks = number of calls to TF_Tick()
|
|
||||||
#define TF_PARSER_TIMEOUT_TICKS 10
|
|
||||||
|
|
||||||
// Whether to use mutex - requires you to implement TF_ClaimTx() and TF_ReleaseTx()
|
|
||||||
#define TF_USE_MUTEX 1
|
|
||||||
|
|
||||||
// Error reporting function. To disable debug, change to empty define
|
|
||||||
#define TF_Error(format, ...) printf("[TF] " format "\n", ##__VA_ARGS__)
|
|
||||||
|
|
||||||
//------------------------- End of user config ------------------------------
|
|
||||||
|
|
||||||
#endif //TF_CONFIG_H
|
|
||||||
2
proto
2
proto
Submodule proto updated: 37c0e46f59...2142d03586
@@ -6,7 +6,6 @@ ${PROTO_SRC_DIR}/firmware.proto
|
|||||||
${PROTO_SRC_DIR}/light.proto
|
${PROTO_SRC_DIR}/light.proto
|
||||||
${PROTO_SRC_DIR}/usb.proto
|
${PROTO_SRC_DIR}/usb.proto
|
||||||
${PROTO_SRC_DIR}/cls_device.proto
|
${PROTO_SRC_DIR}/cls_device.proto
|
||||||
${PROTO_SRC_DIR}/headlight.proto
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Specify where you want to generate the python code
|
# Specify where you want to generate the python code
|
||||||
|
|||||||
@@ -4,26 +4,25 @@ from google.protobuf.message import DecodeError
|
|||||||
from serial.tools import list_ports
|
from serial.tools import list_ports
|
||||||
|
|
||||||
from light_pb2 import GlobalBrightness, Theme, GlobalTheme, ThemeSettings
|
from light_pb2 import GlobalBrightness, Theme, GlobalTheme, ThemeSettings
|
||||||
from headlight_pb2 import Settings, RequestSettings
|
|
||||||
from usb_pb2 import PackageType
|
from usb_pb2 import PackageType
|
||||||
from vcp_driver import *
|
from vcp_driver import *
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
ser = setup_connection()
|
ser = setup_connection()
|
||||||
# Create a message
|
# Create a message
|
||||||
#request = GlobalBrightness()
|
request = GlobalBrightness()
|
||||||
#request.brightness = 100
|
request.brightness = 100
|
||||||
# Serialize the request to a bytearray
|
# Serialize the request to a bytearray
|
||||||
#request_data = request.SerializeToString()
|
request_data = request.SerializeToString()
|
||||||
|
|
||||||
# Send the request
|
# Send the request
|
||||||
#send_package(PackageType.LIGHT_GLOBAL_BRIGHT, request_data, ser)
|
send_package(PackageType.LIGHT_GLOBAL_BRIGHT, request_data, ser)
|
||||||
|
|
||||||
|
|
||||||
#request = GlobalTheme()
|
request = GlobalTheme()
|
||||||
#request.theme = 1
|
request.theme = 1
|
||||||
#request_data = request.SerializeToString()
|
request_data = request.SerializeToString()
|
||||||
#send_package(PackageType.LIGHT_GLOBAL_THEME, request_data, ser)
|
send_package(PackageType.LIGHT_GLOBAL_THEME, request_data, ser)
|
||||||
|
|
||||||
|
|
||||||
# request = ThemeSettings()
|
# request = ThemeSettings()
|
||||||
@@ -34,14 +33,3 @@ if __name__ == "__main__":
|
|||||||
# request.animation = 2
|
# request.animation = 2
|
||||||
# request_data = request.SerializeToString()
|
# request_data = request.SerializeToString()
|
||||||
# send_package(PackageType.LIGHT_SETTING_THEME, request_data, ser)
|
# send_package(PackageType.LIGHT_SETTING_THEME, request_data, ser)
|
||||||
|
|
||||||
|
|
||||||
request = Settings()
|
|
||||||
request.deviceId = 1
|
|
||||||
request.alpha = 0.001
|
|
||||||
request.on_threshold = 600
|
|
||||||
request.off_threshold = 400
|
|
||||||
request.on_time = 100
|
|
||||||
request.input_invert = False
|
|
||||||
request_data = request.SerializeToString()
|
|
||||||
send_package(PackageType.HEADLIGHT_SETTINGS, request_data, ser)
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ if __name__ == "__main__":
|
|||||||
ser = setup_connection()
|
ser = setup_connection()
|
||||||
# Create a message
|
# Create a message
|
||||||
request = UpdateDeviceSettings()
|
request = UpdateDeviceSettings()
|
||||||
request.device = 0
|
request.device = 5
|
||||||
request.type = Type.COMMING_HOME
|
request.type = Type.LIGHT
|
||||||
request.position.append(Position.LEFT)
|
request.position.append(Position.RIGHT)
|
||||||
request.position.append(Position.CENTER)
|
request.position.append(Position.FLOOR)
|
||||||
# Serialize the request to a bytearray
|
# Serialize the request to a bytearray
|
||||||
request_data = request.SerializeToString()
|
request_data = request.SerializeToString()
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,21 @@ import struct
|
|||||||
from google.protobuf.message import DecodeError
|
from google.protobuf.message import DecodeError
|
||||||
from serial.tools import list_ports
|
from serial.tools import list_ports
|
||||||
|
|
||||||
from headlight_pb2 import Settings, RequestSettings
|
from light_pb2 import RequestThemeSetting, Theme, ThemeSettings
|
||||||
from usb_pb2 import PackageType
|
from usb_pb2 import PackageType
|
||||||
from vcp_driver import *
|
from vcp_driver import *
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
ser = setup_connection()
|
ser = setup_connection()
|
||||||
|
|
||||||
request = RequestSettings()
|
request = RequestThemeSetting()
|
||||||
request.deviceId = 1
|
request.deviceId = 0
|
||||||
|
request.theme = 1
|
||||||
print("send request")
|
print("send request")
|
||||||
print(request)
|
print(request)
|
||||||
|
|
||||||
request_data = request.SerializeToString()
|
request_data = request.SerializeToString()
|
||||||
send_package(PackageType.HEADLIGHT_REQUEST_SETTINGS, request_data, ser)
|
send_package(PackageType.LIGHT_REQUEST_THEME, request_data, ser)
|
||||||
|
|
||||||
|
|
||||||
print("wait for response")
|
print("wait for response")
|
||||||
@@ -29,13 +30,13 @@ if __name__ == "__main__":
|
|||||||
print(length, typeid, check)
|
print(length, typeid, check)
|
||||||
|
|
||||||
# Check if the type is RESPONSE_DEVICE_LIST
|
# Check if the type is RESPONSE_DEVICE_LIST
|
||||||
if typeid == PackageType.HEADLIGHT_SETTINGS:
|
if typeid == PackageType.LIGHT_SETTING_THEME:
|
||||||
# Read the response data from the serial port
|
# Read the response data from the serial port
|
||||||
response_data = ser.read(length)
|
response_data = ser.read(length)
|
||||||
|
|
||||||
# Try to parse the data as a ResponseDeviceList message
|
# Try to parse the data as a ResponseDeviceList message
|
||||||
try:
|
try:
|
||||||
response = Settings.FromString(response_data)
|
response = ThemeSettings.FromString(response_data)
|
||||||
|
|
||||||
except DecodeError:
|
except DecodeError:
|
||||||
# If we get a DecodeError, it means the data we read is not a valid
|
# If we get a DecodeError, it means the data we read is not a valid
|
||||||
|
|||||||
Reference in New Issue
Block a user