at_init_air720.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * File : at_sample_air720.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2019-12-07 liang.shao first version
  23. */
  24. #include <at_device_air720.h>
  25. #include "sys_config.h"
  26. #include <easyflash.h>
  27. #define LOG_TAG "at.reg"
  28. #include <at_log.h>
  29. #define AIR720_SAMPLE_DEIVCE_NAME "air720"
  30. #define AT_DEVICE_CTRL_REBOOT 0x0DL
  31. extern rt_uint8_t export_logdata_flag;
  32. extern int w5500Start(void);
  33. static struct at_device_air720 sim0 =
  34. {
  35. AIR720_SAMPLE_DEIVCE_NAME,
  36. AIR720_SAMPLE_CLIENT_NAME,
  37. AIR720_SAMPLE_POWER_PIN,
  38. AIR720_SAMPLE_STATUS_PIN,
  39. AIR720_SAMPLE_RECV_BUFF_LEN,
  40. };
  41. extern int ftp_start_download(void);
  42. #define W5500_P GET_PIN(B, 1) // 高开低断
  43. #define Air720_P GET_PIN(D, 9) // 高开低断
  44. #define W5500_OFF rt_pin_write(W5500_P, 0);
  45. #define W5500_ON rt_pin_write(W5500_P, 1);
  46. #define Air720_OFF rt_pin_write(Air720_P, 0);
  47. #define Air720_ON rt_pin_write(Air720_P, 1);
  48. // static int air720_device_register(void)
  49. int air720_device_register(void)
  50. {
  51. struct at_device_air720 *air720 = &sim0;
  52. extern Sector qxz;
  53. rt_pin_mode(W5500_P, PIN_MODE_OUTPUT);
  54. rt_pin_mode(Air720_P, PIN_MODE_OUTPUT);
  55. if (ef_get_env_blob("upload_mode_swtich_flag", &qxz.Param.upload_mode_swtich_flag, sizeof(qxz.Param.upload_mode_swtich_flag), NULL))
  56. // 如果设置为有线网络连接+device_sn不是初始值18054384,则不初始化
  57. {
  58. if ((qxz.Param.upload_mode_swtich_flag) && (rt_strcmp(qxz.Param.device_sn, "18054384") != 0))
  59. {
  60. LOG_W("qxz.Param.device_sn != 18054384");
  61. // w5500Start();
  62. Air720_OFF;
  63. W5500_ON;
  64. goto end;
  65. }
  66. else if (qxz.Param.upload_mode_swtich_flag)
  67. {
  68. LOG_W("Use W5500 , jump Air720");
  69. /**
  70. * @brief 251210 新增 若使用4G则断开W5500供电 反之断开4G供电
  71. *
  72. */
  73. Air720_OFF;
  74. W5500_ON;
  75. // w5500Start();
  76. goto end;
  77. }
  78. }
  79. if (ef_get_env_blob("export_logdata_flag", &export_logdata_flag, sizeof(export_logdata_flag), NULL))
  80. {
  81. if (export_logdata_flag == 1)
  82. {
  83. LOG_W("detect logdata export flag. jump over 4G init !");
  84. goto end;
  85. } // 如果当前需要导出数据 则不初始化联网
  86. }
  87. Air720_OFF;
  88. W5500_OFF;
  89. // 2023.6.9 新增延时3秒 为参数校验争取时间
  90. rt_thread_mdelay(3000);
  91. Air720_ON;
  92. // rt_kprintf("W5500 %d , Air720 %d \n" ,rt_pin_read(W5500_P),rt_pin_read(Air720_P));
  93. char FTP_UPFLG = 0; // 升级成功升级变量置零并写入保存
  94. ef_get_env_blob("FTP_UPFLG", &FTP_UPFLG, sizeof(FTP_UPFLG), NULL);
  95. if (FTP_UPFLG == 0x9D)
  96. {
  97. rt_kprintf("do not start air720 \n");
  98. FTP_UPFLG = 0;
  99. ef_set_env_blob("FTP_UPFLG", &FTP_UPFLG, sizeof(FTP_UPFLG));
  100. ef_set_env_blob("FTP_UPFLG", &FTP_UPFLG, sizeof(FTP_UPFLG));
  101. ef_set_env_blob("FTP_UPFLG", &FTP_UPFLG, sizeof(FTP_UPFLG));
  102. char update_flag = 0;
  103. ef_set_env_blob("update_flag", &update_flag, sizeof(update_flag));
  104. ftp_start_download();
  105. }
  106. else
  107. {
  108. rt_kprintf("start air720 \n");
  109. Air720_ON;
  110. at_device_register(&(air720->device),
  111. air720->device_name,
  112. air720->client_name,
  113. AT_DEVICE_CLASS_AIR720,
  114. (void *)air720);
  115. }
  116. return 0;
  117. end:
  118. rt_kprintf("W5500 %d , Air720 %d \n", rt_pin_read(W5500_P), rt_pin_read(Air720_P));
  119. return RT_EOK;
  120. }
  121. INIT_APP_EXPORT(air720_device_register);
  122. // INIT_COMPONENT_EXPORT(air720_device_register);
  123. // MSH_CMD_EXPORT(air720_device_register, air720_device_register);
  124. // MSH_CMD_EXPORT_ALIAS(air720_reboot, reboot_720, reboot_720 to manual);
  125. // int air720_reboot(void)
  126. //{
  127. // struct at_device_air720 *air720 = &sim0;
  128. // air720->device.is_init = RT_FALSE;//可以启动初始化线程
  129. // return at_device_control(&(air720->device), AT_DEVICE_CTRL_REBOOT, RT_NULL);
  130. // }