int main(int argc, char** argv) { if (argc != 2) { std::cout << "usage: " << argv[0] << " " << LENNARD_JONES_POTENTIAL << "|" << TERSOFF_POTENTIAL << "\n"; exit(-1); } CrystallProblemFactory cpf(argv[1]); COMPI::MPProblem<double>& mpp = *cpf.get(); const int n = mpp.mVarTypes.size(); CRYSTAL::EnergyFunc* ef = dynamic_cast<CRYSTAL::EnergyFunc*> (mpp.mObjectives.at(0)); SG_ASSERT(ef); ef->getEnergy().setFixedAtoms(true); COMPI::FuncCnt<double> *obj = new COMPI::FuncCnt<double>(*(mpp.mObjectives.at(0))); mpp.mObjectives.pop_back(); mpp.mObjectives.push_back(obj); std::cout.precision(10); std::cout.setf(std::ios::fixed, std::ios::floatfield); std::cout << "Enter string\n"; std::string s; std::getline(std::cin, s); double x[N]; snowgoose::VecUtils::vecRead(s, N, x); std::cout << snowgoose::VecUtils::vecPrint(N, x) << "\n"; std::cout << "Energy = " << obj->func(x) << "\n"; if (std::string(argv[1]) == TERSOFF_POTENTIAL) { lattice::TersoffEnergy& tsen = (lattice::TersoffEnergy&)ef->getEnergy(); for (auto i : tsen.getLBounds()) { std::cout << i << "\n"; } for (auto i : tsen.getUBounds()) { std::cout << i << "\n"; } } int cnt = 0; auto stopper = [&](double xdiff, double fdiff, double gran, double fval, int n) { cnt++; //std::cout << "cnt = " << cnt << ", fval =" << fval << "\n"; if (cnt > 7000) return true; else return false; }; LOCSEARCH::CoorDesc<double> desc(mpp, stopper); double v; bool rv = desc.search(x, v); std::cout << desc.about() << "\n"; std::cout << "In " << cnt << " iterations found v = " << v << "\n"; std::cout << " at " << snowgoose::VecUtils::vecPrint(n, x, 10) << "\n"; // std::cout << " with height " << computeHeight(x) << "\n"; return 0; }
/*--------------------------------------------------------------------------*/ IsotimeEpoch _string2epoch(const char *epoch_s) { long base; IsotimeEpoch epoch; char epobuf[EPOLEN], *pr; char secbuf[SLEN], *ps; char frabuf[SLEN], *pf; long sec=0; double fract=0.0; if (ISOTIME_debug>0) fprintf(stderr,"_string2epoch >>%s<<\n",epoch_s); epoch.status = -1; epoch.sec = 0; epoch.fract = 0.0; epoch.offset = 0; // trim isotime_s, convert to uppercase and copy to trimmed ps = trim( epobuf, EPOLEN, epoch_s ); if (ISOTIME_debug>1) fprintf(stderr," trim returns >>%s<<\n",ps); // copy seconds pf = cps( secbuf, SLEN, ps ); if (ISOTIME_debug>1) fprintf(stderr," section >>%s<<\n",secbuf); // copy fraction pr = cpf( frabuf, SLEN, pf ); if (ISOTIME_debug>1) fprintf(stderr," fraction >>%s<<\n",frabuf); if ( strlen(pr) ) { // error, if rest is not empty fprintf( stderr, "ERROR: Cannot read epoch \"%s\"\n",epobuf ); fprintf( stderr, " Format: [+|-]sssssssssss[.uuuuuuu]\n" ); fprintf( stderr, " e.g. \"1149254287\", \"+1149254287.1\"\n"); goto _string2epocherr; } sscanf(secbuf,"%ld",&sec); sscanf(frabuf,"%lf",&fract); epoch.sec = sec; if (sec>=0) epoch.fract = fract; epoch.fract = -fract; // normalize fract and sec base = floor(epoch.fract); epoch.fract -= (double) base; epoch.sec += base; epoch.status = 0; if (ISOTIME_debug>0) fprintf(stderr,"_string2epoch END\n"); return ( epoch ); _string2epocherr: if (ISOTIME_debug>0) fprintf(stderr,"_string2epoch END\n"); return ( epoch ); } // _string2epoch
/*--------------------------------------------------------------------------*/ IsotimeEpoch _isotime2epoch(const char * isotime_s) { char osign_c; long osign; long year=0, month=0, day=0, hh=0, mm=0, ss=0; long Hh=0, Mm=0, Ss=0; double uuuuuu=0.0; char trimmed[TRIMLEN], *pd, *pt, *pf, *po, *pr; char datbuf[DLEN]; char timbuf[TLEN]; char frabuf[FLEN]; char offbuf[OLEN]; IsotimeEpoch epoch; if (ISOTIME_debug>0) fprintf(stderr,"_isotime2epoch >>%s<< BEGIN\n", isotime_s); // trim isotime_s, convert to uppercase and copy to trimmed pd = trim( trimmed, TRIMLEN, isotime_s ); if (ISOTIME_debug>1) fprintf(stderr," trim returns >>%s<<\n",pd); // copy date pt = cpd( datbuf, DLEN, pd ); if (ISOTIME_debug>1) fprintf(stderr," date >>%s<<\n",datbuf); // copy time pf = cpt( timbuf, TLEN, pt ); if (ISOTIME_debug>1) fprintf(stderr," time >>%s<<\n",timbuf); // copy fraction po = cpf( frabuf, FLEN, pf ); if (ISOTIME_debug>1) fprintf(stderr," fraction >>%s<<\n",frabuf); // copy offset pr = cpo( offbuf, OLEN, po ); if (ISOTIME_debug>1) fprintf(stderr," offset >>%s<<\n",offbuf); sscanf(datbuf,"%4ld%2ld%2ld",&year,&month,&day); sscanf(timbuf,"%2ld%2ld%2ld",&hh,&mm,&ss); sscanf(frabuf,"%lf",&uuuuuu); sscanf(offbuf,"%c%2ld%2ld%2ld",&osign_c,&Hh, &Mm, &Ss); if ( strlen(pr)||(day==0) ) month=0; // error, if rest is not empty or day 0 osign = (osign_c=='-')?-1:+1; epoch = _convert2epoch(year,month,day,hh,mm,ss,uuuuuu,osign,Hh,Mm,Ss); if ( epoch.status ) { fprintf( stderr, "ERROR: Cannot read time \"%s\"\n",trimmed ); fprintf( stderr, " Format: YYYY-MM-DDThh:mm:ss[.uuuuuu][+Hh:Mm]\n" ); } if (ISOTIME_debug>0) fprintf(stderr,"_isotime2epoch >>%s<< END\n", isotime_s); return( epoch ); } // _isotime2epoch
int df1_close(_comm_header * comm, _path * path, _df1_comm *df1_comm, int debug) { int x,ret=0; _data_buffer *buff; _encaps_header *head; _data_buffer *cpf_buffer; _data_buffer *sendbuff; _data_buffer *msgbuff; _ioi_data *ioi1; dprint(DEBUG_TRACE, "df1_close.c entered.\n"); if (path == NULL) { CELLERROR(1,"path structure not allocated"); return -1; } if (df1_comm == NULL) { CELLERROR(2,"df1_comm structure not allocated"); return -1; } buff = malloc(sizeof(_data_buffer)); if (buff == NULL) { CELLERROR(3,"Could not allocate memory for data buffer"); return -1; } msgbuff = malloc(sizeof(_data_buffer)); if (msgbuff == NULL) { CELLERROR(4,"Could not allocate memory for msgdata buffer"); free(buff); return -1; } head = malloc(sizeof(_encaps_header)); if (head == NULL) { CELLERROR(5,"Could not allocate memory for Encaps Header"); free(buff); free(msgbuff); return -1; } cpf_buffer = malloc(sizeof(_data_buffer)); if (cpf_buffer == NULL) { CELLERROR(6,"Could not allocate memory for cpf_buffer"); free(buff); free(msgbuff); free(head); return -1; } sendbuff = malloc(sizeof(_data_buffer)); if (sendbuff == NULL) { CELLERROR(7,"Could not allocate memory for send buffer"); free(buff); free(msgbuff); free(head); free(cpf_buffer); return -1; } ioi1 = malloc(sizeof(_ioi_data)); if (ioi1 == NULL) { CELLERROR(8,"Could not allocate memory for ioi buffer"); free(buff); free(msgbuff); free(head); free(cpf_buffer); free(sendbuff); return -1; } memset(buff, 0, sizeof(_data_buffer)); memset(msgbuff, 0, sizeof(_data_buffer)); memset(head, 0, sizeof(_encaps_header)); memset(cpf_buffer, 0, sizeof(_data_buffer)); memset(sendbuff, 0, sizeof(_data_buffer)); memset(ioi1, 0, sizeof(_ioi_data)); msgbuff->len = 0; msgbuff->data[msgbuff->len++] = (byte)(df1_comm->conn_serial & 255); msgbuff->data[msgbuff->len++] = (byte)(df1_comm->conn_serial >> 8); msgbuff->data[msgbuff->len++] = (byte)(df1_comm->conn_serial >> 16); msgbuff->data[msgbuff->len++] = (byte)(df1_comm->conn_serial >> 24); msgbuff->data[msgbuff->len++] = (byte)(VENDOR_ID & 255); msgbuff->data[msgbuff->len++] = (byte)(VENDOR_ID / 256); msgbuff->data[msgbuff->len++] = (byte)(VENDOR_SN & 255); msgbuff->data[msgbuff->len++] = (byte)(VENDOR_SN >> 8); msgbuff->data[msgbuff->len++] = (byte)(VENDOR_SN >> 16); msgbuff->data[msgbuff->len++] = (byte)(VENDOR_SN >> 24); msgbuff->data[msgbuff->len++] = 0; msgbuff->data[msgbuff->len++] = 0; if (debug != DEBUG_NIL) { dprint(DEBUG_BUILD, "Msgbuff = "); for (x = 0; x < msgbuff->len; x++) dprint(DEBUG_BUILD, "%02X ", msgbuff->data[x]); dprint(DEBUG_BUILD, "\n"); } /*pathsize = msgbuff->len++; count = 0; if (path->device1 != -1) { count++; msgbuff->data[msgbuff->len++] = path->device1; } if (path->device2 != -1) { count++; msgbuff->data[msgbuff->len++] = path->device2; } if (path->device3 != -1) { count++; msgbuff->data[msgbuff->len++] = path->device3; } if (path->device4 != -1) { count++; msgbuff->data[msgbuff->len++] = path->device4; } if (path->device5 != -1) { count++; msgbuff->data[msgbuff->len++] = path->device5; } if (path->device6 != -1) { count++; msgbuff->data[msgbuff->len++] = path->device6; } if (path->device7 != -1) { count++; msgbuff->data[msgbuff->len++] = path->device7; } if (path->device8 != -1) { count++; msgbuff->data[msgbuff->len++] = path->device8; } msgbuff->data[msgbuff->len++] = 0x20; msgbuff->data[msgbuff->len++] = DF1CMD; msgbuff->data[msgbuff->len++] = 0x24; msgbuff->data[msgbuff->len++] = FIRST_INSTANCE; msgbuff->data[msgbuff->len++] = 0x2c; msgbuff->data[msgbuff->len++] = dh_channel; if (count & 1) { msgbuff->data[msgbuff->len++] = 0; count++; } msgbuff->data[pathsize] = (count + 6)/2; */ if (debug != DEBUG_NIL) { dprint(DEBUG_BUILD, "Msgbuff = "); for (x = 0; x < msgbuff->len; x++) dprint(DEBUG_BUILD, "%02X ", msgbuff->data[x]); dprint(DEBUG_BUILD, "\n"); } if (path->device1 != -1) { cpf_buffer->data[cpf_buffer->len++] = PDU_Forward_Close; ioi1->ioiclass = CONNECTION_MANAGER; ioi1->instance = FIRST_INSTANCE; ioi1->member = -1; ioi1->point = -1; ioi1->attribute = -1; ioi1->tagname = NULL; ioi1->elem[0] = -1; ioi1->elem[1] = -1; ioi1->elem[2] = -1; ioi(cpf_buffer, ioi1, NULL, debug); settimeout(6, 0x9a, cpf_buffer, debug); // cpf_buffer->data[cpf_buffer->len++] = msgbuff->len & 255; // cpf_buffer->data[cpf_buffer->len++] = msgbuff->len / 0x100; } memcpy(cpf_buffer->data + cpf_buffer->len, msgbuff->data, msgbuff->len); cpf_buffer->len += msgbuff->len; sendRRdata(10, comm, head, buff, debug); cpf(CPH_Null, NULL, CPH_Unconnected_message, cpf_buffer, buff, debug); head->len = buff->len; memcpy(sendbuff->data, head, ENCAPS_Header_Length); sendbuff->overall_len = ENCAPS_Header_Length; if (debug != DEBUG_NIL) { dprint(DEBUG_BUILD, "Loading sendbuffer with command data.\n"); for (x = 0; x < buff->len; x++) dprint(DEBUG_BUILD, "%02X ", buff->data[x]); dprint(DEBUG_BUILD, "\n"); } memcpy(sendbuff->data + sendbuff->overall_len, buff->data, buff->len); sendbuff->overall_len += buff->len; ret = senddata(sendbuff, comm, debug); if (!ret) ret = readdata(buff, comm, debug); comm->df1_tns += 4; memset(head, 0, ENCAPS_Header_Length); memcpy(head, buff->data, ENCAPS_Header_Length); if (head->status != 0) { ret=-1; dprint(DEBUG_VALUES, "df1_close command returned an error.\n"); CELLERROR(9,"DF1 Close command returned an error"); } if (ret) { free(buff); free(msgbuff); free(head); free(cpf_buffer); free(sendbuff); free(ioi1); return -1; } //buff = buff + ENCAPS_Header_Length; memset (df1_comm, 0, sizeof(_df1_comm)); if (debug != DEBUG_NIL) { dprint(DEBUG_VALUES, "Got good reply to DF1 Open Command - %d\n", buff->overall_len); for (x = 44; x < buff->overall_len; x++) dprint(DEBUG_VALUES, "%02X ", buff->data[x]); dprint(DEBUG_VALUES, "\n"); } free(buff); free(msgbuff); free(head); free(cpf_buffer); free(sendbuff); free(ioi1); dprint(DEBUG_TRACE, "Exiting df1_close.c\n"); return 0; }
int get_remote_dh(_comm_header * comm, _path * path, _data_buffer *data, int dhport, int debug) { int x,ret=0; _data_buffer *buff; _encaps_header *head; _data_buffer *cpf_buffer; _data_buffer *sendbuff; _data_buffer *msgbuff; _ioi_data *ioi1; dprint(DEBUG_TRACE, "get_remote_dh.c entered.\n"); if (path == NULL) { CELLERROR(1,"path structure not allocated"); return -1; } if (data == NULL) { CELLERROR(2,"data structure not allocated"); return -1; } buff = malloc(sizeof(_data_buffer)); if (buff == NULL) { CELLERROR(3,"Could not allocate memory for data buffer"); return -1; } msgbuff = malloc(sizeof(_data_buffer)); if (msgbuff == NULL) { CELLERROR(4,"Could not allocate memory for msgdata buffer"); free(buff); return -1; } head = malloc(sizeof(_encaps_header)); if (head == NULL) { CELLERROR(5,"Could not allocate memory for Encaps Header"); free(buff); free(msgbuff); return -1; } cpf_buffer = malloc(sizeof(_data_buffer)); if (cpf_buffer == NULL) { CELLERROR(6,"Could not allocate memory for cpf_buffer"); free(buff); free(msgbuff); free(head); return -1; } sendbuff = malloc(sizeof(_data_buffer)); if (sendbuff == NULL) { CELLERROR(7,"Could not allocate memory for send buffer"); free(buff); free(msgbuff); free(head); free(cpf_buffer); return -1; } ioi1 = malloc(sizeof(_ioi_data)); if (ioi1 == NULL) { CELLERROR(8,"Could not allocate memory for ioi buffer"); free(buff); free(msgbuff); free(head); free(cpf_buffer); free(sendbuff); return -1; } memset(buff, 0, sizeof(_data_buffer)); memset(msgbuff, 0, sizeof(_data_buffer)); memset(head, 0, sizeof(_encaps_header)); memset(cpf_buffer, 0, sizeof(_data_buffer)); memset(sendbuff, 0, sizeof(_data_buffer)); memset(ioi1, 0, sizeof(_ioi_data)); buff->len = 0; msgbuff->data[msgbuff->len++] = GET_ATTRIBUTE_ALL; ioi1->ioiclass = REMOTE_DH; ioi1->instance = FIRST_INSTANCE; ioi1->member = -1; ioi1->point = -1; ioi1->attribute = dhport; ioi1->tagname = NULL; ioi1->elem[0] = -1; ioi1->elem[1] = -1; ioi1->elem[2] = -1; ioi(msgbuff, ioi1, NULL, debug); if (debug != DEBUG_NIL) { dprint(DEBUG_BUILD, "Msgbuff = "); for (x = 0; x < msgbuff->len; x++) dprint(DEBUG_BUILD, "%02X ", msgbuff->data[x]); dprint(DEBUG_BUILD, "\n"); } if (path->device1 != -1) { cpf_buffer->data[cpf_buffer->len++] = PDU_Unconnected_Send; ioi1->ioiclass = CONNECTION_MANAGER; ioi1->instance = FIRST_INSTANCE; ioi1->member = -1; ioi1->point = -1; ioi1->attribute = -1; ioi1->tagname = NULL; ioi1->elem[0] = -1; ioi1->elem[1] = -1; ioi1->elem[2] = -1; ioi(cpf_buffer, ioi1, NULL, debug); settimeout(6, 0x9a, cpf_buffer, debug); cpf_buffer->data[cpf_buffer->len++] = msgbuff->len & 255; cpf_buffer->data[cpf_buffer->len++] = msgbuff->len / 0x100; } makepath(path, msgbuff, debug); memcpy(cpf_buffer->data + cpf_buffer->len, msgbuff->data, msgbuff->len); cpf_buffer->len += msgbuff->len; sendRRdata(10, comm, head, buff, debug); cpf(CPH_Null, NULL, CPH_Unconnected_message, cpf_buffer, buff, debug); head->len = buff->len; memcpy(sendbuff->data, head, ENCAPS_Header_Length); sendbuff->overall_len = ENCAPS_Header_Length; if (debug != DEBUG_NIL) { dprint(DEBUG_BUILD, "Loading sendbuffer with command data.\n"); for (x = 0; x < buff->len; x++) dprint(DEBUG_BUILD, "%02X ", buff->data[x]); dprint(DEBUG_BUILD, "\n"); } memcpy(sendbuff->data + sendbuff->overall_len, buff->data, buff->len); sendbuff->overall_len += buff->len; ret = senddata(sendbuff, comm, debug); if (!ret) ret = readdata(buff, comm, debug); memset(head, 0, ENCAPS_Header_Length); memcpy(head, buff->data, ENCAPS_Header_Length); if (head->status != 0) { ret=-1; dprint(DEBUG_VALUES, "Get remote DH command returned an error.\n"); CELLERROR(9,"Get remote DH command returned an error"); } if (ret) { free(buff); free(msgbuff); free(head); free(cpf_buffer); free(sendbuff); free(ioi1); return -1; } //buff = buff + ENCAPS_Header_Length; if (buff->overall_len > 44) { memset(data, 0, sizeof(_data_buffer)); memcpy(data, buff->data + 44, sizeof(_data_buffer)-44); data->overall_len = buff->overall_len - 44; } if (debug != DEBUG_NIL) { dprint(DEBUG_VALUES, "Got good reply to Get Remote DH Command - %d\n", buff->overall_len); for (x = 44; x < buff->overall_len; x++) dprint(DEBUG_VALUES, "%02X ", buff->data[x]); dprint(DEBUG_VALUES, "\n"); } free(buff); free(msgbuff); free(head); free(cpf_buffer); free(sendbuff); free(ioi1); dprint(DEBUG_TRACE, "Exiting get_remote_dh.c\n"); return 0; }
int get_object_config(_comm_header * comm, _path * path, _tag_detail * tag, int debug) { int x, start; int ret=0; int tagsize; _data_buffer *buff; _encaps_header *head; _data_buffer *cpf_buffer; _data_buffer *sendbuff; _data_buffer *msgbuff; _ioi_data *ioi1; _ioi_data *ioi2; _ioi_data ioiCM; dprint(DEBUG_TRACE, "get_object_config.c entered.\n"); ioi2 = NULL; if (path == NULL) { CELLERROR(1,"path structure not allocated"); return -1; } if (tag == NULL) { CELLERROR(2,"tag structure not allocated"); return -1; } buff = malloc(sizeof(_data_buffer)); if (buff == NULL) { CELLERROR(3,"Could not allocate memory for data buffer"); return -1; } msgbuff = malloc(sizeof(_data_buffer)); if (msgbuff == NULL) { CELLERROR(4,"Could not allocate memory for msgdata buffer"); free(buff); return -1; } head = malloc(sizeof(_encaps_header)); if (head == NULL) { CELLERROR(5,"Could not allocate memory for Encaps Header"); free(buff); free(msgbuff); return -1; } cpf_buffer = malloc(sizeof(_data_buffer)); if (cpf_buffer == NULL) { CELLERROR(6,"Could not allocate memory for cpf_buffer"); free(buff); free(msgbuff); free(head); return -1; } sendbuff = malloc(sizeof(_data_buffer)); if (sendbuff == NULL) { CELLERROR(7,"Could not allocate memory for send buffer"); free(buff); free(msgbuff); free(head); free(cpf_buffer); return -1; } ioi1 = malloc(sizeof(_ioi_data)); if (ioi1 == NULL) { CELLERROR(8,"Could not allocate memory for ioi1 buffer"); free(buff); free(msgbuff); free(head); free(cpf_buffer); free(sendbuff); return -1; } memset(buff, 0, sizeof(_data_buffer)); memset(msgbuff, 0, sizeof(_data_buffer)); memset(head, 0, sizeof(_encaps_header)); memset(cpf_buffer, 0, sizeof(_data_buffer)); memset(sendbuff, 0, sizeof(_data_buffer)); memset(ioi1, 0, sizeof(_ioi_data)); buff->len = 0; msgbuff->data[msgbuff->len++] = GET_ATTRIBUTE_LIST; ioi1->ioiclass = OBJECT_CONFIG; ioi1->instance = tag->base; if (tag->id != 0) { ioi1->ioiclass = OBJECT_SUB_OBJECT; ioi1->instance = tag->base; } ioi1->member = -1; ioi1->point = -1; ioi1->attribute = -1; ioi1->tagname = NULL; ioi1->elem[0] = -1; ioi1->elem[1] = -1; ioi1->elem[2] = -1; if (tag->id != 0) { ioi2 = malloc(sizeof(_ioi_data)); if (ioi2 == NULL) { CELLERROR(9,"Could not allocate memory for ioi2 buffer"); free(buff); free(msgbuff); free(head); free(cpf_buffer); free(sendbuff); free(ioi1); return -1; } memset(ioi2, 0, sizeof(_ioi_data)); ioi2->ioiclass = OBJECT_CONFIG; ioi2->instance = tag->id; ioi2->member = -1; ioi2->point = -1; ioi2->attribute = -1; ioi2->tagname = NULL; ioi2->elem[0] = -1; ioi2->elem[1] = -1; ioi2->elem[2] = -1; } ioi(msgbuff, ioi1, ioi2, debug); msgbuff->data[msgbuff->len++] = 3; msgbuff->data[msgbuff->len++] = 0; msgbuff->data[msgbuff->len++] = 1; msgbuff->data[msgbuff->len++] = 0; msgbuff->data[msgbuff->len++] = 2; msgbuff->data[msgbuff->len++] = 0; msgbuff->data[msgbuff->len++] = 3; msgbuff->data[msgbuff->len++] = 0; if (debug != DEBUG_NIL) { dprint(DEBUG_BUILD, "Msgbuff = "); for (x = 0; x < msgbuff->len; x++) dprint(DEBUG_BUILD, "%02X ", msgbuff->data[x]); dprint(DEBUG_BUILD, "\n"); } cpf_buffer->data[cpf_buffer->len++] = PDU_Unconnected_Send; ioiCM.ioiclass = CONNECTION_MANAGER; ioiCM.instance = FIRST_INSTANCE; ioiCM.member = -1; ioiCM.point = -1; ioiCM.attribute = -1; ioiCM.tagname = NULL; ioiCM.elem[0] = -1; ioiCM.elem[1] = -1; ioiCM.elem[2] = -1; ioi(cpf_buffer, &ioiCM, NULL, debug); settimeout(6, 0x9a, cpf_buffer, debug); cpf_buffer->data[cpf_buffer->len++] = msgbuff->len & 255; cpf_buffer->data[cpf_buffer->len++] = msgbuff->len / 0x100; makepath(path, msgbuff, debug); memcpy(cpf_buffer->data + cpf_buffer->len, msgbuff->data, msgbuff->len); cpf_buffer->len += msgbuff->len; sendRRdata(10, comm, head, buff, debug); cpf(CPH_Null, NULL, CPH_Unconnected_message, cpf_buffer, buff, debug); head->len = buff->len; memcpy(sendbuff->data, head, ENCAPS_Header_Length); sendbuff->overall_len = ENCAPS_Header_Length; if (debug != DEBUG_NIL) { dprint(DEBUG_BUILD, "Loading sendbuffer with command data.\n"); for (x = 0; x < buff->len; x++) dprint(DEBUG_BUILD, "%02X ", buff->data[x]); dprint(DEBUG_BUILD, "\n"); } memcpy(sendbuff->data + sendbuff->overall_len, buff->data, buff->len); sendbuff->overall_len += buff->len; ret = senddata(sendbuff, comm, debug); if (!ret) ret = readdata(buff, comm, debug); memset(head, 0, ENCAPS_Header_Length); memcpy(head, buff->data, ENCAPS_Header_Length); if (head->status != 0) { ret=-1; dprint(DEBUG_VALUES, "Get Object Config command returned an error.\n"); CELLERROR(10, "Get Object Config command returned an error."); } if (ret) { if (ioi2 != NULL) free(ioi2); free(buff); free(msgbuff); free(head); free(cpf_buffer); free(sendbuff); free(ioi1); return -1; } //buff = buff + ENCAPS_Header_Length; if (debug != DEBUG_NIL) { dprint(DEBUG_VALUES, "Got good reply to Get Object Config Command - %d\n", buff->overall_len); for (x = 44; x < buff->overall_len; x++) dprint(DEBUG_VALUES, "%02X ", buff->data[x]); dprint(DEBUG_VALUES, "\n"); } start = 50; tag->arraysize1 = buff->data[start] + (buff->data[start + 1] * 0x100) + (buff->data[start + 2] * 0x10000) + (buff->data[start + 3] * 0x1000000); start += 4; tag->arraysize2 = buff->data[start] + (buff->data[start + 1] * 0x100) + (buff->data[start + 2] * 0x10000) + (buff->data[start + 3] * 0x1000000); start += 4; tag->arraysize3 = buff->data[start] + (buff->data[start + 1] * 0x100) + (buff->data[start + 2] * 0x10000) + (buff->data[start + 3] * 0x1000000); start += 8; tag->type = buff->data[start] + (buff->data[start + 1] * 256); start += 6; tag->linkid = buff->data[start] + (buff->data[start + 1] * 0x100) + (buff->data[start + 2] * 0x10000) + (buff->data[start + 3] * 0x1000000); start += 8; tag->topbase = buff->data[start] + (buff->data[start + 1] * 256); start += 8; tagsize = getsize(tag); if (!tagsize) { CELLERROR(21,"Cannot allocate a tag of size 0"); ret=0; } else { tag->data = malloc(tagsize); if (tag->data == NULL) { CELLERROR(11,"Could not allocate memory for tag data storage."); ret=-1; } } if (ioi2 != NULL) free(ioi2); free(buff); free(msgbuff); free(head); free(sendbuff); free(cpf_buffer); free(ioi1); dprint(DEBUG_TRACE, "get_object_config.c exited. ret=%d\n",ret); return ret; }