通常,當我使用 a 發送和接收資料時,send_now我使用本教程代碼中的結構。這樣一來,我就遇到了一個問題,就是宣告一個陣列,我需要在結構內部宣告大小,以確保發送和接收程序正確完成。雖然有時我需要發送一個陣列,但我不知道它的大小,例如,這個陣列
double *arry=(double*)malloc(size*sizeof(double));
那么我可以不使用結構發送嗎?或者我可以在沒有大小的情況下宣告結構內部的 arry[] 嗎?然后指定它的大小?
發件人結構:
typedef struct test_struct {
int arry[]; I need to send this array but I do not know its size yet
} test_struct;
接收器結構:
typedef struct test_struct {
int arry[];
} test_struct;
更新:我試圖喜歡這個,但我在發件人中收到了不正確的值
int sizee=100;
double *by=(double*)malloc(sizee*sizeof(double));
for (int i=0; i < 100; i ) {
by[i]=i;
Serial.println(by[i]);
}
esp_err_t result = esp_now_send(0, (uint8_t *) &by, sizeof(double));
在接收器中
int sizee=100;
double *by=(double*)malloc(sizee*sizeof(double));
Serial.print("rearray=: ");
for(int i=0;i<100;i ){
Serial.print(by[i]);
}
Serial.println();
}
uj5u.com熱心網友回復:
如果您只是嘗試發送 100 個雙精度浮點數,則可以這樣做:
int sizee=100;
double *by=(double*)malloc(sizee*sizeof(double));
for (int i=0; i < sizee; i ) {
by[i]=i;
Serial.println(by[i]);
}
esp_err_t result = esp_now_send(0, (uint8_t *) by, sizee*sizeof(double));
接收者必須是回呼,對嗎?像這樣的東西:
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
double *by=(double*)incomingData;
Serial.print("rearray=: ");
for(int i=0;i<100;i ){
Serial.print(by[i]);
}
Serial.println();
}
我不知道是否Serial.print可以處理雙打。你必須檢查一下。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/473157.html
標籤:C esp32 arduino-ide arduino-c
上一篇:將數字的數字存盤在陣列中
下一篇:在C(或C )中更改宏
