Statistics
| Branch: | Tag: | Revision:

amiro-os / include / amiro / serial_reset / serial_can_mux.hpp @ 58fe0e0b

History | View | Annotate | Download (1.521 KB)

1 58fe0e0b Thomas Schöpping
#ifndef SERIAL_CAN_MUX_HPP_
2
#define SERIAL_CAN_MUX_HPP_
3
4
#include <ch.hpp>
5
6
#define OFFSET_TIME_RESET_MS                2000
7
#define INPUT_BL_RESET_ADDITIONAL_BYTES     0
8
#define INPUT_BL_RESET_LENGTH               3
9
10
namespace amiro {
11
12
  class SerialCanMux : public chibios_rt::BaseSequentialStreamInterface {
13
  public:
14
    SerialCanMux(SerialDriver *_sd_, CANDriver *can, const uint8_t boardId);
15
    virtual ~SerialCanMux();
16
17
    void convCan2Serial(uint8_t *inputs, size_t n);
18
    void sendSwitchCmd(uint8_t setid);
19
    void rcvSwitchCmd(uint8_t setid);
20
21
    size_t write(const uint8_t *bp, size_t n);
22
    size_t read(uint8_t *bp, size_t n);
23
    msg_t put(uint8_t b);
24
    msg_t get(void);
25
26
  protected:
27
28
  private:
29
    /* Reset command. */
30
    const uint8_t inputBLReset[3] = {0x02, 0xFF, 0x00};
31
//    const uint8_t inputchshell[3] = {0x00, 0x68, 0x0D};
32
//    const uint8_t inputsh_board[8] = {0x73, 0x68, 0x5F, 0x62, 0x6F, 0x61, 0x72, 0x6C};
33
34
    void restartSystem(void);
35
    bool checkByteForBLReset(uint8_t *inputs, size_t size);
36
    msg_t sendViaCan(uint32_t id, uint8_t *inputs, size_t size);
37
38
    uint8_t inputAddBytes[INPUT_BL_RESET_ADDITIONAL_BYTES];    // Buffer for additional bytes.
39
    uint8_t resetStatus;      // Status of reset
40
    uint8_t resetAddBytes;    // Counter of additional bytes
41
42
    SerialDriver *sd_;
43
    CANDriver *canDriver;
44
    uint8_t myID;
45
    volatile uint8_t queryShellID;
46
    volatile uint8_t replyShellID;
47
48
    CANTxFrame txmsg;
49
    uint8_t inputChar[16] = {};
50
  };
51
52
} /* amiro */
53
54
#endif /* SERIAL_CAN_MUX_HPP_ */
55