diff --git a/app/a.exe b/app/a.exe index 5b570f6..663c3e4 100644 Binary files a/app/a.exe and b/app/a.exe differ diff --git a/app/main.c b/app/main.c index 24505cd..d8693b3 100644 --- a/app/main.c +++ b/app/main.c @@ -9,6 +9,7 @@ PORT serial_port; int serial_com_id; int main(int argc, char *argv[]) { + int i = 0; /* 参数判断 */ if (argc != 2) { printf("please input com id\n"); @@ -27,7 +28,9 @@ int main(int argc, char *argv[]) { serial_port = serial_init(serial_com_id, 115200, 8, 1, 0); while (1) { - Serial_SendData(serial_port, "hello finny", 12); + steering_gear_set_position(serial_port, (i % 5)); + i = i + 1; + printf("i:%d\n", i); Sleep(1000); } diff --git a/app/steering_gear.c b/app/steering_gear.c index e69de29..3af46e8 100644 --- a/app/steering_gear.c +++ b/app/steering_gear.c @@ -0,0 +1,34 @@ +#include "steering_gear.h" + +#include + +void steering_gear_set_position(PORT serial_com, int switch_position_mode) { + char buf_position_0[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x00, 0x00, 0x00, 0x00, 0xca}; + char buf_position_1024[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x04, 0x00, 0x00, 0x00, 0xc6}; + char buf_position_2048[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x08, 0x00, 0x00, 0x00, 0xc2}; + char buf_position_3071[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x0b, 0xff, 0x00, 0x00, 0xc0}; + char buf_position_4095[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x0f, 0xff, 0x00, 0x00, 0xbc}; + + printf("switch:%d\n", switch_position_mode); + + switch (switch_position_mode) { + case 0: + Serial_SendData(serial_com, buf_position_0, sizeof(buf_position_0)); + break; + case 1: + Serial_SendData(serial_com, buf_position_1024, sizeof(buf_position_1024)); + break; + case 2: + Serial_SendData(serial_com, buf_position_2048, sizeof(buf_position_2048)); + break; + case 3: + Serial_SendData(serial_com, buf_position_3071, sizeof(buf_position_3071)); + break; + case 4: + Serial_SendData(serial_com, buf_position_4095, sizeof(buf_position_4095)); + break; + + default: + break; + } +} \ No newline at end of file diff --git a/app/steering_gear.h b/app/steering_gear.h index e69de29..255f333 100644 --- a/app/steering_gear.h +++ b/app/steering_gear.h @@ -0,0 +1,3 @@ +#include "serial.h" + +void steering_gear_set_position(PORT serial_com, int switch_position_mode);