Gitee

https://gitee.com/WangXi_Chn/PcComTestApp

应用版本V1.0

应用功能

  • 作为应用程序编写范例,可作为模板参考
  • 可与上位机通信(遵从板级串口通信模块的通信协议)
  • 支持JC24B无线串口透传模块
  • 支持HMI界面数据显示
  • 支持与其他STM32单片机通信(遵从板级串口通信模块的通信协议)
  • 支持LED频闪显示自身ID

    开发环境

    CubeMX
    MDK5 IDE
    STM32F103C8T6 芯片
    Stm32最小系统板
    RT-Thread操作系统
    面向对象模块接口设计
    陶晶驰HMI串口屏
    JC24B无线串口

    应用特性

    模块化设计自由裁剪
    多线程工作
    通信模块通用,分自身ID和目标ID,可迅速部署通信网络
    数据表大小0xFF个int类型数据

    源文件

    App_PcComTest.c

    ```c /*
    • Copyright (c) 2020 - ~, HIT_HERO Team *
    • PCCOMTEST APP SOUCE FILE
    • Used in RT-Thread Operate System *
    • Change Logs:
    • Date Author Notes Mail
    • 2020-09-06 WangXi first version WangXi_chn@foxmail.com */

include “App_PcComTest.h”

include

static void APP_PcComTestInit(APP_PCCOMTEST Application); static void APP_PcComTestRun(APP_PCCOMTEST Application);

static void PcComTestLed_entry(void parameter); static void PcComTestUpdate_entry(void parameter); static void PcComTestDeal_entry(void *parameter);

void APP_PcComTest_Config(APP_PCCOMTEST *Application) { if( Application->Method_Init == NULL && Application->Method_Run == NULL

  1. ){
  2. /* Link the Method */
  3. Application->Method_Init = APP_PcComTestInit;
  4. Application->Method_Run = APP_PcComTestRun;
  5. }
  6. else{
  7. rt_kprintf("Warning: Module Led is Configed twice\n");
  8. return;
  9. }
  10. /* Device Init */
  11. Application->Method_Init(Application);
  12. /* Module Config */
  13. Module_UartCom_Config(&(Application->dev_UartBsp));
  14. Module_Led_Config(&(Application->dev_Led));
  15. Module_UartHMI_Config(&(Application->dev_UartHMI));
  16. return;

}

static void APP_PcComTestInit(APP_PCCOMTEST Application) { / Module param list ————————————————————————————————————- / / LED Pin device / / Pin: PC13 Low power enable */ Application->dev_Led.Property_pin = GET_PIN(C, 13); Application->dev_Led.Property_Mode = FLASH_LED_MODE; Application->dev_Led.LED_TIME_CYCLE = 1500; Application->dev_Led.LED_TIME_OUTPUT = 150;

  1. /* JC24B 2.4G Uart communication device */
  2. /* Pin: PA2 Uart2_TX */
  3. /* Pin: PA3 Uart2_RX */
  4. /* Pin: PB12 Set Pin */
  5. Application->dev_UartBsp.Property_UartDevName = "uart2";
  6. Application->dev_UartBsp.Property_BaudRate = 9600;
  7. Application->dev_UartBsp.Property_MyID = MYID;
  8. Application->dev_UartBsp.Property_NetID = 0x10;
  9. Application->dev_UartBsp.Property_Device = JC24B;
  10. Application->dev_UartBsp.Property_JC24BsetPin = GET_PIN(B, 12);
  11. /* HMI Uart communication device */
  12. /* Pin: PB10 Uart3_TX */
  13. /* Pin: PB11 Uart3_RX */
  14. Application->dev_UartHMI.Property_UartDevName = "uart3";
  15. /* Data Sheet Default Value ------------------------------------------------------------------ */

}

static void APP_PcComTestRun(APP_PCCOMTEST Application) { / Let the LED flash module show the machine ID */
Application->dev_Led.Method_Set(&Application->dev_Led,MYID);

  1. rt_thread_t PcComTestLed_thread = rt_thread_create("PcComTestLed", PcComTestLed_entry,
  2. Application,512, RT_THREAD_PRIORITY_MAX - 2, 20);
  3. if (PcComTestLed_thread != RT_NULL){
  4. rt_thread_startup(PcComTestLed_thread);
  5. }
  6. rt_thread_t PcComTestUpdate_thread = rt_thread_create("PcComTestUpdate", PcComTestUpdate_entry,
  7. Application,512, RT_THREAD_PRIORITY_MAX - 3, 20);
  8. if (PcComTestUpdate_thread != RT_NULL){
  9. rt_thread_startup(PcComTestUpdate_thread);
  10. }
  11. rt_thread_t PcComTestDeal_thread = rt_thread_create("PcComTestDeal", PcComTestDeal_entry,
  12. Application,1024, RT_THREAD_PRIORITY_MAX - 3, 20);
  13. if (PcComTestDeal_thread != RT_NULL){
  14. rt_thread_startup(PcComTestDeal_thread);
  15. }

}

/ thread entry list ——————————————————————————————————————- / static void PcComTestLed_entry(void parameter) { APP_PCCOMTEST Application = (APP_PCCOMTEST *)parameter; while(1) { rt_thread_mdelay(1); Application->dev_Led.Method_Handle(&(Application->dev_Led)); }
}

static void PcComTestUpdate_entry(void parameter) { APP_PCCOMTEST Application = (APP_PCCOMTEST *)parameter;

  1. Application->dev_UartBsp.Method_Feed( &(Application->dev_UartBsp),
  2. &(Application->Value_PacketID),
  3. Application->Value_DataSheet);

}

static void PcComTestDeal_entry(void parameter) { APP_PCCOMTEST Application = (APP_PCCOMTEST *)parameter; char str[50]; while (1) { rt_thread_mdelay(1); sprintf(str, “tempreture.txt=\”%d\””, Application->Value_DataSheet[gytempreture_ID]); Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);

  1. sprintf(str, "offsetdata.txt=\"%d\"", Application->Value_DataSheet[gylingdata_ID]);
  2. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  3. sprintf(str, "origindata.txt=\"%d\"", Application->Value_DataSheet[qystartdata_ID]);
  4. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  5. sprintf(str, "dealdata.txt=\"%d\"", Application->Value_DataSheet[gylvdata_ID]);
  6. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  7. sprintf(str, "groAngle.txt=\"%d\"", Application->Value_DataSheet[gyangle_ID]);
  8. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  9. sprintf(str, "sampleNum.txt=\"%d\"", Application->Value_DataSheet[maNumber]);
  10. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  11. sprintf(str, "magXorigin.txt=\"%d\"", Application->Value_DataSheet[ma]);
  12. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  13. sprintf(str, "magXdeal.txt=\"%d\"", Application->Value_DataSheet[malvX]);
  14. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  15. sprintf(str, "magYorigin.txt=\"%d\"", Application->Value_DataSheet[mastartY]);
  16. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  17. sprintf(str, "magYdeal.txt=\"%d\"", Application->Value_DataSheet[malvY]);
  18. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  19. sprintf(str, "magXoffset.txt=\"%d\"", Application->Value_DataSheet[malingX]);
  20. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  21. sprintf(str, "magYoffset.txt=\"%d\"", Application->Value_DataSheet[malingY]);
  22. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  23. sprintf(str, "magCircle.txt=\"%d\"", Application->Value_DataSheet[macircle]);
  24. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  25. sprintf(str, "magAngle.txt=\"%d\"", Application->Value_DataSheet[maAngle]);
  26. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  27. sprintf(str, "AimX.txt=\"%d\"", Application->Value_DataSheet[coX]);
  28. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  29. sprintf(str, "AimY.txt=\"%d\"", Application->Value_DataSheet[coY]);
  30. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  31. sprintf(str, "AimR.txt=\"%d\"", Application->Value_DataSheet[coangle]);
  32. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  33. sprintf(str, "Mode.txt=\"%d\"", Application->Value_DataSheet[mo360]);
  34. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  35. sprintf(str, "GPSX.txt=\"%d\"", Application->Value_DataSheet[allX]);
  36. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  37. sprintf(str, "GPSY.txt=\"%d\"", Application->Value_DataSheet[allY]);
  38. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  39. sprintf(str, "GPSAng.txt=\"%d\"", Application->Value_DataSheet[allziangle]);
  40. Application->dev_UartHMI.Method_Send(&Application->dev_UartHMI,str);
  41. }

}

/** (C) COPYRIGHT 2020 WANGXI **END OF FILE**/

  1. - 方法API解释
  2. - Config全局函数中,实现对应用对象的初始化
  3. - 绑定函数方法,调用Init初始化方法(配置成员模块的必要参数,初始化数据表默认数值)
  4. - 调用各个模块的Config全局函数,实现对各个模块的初始化
  5. - Run方法被main调用,指示应用开始运行
  6. - 调用成员模块的方法,执行外设功能
  7. - 创建线程,启动线程
  8. - 初始化所需信号量等
  9. - 线程解释
  10. - PcComTestLed
  11. - 应用状态灯线程,通过频闪次数指示自身在网中的ID
  12. - PcComTestUpdate
  13. - 数据更新线程,接收串口数据更新数据表
  14. - PcComTestDeal
  15. - 数据处理线程,这里仅将数据表中的信息对应显示在了串口屏中
  16. <a name="hACgS"></a>
  17. #### App_PcComTest.h
  18. ```c
  19. /*
  20. * Copyright (c) 2020 - ~, HIT_HERO Team
  21. *
  22. * PCCOMTEST APP HEAD FILE
  23. * Used in RT-Thread Operate System
  24. *
  25. * Change Logs:
  26. * Date Author Notes Mail
  27. * 2020-09-06 WangXi first version WangXi_chn@foxmail.com
  28. */
  29. #ifndef _APP_PCCOMTEST_H_
  30. #define _APP_PCCOMTEST_H_
  31. #include <rtthread.h>
  32. #include <rtdevice.h>
  33. #include <board.h>
  34. #include "Module_UartCom.h"
  35. #include "Module_LED.h"
  36. #include "Module_UartHMI.h"
  37. struct _APP_PCCOMTEST
  38. {
  39. /* Property */
  40. MODULE_UARTCOM dev_UartBsp;
  41. MODULE_LED dev_Led;
  42. MODULE_UARTHMI dev_UartHMI;
  43. /* Value */
  44. UARTCOM_PACKETID Value_PacketID;
  45. rt_int32_t Value_DataSheet[0xFF];
  46. /* Method */
  47. void (*Method_Init)(struct _APP_PCCOMTEST *Application);
  48. void (*Method_Run)(struct _APP_PCCOMTEST *Application);
  49. };
  50. typedef struct _APP_PCCOMTEST APP_PCCOMTEST;
  51. void APP_PcComTest_Config(APP_PCCOMTEST *Application);
  52. //Machine_ID define--------------------------------------------------------------
  53. #define MYID 0x01
  54. #define PCID 0x11
  55. //Packet_ID define---------------------------------------------------------------
  56. //陀螺仪
  57. //陀螺仪芯片温度 gytempreture 0X01
  58. #define gytempreture_ID 0x01
  59. //陀螺仪Z轴零偏数据 gylingdata 0X02
  60. #define gylingdata_ID 0x02
  61. //陀螺仪Z轴原始数据 qystartdata 0X03
  62. #define qystartdata_ID 0X03
  63. //陀螺仪Z轴滤波数据 gylvdata 0X04
  64. #define gylvdata_ID 0X04
  65. //陀螺仪计算角度 gyangle 0X05
  66. #define gyangle_ID 0X05
  67. //陀螺仪Kalman滤波器参数 估算协方差P gyP 0X06
  68. #define gyP 0x06
  69. //陀螺仪Kalman滤波器参数 过程噪声协方差Q gyQ 0X07
  70. #define gyQ 0X07
  71. //陀螺仪Kalman滤波器参数 观测噪声协方差R gyR 0X08
  72. #define gyR 0X08
  73. //磁力计
  74. //磁位计X轴原始数据 ma 0X11
  75. #define ma 0X11
  76. //磁位计X轴滤波数据 malvX 0X12
  77. #define malvX 0X12
  78. //磁位计Y轴原始数据 mastartY 0X13
  79. #define mastartY 0X13
  80. //磁位计Y轴滤波数据 malvY 0X14
  81. #define malvY 0X14
  82. //磁位计计算角度 maAngle 0X15
  83. #define maAngle 0X15
  84. //设置零偏采样值个数 maNumber 0X16
  85. #define maNumber 0X16
  86. //磁位计X轴零偏数据 malingX 0X17
  87. #define malingX 0X17
  88. //磁位计Y轴零偏数据 malingY 0X18
  89. #define malingY 0X18
  90. //磁位计圆化率 macircle 0X19
  91. #define macircle 0X19
  92. //磁位计Kalman滤波器参数 估算协方差P maP 0X1A
  93. #define maP 0X1A
  94. //磁位计Kalman滤波器参数 过程噪声协方差Q maQ 0X1B
  95. #define maQ 0X1B
  96. //磁位计Kalman滤波器参数 观测噪声协方差R maR 0X1C
  97. #define maR 0X1C
  98. //整体部分读取
  99. //互补滤波角度 allangle 0X21
  100. #define allangle 0X21
  101. //全局定位X坐标值 allX 0X22
  102. #define allX 0x22
  103. //全局定位Y坐标值 allY 0X23
  104. #define allY 0x23
  105. //全局定位姿态角值 allziangle 0X24
  106. #define allziangle 0X24
  107. //模式部分
  108. //选择360° mo360 0X31
  109. #define mo360 0X31
  110. //±180°模式 mo180 0X32
  111. #define mo180 0X32
  112. //控制部分读取
  113. //装置目标位置值 cogoallocation 0X41
  114. #define cogoallocation 0X41
  115. //装置实际位置值 coactuallocation 0X42
  116. #define coactuallocation 0X42
  117. //装置目标角度值 cogoalangle 0X43
  118. #define cogoalangle 0X43
  119. //装置实际位置值 coactualangle 0X44
  120. #define coactualangle 0X44
  121. //装置坐标值X coX 0X45
  122. #define coX 0X45
  123. //装置坐标值Y coY 0X46
  124. #define coY 0X46
  125. //装置姿态角 coangle 0X47
  126. #define coangle 0X47
  127. #endif
  128. /************************ (C) COPYRIGHT 2020 WANGXI **************END OF FILE****/
  • 将帧的ID作为数据表(数组)的检索,对数据表读取或存储

    使用main.c

    ```c /*
    • Copyright (c) 2020 - ~, HIT_HERO Team *
    • STM32F103C8T6 MIN SYSTEM MAIN SOUCE FILE
    • Used in RT-Thread Operate System *
    • Change Logs:
    • Date Author Notes Mail
    • 2020-09-03 WangXi first version WangXi_chn@foxmail.com *
    • Note:
    • Finsh: uart1
    • uart1_tx —> PA9
    • uart1_rx —> PA10 */

include

include

include

include “App_PcComTest.h”

APP_PCCOMTEST app_pccomtest;

int main(void) { APP_PcComTest_Config(&app_pccomtest); app_pccomtest.Method_Run(&app_pccomtest);

  1. return 0;

}

/** (C) COPYRIGHT 2020 WANGXI **END OF FILE**/

```

屏幕界面

image.png
显示屏程序
TJC3224T022_011_TESTMACH.rar

补充说明

  • 该应用程序并非正式投入使用的程序,只是各项功能的先行验证版本
  • 同时也是通过应用封装各个模块的模板说明,为如何组织各个模块工作提供范例
  • 将视情况选择是否继续更新

应用版本V2.0

功能更新

  • 赋予项目名称 Ratel(蜜獾)
  • 寓意勇敢尝试,实验新的功能
  • 试验了无线串口通信的组网功能
  • 试验了通过单片机自定义ID的功能
  • 试验了OLED显示功能