diff --git a/arduino/main/main.ino b/arduino/main/main.ino index b9a5c19..62f5ec6 100644 --- a/arduino/main/main.ino +++ b/arduino/main/main.ino @@ -70,10 +70,12 @@ double target_angle = 91; double target_voltage = 0; void onPacketCallBack(AsyncUDPPacket packet) { - - target_velocity = atoi((char*)(packet.data())); - Serial.print("数据内容: "); - Serial.println(target_velocity); + char* da; + da= (char*)(packet.data()); + Serial.println(da); +// target_velocity = atoi(); +// Serial.print("数据内容: "); +// Serial.println(target_velocity); wifi_flag = 1; // packet.print("reply data"); } @@ -357,4 +359,5 @@ void wifi_print(char * s,double num) strcat(str, n); strcat(buf+strlen(buf), str); strcat(buf, ","); + } diff --git a/ctest/com.cpp b/ctest/com.cpp new file mode 100644 index 0000000..58c3cb1 --- /dev/null +++ b/ctest/com.cpp @@ -0,0 +1,26 @@ +#include "com.h" +void Command::run(char* str){ + for(int i=0; i < call_count; i++){ + if(call_ids[i]){ + call_list[i](&str); + break; + } + } +} +void Command::add(char* id, CommandCallback onCommand){ + call_list[call_count] = onCommand; + call_ids[call_count] = id; + call_count++; +} +void Command::scalar(float* value, char* user_cmd){ + *value = atof(user_cmd); +} +bool Commander::isSentinel(char* ch,char* str) +{ + char s[strlen(ch)]; + strncpy(s,str,strlen(ch)); + if(strcmp(ch, s) == 0) + return true; + else + return false; +} diff --git a/ctest/com.h b/ctest/com.h new file mode 100644 index 0000000..0c4a509 --- /dev/null +++ b/ctest/com.h @@ -0,0 +1,16 @@ +// callback function pointer definiton +typedef void (* CommandCallback)(char*); //!< command callback function pointer +class Command +{ + public: + void add(char* id , CommandCallback onCommand); + void run(char* str); + void Command::scalar(float* value, char* user_cmd); + bool Commander::isSentinel(char* ch); + private: + // Subscribed command callback variables + CommandCallback call_list[20];//!< array of command callback pointers - 20 is an arbitrary number + char* call_ids[20]; //!< added callback commands + int call_count = 0;//!< number callbacks that are subscribed + +} diff --git a/ctest/ctest1.cpp b/ctest/ctest1.cpp new file mode 100644 index 0000000..dfb59b3 --- /dev/null +++ b/ctest/ctest1.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include "com.h" +char buf[255]; +void wifi_print(char * s,double num) +{ + char str[255]; + char n[255]; + sprintf(n, "%.2f",num); + strcpy(str,s); + strcat(str, n); + strcat(buf+strlen(buf), str); + strcat(buf, ","); +} +float v = 0.1; +void re_command(float *num) +{ + *num = *num + 1; +} +char* str = "abc23"; +char* cmd_id = "abc"; +main() +{ + re_command(&v); + char s[strlen(cmd_id)]; + + strncpy(s,str,strlen(cmd_id)); + printf("%s", s); + if(strcmp(cmd_id, s) == 0) + { + printf("%f", v); + v = atof(str+strlen(cmd_id)); + printf("%f", v); + } + +// char* da; +// da = "123456"; +// if (da[0] == '2') + +} diff --git a/ctest/ctest1.exe b/ctest/ctest1.exe new file mode 100644 index 0000000..f9108e6 Binary files /dev/null and b/ctest/ctest1.exe differ