This repository has been archived on 2024-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
SummerSchool2-Controller/306-controller_interface.X/app/can_message.c

235 lines
6.5 KiB
C
Raw Normal View History

2023-08-25 12:13:51 +00:00
/**
* @author R<EFBFBD>mi Heredero
* @version 1.0.0
* @date August 2023
* @file can_message.c
*/
2023-08-27 15:39:45 +00:00
#include "can_message.h"
2023-08-25 16:23:36 +00:00
#include "car.h"
#include "../app/factory/factory.h"
2023-08-28 10:57:16 +00:00
#include "../middleware/can_interface.h"
2023-08-25 12:13:51 +00:00
2023-08-25 16:23:36 +00:00
typedef union {
struct {
uint8_t byte0;
uint8_t byte1;
uint8_t byte2;
uint8_t byte3;
} separate;
struct {
uint32_t bytes;
} full;
} BYTES_4;
void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){
switch(idSender){
2023-08-28 10:57:16 +00:00
/*********************
* BROADCAST / DEBUG *
*********************/
case 0:
2023-08-28 07:09:54 +00:00
if(idMsg == 0x0) { // CONTROL_SETUP
2023-08-28 10:57:16 +00:00
// steeringMode - - controlAliveTime
BYTES_4 tmpData;
tmpData.full.bytes = data;
CAR_CST.CONTROL_STEERING_MODE = tmpData.separate.byte0;
CAR_CST.CONTROL_ALIVE_TIME = tmpData.separate.byte3;
MEM_write_1_byte(MEMADD_CONTROL_STEERING_MODE, CAR_CST.CONTROL_STEERING_MODE);
MEM_write_1_byte(MEMADD_CONTROL_ALIVE_TIME, CAR_CST.CONTROL_ALIVE_TIME);
WATCHDOG_setTime(WDcontroller(), CAR_CST.CONTROL_ALIVE_TIME);
2023-08-28 07:09:54 +00:00
}
if(idMsg == 0x1) { // CONTROL_SPEED_FACTOR
2023-08-28 10:57:16 +00:00
// valHH valH valL valLL
2023-08-28 07:09:54 +00:00
}
if(idMsg == 0x2) { // CONTROL_POWER_FACTOR
2023-08-28 10:57:16 +00:00
// valHH valH valL valLL
2023-08-28 07:09:54 +00:00
}
if(idMsg == 0x3) { // CONTROL_STEERING_FACTOR
2023-08-28 10:57:16 +00:00
// valHH valH valL valLL
2023-08-28 07:09:54 +00:00
}
if(idMsg == 0x4) { // CONTROL_SECURITY_PARAM
2023-08-28 10:57:16 +00:00
// maxSpeedFw maxSpeedBw - -
2023-08-28 07:09:54 +00:00
}
if(idMsg == 0x5) { // CONTROL_SETUP_PARAM
2023-08-28 10:57:16 +00:00
// displayAliveTime steeringAliveTime - -
2023-08-28 07:09:54 +00:00
}
if(idMsg == 0x6) { // CONTROL_SETUP_PARAM_JOY
// joystickMode joystickParam1 joystickParam2 joystickAliveTime
BYTES_4 tmpData;
tmpData.full.bytes = data;
2023-08-28 10:57:16 +00:00
CAR_CST.JOYSTICK_MODE = tmpData.separate.byte0;
CAR_CST.JOYSTICK_PARAM1 = tmpData.separate.byte1;
CAR_CST.JOYSTICK_PARAM2 = tmpData.separate.byte2;
CAR_CST.JOYSTICK_ALIVE_TIME = tmpData.separate.byte3;
MEM_write_1_byte(MEMADD_JOYSTICK_MODE, CAR_CST.JOYSTICK_MODE);
MEM_write_1_byte(MEMADD_JOYSTICK_PARAM1, CAR_CST.JOYSTICK_PARAM1);
MEM_write_1_byte(MEMADD_JOYSTICK_PARAM2, CAR_CST.JOYSTICK_PARAM2);
MEM_write_1_byte(MEMADD_JOYSTICK_ALIVE_TIME, CAR_CST.JOYSTICK_ALIVE_TIME);
2023-08-28 07:09:54 +00:00
ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
CM_JOY_SETUP(NULL);
}
if(idMsg == 0x7) { // CONTROL_SETUP_PARAM_DRIVE
2023-08-28 10:57:16 +00:00
// driveAliveTime driveSpeedTime driveStopTime -
2023-08-28 07:09:54 +00:00
}
if(idMsg == 0x8) { // CONTROL_SETUP_PARAM_BATTERY
2023-08-28 10:57:16 +00:00
// batteryVoltTime batteryCurrentTime batteryEnergyTime batteryAliveTime
2023-08-28 07:09:54 +00:00
}
2023-08-25 16:23:36 +00:00
break;
2023-08-28 10:57:16 +00:00
/************
* JOYSTICK *
************/
case 2:
2023-08-25 16:23:36 +00:00
if(idMsg == 0x1) { // JOY_MESURE
2023-08-28 10:57:16 +00:00
// posX posY button -
2023-08-25 16:23:36 +00:00
}
if(idMsg == 0xF) { // JOY_ALIVE
2023-08-28 10:57:16 +00:00
// - - - -
2023-08-25 16:23:36 +00:00
ALIVE_CHECKER_ISALIVE(ACjoy());
2023-08-25 20:53:04 +00:00
if(ACjoy()->state == STAC_DEAD){
2023-08-28 10:57:16 +00:00
CAR_CST.JOYSTICK_MODE = MEM_read_1_byte(MEMADD_JOYSTICK_MODE);
CAR_CST.JOYSTICK_PARAM1 = MEM_read_1_byte(MEMADD_JOYSTICK_PARAM1);
CAR_CST.JOYSTICK_PARAM2 = MEM_read_1_byte(MEMADD_JOYSTICK_PARAM2);
CAR_CST.JOYSTICK_ALIVE_TIME = MEM_read_1_byte(MEMADD_JOYSTICK_ALIVE_TIME);
2023-08-27 19:35:19 +00:00
ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
2023-08-25 20:53:04 +00:00
ALIVE_CHECKER_emitBorn(ACjoy(), 0, 0);
ALIVE_CHECKER_emitReady(ACjoy(), 100, 0);
}
2023-08-25 16:23:36 +00:00
}
break;
2023-08-28 10:57:16 +00:00
/***********
* DISPLAY *
***********/
case 3:
if(idMsg == 0xF) { // DISPLAY_ALIVE
// powerMode - - -
}
2023-08-25 16:23:36 +00:00
break;
2023-08-28 10:57:16 +00:00
/*********
* DRIVE *
*********/
case 4:
if(idMsg == 0x0) { // DRIVE_SPEED
// speedHH speedH speedL speedLL
}
if(idMsg == 0xF) { // DRIVE_ALIVE
// statusH statusL - -
}
2023-08-25 16:23:36 +00:00
break;
2023-08-28 10:57:16 +00:00
/************
* STEERING *
************/
case 5:
if(idMsg == 0x1) { // STEERING_GET_CENTER
// valHH valH valL valLL
}
if(idMsg == 0x2) { // STEERING_GET_POSITION
// valHH valH valL valLL
}
if(idMsg == 0xF) { // STEERING_ALIVE
// statusH statusL - -
}
2023-08-25 16:23:36 +00:00
break;
2023-08-28 10:57:16 +00:00
/**********
* SUPPLY *
**********/
case 6:
if(idMsg == 0xF) { // BATTERY_ALIVE
// - - - -
}
2023-08-25 16:23:36 +00:00
break;
2023-08-28 10:57:16 +00:00
/*************
* UNDEFINED *
*************/
case 7:
2023-08-25 16:23:36 +00:00
break;
}
}
void CM_CONTROLLER_ALIVE(void* p) {
2023-08-25 12:13:51 +00:00
CAN_Send(0x0, 0xF, 0);
2023-08-25 16:23:36 +00:00
}
void CM_JOY_SETUP(void* p) {
BYTES_4 joy;
joy.separate.byte0 = CAR_CST.JOYSTICK_MODE;
joy.separate.byte1 = CAR_CST.JOYSTICK_PARAM1;
joy.separate.byte2 = CAR_CST.JOYSTICK_PARAM2;
joy.separate.byte3 = CAR_CST.JOYSTICK_ALIVE_TIME;
CAN_Send(2, 0, joy.full.bytes);
}
void CM_DISPLAY_SETUP(void* p) {
}
void CM_DISPLAY_SPEED(void* p) {
}
void CM_DISPLAY_DIRECTION(void* p) {
}
void CM_DRIVE_SETUP(void* p) {
}
void CM_DRIVE_POWER(void* p) {
}
void CM_STEERING_SETUP(void* p) {
}
void CM_STEERING_SET(void* p) {
}
void CM_SETUP_CONTROL(void* p) {
}