tabr

CybergunProtoClass.hpp

Jul 4th, 2022 (edited)
389
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.58 KB | None
  1. /*
  2. * CybergunProtoClass.hpp
  3. *
  4. * Created: 03.06.2022 13:21:22
  5. * Author: tabr
  6. */
  7.  
  8.  
  9. #ifndef __CYBERGUNPROTOCLASS_HPP__
  10. #define __CYBERGUNPROTOCLASS_HPP__
  11. #ifdef USE_UART_DEBUG_COMMANDS
  12. #warning("ANY DATA CANNOT BE MORE THAN 250")
  13. #endif //USE_UART_DEBUG_COMMANDS
  14. class CybergunProtoClass{
  15.     public:
  16.     const static uint8_t STUCK_THRESHOLD = 10;
  17.     #ifdef USE_UART_DEBUG_COMMANDS
  18.         const static uint8_t UART_COMMAND_DUMMY         = 0xFF;
  19.         const static uint8_t UART_COMMAND_PRORO_RESET   = 0xFE;
  20.         const static uint8_t UART_COMMAND_SHOT          = 0xFD;
  21.     #endif //USE_UART_DEBUG_COMMANDS
  22.     const static uint8_t CRC_LENGTH_BYTES       = 2;
  23.     const static uint8_t PACKET_COMMAND_EMPTY   = 0x00;
  24.     enum CG_PACKET_STUCTURE{
  25.         CG_PACKET_STUCTURE_HEAD,
  26.         CG_PACKET_STUCTURE_SUBHEAD,
  27.         CG_PACKET_STUCTURE_DATA0,
  28.         CG_PACKET_STUCTURE_DATA1,
  29.         CG_PACKET_STUCTURE_DATA2,
  30.         CG_PACKET_STUCTURE_DATA3,
  31.         CG_PACKET_STUCTURE_CRC16H,
  32.         CG_PACKET_STUCTURE_CRC16L,
  33.         CG_PACKET_STUCTURE_PACKET_SIZE
  34.     };
  35.     enum CG_PACKET_STUCTURE_HEAD_TYPES{
  36.         CG_PACKET_STUCTURE_HEAD_TYPE_REQUEST,
  37.         CG_PACKET_STUCTURE_HEAD_TYPE_ANSWER,
  38.         CG_PACKET_STUCTURE_HEAD_TYPE_MCUIRQ,
  39.         CG_PACKET_STUCTURE_HEAD_TYPE_ERROR,
  40.         CG_PACKET_STUCTURE_HEAD_TYPE_SIZE
  41.     };
  42.     enum CG_PACKET_STUCTURE_REQUESTS{
  43.         CG_PACKET_STUCTURE_REQUEST_SET_STORAGE,
  44.         CG_PACKET_STUCTURE_REQUEST_GET_STORAGE,
  45.         CG_PACKET_STUCTURE_REQUEST_SET_PIN,//unimplemented
  46.         CG_PACKET_STUCTURE_REQUEST_GET_PIN,//unimplemented
  47.         CG_PACKET_STUCTURE_REQUEST_RESTART_MCU,//unimplemented
  48.         CG_PACKET_STUCTURE_REQUEST_RESTART_BTDEVICE,//unimplemented
  49.         CG_PACKET_STUCTURE_REQUEST_RESTART_FULL,//unimplemented
  50.         CG_PACKET_STUCTURE_REQUEST_PING,//unimplemented
  51.         CG_PACKET_STUCTURE_REQUEST_UPTIME,
  52.         CG_PACKET_STUCTURE_REQUEST_SIZE
  53.     };
  54.     enum STATUSES{
  55.         STATUS_AWAINING_REQUEST,
  56.         STATUSES_SIZE
  57.     };
  58.     //    enum CG_PACKET_STUCTURE_ANSWERS{ ANSWERS = REQUSTS
  59.     //    CG_PACKET_STUCTURE_ANSWER_OK,
  60.     //    };
  61.     enum CG_PACKET_STUCTURE_ERRORS{
  62.         CG_PACKET_STUCTURE_ERROR_NO_ERROR,
  63.         CG_PACKET_STUCTURE_ERROR_UNKNOWN_ERROR,
  64.         CG_PACKET_STUCTURE_ERROR_UNKNOWN_PACKET_HEAD,
  65.         CG_PACKET_STUCTURE_ERROR_INTERNAL_ERROR_BUFFER_PTR,
  66.         CG_PACKET_STUCTURE_ERROR_UNKNOWN_REQUEST,
  67.         CG_PACKET_STUCTURE_ERROR_CRC_ERROR,
  68.         CG_PACKET_STUCTURE_ERROR_SHOT_DETECTED_ON_ZERO_BULLETS,
  69.         CG_PACKET_STUCTURE_ERROR_STUCK_DETECTED,
  70.     };
  71.     enum MCUIRQ_COMMANDS{
  72.         MCUIRQ_COMMAND_SHOT_DETECTED,
  73.         MCUIRQ_COMMAND_ERROR_DETECTED,
  74.         };
  75.     void rx_ISR(uint8_t data);
  76.     void ms_ISR(void);
  77.     void clear_rx_bufer(void);
  78.     void clear_tx_bufer(void);
  79.     void reset(void);
  80.     bool is_packet_valid(void);
  81.     uint16_t get_packet_crcr16(void);
  82.     bool is_packet_ready_to_proceed(void);
  83.     void main(void);
  84.     void pin_reset_up(void);
  85.     void pin_reset_down(void);
  86.     void pin_pio11_up(void);
  87.     void pin_pio11_down(void);
  88.     CybergunProtoClass(void);
  89.     void send_answer(uint16_t dataMSB);
  90.     void send_answer(uint32_t dataMSB);
  91.     void send_answer_operation_successfull(void);
  92.     void send_answer(uint8_t data0, uint8_t data1);
  93.     void send_answer(uint8_t data0, uint8_t data1, uint8_t data2, uint8_t data3);
  94.     //void send_mcuirq_command(MCUIRQ_COMMANDS command);
  95.     void send_mcuirq_command(MCUIRQ_COMMANDS command, uint8_t data);
  96.     void send_error(CG_PACKET_STUCTURE_ERRORS error);
  97.     private:
  98.     void refresh_tx_packet_crc(void);
  99.     uint16_t calculate_tx_packet_crc(void);
  100.     void send_buffer(void);
  101.     uint8_t rx_buffer[CG_PACKET_STUCTURE_PACKET_SIZE];
  102.     volatile uint8_t rx_buffer_ptr;
  103.     uint8_t tx_buffer[CG_PACKET_STUCTURE_PACKET_SIZE];
  104.     //volatile uint8_t tx_buffer_ptr;
  105.     STATUSES current_status;
  106.     volatile uint8_t antistuck_counter;
  107. };
  108. #endif //__CYBERGUNPROTOCLASS_HPP__
  109.  
RAW Paste Data Copied