linkup.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "bsp_uart.h"
  2. #include "bsp_protocol.h"
  3. void send_to_uart_AABBCC(uint8_t index,uint8_t cmd,uint8_t* dat,uint8_t datLen)
  4. {
  5. uint8_t buf[255];
  6. uint16_t Len = datLen+5;
  7. uint16_t L=0;
  8. uint8_t i;
  9. uint8_t ver = 0;
  10. if(Len>255) return;
  11. buf[L++] = 0xAA; ver += 0xAA; //屐遊
  12. buf[L++] = Len; ver += Len; //海業
  13. buf[L++] = ~Len; ver += (~Len);//海業郡鷹
  14. buf[L++] = cmd; ver += cmd; //凋綜
  15. for(i=0;i<datLen;i++){ buf[L++] = dat[i]; ver += dat[i];} //方象
  16. buf[L++] = ver; //丕刮
  17. for(i=0;i<L;i++) app_uart_put(buf[i]); //堪笥補竃方象
  18. app_uart_put(0x0d);
  19. }
  20. struct pm_type pm;
  21. struct pm_other_type pm_other;
  22. void send_uart_data_UPDATE_BASEINFO(void)
  23. {
  24. uint8_t buf[100];
  25. uint8_t L=0;
  26. int i=0;
  27. buf[L++]=UPDATE_BASEINFO;
  28. buf[L++]=pm.power;
  29. buf[L++]=pm.inner_temperature;
  30. buf[L++]=pm.pressure[0];
  31. buf[L++]=pm.pressure[1];
  32. buf[L++]=pm.pressure[2];
  33. buf[L++]=pm.pressure[3];
  34. buf[L++]=pm_other.power;
  35. buf[L++]=pm_other.inner_temperature;
  36. buf[L++]=pm_other.pressure[0];
  37. buf[L++]=pm_other.pressure[1];
  38. buf[L++]=pm_other.pressure[2];
  39. buf[L++]=pm_other.pressure[3];
  40. // SEGGER_RTT_printf(0,"buff= 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++]);
  41. send_to_uart_AABBCC(DEX_NUM,CMD_UPDATE,buf,L);
  42. }
  43. void load_pm_other(unsigned char* buf)
  44. {
  45. int i=8;
  46. pm_other.power = buf[i++];
  47. pm_other.inner_temperature = buf[i++];
  48. pm_other.pressure[0]=buf[i++];
  49. pm_other.pressure[1]=buf[i++];
  50. pm_other.pressure[2]=buf[i++];
  51. pm_other.pressure[3]=buf[i++];
  52. // SEGGER_RTT_printf(0,"buff= 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++]);
  53. // SEGGER_RTT_printf(0,"output power= %d%% ,temperature= %d ,pressure= 0x%x 0x%x 0x%x 0x%x\n",pm_other.power,pm_other.inner_temperature,pm_other.pressure[0],pm_other.pressure[1],pm_other.pressure[2],pm_other.pressure[3]);
  54. send_uart_data_UPDATE_BASEINFO();
  55. }
  56. //凋綜侃尖痕方
  57. void AABBCC_callback(unsigned char* data,char len)
  58. {
  59. switch(data[3])//心凋綜催
  60. {
  61. case CMD_UPDATE: //臥儂児云佚連
  62. switch(data[4])//心徨凋綜
  63. {
  64. case UPDATE_BASEINFO:
  65. SEGGER_RTT_printf(0,"AABBCC_callback -> UPDATE_BASEINFO\n");
  66. send_uart_data_UPDATE_BASEINFO();//窟僕譜姥児云佚連
  67. break;
  68. }
  69. //printf("AABBCC_callback -> UPDATE_BASEINFO\n");
  70. break;
  71. default:
  72. break;
  73. }
  74. }
  75. unsigned char AABBCC_buff[50];
  76. void AABBCC_REC(unsigned char data)
  77. {
  78. static char len=0;
  79. static char crc=0;
  80. if(((len==0)&&(data==0xAA))
  81. || ( len==1)
  82. || ((len==2)&&(AABBCC_buff[1] + data==0xFF))
  83. || ((len >2)&&(AABBCC_buff[1]-1 > len))
  84. )
  85. {
  86. AABBCC_buff[len++]=data;
  87. crc+=data;
  88. }
  89. else if((AABBCC_buff[1]-1 == len) && ( crc==data ))
  90. {
  91. AABBCC_buff[len]=data;
  92. AABBCC_callback(AABBCC_buff,len);//俊辺頼撹�指距並周痕方
  93. }
  94. else
  95. {
  96. len=0;
  97. crc=0;
  98. }
  99. }
  100. //。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。