Skip to content

Commit 20175e2

Browse files
committed
修改 ai无法 彻底处理的问题
1 parent e93e3d4 commit 20175e2

12 files changed

Lines changed: 75 additions & 126 deletions

File tree

common/log/salof_config.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,6 @@
1919
#define SALOF_USING_LINUX 4
2020
#define SALOF_USING_WINDOWS 5
2121

22-
/*
23-
* 编译时自动平台检测 (Automatic platform detection at compile time)
24-
*
25-
* 本文件会在编译时自动检测操作系统平台,无需手动配置 SALOF_OS
26-
* This file automatically detects the OS platform at compile time without manual SALOF_OS configuration
27-
*
28-
* 支持的平台 (Supported platforms):
29-
* - Windows (通过 _WIN32, _WIN64, __CYGWIN__, _MSC_VER 检测)
30-
* - Linux/Unix (通过 __linux__, __unix__, __APPLE__ 检测)
31-
* - FreeRTOS (通过 __FREERTOS__, FREERTOS, INC_FREERTOS_H 检测)
32-
* - RT-Thread (通过 __RTTHREAD__, RT_USING_RTTHREAD, RT_THREAD_H__ 检测)
33-
* - TencentOS (通过 __TENCENTOS__, TOS_CFG_TASK_PRIO_MAX 检测)
34-
*
35-
* 如需手动指定平台,可在包含本文件前定义 SALOF_OS
36-
* To manually specify platform, define SALOF_OS before including this file
37-
*/
38-
#ifndef SALOF_OS
39-
/* Auto-detect Windows platform (自动检测 Windows 平台) */
40-
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) || defined(_MSC_VER)
41-
#define SALOF_OS SALOF_USING_WINDOWS
42-
/* Auto-detect Linux/Unix platform (自动检测 Linux/Unix 平台) */
43-
#elif defined(__linux__) || defined(__unix__) || defined(__APPLE__)
44-
#define SALOF_OS SALOF_USING_LINUX
45-
/* Auto-detect FreeRTOS (自动检测 FreeRTOS) */
46-
#elif defined(__FREERTOS__) || defined(FREERTOS) || defined(INC_FREERTOS_H)
47-
#define SALOF_OS SALOF_USING_FREERTOS
48-
/* Auto-detect RT-Thread (自动检测 RT-Thread) */
49-
#elif defined(__RTTHREAD__) || defined(RT_USING_RTTHREAD) || defined(RT_THREAD_H__)
50-
#define SALOF_OS SALOF_USING_RTT
51-
/* Auto-detect TencentOS (自动检测 TencentOS) */
52-
#elif defined(__TENCENTOS__) || defined(TOS_CFG_TASK_PRIO_MAX)
53-
#define SALOF_OS SALOF_USING_TENCENTOS
54-
#endif
55-
#endif
5622

5723
/* Include mqtt_config.h for MQTT-specific settings (can override SALOF_OS if needed) */
5824
#include "mqtt_config.h"

common/log/salof_defconfig.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
#ifndef _SALOF_DEFCONFIG_H_
99
#define _SALOF_DEFCONFIG_H_
1010

11-
/*
12-
* Platform constants are now defined in salof_config.h
13-
* so they're available before any detection code runs
14-
* 平台常量现在在 salof_config.h 中定义,在任何检测代码运行之前就可用
15-
*/
1611
#include "salof_config.h"
1712

1813
#ifdef SALOF_USING_LOG
@@ -67,16 +62,7 @@
6762

6863
#endif
6964

70-
/* Fallback platform detection if SALOF_OS isn't defined by mqtt_config.h */
71-
#if !defined(SALOF_OS)
72-
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) || defined(_MSC_VER)
73-
#define SALOF_OS SALOF_USING_WINDOWS
74-
#elif defined(__linux__) || defined(__unix__)
75-
#define SALOF_OS SALOF_USING_LINUX
76-
#else
77-
#error "SALOF_OS isn't defined and platform cannot be auto-detected"
78-
#endif
79-
#endif
65+
8066

8167
#if (SALOF_OS == SALOF_USING_FREERTOS)
8268
#include "FreeRTOS.h"

config/mqtt_config.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@
1010
#define MQTT_LOG_IS_SALOF
1111

1212
#define MQTT_LOG_LEVEL MQTT_LOG_INFO_LEVEL //MQTT_LOG_WARN_LEVEL MQTT_LOG_DEBUG_LEVEL
13+
// Only define SALOF_OS if not already defined by salof_config.h
14+
// salof_config.h has comprehensive platform detection that should be used first
15+
#ifndef SALOF_OS
16+
// Fallback platform detection if salof_config.h didn't define it
17+
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
18+
#define SALOF_OS SALOF_USING_WINDOWS
19+
#else
20+
#define SALOF_OS SALOF_USING_LINUX
21+
#endif
22+
#endif
1323

1424
#ifdef MQTT_LOG_IS_SALOF
1525
#define SALOF_USING_LOG (1U)
1626
#define SALOF_USING_SALOF (1U)
1727
#define SALOF_LOG_LEVEL MQTT_LOG_LEVEL
1828

19-
// Only define SALOF_OS if not already defined by salof_config.h
20-
// salof_config.h has comprehensive platform detection that should be used first
21-
#ifndef SALOF_OS
22-
// Fallback platform detection if salof_config.h didn't define it
23-
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
24-
#define SALOF_OS SALOF_USING_WINDOWS
25-
#else
26-
#define SALOF_OS SALOF_USING_LINUX
27-
#endif
28-
#endif
29+
2930

3031
#define SALOF_USING_IDLE_HOOK (0U)
3132
#define SALOF_LOG_COLOR (1U)

example/ali/ali.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,7 @@
88
#include <stdio.h>
99
#include <stdlib.h>
1010
#include <string.h>
11-
12-
/* Platform-specific includes */
13-
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
14-
#include <windows.h>
15-
#define sleep(x) Sleep((x)*1000) /* Windows Sleep is in milliseconds */
16-
typedef HANDLE pthread_t;
17-
typedef DWORD (WINAPI *thread_func_t)(LPVOID);
18-
#define pthread_create(thread, attr, start_routine, arg) \
19-
((*thread = CreateThread(NULL, 0, (thread_func_t)(start_routine), arg, 0, NULL)) == NULL ? -1 : 0)
20-
#else
21-
#include <unistd.h>
22-
#include <fcntl.h>
23-
#include <pthread.h>
24-
#endif
11+
#include "../example.h"
2512

2613
#include "mqttclient.h"
2714

@@ -44,7 +31,6 @@ void *mqtt_publish_thread(void *arg)
4431

4532
sleep(2);
4633

47-
mqtt_list_subscribe_topic(client);
4834

4935
msg.payload = (void *) buf;
5036
msg.qos = 0;

example/ali/mqtt_config.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010
#define MQTT_LOG_IS_SALOF
1111

1212
#define MQTT_LOG_LEVEL MQTT_LOG_INFO_LEVEL //MQTT_LOG_WARN_LEVEL MQTT_LOG_DEBUG_LEVEL
13-
13+
// Only define SALOF_OS if not already defined by salof_config.h
14+
// salof_config.h has comprehensive platform detection that should be used first
15+
#ifndef SALOF_OS
16+
// Fallback platform detection if salof_config.h didn't define it
17+
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
18+
#define SALOF_OS SALOF_USING_WINDOWS
19+
#else
20+
#define SALOF_OS SALOF_USING_LINUX
21+
#endif
22+
#endif
1423
#ifdef MQTT_LOG_IS_SALOF
1524
#define SALOF_USING_LOG (1U)
1625
#define SALOF_USING_SALOF (1U)
1726
#define SALOF_LOG_LEVEL MQTT_LOG_LEVEL
18-
#define SALOF_OS SALOF_USING_LINUX
1927
#define SALOF_USING_IDLE_HOOK (0U)
2028
#define SALOF_LOG_COLOR (1U)
2129
#define SALOF_LOG_TS (0U)

example/baidu/baidu.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,7 @@
88
#include <stdio.h>
99
#include <stdlib.h>
1010
#include <string.h>
11-
12-
/* Platform-specific includes */
13-
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
14-
#include <windows.h>
15-
#define sleep(x) Sleep((x)*1000) /* Windows Sleep is in milliseconds */
16-
typedef HANDLE pthread_t;
17-
typedef DWORD (WINAPI *thread_func_t)(LPVOID);
18-
#define pthread_create(thread, attr, start_routine, arg) \
19-
((*thread = CreateThread(NULL, 0, (thread_func_t)(start_routine), arg, 0, NULL)) == NULL ? -1 : 0)
20-
#else
21-
#include <unistd.h>
22-
#include <fcntl.h>
23-
#include <pthread.h>
24-
#endif
25-
11+
#include "../example.h"
2612
#include "mqttclient.h"
2713

2814
// #define TEST_USEING_TLS
@@ -70,7 +56,6 @@ void *mqtt_publish_thread(void *arg)
7056

7157
sleep(2);
7258

73-
mqtt_list_subscribe_topic(client);
7459

7560
msg.payload = (void *) buf;
7661
msg.qos = 0;

example/baidu/mqtt_config.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010
#define MQTT_LOG_IS_SALOF
1111

1212
#define MQTT_LOG_LEVEL MQTT_LOG_INFO_LEVEL //MQTT_LOG_WARN_LEVEL MQTT_LOG_DEBUG_LEVEL
13-
13+
// Only define SALOF_OS if not already defined by salof_config.h
14+
// salof_config.h has comprehensive platform detection that should be used first
15+
#ifndef SALOF_OS
16+
// Fallback platform detection if salof_config.h didn't define it
17+
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
18+
#define SALOF_OS SALOF_USING_WINDOWS
19+
#else
20+
#define SALOF_OS SALOF_USING_LINUX
21+
#endif
22+
#endif
1423
#ifdef MQTT_LOG_IS_SALOF
1524
#define SALOF_USING_LOG (1U)
1625
#define SALOF_USING_SALOF (1U)
1726
#define SALOF_LOG_LEVEL MQTT_LOG_LEVEL
18-
#define SALOF_OS SALOF_USING_LINUX
1927
#define SALOF_USING_IDLE_HOOK (0U)
2028
#define SALOF_LOG_COLOR (1U)
2129
#define SALOF_LOG_TS (0U)

example/emqx/emqx.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,7 @@
99
#include <stdlib.h>
1010
#include <string.h>
1111

12-
/* Platform-specific includes */
13-
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
14-
#include <windows.h>
15-
#define sleep(x) Sleep((x)*1000) /* Windows Sleep is in milliseconds */
16-
typedef HANDLE pthread_t;
17-
typedef DWORD (WINAPI *thread_func_t)(LPVOID);
18-
#define pthread_create(thread, attr, start_routine, arg) \
19-
((*thread = CreateThread(NULL, 0, (thread_func_t)(start_routine), arg, 0, NULL)) == NULL ? -1 : 0)
20-
#else
21-
#include <unistd.h>
22-
#include <fcntl.h>
23-
#include <pthread.h>
24-
#endif
12+
#include "../example.h"
2513

2614
#include "mqtt_config.h"
2715
#include "mqtt_log.h"
@@ -50,7 +38,6 @@ void *mqtt_publish_thread(void *arg)
5038

5139
sleep(2);
5240

53-
mqtt_list_subscribe_topic(client);
5441

5542
msg.payload = (void *) buf;
5643

example/emqx/mqtt_config.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010
#define MQTT_LOG_IS_SALOF
1111

1212
#define MQTT_LOG_LEVEL MQTT_LOG_INFO_LEVEL //MQTT_LOG_WARN_LEVEL MQTT_LOG_DEBUG_LEVEL
13-
13+
// Only define SALOF_OS if not already defined by salof_config.h
14+
// salof_config.h has comprehensive platform detection that should be used first
15+
#ifndef SALOF_OS
16+
// Fallback platform detection if salof_config.h didn't define it
17+
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
18+
#define SALOF_OS SALOF_USING_WINDOWS
19+
#else
20+
#define SALOF_OS SALOF_USING_LINUX
21+
#endif
22+
#endif
1423
#ifdef MQTT_LOG_IS_SALOF
1524
#define SALOF_USING_LOG (1U)
1625
#define SALOF_USING_SALOF (1U)
1726
#define SALOF_LOG_LEVEL MQTT_LOG_LEVEL
18-
#define SALOF_OS SALOF_USING_LINUX
1927
#define SALOF_USING_IDLE_HOOK (0U)
2028
#define SALOF_LOG_COLOR (1U)
2129
#define SALOF_LOG_TS (0U)

example/example.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef _EXAMPLE_H_
2+
#define _EXAMPLE_H_
3+
/* Platform-specific includes */
4+
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
5+
#include <windows.h>
6+
#define sleep(x) Sleep((x)*1000) /* Windows Sleep is in milliseconds */
7+
typedef HANDLE pthread_t;
8+
typedef DWORD(WINAPI* thread_func_t)(LPVOID);
9+
#define pthread_create(thread, attr, start_routine, arg) \
10+
((*thread = CreateThread(NULL, 0, (thread_func_t)(start_routine), arg, 0, NULL)) == NULL ? -1 : 0)
11+
#define SALOF_OS SALOF_USING_WINDOWS
12+
#else
13+
#include <unistd.h>
14+
#include <fcntl.h>
15+
#include <pthread.h>
16+
#define SALOF_OS SALOF_USING_LINUX
17+
#endif
18+
#endif

0 commit comments

Comments
 (0)