56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include <stdio.h>
 | 
						||
#include <string.h>
 | 
						||
#include "json_parser.h"
 | 
						||
 | 
						||
// 测试JSON解析功能
 | 
						||
void test_json_parsing() {
 | 
						||
    printf("=== JSON解析测试 ===\n");
 | 
						||
    
 | 
						||
    // 测试命令1:旋转+显示+清屏
 | 
						||
    char test1[] = "{\"cmd\":1,\"text\":\"Hello World\"}";
 | 
						||
    JsonCommand cmd1;
 | 
						||
    if (ParseJsonCommand(test1, &cmd1) == 0) {
 | 
						||
        printf("测试1成功: cmd=%d, text=%s\n", cmd1.cmd, cmd1.text);
 | 
						||
    } else {
 | 
						||
        printf("测试1失败\n");
 | 
						||
    }
 | 
						||
    
 | 
						||
    // 测试命令2:顺时针旋转
 | 
						||
    char test2[] = "{\"cmd\":2,\"text\":\"\"}";
 | 
						||
    JsonCommand cmd2;
 | 
						||
    if (ParseJsonCommand(test2, &cmd2) == 0) {
 | 
						||
        printf("测试2成功: cmd=%d, text=%s\n", cmd2.cmd, cmd2.text);
 | 
						||
    } else {
 | 
						||
        printf("测试2失败\n");
 | 
						||
    }
 | 
						||
    
 | 
						||
    // 测试命令3:逆时针旋转
 | 
						||
    char test3[] = "{\"cmd\":3,\"text\":\"ignored\"}";
 | 
						||
    JsonCommand cmd3;
 | 
						||
    if (ParseJsonCommand(test3, &cmd3) == 0) {
 | 
						||
        printf("测试3成功: cmd=%d, text=%s\n", cmd3.cmd, cmd3.text);
 | 
						||
    } else {
 | 
						||
        printf("测试3失败\n");
 | 
						||
    }
 | 
						||
    
 | 
						||
    // 测试IP消息创建
 | 
						||
    printf("\n=== IP消息创建测试 ===\n");
 | 
						||
    char ip_msg[128];
 | 
						||
    CreateIpMessage("192.168.1.100", ip_msg, sizeof(ip_msg));
 | 
						||
    printf("IP消息: %s\n", ip_msg);
 | 
						||
}
 | 
						||
 | 
						||
// 测试舵机控制逻辑
 | 
						||
void test_servo_commands() {
 | 
						||
    printf("\n=== 舵机命令测试 ===\n");
 | 
						||
    
 | 
						||
    printf("命令1: 顺时针90°+显示+10秒后逆时针90°+清屏\n");
 | 
						||
    printf("命令2: 顺时针90°\n");
 | 
						||
    printf("命令3: 逆时针90°\n");
 | 
						||
}
 | 
						||
 | 
						||
int main() {
 | 
						||
    test_json_parsing();
 | 
						||
    test_servo_commands();
 | 
						||
    return 0;
 | 
						||
} |