main.c.bak 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program body
  5. ******************************************************************************
  6. ** This notice applies to any and all portions of this file
  7. * that are not between comment pairs USER CODE BEGIN and
  8. * USER CODE END. Other portions of this file, whether
  9. * inserted by the user or by software development tools
  10. * are owned by their respective copyright owners.
  11. *
  12. * COPYRIGHT(c) 2019 STMicroelectronics
  13. *
  14. * Redistribution and use in source and binary forms, with or without modification,
  15. * are permitted provided that the following conditions are met:
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ******************************************************************************
  37. */
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"
  40. #include "stm32f1xx_hal.h"
  41. #include "delay.h"
  42. #include "sys.h"
  43. #include "usart.h"
  44. #include "led.h"
  45. #include "usmart.h"
  46. #include "24cxx.h"
  47. #include "task.h"
  48. #include "sim7600.h"
  49. #include "iwdg.h"
  50. #include "gpio.h"
  51. const u8 TEXT_Buffer[]={"4G_SIM7600C STM32F103 IIC TEST"};
  52. BOOL posted = false;
  53. #define SIZE sizeof(TEXT_Buffer)
  54. void http_post_callback(char *buffer) {
  55. PRINTF(buffer);
  56. posted = true;
  57. }
  58. int main(void)
  59. {
  60. u8 datatemp[SIZE];
  61. task *task;
  62. // u8 time;
  63. HAL_Init();
  64. Stm32_Clock_Init(RCC_PLL_MUL9); //设置时钟,72M
  65. delay_init(72); //初始化延时函数
  66. uart2_init(115200); //初始化串口2
  67. uart3_init(115200); //初始化串口3
  68. usmart_dev.init(36); //初始化USMART
  69. LED_Init(); //初始化LED
  70. sim7600_rst();
  71. AT24CXX_Init(); //初始化IIC
  72. // time=RTC_Init(); //初始化RTC
  73. // sim7600_Init(); //4G模块初始化
  74. while(AT24CXX_Check())//检测不到24c02
  75. {
  76. // SIM7600_led=0;
  77. delay_ms(50);
  78. SIM7600_led=1;
  79. delay_ms(50);
  80. }
  81. // AT24CXX_Write(0,(u8*)TEXT_Buffer,SIZE);
  82. // delay_us(50);
  83. AT24CXX_Read(0,datatemp,SIZE);
  84. SIM7600_led=1;
  85. while (1)
  86. {
  87. if(MODULE_OFF_LINE == get_module_status())
  88. {
  89. module_system_start();
  90. }
  91. else if(MODULE_SYNC == get_module_status())
  92. {
  93. module_system_init();
  94. }
  95. else if(MODULE_GET_IP == get_module_status())
  96. {
  97. set_module_status(MODULE_INIT_DONE);
  98. PRINTF("Init Getway\r\n");
  99. SIM7600_led=0;
  100. if(!posted){
  101. module_http_post("http://118.190.199.225:8099/test", "", http_post_callback);
  102. posted = true;
  103. }
  104. }
  105. while((task = pop_task()) != NULL)
  106. {
  107. if(task->handler != NULL)
  108. {
  109. task->handler(task->pdata);
  110. //delete_task(task);
  111. }
  112. if(task != NULL)
  113. {
  114. delete_task(task);
  115. }
  116. }
  117. }
  118. }
  119. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/