NessLab.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * NessLab.c
  3. *
  4. * Created on: Aug 3, 2020
  5. * Author: parkyj
  6. */
  7. #include "main.h"
  8. #include "NessLab.h"
  9. #include "adc.h"
  10. #include "crc.h"
  11. #include "flash.h"
  12. #include "NessLab.h"
  13. //extern uint8_t NessLab_Checksum(uint8_t* data,uint8_t size);
  14. #define NESSLAB_DATARESPONSE_INDEXSIZE 23
  15. #define NESSLAB_TABLE_LENGTH 110
  16. Nesslab_Prot Currstatus;
  17. extern volatile uint16_t ADC1value[ADC1_CNT];
  18. volatile uint8_t NessLab_TxData[200] = {0,};
  19. uint8_t Flash_DataArray[200] = {0,};
  20. void NessLab_TalbleFlash_Read(uint8_t* data,uint8_t size) // ?占쏙옙湲고븿?占쏙옙
  21. {
  22. }
  23. void NessLab_Operate(uint8_t* data){
  24. uint8_t datatype = data[NessLab_MsgID0];
  25. uint8_t UartLength = 0;
  26. static uint16_t MSG_SNCnt = 0;
  27. switch(datatype){
  28. case NessLab_STATUS_REQ:
  29. ADC_Check();
  30. UartLength = NessLab_MAX_INDEX + 1;
  31. MSG_SNCnt = data[NessLab_Req_MsgSN0] << 8 | data[NessLab_Req_MsgSN1];
  32. MSG_SNCnt++;
  33. // if(data[NessLab_Req_Data_Cnt0] > 0)
  34. // NessLab_TxData[NessLab_Over_Power_Alarm] = 1;
  35. // else
  36. // NessLab_TxData[NessLab_Over_Power_Alarm] = 0;
  37. // if(data[NessLab_Req_Data_Cnt1] > 0)
  38. // NessLab_TxData[NessLab_VSWR_ALARM] = 1;
  39. // else
  40. // NessLab_TxData[NessLab_VSWR_ALARM] = 0;
  41. NessLab_TxData[NessLab_MsgSN0] = (uint8_t)((MSG_SNCnt & 0xFF00) >>8);//data[NessLab_Req_MsgSN0];
  42. NessLab_TxData[NessLab_MsgSN1] = (uint8_t)((MSG_SNCnt & 0x00FF));//data[NessLab_Req_MsgSN1] ;
  43. NessLab_Frame_Set(NessLab_TxData,12);
  44. // NessLab_TxData[10] = 1;
  45. // NessLab_TxData[11] = 0;
  46. // NessLab_TxData[12] = 1;
  47. // NessLab_TxData[13] = 0;
  48. // NessLab_TxData[14] = 1;
  49. // NessLab_TxData[15] = 0;
  50. // NessLab_TxData[16] = 1;
  51. // NessLab_TxData[17] = 0;
  52. break;
  53. case NessLab_Table_REQ:
  54. UartLength = NESSLAB_TABLE_LENGTH;
  55. NessLab_Table_Frame_Set(NessLab_TxData,100);
  56. printf("NessLab_Table_REQ \r\n");
  57. break;
  58. case NessLab_TableSet_REQ:
  59. DataErase_Func(FLASH_USER_USE_START_ADDR,200);
  60. printf("Ram Data Display \r\n");
  61. for(int i = 0; i < data[NessLab_DataLength]; i++){
  62. Flash_DataArray[i] = data[NessLab_Data_ADC1_H + i];
  63. printf("%x ",Flash_DataArray[i]);
  64. }
  65. FLASH_Write_Func(&Flash_DataArray[0],data[NessLab_DataLength]);
  66. UartLength = NESSLAB_TABLE_LENGTH;
  67. NessLab_Table_Frame_Set(NessLab_TxData,100);
  68. printf("\r\nNessLab_TableSet_REQ \r\n");
  69. break;
  70. }
  71. Uart1_Data_Send(&NessLab_TxData[NessLab_Header0], UartLength);
  72. }
  73. void NessLab_Frame_Set(uint8_t* data,uint8_t size){
  74. data[NessLab_Header0] = 0x7E;
  75. data[NessLab_Header1] = 0x7E;
  76. data[NessLab_MsgID0] = NessLab_STATUS_RES;// ID
  77. // data[NessLab_MsgSN0] = 0; // SEQ NUMBER
  78. // data[NessLab_MsgSN1] = 0; // SEQ NUMBER
  79. data[NessLab_Reserve0] = 0; // NessLab_Reserve0
  80. data[NessLab_DataLength] = size; // Nesslab Size
  81. data[NessLab_Data_ADC1_H] = Currstatus.DownLink_Forward_Det_H;//(uint8_t)((ADC1value[0] & 0xFF00) >> 8);
  82. data[NessLab_Data_ADC1_L] = Currstatus.DownLink_Forward_Det_L;//(uint8_t)(ADC1value[0] & 0x00FF);
  83. data[NessLab_DC_FAIL_ALARM] = 0;
  84. data[NessLab_DownLink_Status] = 0;
  85. data[NessLab_Over_Power_Alarm] = 0;
  86. data[NessLab_VSWR_ALARM] = 0;
  87. data[NessLab_Over_Input_Alarm] = 0;
  88. data[NessLab_Over_Temp_Alarm] = 0;
  89. data[NessLab_Temp_Monitor] = 0;
  90. data[NessLab_ALC_ALARM] = 0;
  91. data[NessLab_ChecksumVal] = NessLab_Checksum(&data[NessLab_MsgID0], NessLab_MAX_INDEX - 5);
  92. /* Exception Header Tail Checksum */
  93. data[NessLab_Tail0] = 0x7E;
  94. data[NessLab_Tail1] = 0x7E;
  95. data[NessLab_Tail1 + 1] = 0x0A;
  96. }
  97. void NessLab_Table_Frame_Set(uint8_t* data,uint8_t size){
  98. uint32_t i = 0;
  99. uint32_t CurrApiAddress = 0;
  100. CurrApiAddress = FLASH_USER_USE_START_ADDR;
  101. uint8_t* Currdata = (uint8_t*)CurrApiAddress;
  102. uint8_t* pdata;
  103. data[i++] = 0x7E;
  104. data[i++] = 0x7E;
  105. data[i++] = NessLab_STATUS_RES;// ID
  106. data[i++] = 0; // SEQ NUMBER
  107. data[i++] = 0; // SEQ NUMBER
  108. data[i++] = 0; // NessLab_Reserve0
  109. data[i++] = size; // Nesslab Size
  110. // NessLab_TalbleFlash_Read(&data[NessLab_DataLength + 1],100);
  111. for(int a = 0; a < size; a++){
  112. data[i++] = Currdata[a];
  113. // printf("%02x ",Currdata[i]);
  114. }
  115. data[i++] = NessLab_Checksum(&data[NessLab_MsgID0], 100 + 5);
  116. /* Exception Header Tail Checksum */
  117. data[i++] = 0x7E;
  118. data[i++] = 0x7E;
  119. }
  120. void NessLab_Status_Check(){
  121. //HAL_GPIO_ReadPin(, GPIO_Pin)
  122. }
  123. void NessLab_PAU_Enable(){
  124. HAL_GPIO_WritePin(AMP_EN_GPIO_Port,AMP_EN_Pin, HAL_GPIO_ReadPin(PAU_EN_GPIO_Port, PAU_EN_Pin));
  125. //HAL_GPIO_WritePin(AMP_EN_GPIO_Port,AMP_EN_Pin, HAL_GPIO_ReadPin(PAU_RESET_GPIO_Port, PAU_RESET_Pin));
  126. }
  127. void NessLab_GPIO_Operate(){
  128. NessLab_PAU_Enable();
  129. }