int readreq(int con, char *recv) { if( Rio_readn(con, recv, 4) != 4) { #ifdef DEBUG printf("server receive bytes < 4 bytes\n"); #endif return 1; } int len = atoi(recv); Rio_readn(con, recv + 4, len); #ifdef DEBUG printf("server receive %d bytes\n%s\n" , strlen(recv), recv); #endif runlog("", 0, "Recv=[%s]\n", recv); return 0; }
int writeresp(Recv *R, Send *S) { Rio_writen(S->conn, S->buffer, S->len + 4); //发送实际包长度为S->len + 4 #ifdef DEBUG printf("server send %d bytes(strlen)\n%s\n", strlen(S->buffer), S->buffer); #endif runlog("", 0, "Send=[%s]\n",S->buffer); /****** 如果是7008业务,发送批量扣款信息 ************************/ if(R->code == BMONTHQ && strlen(S->file) > 0) { FILE *fp = fopen(S->file,"r"); int count = 0; char lineb[LINE7008]; count = S->filelen / LINE7008; for (; count > 0; count --) { fread(lineb, LINE7008, 1, fp); Rio_writen(S->conn, lineb, LINE7008); } } }
/** Execute the algorithm. Currently just calls SaveISISNexusProcessed but could * call write other formats if support added * * @throw runtime_error Thrown if algorithm cannot execute */ void SaveISISNexus::exec() { // Retrieve the filename from the properties inputFilename = getPropertyValue("InputFileName"); m_isisRaw = new ISISRAW2; rawFile = fopen(inputFilename.c_str(), "rb"); if (rawFile == nullptr) { throw Exception::FileError("Cannot open file ", inputFilename); } m_isisRaw->ioRAW(rawFile, true); nper = m_isisRaw->t_nper; // number of periods nsp = m_isisRaw->t_nsp1; // number of spectra ntc = m_isisRaw->t_ntc1; // number of time channels nmon = m_isisRaw->i_mon; // number of monitors ndet = m_isisRaw->i_det; // number of detectors std::string outputFilename = getPropertyValue("OutputFileName"); NXstatus status; float flt; status = NXopen(outputFilename.c_str(), NXACC_CREATE5, &handle); if (status != NX_OK) { throw std::runtime_error("Cannot open file " + outputFilename + " for writing."); } NXmakegroup(handle, "raw_data_1", "NXentry"); NXopengroup(handle, "raw_data_1", "NXentry"); write_isis_vms_compat(); saveString("beamline", " "); flt = static_cast<float>(m_isisRaw->rpb.r_dur); // could be wrong saveFloatOpen("collection_time", &flt, 1); putAttr("units", "second"); close(); saveStringOpen("definition", "TOFRAW"); putAttr("version", "1.0"); putAttr("url", "http://definition.nexusformat.org/instruments/TOFRAW/?version=1.0"); close(); saveStringOpen("definition_local", "ISISTOFRAW"); putAttr("version", "1.0"); putAttr("url", "http://svn.isis.rl.ac.uk/instruments/ISISTOFRAW/?version=1.0"); close(); flt = static_cast<float>(m_isisRaw->rpb.r_dur); saveFloatOpen("duration", &flt, 1); putAttr("units", "second"); close(); start_time_str.assign(m_isisRaw->hdr.hd_date, m_isisRaw->hdr.hd_date + 12); toISO8601(start_time_str); start_time_str += 'T'; start_time_str += std::string(m_isisRaw->hdr.hd_time, m_isisRaw->hdr.hd_time + 8); saveCharOpen("start_time", &start_time_str[0], 19); putAttr("units", "ISO8601"); close(); std::string str; str.assign(m_isisRaw->rpb.r_enddate, m_isisRaw->rpb.r_enddate + 12); toISO8601(str); str += 'T'; str += std::string(m_isisRaw->rpb.r_endtime, m_isisRaw->rpb.r_endtime + 8); saveCharOpen("end_time", &str[0], 19); putAttr("units", "ISO8601"); close(); saveChar("title", m_isisRaw->r_title, 80); saveInt("good_frames", &m_isisRaw->rpb.r_goodfrm); std::string experiment_identifier = std::to_string(m_isisRaw->rpb.r_prop); saveChar("experiment_identifier", &experiment_identifier[0], static_cast<int>(experiment_identifier.size())); int tmp_int(0); saveInt("measurement_first_run", &tmp_int); saveString("measurement_id", " "); saveString("measurement_label", " "); saveString("measurement_subid", " "); saveString("measurement_type", " "); saveCharOpen("name", &m_isisRaw->i_inst, 8); putAttr("short_name", m_isisRaw->hdr.inst_abrv, 3); close(); logNotes(); saveString("program_name", "isisicp"); saveFloatOpen("proton_charge", &m_isisRaw->rpb.r_gd_prtn_chrg, 1); putAttr("units", "uamp.hour"); close(); saveFloatOpen("proton_charge_raw", &m_isisRaw->rpb.r_tot_prtn_chrg, 1); putAttr("units", "uamp.hour"); close(); saveInt("raw_frames", &m_isisRaw->rpb.r_rawfrm); run_cycle(); saveInt("run_number", &m_isisRaw->r_number); // script_name // seci_config instrument(); make_detector_1_link(); write_monitors(); user(); sample(); runlog(); selog(); NXclosegroup(handle); // raw_data_1 status = NXclose(&handle); delete m_isisRaw; }
/*============================================================================== main 主函数 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 参数: 无 返回码: 无 ==============================================================================*/ main(int argc,char *argv[]) { if(argc < 2) { printf("testfile 8 批量扣款信息查询 9 批量扣款信息返回\n"); } int sd,j; /* socket descriptor */ char ydport[10]; char ydhost[40]; char sendbuf[1024]; char buf[1024]; char recvbuf[1024]; char filelen[18+1]; int len; TCPPARMS tcpp; int retCode; memset(sendbuf,0,sizeof(sendbuf)); memset(recvbuf,0,sizeof(recvbuf)); memset(buf,0,sizeof(buf)); char recvfile[] = { "7008recv" }; char sendfile[] = { "7009send" }; int i = 0; switch(atoi(argv[1])) { case 8: sprintf(sendbuf,"%-4.4s%-4.4s%-4.4s%-18.18s","0026","7008","",""); break; case 9: i = productext(recvfile, sendfile); sprintf(sendbuf,"%-4.4s%-4.4s%-4.4s%-18.18d","0026","7009","",i); break; default: exit(0); } runlog(__FILE__,__LINE__,"sendbuf=[%s]\n",sendbuf); //设置服务端ip地址、端口号 //strcpy(ydhost,"172.20.8.206"); //strcpy(ydport,"443"); strcpy(ydhost,"192.168.8.205"); strcpy(ydport,"9005"); if(tcp_init(atoi(ydport),ydhost,&tcpp) < 0){ printf("TCP初始化失败!\n"); return -1; }; if((sd = tcp_connect(&tcpp)) < 0){ printf("TCP连接失败!\n"); closesocket(sd); return -1; } if(writen(sd,sendbuf,strlen(sendbuf)) < strlen(sendbuf)){ printf("TCP发送报文失败!\n"); closesocket(sd); return -1; } //接受文件 switch(atoi(argv[1])) case 8: { if(readn(sd,recvbuf,30)<0){/*失败*/ printf("TCP接收报文失败![%d]\n",len); closesocket(sd); return -1; } sprintf(filelen,"%18.18s",recvbuf+12); recvtext(sd,"7008recv",filelen); break; case 9: sendtext(sd, sendfile, i); break; } closesocket(sd); runlog(__FILE__,__LINE__,"recvbuf=[%s]\n",recvbuf); return 0; } /*main*/