iec104_init.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #include "dwt.h"
  2. #include "fly_param.h"
  3. #include "iec104_conf.h"
  4. #include "iec104_queue.h"
  5. #include "iec104_types.h"
  6. #include "main.h"
  7. #include "nor_flash.h"
  8. #include <string.h>
  9. #define TEST_BUF_SIZE 2048
  10. #define TEST_SECTOR_NO 127 /* 测试扇区号,值域【0,128】 */
  11. uint8_t g_test_buf[TEST_BUF_SIZE]; /* 数据测试用缓冲区 */
  12. /*******************************************************************************
  13. * Function Name : fly_init
  14. * Description : fly_init program
  15. * Input : None
  16. * Output : None
  17. * Return : None
  18. *******************************************************************************/
  19. static int fly_init(void)
  20. {
  21. return 0;
  22. }
  23. static void *fly_malloc(unsigned char nbyte)
  24. {
  25. return malloc(nbyte);
  26. }
  27. static void fly_free(void *pblock)
  28. {
  29. free(pblock);
  30. }
  31. static iec_32u fly_set_time(PCP56Time2a_T time)
  32. {
  33. return RET_SUCESS;
  34. }
  35. static iec_32u fly_get_time(PCP56Time2a_T time)
  36. {
  37. return RET_SUCESS;
  38. }
  39. static iec_8s fly_get_station_info(iec_16u *addr, iec_8u n, iec_8u *MaxNum)
  40. {
  41. *MaxNum = WTP_SUPPORT_END_NUMBER;
  42. *addr = n;
  43. return RET_SUCESS;
  44. }
  45. static float fly_get_station_temp(iec_16u addr)
  46. {
  47. return 30;
  48. }
  49. static iec_16u fly_get_link_addr(void)
  50. {
  51. return 0x0001;
  52. }
  53. static void fly_close_link(void)
  54. {
  55. // GPRSFlag = SYSTEM_FLAG_GPRS_CLOSE;
  56. // IEC104_STATE_FLAG_INIT = IEC104_FLAG_CLOSED;
  57. }
  58. void delay_ms(iec_16u ms)
  59. {
  60. us_delay(ms * 1000);
  61. }
  62. iec_8u fly_send(int socketfd, char *buf, int len)
  63. {
  64. int i;
  65. if (-1 == write(socketfd, buf, len))
  66. {
  67. LOG("-%s-,Send error \n", __FUNCTION__);
  68. return RET_ERROR;
  69. }
  70. // for (i = 0; i < len; i++)
  71. // {
  72. // NOR_WriteByte(TEST_SECTOR_NO * NOR_SECTOR_SIZE, buf[i]);
  73. // if (NOR_WriteBuffer(buf, TEST_SECTOR_NO * NOR_SECTOR_SIZE + 1, len) == NOR_SUCCESS)
  74. // {
  75. // printf("send sram buffer ok!\r\n");
  76. // }
  77. // }
  78. LOG("Send Ok!\r\n");
  79. return RET_SUCESS;
  80. }
  81. iec_8s fly_get_info_num(iec_8u *info_num, iec_8u dev_type)
  82. {
  83. return 0;
  84. }
  85. iec_8s fly_set_onfig(long value, iec_32u addr)
  86. {
  87. return 0;
  88. }
  89. iec_8s fly_save_firmware(iec_8u firm_len, iec_8u *buf, iec_32u firmware_type, iec_32u iec104_update_seek_addr)
  90. {
  91. return 0;
  92. }
  93. iec_8s fly_check_firmware(iec_32u firmware_type, iec_32u total_len)
  94. {
  95. return 0;
  96. }
  97. iec_8s fly_update_firmware(iec_32u firmware_type)
  98. {
  99. return 0;
  100. }
  101. iec_8s fly_back_off_firmware(iec_32u firmware_type)
  102. {
  103. return 0;
  104. }
  105. void fly_lock(void)
  106. {
  107. INT8U err;
  108. OSMutexPend(net_mutex, 0, &err);
  109. // pthread_mutex_lock(&mutex);
  110. LOG("Net_mutex lock!\r\n");
  111. }
  112. void fly_unlock()
  113. {
  114. OSMutexPost(net_mutex);
  115. // pthread_mutex_unlock(&mutex);
  116. LOG("Net_mutex unlock!\r\n");
  117. }
  118. static iec104_t fly = {
  119. "fly_iec104",
  120. fly_init,
  121. delay_ms,
  122. fly_close_link,
  123. fly_malloc,
  124. fly_free,
  125. iec104_prio_enqueue,
  126. iec104_prio_dequeue,
  127. iec104_prio_queue_find_head,
  128. iec10x_prio_highest, /* Get the highest Prio Queue*/
  129. iec104_prio_queue_init,
  130. iec104_prio_queue_clear,
  131. fly_send,
  132. fly_set_time,
  133. fly_get_time,
  134. fly_get_station_info,
  135. fly_get_station_temp,
  136. fly_get_link_addr,
  137. fly_get_info_num,
  138. fly_set_onfig,
  139. fly_save_firmware,
  140. fly_check_firmware,
  141. fly_update_firmware,
  142. fly_back_off_firmware,
  143. #ifdef IEC104LOCK
  144. fly_lock,
  145. fly_unlock
  146. #endif
  147. };
  148. iec_32u iec10x_regist(void)
  149. {
  150. return iec104_module_register(&fly);
  151. }