-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMESSAGES.c
142 lines (120 loc) · 3.79 KB
/
MESSAGES.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* File: MESSAGES.c
* Author: 93Urbano
*
* Created on September 20, 2021, 10:50 AM
*/
#include "MESSAGES.h"
#include "mcc_generated_files/mcc.h"
#include "PARAMETERS.h"
#include "LEDS.h"
#include "SPEAKER.h"
//VARIABLES
uint8_t CANDATAdata[8];
//FUNCIONES
void CANWriteMessage( unsigned long id, unsigned char dataLength, unsigned char data1, unsigned char data2, unsigned char data3, unsigned char data4, unsigned char data5, unsigned char data6, unsigned char data7, unsigned char data8)
{
CANDATAdata [0] = data1;
CANDATAdata [1] = data2;
CANDATAdata [2] = data3;
CANDATAdata [3] = data4;
CANDATAdata [4] = data5;
CANDATAdata [5] = data6;
CANDATAdata [6] = data7;
CANDATAdata [7] = data8;
msgTransmit.msgId = id;
msgTransmit.field.formatType = CAN_2_0_FORMAT; //CAN 2.0
msgTransmit.field.brs = CAN_NON_BRS_MODE; //NO BRS
msgTransmit.field.frameType = CAN_FRAME_DATA; //FRAME DATA, NO REMOTE
msgTransmit.field.idType = CAN_FRAME_STD; //CAN VERSION STANDARD
msgTransmit.field.dlc = ( dataLength & 0x0F ); //DATA LENGTH
msgTransmit.data = CANDATAdata;
if(CAN1_IsBusOff() == TRUE)
{
Nop();
}
if(CAN1_IsTxErrorPassive() == TRUE)
{
Nop();
}
if(CAN1_IsTxErrorWarning() == TRUE)
{
Nop();
}
if(CAN1_IsTxErrorActive() == TRUE)
{
Nop();
}
if(CAN_TX_FIFO_AVAILABLE == (CAN1_TransmitFIFOStatusGet(CAN1_TX_TXQ) & CAN_TX_FIFO_AVAILABLE))
{
CAN1_Transmit(CAN1_TX_TXQ, &msgTransmit);
Nop();
}
}
void CANReadMessage (void)
{
uint32_t id;
unsigned char idType;
unsigned char dlc;
unsigned char data1;
unsigned char data2;
unsigned char data3;
unsigned char data4;
unsigned char data5;
unsigned char data6;
unsigned char data7;
unsigned char data8;
Nop();
if(CAN1_ReceivedMessageCountGet() > 0)
{
if(true == CAN1_Receive(&msgReceipt))
{
Nop();
id = msgReceipt.msgId;
idType = msgReceipt.field.idType;
dlc = msgReceipt.field.dlc;
data1 = msgReceipt.data[0];
data2 = msgReceipt.data[1];
data3 = msgReceipt.data[2];
data4 = msgReceipt.data[3];
data5 = msgReceipt.data[4];
data6 = msgReceipt.data[5];
data7 = msgReceipt.data[6];
data8 = msgReceipt.data[7];
switch (id)
{
case DV_SYSTEM_STATUS:
ucASState_prev = ucASState;
ucASState = ( data1 & 0x07 );
if (ucASState_prev != ucASState)
{
//ENVIAR AQUI MENSAJE DE ESTADO ASSI con el AS que estoy y el anterior
LEDS();
SPEAKER();
MESSSAGES_ASSIState();
}
break;
default:
Nop();
break;
}
}
}
}
// MESSSAGES_ASSIState //
//Ejecutar este mensaje cada 10s aprox y meter en que estado se encuentra el ASSI
void MESSSAGES_ASSIState (void)
{
switch ( ucASSIName )
{
case ASSI_CENTER:
CANWriteMessage(ID_ASSIS_C, data_lenght8, ucASState, ucASState_prev, 0, 0, 0, 0, 0, 0);
break;
case ASSI_LEFT:
CANWriteMessage(ID_ASSIS_R, data_lenght8, ucASState, ucASState_prev, 0, 0, 0, 0, 0, 0);
break;
case ASSI_RIGHT:
CANWriteMessage(ID_ASSIS_L, data_lenght8, ucASState, ucASState_prev, 0, 0, 0, 0, 0, 0);
break;
}
}