create alive_checker
This commit is contained in:
parent
deba3fbf0d
commit
88096a007c
@ -6,7 +6,94 @@
|
||||
*/
|
||||
|
||||
#include "../middleware/can_interface.h"
|
||||
#include "car.h"
|
||||
#include "../app/factory/factory.h"
|
||||
|
||||
void CM_controller_alive(void* p) {
|
||||
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){
|
||||
case 0: // Broadcast / Debug
|
||||
break;
|
||||
|
||||
case 2: // Joystick
|
||||
if(idMsg == 0x1) { // JOY_MESURE
|
||||
|
||||
}
|
||||
|
||||
if(idMsg == 0xF) { // JOY_ALIVE
|
||||
ALIVE_CHECKER_ISALIVE(ACjoy());
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: // Display
|
||||
break;
|
||||
|
||||
case 4: // Drive
|
||||
break;
|
||||
|
||||
case 5: // Steering
|
||||
break;
|
||||
|
||||
case 6: // Supply
|
||||
break;
|
||||
|
||||
case 7: // Undefined
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CM_CONTROLLER_ALIVE(void* p) {
|
||||
CAN_Send(0x0, 0xF, 0);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,18 @@ S R M
|
||||
1 6 0 SETUP_CONTROL batteryVoltTime batteryCurrentTime batteryEnergyTime aliveTime
|
||||
*/
|
||||
|
||||
void CM_controller_alive(void* p);
|
||||
void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data);
|
||||
void CM_CONTROLLER_ALIVE(void* p);
|
||||
void CM_JOY_SETUP(void* p);
|
||||
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);
|
||||
|
||||
|
||||
#endif /* CAN_MESSAGE_H */
|
||||
|
||||
|
@ -23,20 +23,23 @@
|
||||
/*******************
|
||||
* MEMORY ADRESSES *
|
||||
*******************/
|
||||
#define MEMADD_CONTROL_STEERING_MODE 0x00
|
||||
#define MEMADD_CONTROL_ALIVE_TIME 0x01
|
||||
#define MEMADD_CONTROL_SPEED_FACTOR 0x02
|
||||
#define MEMADD_CONTROL_POWER_FACTOR 0x06
|
||||
#define MEMADD_CONTROL_STEERING_FACTOR 0x0A
|
||||
#define MEMADD_CONTROL_MAX_SPEED_FW 0x0E
|
||||
#define MEMADD_CONTROL_MAX_SPEED_BW 0x0F
|
||||
#define MEMADD_JOYSTICK_ALIVE_TIME 0x10
|
||||
#define MEMADD_DISPLAY_ALIVE_TIME 0x11
|
||||
#define MEMADD_DRIVE_SPEED_TIME 0x12
|
||||
#define MEMADD_DRIVE_STOP_TIME 0x13
|
||||
#define MEMADD_DRIVE_ALIVE_TIME 0x14
|
||||
#define MEMADD_STEERING_ALIVE_TIME 0x15
|
||||
#define MEMADD_BATTERY_ALIVE_TIME 0x16
|
||||
#define MEMADD_CONTROL_STEERING_MODE 0x01
|
||||
#define MEMADD_CONTROL_ALIVE_TIME 0x02
|
||||
#define MEMADD_CONTROL_SPEED_FACTOR 0x03
|
||||
#define MEMADD_CONTROL_POWER_FACTOR 0x07
|
||||
#define MEMADD_CONTROL_STEERING_FACTOR 0x0B
|
||||
#define MEMADD_CONTROL_MAX_SPEED_FW 0x0F
|
||||
#define MEMADD_CONTROL_MAX_SPEED_BW 0x10
|
||||
#define MEMADD_JOYSTICK_MODE 0x11
|
||||
#define MEMADD_JOYSTICK_PARAM1 0x12
|
||||
#define MEMADD_JOYSTICK_PARAM2 0x13
|
||||
#define MEMADD_JOYSTICK_ALIVE_TIME 0x14
|
||||
#define MEMADD_DISPLAY_ALIVE_TIME 0x
|
||||
#define MEMADD_DRIVE_SPEED_TIME 0x
|
||||
#define MEMADD_DRIVE_STOP_TIME 0x
|
||||
#define MEMADD_DRIVE_ALIVE_TIME 0x
|
||||
#define MEMADD_STEERING_ALIVE_TIME 0x
|
||||
#define MEMADD_BATTERY_ALIVE_TIME 0x
|
||||
|
||||
typedef struct {
|
||||
uint8_t CONTROL_STEERING_MODE;
|
||||
@ -46,6 +49,10 @@ typedef struct {
|
||||
uint32_t CONTROL_STEERING_FACTOR;
|
||||
uint8_t CONTROL_MAX_SPEED_FW;
|
||||
uint8_t CONTROL_MAX_SPEED_BW;
|
||||
|
||||
uint8_t JOYSTICK_MODE;
|
||||
uint8_t JOYSTICK_PARAM1;
|
||||
uint8_t JOYSTICK_PARAM2;
|
||||
uint8_t JOYSTICK_ALIVE_TIME;
|
||||
uint8_t DISPLAY_ALIVE_TIME;
|
||||
uint8_t DRIVE_SPEED_TIME;
|
||||
|
@ -34,6 +34,10 @@ WATCHDOG* WDcontroller(){
|
||||
return &theFactory.WDcontroller_;
|
||||
}
|
||||
|
||||
ALIVE_CHECKER* ACjoy() {
|
||||
return &theFactory.ACjoy_;
|
||||
}
|
||||
|
||||
|
||||
//initialize all objects
|
||||
void Factory_init() {
|
||||
@ -63,8 +67,15 @@ void Factory_init() {
|
||||
|
||||
// TODO init watchdog with EPROM CST
|
||||
WATCHDOG_init(WDcontroller());
|
||||
CAR_CST.CONTROL_ALIVE_TIME = 10;
|
||||
CAR_CST.CONTROL_ALIVE_TIME = 100;
|
||||
WATCHDOG_setTime(WDcontroller(), CAR_CST.CONTROL_ALIVE_TIME);
|
||||
|
||||
// TODO init ALIVE CHECKER with EPROM CST
|
||||
CAR_CST.JOYSTICK_MODE = 0;
|
||||
CAR_CST.JOYSTICK_PARAM1 = 100;
|
||||
CAR_CST.JOYSTICK_PARAM2 = 1;
|
||||
CAR_CST.JOYSTICK_ALIVE_TIME = 10;
|
||||
ALIVE_CHECKER_init(ACjoy());
|
||||
}
|
||||
|
||||
void foo(uint8_t a, uint8_t b, uint32_t c){
|
||||
@ -81,11 +92,18 @@ void Factory_build() {
|
||||
ECAN_SetRXBnInterruptHandler(CAN_newMsg);
|
||||
CAN_onReceiveCan(foo);
|
||||
|
||||
WATCHDOG_onAlive(WDcontroller(), CM_controller_alive, NULL);
|
||||
WATCHDOG_onAlive(WDcontroller(), CM_CONTROLLER_ALIVE, NULL);
|
||||
ALIVE_CHECKER_onSetup(ACjoy(), CM_JOY_SETUP, NULL);
|
||||
ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME);
|
||||
|
||||
}
|
||||
|
||||
//start all state machines
|
||||
void Factory_start() {
|
||||
CAN_startBehaviour();
|
||||
WATCHDOG_startBehaviour(WDcontroller());
|
||||
ALIVE_CHECKER_startBehaviour(ACjoy());
|
||||
ALIVE_CHECKER_emitBorn(ACjoy(), 100, 0);
|
||||
ALIVE_CHECKER_emitReady(ACjoy(), 200, 0);
|
||||
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ typedef struct {
|
||||
LED l8_;
|
||||
|
||||
WATCHDOG WDcontroller_;
|
||||
ALIVE_CHECKER ACjoy_;
|
||||
|
||||
} Factory;
|
||||
|
||||
@ -51,6 +52,7 @@ LED* l7();
|
||||
LED* l8();
|
||||
|
||||
WATCHDOG* WDcontroller();
|
||||
ALIVE_CHECKER* ACjoy();
|
||||
|
||||
|
||||
#endif
|
@ -56,6 +56,7 @@ bool ALIVE_CHECKER_processEvent(Event* ev) {
|
||||
} else {
|
||||
me->state = STAC_DEAD;
|
||||
}
|
||||
me->isAlive = false;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -101,7 +102,6 @@ bool ALIVE_CHECKER_processEvent(Event* ev) {
|
||||
break;
|
||||
|
||||
case STAC_WAIT:
|
||||
me->isAlive = false;
|
||||
if (me->wait.f != NULL) {
|
||||
me->wait.f(me->wait.p);
|
||||
}
|
||||
|
@ -88,13 +88,13 @@ bool CAN_processEvent(Event* ev) {
|
||||
canMsg.frame.idType = dSTANDARD_CAN_MSG_ID_2_0B; // standard
|
||||
canMsg.frame.dlc = 4; // 4 bytes to send
|
||||
canMsg.frame.rtr = 0; // no remote frame
|
||||
canMsg.frame.data3 = (uint8_t) data;
|
||||
data = data >> 8;
|
||||
canMsg.frame.data2 = (uint8_t) data;
|
||||
canMsg.frame.data0 = (uint8_t) data;
|
||||
data = data >> 8;
|
||||
canMsg.frame.data1 = (uint8_t) data;
|
||||
data = data >> 8;
|
||||
canMsg.frame.data0 = (uint8_t) data;
|
||||
canMsg.frame.data2 = (uint8_t) data;
|
||||
data = data >> 8;
|
||||
canMsg.frame.data3 = (uint8_t) data;
|
||||
data = data >> 8;
|
||||
canMsg.frame.id = (uint32_t) data;
|
||||
CAN_transmit(&canMsg);
|
||||
|
Reference in New Issue
Block a user