typedef struct{ short Nom_form; void *Name_struct;}Form_count;// функция добавляющая очередную структуру для обменаbool client:: addNewStruct(short Nom_Form ,void* _struct){ int sz=ST_FORM.size(); for(int i=0; i<sz;i++) { if(Nom_Form==ST_FORM.at(i).Nom_form)// такой формуляр уже есть { emit Err_addStruct(Nom_Form); return false; } } Form_count fct; fct.Name_struct= _struct; fct.Nom_form=Nom_Form; ST_FORM.append(fct); if(sz+1==ST_FORM.size()) return true; else return false;}//использованиеstruct INn //IN{ short field2; // controlling flag. 0 - no connection, 1 - training, 2 - training stops, 3 training ends. short reg; // short v; short tip; short gl_m; short tip1; float kr; float x_nl; float y_nl; float h_nl; float k_nl; float C_z[20]; float H_z[20]; short num_hc; float K_otr[11]; float v_vet; int num_cel; dan_cel cel[5]; int day; int hour; int minute; int sec; }; extern struct INn IN_ST1; //INaddNewStruct(101,&IN_ST1);
struct Config_client{ unsigned int pulseCount;// номер посылки unsigned char crc; // контрольная сумма short id_Form; // номер формуляра unsigned int ST_size; // размер данных};Config_client conf_in;
void client::readDatagrams(){ while( udp_in->hasPendingDatagrams() ) { QByteArray datagram; datagram.resize( udp_in->pendingDatagramSize() ); QHostAddress sender; quint16 senderPort; udp_in->readDatagram( datagram.data(), datagram.size(), &sender, &senderPort ); processTheDatagramFromStm(datagram); }}void client::processTheDatagramFromStm(QByteArray dtgr){ memmove((char *)&conf_in, (char *)dtgr.data(), sizeof(conf_in)); char crc; int sz; sz=sizeof(conf_in); crc=calc_control_summ( (unsigned char*)&conf_in, sz-1 ); if( conf_in.crc !=crc) emit errorCrc_in(); sz=ST_FORM.size(); for(int i=0; i<sz;i++) { if(conf_in.id_Form==ST_FORM.at(i).Nom_form) { QByteArray arr; arr=dtgr.mid(sizeof(Config_client)+1,conf_in.ST_size); memmove((char *)&ST_FORM.at(i).Name_struct, (char *)arr.data(), conf_in.ST_size); // ???неверно } }}
void client::send_data_slot(){ int sz=0; conf_out.id_Form=101; conf_out.pulseCount+=1; conf_out.ST_size=sizeof(IN_ST1); sz=sizeof(conf_out); conf_out.crc=calc_control_summ( (unsigned char*)&conf_out, sz-1 ); QByteArray datagram,arr,ARR_REZ,arr1; QDataStream out( &datagram, QIODevice::WriteOnly );; out.setVersion( QDataStream::Qt_4_2 ); arr.append((char*)&conf_out.pulseCount,sizeof(unsigned int)); arr.append((char*)&conf_out.crc,sizeof(unsigned char)); arr.append((char*)&conf_out.id_Form,sizeof(short)); arr.append((char*)&conf_out.ST_size,sizeof(unsigned int)); ARR_REZ.append(arr); bool yy=memmove((char *)&arr1 ,(char *)&IN_ST1, sizeof(IN_ST1)); sz=arr1.size(); ARR_REZ.append(arr1); out.writeRawData(ARR_REZ,ARR_REZ.size()); sz=udp_out->writeDatagram( datagram, QHostAddress::Broadcast, port_out); // пФРТБЧЙФШ ДБООЩЕ Ч уптд}
// заполняем данные int sz=0; conf_out.id_Form=101; conf_out.pulseCount+=1; conf_out.ST_size=sizeof(IN_ST1); sz=sizeof(conf_out); conf_out.crc=calc_control_summ( (unsigned char*)&conf_out, sz-1 ); // создаём отправной массив и поток QByteArray datagram; QDataStream out( &datagram, QIODevice::WriteOnly );; out.setVersion( QDataStream::Qt_4_2 ); // запихивает все данные в поток out << conf_out.id_Form << conf_out.pulseCount << conf_out.ST_size << conf_out.crc; // отправляем sz=udp_out->writeDatagram( datagram, QHostAddress::Broadcast, port_out);