Files
License_plate_recognition/test_json.c
2025-10-18 16:05:39 +08:00

56 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}