amiro-os / include / amiro / serial_reset / iwrap_can_mux.hpp @ b24df8ad
History | View | Annotate | Download (2.411 KB)
1 |
#ifndef IWRAP_CAN_MUX_HPP_
|
---|---|
2 |
#define IWRAP_CAN_MUX_HPP_
|
3 |
|
4 |
#include <ch.hpp> |
5 |
|
6 |
#define BLUETOOTH_START_FRAME 0xBF |
7 |
/** \brief Define bluetooth link address to iWRAP control */
|
8 |
#define BLUETOOTH_LINK 0x00 |
9 |
/** \brief Define bluetooth frame flags */
|
10 |
#define BLUETOOTH_FLAGS 0x00 |
11 |
/** \brief Define nLINK = {LINK} XOR 0xFF */
|
12 |
#define BLUETOOTH_NLINK 0xFF |
13 |
|
14 |
/* States of bluetooth communication */
|
15 |
/** \brief bluetooth waiting for start frame signal */
|
16 |
#define BLUETOOTH_STATUS_START 0 |
17 |
/** \brief bluetooth waiting for link address */
|
18 |
#define BLUETOOTH_STATUS_LINK 1 |
19 |
/** \brief bluetooth waiting for frame flags */
|
20 |
#define BLUETOOTH_STATUS_FLAGS 2 |
21 |
/** \brief bluetooth waiting for data length */
|
22 |
#define BLUETOOTH_STATUS_LENGTH 3 |
23 |
/** \brief bluetooth waiting for data */
|
24 |
#define BLUETOOTH_STATUS_DATA 4 |
25 |
/** \brief bluetooth waiting for frame end (nLINK) */
|
26 |
#define BLUETOOTH_STATUS_END 5 |
27 |
|
28 |
#define OFFSET_TIME_RESET_MS 2000 |
29 |
#define INPUT_BL_RESET_ADDITIONAL_BYTES 0 |
30 |
#define INPUT_BL_RESET_LENGTH 3 |
31 |
|
32 |
namespace amiro {
|
33 |
|
34 |
class IwrapCanMux : public chibios_rt::BaseSequentialStreamInterface { |
35 |
public:
|
36 |
IwrapCanMux(SerialDriver *_sd_, CANDriver *can, const uint8_t boardId);
|
37 |
virtual ~IwrapCanMux();
|
38 |
|
39 |
void convCan2Serial(uint8_t *inputs, size_t n);
|
40 |
void sendSwitchCmd(uint8_t setid);
|
41 |
void rcvSwitchCmd(uint8_t setid);
|
42 |
|
43 |
size_t write(const uint8_t *bp, size_t n);
|
44 |
size_t read(uint8_t *bp, size_t n); |
45 |
msg_t put(uint8_t b); |
46 |
msg_t get(void);
|
47 |
|
48 |
protected:
|
49 |
|
50 |
|
51 |
private:
|
52 |
/* Reset command. */
|
53 |
const uint8_t inputBLReset[3] = {0x02, 0xFF, 0x00}; |
54 |
// const uint8_t inputchshell[3] = {0x00, 0x68, 0x0D};
|
55 |
// const uint8_t inputsh_board[8] = {0x73, 0x68, 0x5F, 0x62, 0x6F, 0x61, 0x72, 0x6C};
|
56 |
|
57 |
// void checkBluetoothStatus(void)
|
58 |
void restartSystem(void); |
59 |
bool checkByteForBLReset(uint8_t *inputs, size_t size);
|
60 |
msg_t sendViaCan(uint32_t id, uint8_t *inputs, size_t size); |
61 |
|
62 |
uint8_t inputAddBytes[INPUT_BL_RESET_ADDITIONAL_BYTES]; // Buffer for additional bytes.
|
63 |
uint8_t resetStatus; // Status of reset
|
64 |
uint8_t resetAddBytes; // Counter of additional bytes
|
65 |
uint8_t bluetoothStatus; |
66 |
|
67 |
SerialDriver *sd_; |
68 |
CANDriver *canDriver; |
69 |
uint8_t myID; |
70 |
volatile uint8_t queryShellID;
|
71 |
volatile uint8_t replyShellID;
|
72 |
|
73 |
CANTxFrame txmsg; |
74 |
uint8_t inputChar[16] = {};
|
75 |
}; |
76 |
|
77 |
} /* amiro */
|
78 |
|
79 |
#endif /* IWRAP_CAN_MUX_HPP_ */ |
80 |
|
81 |
|