Игра найди ошибку
- Войдите на сайт для отправки комментариев
Всем добрый день!
Столкнулся с проблемой компила) Так чувство что где-то скобки не правильно стоят. Ведь компилятор как-будто путает тип данных.Весь код не хочется вставлять ибо 1к строк. Вставил все зависимости(для функции) которые заметил
struct type_one_sensor { uint8_t id; uint8_t type; int16_t v_bat; uint8_t status_sensor; uint8_t signal_lvl; uint8_t temp; uint8_t humdacity; int16_t heat_index; uint8_t kef; }; struct type_two_sensor { uint8_t id; uint8_t type; int16_t v_bat; uint8_t status_sensor; uint8_t signal_lvl; boolean relays[5]; uint8_t kef; }; type_one_sensor last_type_one[40]; type_two_sensor last_type_two[40]; uint8_t get_data(uint8_t id_sensor, uint8_t type_sensor) { Serial.print("Sensor №: "); Serial.print(id_sensor); Serial.print(" Type:"); Serial.println(type_sensor); radio.stopListening(); sensors_template[0] = (uint8_t)id_sensor; radio.openWritingPipe(sensors_template); uint8_t request = 101; radio.write(&request, sizeof(request)); radio.startListening(); uint8_t i = 0; while (i < 5) { if (radio.available()) { break; } delay(10); i++; } delay(5);//Чтобы все что не нужно модуль отфильтровал if (i == 5) { Serial.println("Sensor did not respond"); return false; } switch (type_sensor) { case 1: Serial.println("[INFO] Sensor type 1 parsing data..."); type_one_sensor rx_data_temp; radio.read(&rx_data_temp, sizeof(rx_data_temp)); Serial.println("-----------DATA-----------"); Serial.print(" ID:"); Serial.println(rx_data_temp.id); Serial.print(" Type:"); Serial.println(rx_data_temp.type); Serial.print(" V-BAT:"); Serial.println(float(rx_data_temp.v_bat) / float(rx_data_temp.kef)); //Serial.print(" Status sensor:"); //Serial.println(rx_data_temp.status_sensor); //Serial.print(" Level of signal:"); //Serial.println(rx_data_temp.signal_lvl); Serial.print(" Temperature:"); Serial.println(rx_data_temp.temp); Serial.print(" Humdacity:"); Serial.println(rx_data_temp.humdacity); Serial.print(" Heat index:"); Serial.println(float(rx_data_temp.heat_index) / float(rx_data_temp.kef)); Serial.println("--------------------------"); Serial.println(data_manager_write(rx_data_temp)); //Serial.println(data_write_t1(rx_data_temp)); break; case 2: Serial.println("[INFO] Sensor type 2 parsing data"); type_two_sensor rx_data_temp_two; radio.read(&rx_data_temp_two, sizeof(rx_data_temp_two)); Serial.println("-----------DATA-----------"); Serial.print(" ID:"); Serial.println(rx_data_temp_two.id); Serial.print(" Type:"); Serial.println(rx_data_temp_two.type); Serial.print(" V-BAT:"); Serial.println(float(rx_data_temp_two.v_bat) / float(rx_data_temp_two.kef)); Serial.println("-----------CHANELS-----------"); for (uint8_t i = 0; i < 5; i++) { Serial.print("Chanell "); Serial.print(i); Serial.print(": "); Serial.println(rx_data_temp_two.relays[i]); } Serial.println("--------------------------"); //Serial.println(data_manager_write(rx_data_temp_two)); break; default: Serial.println("[ERROR] Type of sensor not found!"); return false; } return true; } template<typename T> uint8_t data_manager_write(T & pack) { /* Input packet of recived info Return: 1 - memory found and data was writed 2 - memory found but verifying err 3 - memory not found! BIG ERROR 4 - data not understand */ boolean founded = false; uint8_t found_index = 0; Serial.println("Manager started"); Serial.print("Sensor id: "); Serial.print(pack.id); uint8_t type = get_type(pack.id); if (type == 0) { Serial.println("Type error 0!"); return 4; } Serial.print(" Type sensor(and packet)"); Serial.println(type); if (type == 1) { uint8_t memory = sizeof(last_type_one) / sizeof(last_type_one[0]); for (uint8_t i = 0; i < memory; i++) { if (last_type_one[i].id == pack.id) { founded = true; found_index = i; break; } } if (!founded) { Serial.println("Previus data from this sensor not found"); Serial.println("Searching empty memory"); for (uint8_t i = 0; i < memory; i++) { if (last_type_one[i].id == 0) { founded = true; found_index = i; break; } } } if (!founded) { Serial.println("Empty memory not found!"); return 3; } Serial.println("Ok, memory founded!"); last_type_one[found_index].id = pack.id; last_type_one[found_index].type = pack.type; last_type_one[found_index].v_bat = pack.v_bat; last_type_one[found_index].status_sensor = pack.status_sensor; last_type_one[found_index].signal_lvl = pack.signal_lvl; last_type_one[found_index].temp = pack.temp; last_type_one[found_index].humdacity = pack.humdacity; last_type_one[found_index].heat_index = pack.heat_index; last_type_one[found_index].kef = pack.kef; Serial.println("Verifying.."); if (last_type_one[found_index].id == pack.id and last_type_one[found_index].temp == pack.temp and last_type_one[found_index].humdacity == pack.humdacity) { Serial.println("Verifyed!"); return 1; } return 2; } else if (type == 2) { Serial.println("Data type 2"); uint8_t memory = sizeof(last_type_two) / sizeof(last_type_two[0]); for (uint8_t i = 0; i < memory; i++) { if (last_type_two[i].id == pack.id) { founded = true; found_index = i; break; } } if (!founded) { Serial.println("Previus data from this sensor not found"); Serial.println("Searching empty memory"); for (uint8_t i = 0; i < memory; i++) { if (last_type_two[i].id == 0) { founded = true; found_index = i; break; } } } if (!founded) { Serial.println("Empty memory not found!"); return 3; } Serial.println("Ok, memory founded!"); last_type_two[found_index].id = pack.id; last_type_two[found_index].type = pack.type; last_type_two[found_index].v_bat = pack.v_bat; last_type_two[found_index].status_sensor = pack.status_sensor; last_type_two[found_index].signal_lvl = pack.signal_lvl; last_type_two[found_index].kef = pack.kef; for (uint8_t i = 0; i < 5; i++) { last_type_two[found_index].relays[i] = pack.relays[i]; } Serial.println("Verifying.."); if (last_type_two[found_index].id == pack.id and last_type_two[found_index].type == pack.type) { Serial.println("Verifyed!"); return 1; } return 2; } else { Serial.println("Data ERROR"); return 4; } }
Ошибка будет если раскоментить строку Serial.println(data_manager_write(rx_data_temp_two));
Ошибка такая:
D:\disk_SYSTEM_2020_02_05\ARDUINO_SMART_HOME\__Smart_home_2020\RX_esp8266_v.1.1\RX_esp8266_v.1.1.ino: In instantiation of 'uint8_t data_manager_write(T&) [with T = type_one_sensor; uint8_t = unsigned char]':
D:\disk_SYSTEM_2020_02_05\ARDUINO_SMART_HOME\__Smart_home_2020\RX_esp8266_v.1.1\RX_esp8266_v.1.1.ino:352:53: required from here
RX_esp8266_v.1.1:551:57: error: 'struct type_one_sensor' has no member named 'relays'
last_type_two[found_index].relays = pack.relays;
^
D:\disk_SYSTEM_2020_02_05\ARDUINO_SMART_HOME\__Smart_home_2020\RX_esp8266_v.1.1\RX_esp8266_v.1.1.ino: In instantiation of 'uint8_t data_manager_write(T&) [with T = type_two_sensor; uint8_t = unsigned char]':
D:\disk_SYSTEM_2020_02_05\ARDUINO_SMART_HOME\__Smart_home_2020\RX_esp8266_v.1.1\RX_esp8266_v.1.1.ino:374:57: required from here
RX_esp8266_v.1.1:507:37: error: 'struct type_two_sensor' has no member named 'temp'
last_type_one[found_index].temp = pack.temp;
^
RX_esp8266_v.1.1:508:42: error: 'struct type_two_sensor' has no member named 'humdacity'
last_type_one[found_index].humdacity = pack.humdacity;
^
RX_esp8266_v.1.1:509:43: error: 'struct type_two_sensor' has no member named 'heat_index'
last_type_one[found_index].heat_index = pack.heat_index;
^
RX_esp8266_v.1.1:512:140: error: 'struct type_two_sensor' has no member named 'humdacity'
if (last_type_one[found_index].id == pack.id and last_type_one[found_index].temp == pack.temp and last_type_one[found_index].humdacity == pack.humdacity) {
^
RX_esp8266_v.1.1:512:86: error: 'struct type_two_sensor' has no member named 'temp'
if (last_type_one[found_index].id == pack.id and last_type_one[found_index].temp == pack.temp and last_type_one[found_index].humdacity == pack.humdacity) {
^
exit status 1
'struct type_one_sensor' has no member named 'relays'
Евгений, у меня к вам вопрос "как художник художнику" - с какой целью вы вставили сообщения об ошибке красным по черному? Чтоб прочитать легче было?
Весь код не хочется вставлять
Ну, не хочется, значит "на нет и суда нет". Разбирайтесь самостоятельно.
Игра найди ошибку
Вы пока поиграйте,а я судьёй буду. У меня и свисток есть!
Евгений, у меня к вам вопрос "как художник художнику" - с какой целью вы вставили сообщения об ошибке красным по черному? Чтоб прочитать легче было?
Так получилось =) захотел чтоб текст был красный (легче будет читать). А оно и фон черный подтянуло ну что уже поделаешь.
Весь код не хочется вставлять
Ну, не хочется, значит "на нет и суда нет". Разбирайтесь самостоятельно.
Игра найди ошибку
Вы пока поиграйте,а я судьёй буду. У меня и свисток есть!
Причина уже описана(более 1000, а точнее 1047 строк вряд-ли кому-то помогут), вашего тезиса не понимаю. Написал что вроде все зависимости тоже выложил.
Судья есть, и это компилятор, мне б со командника.
UPD:Переписал на перегруженные функции и все работает