dev_can_id.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /************************************************************************************************
  2. * Include *
  3. ************************************************************************************************/
  4. #include "dev_can_id.h"
  5. #include "dev_can.h"
  6. #include <stdint.h>
  7. /************************************************************************************************
  8. * Config *
  9. ************************************************************************************************/
  10. union
  11. {
  12. uint32_t r;
  13. struct
  14. {
  15. uint8_t sa : 8;
  16. uint8_t ps : 8;
  17. uint8_t pf : 8;
  18. uint8_t dp : 1;
  19. uint8_t r : 1;
  20. uint8_t p : 3;
  21. } b;
  22. } new_can_id;
  23. #define CAN_PGN_PF 0xFFFF00
  24. #define CAN_PGN_PS 0xFF00
  25. uint32_t g_ps = 0xF4;
  26. uint32_t g_can_id = 0x18F011F4;
  27. uint32_t g_can_ota_id = 0x18DFE1F4;
  28. uint32_t get_new_can_id(uint8_t pf)
  29. {
  30. new_can_id.r = g_can_id;
  31. new_can_id.b.ps = new_can_id.b.sa;
  32. new_can_id.b.sa = g_ps;
  33. new_can_id.b.pf = pf;
  34. return new_can_id.r;
  35. }
  36. uint32_t set_new_can_id(uint16_t pgn)
  37. {
  38. new_can_id.r = g_can_id;
  39. new_can_id.b.sa = g_ps;
  40. new_can_id.b.ps = pgn & 0xFF;
  41. new_can_id.b.pf = pgn >> 8;
  42. return new_can_id.r;
  43. }
  44. uint8_t can_id_set(pdu_tag rec_msg)
  45. {
  46. uint8_t ps = 0;
  47. if (rec_msg.data.u8_buf[0] == 0x01)
  48. {
  49. g_ps = rec_msg.data.u8_buf[1];
  50. rec_msg.data.u8_buf[1] = 1;
  51. }
  52. else
  53. {
  54. rec_msg.data.u8_buf[1] = 0;
  55. }
  56. ps = rec_msg.id.b.ps;
  57. rec_msg.id.b.ps = rec_msg.id.b.ps;
  58. rec_msg.id.b.sa = ps;
  59. push_can_message_to_queue(rec_msg.id.r, 2, rec_msg.data.u8_buf);
  60. return 0;
  61. }
  62. uint32_t get_ota_id(uint8_t pf)
  63. {
  64. new_can_id.r = g_can_ota_id;
  65. new_can_id.b.ps = new_can_id.b.sa;
  66. new_can_id.b.sa = g_ps;
  67. new_can_id.b.pf = pf;
  68. return new_can_id.r;
  69. }
  70. /************************************************************************************************
  71. * Data structs *
  72. ************************************************************************************************/
  73. /************************************************************************************************
  74. * implements *
  75. ************************************************************************************************/