can_id_deal.c 2.6 KB

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