void CParser1::dispatch(unsigned const sig) { switch (myState) { case CODE: switch (sig) { case SLASH_SIG: tran(SLASH); // transition to SLASH break; } break; case SLASH: switch (sig) { case STAR_SIG: myCommentCtr += 2; // SLASH-STAR count as comment tran(COMMENT); // transition to COMMENT break; case CHAR_SIG: case SLASH_SIG: tran(CODE); // go back to CODE break; } break; case COMMENT: switch (sig) { case STAR_SIG: tran(STAR); // transition to STAR break; case CHAR_SIG: case SLASH_SIG: ++myCommentCtr; // count the comment char break; } break; case STAR: switch (sig) { case STAR_SIG: ++myCommentCtr; // count STAR as comment break; case SLASH_SIG: myCommentCtr += 2; // count STAR-SLASH as comment tran(CODE); // transition to CODE break; case CHAR_SIG: myCommentCtr += 2; // count STAR-? as comment tran(COMMENT); // go back to COMMENT break; } break; } }
// Return true on success. bool MTSMSMachine::createRPData(RPData &rp_data) { // TODO: Read MIME Type from smqueue!! const char *contentType = tran()->mContentType.c_str(); PROCLOG(DEBUG)<<LOGVAR(contentType)<<LOGVAR(tran()->mMessage); if (strncmp(contentType,"text/plain",10)==0) { TLAddress tlcalling = TLAddress(tran()->calling().digits()); TLUserData tlmessage = TLUserData(tran()->mMessage.c_str()); PROCLOG(DEBUG)<<LOGVAR(tlcalling)<<LOGVAR(tlmessage); rp_data = RPData(this->mRpduRef, RPAddress(gConfig.getStr("SMS.FakeSrcSMSC").c_str()), TLDeliver(tlcalling,tlmessage,0)); } else if (strncmp(contentType,"application/vnd.3gpp.sms",24)==0) { BitVector2 RPDUbits(strlen(tran()->mMessage.c_str())*4); if (!RPDUbits.unhex(tran()->mMessage.c_str())) { LOG(WARNING) << "Message is zero length which is valid"; // This is valid continue return true; } try { // I suspect this is here to catch the above FIXED crash when string is zero length RLFrame RPDU(RPDUbits); LOG(DEBUG) << "SMS RPDU: " << RPDU; rp_data.parse(RPDU); LOG(DEBUG) << "SMS RP-DATA " << rp_data; } catch (SMSReadError) { LOG(WARNING) << "SMS parsing failed (above L3)"; // Cause 95, "semantically incorrect message". //LCH->l2sendf(CPData(L3TI,RPError(95,this->mRpduRef)),3); if you ever use this, it should call l3sendSms return false; } catch (GSM::L3ReadError) { LOG(WARNING) << "SMS parsing failed (in L3)"; // TODO:: send error back to the phone return false; } catch (...) { LOG(ERR) << "Unexpected throw"; // cryptic, but should never happen. return false; } } else { LOG(WARNING) << "Unsupported content type (in incoming SIP MESSAGE) -- type: " << contentType; return false; } return true; }
void ZeroLengthSection::computeSectionDefs(void) { // Get nodal displacements const Vector &u1 = theNodes[0]->getTrialDisp(); const Vector &u2 = theNodes[1]->getTrialDisp(); // Compute differential displacements const Vector diff = u2 - u1; // Set some references to make the syntax nicer Vector &def = *v; const Matrix &tran = *A; def.Zero(); // Compute element basic deformations ... v = A*(u2-u1) for (int i = 0; i < order; i++) for (int j = 0; j < numDOF/2; j++) def(i) += -diff(j)*tran(i,j); }
//${AOs::Philo::SM::thinking} ................................................ Q_STATE_DEF(Philo, thinking) { QP::QState status_; switch (e->sig) { //${AOs::Philo::SM::thinking} case Q_ENTRY_SIG: { m_timeEvt.armX(think_time(), 0U); status_ = Q_RET_HANDLED; break; } //${AOs::Philo::SM::thinking} case Q_EXIT_SIG: { (void)m_timeEvt.disarm(); status_ = Q_RET_HANDLED; break; } //${AOs::Philo::SM::thinking::TIMEOUT} case TIMEOUT_SIG: { status_ = tran(&hungry); break; } //${AOs::Philo::SM::thinking::EAT, DONE} case EAT_SIG: // intentionally fall through case DONE_SIG: { // EAT or DONE must be for other Philos than this one Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(this)); status_ = Q_RET_HANDLED; break; } //${AOs::Philo::SM::thinking::TEST} case TEST_SIG: { status_ = Q_RET_HANDLED; break; } default: { status_ = super(&top); break; } } return status_; }
//${Comp::Philo::SM::hungry} ................................................. Q_STATE_DEF(Philo, hungry) { QP::QState status_; switch (e->sig) { //${Comp::Philo::SM::hungry} case Q_ENTRY_SIG: { TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG); pe->philo = this; AO_Table->postLIFO(pe); status_ = Q_RET_HANDLED; break; } //${Comp::Philo::SM::hungry::EAT} case EAT_SIG: { status_ = tran(&eating); break; } default: { status_ = super(&top); break; } } return status_; }
//${AOs::Philo::SM::hungry} .................................................. Q_STATE_DEF(Philo, hungry) { QP::QState status_; switch (e->sig) { //${AOs::Philo::SM::hungry} case Q_ENTRY_SIG: { TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG); pe->philoNum = PHILO_ID(this); AO_Table->POST(pe, this); status_ = Q_RET_HANDLED; break; } //${AOs::Philo::SM::hungry::EAT} case EAT_SIG: { //${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(TableEvt)->philoNum=~} if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(this)) { status_ = tran(&eating); } else { status_ = Q_RET_UNHANDLED; } break; } //${AOs::Philo::SM::hungry::DONE} case DONE_SIG: { /* DONE must be for other Philos than this one */ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(this)); status_ = Q_RET_HANDLED; break; } default: { status_ = super(&top); break; } } return status_; }
main(int argc, char **argv) { struct ffblk ff; int r; int c = 0; char *prog = argv[0]; printf("PIF transferer dansei@tc :: /h for help\n\n"); while (argc > 1) { if (stricmp(argv[1], "/?") == 0 || stricmp(argv[1], "/h") == 0 || stricmp(argv[1], "--help") == 0) { printf("%s <files list>...\n\tunlink pif files\n", prog); } else for (r = findfirst(argv[1], &ff, 0x1F); r == 0; r = findnext(&ff), c++) { printf(">%s\n", ff.ff_name); tran(ff.ff_name); } argc--; argv++; } printf("transfer finished, total %d files\n", c); return 0; }
AxisRotate::AxisRotate(const QImage &im, const int newW, const int newH): image(im) { mx.fill(0.0); my.fill(0.0); mz.fill(0.0); per.fill(0.0); minusTran.fill(0.0); tran.fill(0.0); minusTran(0,0) = minusTran(1,1) = minusTran(2,2) = minusTran(3,3) = tran(0,0) = tran(1,1) = tran(2,2) = tran(3,3) = 1.0; mx(0,0)=mx(1,1)=mx(2,2)=mx(3,3)=1.0; my(0,0)=my(1,1)=my(2,2)=my(3,3)=1.0; mz(0,0)=mz(1,1)=mz(2,2)=mz(3,3)=1.0; move(0,0)=move(1,1)=move(2,2)=move(3,3)=1.0; move(0,3)=newW/2-im.width()/2; move(1,3)=newH/2-im.height()/2; minusTran(0,3) = im.width()/2.0; minusTran(1,3) = im.height()/2.0; //minusTran(2,3) = 0; nw = newW; nh = newH; tran(0,3) = -im.width() /2.0; tran(1,3) = -im.height()/2.0; //tran(2,3) = 0; per(0,0) = per(1,1) = per(3,3) = 1.0; per(3,2) = 1.0/-200.0; rotatedImage = NULL; }
void Bomb3::init() { m_timeout = INIT_TIMEOUT; tran(&Bomb3::setting); }
// Set basic deformation-displacement transformation matrix for section void ZeroLengthSection::setTransformation(void) { // Allocate transformation matrix if (A != 0) delete A; A = new Matrix(order, numDOF); if (A == 0) opserr << "ZeroLengthSection::setTransformation -- failed to allocate transformation Matrix\n"; // Allocate section deformation vector if (v != 0) delete v; v = new Vector(order); // Get the section code const ID &code = theSection->getType(); // Set a reference to make the syntax nicer Matrix &tran = *A; tran.Zero(); // Loop over the section code for (int i = 0; i < order; i++) { // Fill in row i of A based on section code switch(code(i)) { // The in-plane transformations case SECTION_RESPONSE_MZ: if (numDOF == 6) { tran(i,3) = 0.0; tran(i,4) = 0.0; tran(i,5) = transformation(2,2); } else if (numDOF == 12) { tran(i,9) = transformation(2,0); tran(i,10) = transformation(2,1); tran(i,11) = transformation(2,2); } break; case SECTION_RESPONSE_P: if (numDOF == 6) { tran(i,3) = transformation(0,0); tran(i,4) = transformation(0,1); tran(i,5) = 0.0; } else if (numDOF == 12) { tran(i,6) = transformation(0,0); tran(i,7) = transformation(0,1); tran(i,8) = transformation(0,2); } break; case SECTION_RESPONSE_VY: if (numDOF == 6) { tran(i,3) = transformation(1,0); tran(i,4) = transformation(1,1); tran(i,5) = 0.0; } else if (numDOF == 12) { tran(i,6) = transformation(1,0); tran(i,7) = transformation(1,1); tran(i,8) = transformation(1,2); } break; // The out-of-plane transformations case SECTION_RESPONSE_MY: if (numDOF == 12) { tran(i,9) = transformation(1,0); tran(i,10) = transformation(1,1); tran(i,11) = transformation(1,2); } break; case SECTION_RESPONSE_VZ: if (numDOF == 12) { tran(i,6) = transformation(2,0); tran(i,7) = transformation(2,1); tran(i,8) = transformation(2,2); } break; case SECTION_RESPONSE_T: if (numDOF == 12) { tran(i,9) = transformation(0,0); tran(i,10) = transformation(0,1); tran(i,11) = transformation(0,2); } break; default: break; } // Fill in first half of transformation matrix with negative sign for (int j = 0; j < numDOF/2; j++ ) tran(i,j) = -tran(i,j+numDOF/2); } }
// Set basic deformation-displacement transformation matrix for the materials void ZeroLengthND::setTransformation(void) { // Allocate transformation matrix if (A != 0) delete A; A = (the1DMaterial == 0) ? new Matrix(order, numDOF) : new Matrix(order+1, numDOF); if (A == 0) { opserr << "ZeroLengthND::setTransformation -- failed to allocate transformation Matrix\n"; exit(-1); } if (numDOF == 6) { K = &K6; P = &P6; } else { K = &K12; P = &P12; } if (order == 2) v = &v2; else v = &v3; // Set a reference to make the syntax nicer Matrix &tran = *A; // Loop over the NDMaterial order for (int i = 0; i < order; i++) { if (numDOF == 6) { tran(i,3) = transformation(i,0); tran(i,4) = transformation(i,1); tran(i,5) = 0.0; } else if (numDOF == 12) { tran(i,6) = transformation(i,0); tran(i,7) = transformation(i,1); tran(i,8) = transformation(i,2); } // Fill in first half of transformation matrix with negative sign for (int j = 0; j < numDOF/2; j++ ) tran(i,j) = -tran(i,j+numDOF/2); } // Fill in transformation for UniaxialMaterial if (the1DMaterial != 0) { if (numDOF == 6) { tran(2,3) = transformation(2,0); tran(2,4) = transformation(2,1); tran(2,5) = 0.0; } else if (numDOF == 12) { tran(2,6) = transformation(2,0); tran(2,7) = transformation(2,1); tran(2,8) = transformation(2,2); } // Fill in first half of transformation matrix with negative sign for (int j = 0; j < numDOF/2; j++ ) tran(2,j) = -tran(2,j+numDOF/2); } }
void pSubChain::calc_inertia_body() { // for space // if(!children[1]) return; #ifdef USE_MPI if(sim->rank != rank) return; if(children[0] && sim->rank != children[0]->rank) { // cerr << sim->rank << ": joint (" << last_joint->name << "): recv_inertia from " << children[0]->rank << endl; children[0]->recv_inertia(); } if(children[1] && children[0] != children[1] && sim->rank != children[1]->rank) { // cerr << sim->rank << ": joint (" << last_joint->name << "): recv_inertia from " << children[1]->rank << endl; children[1]->recv_inertia(); } #endif int i, j; // cerr << "---- " << last_joint->name << ": calc_inertia_body" << endl; // P if(children[1]) { P.add(children[0]->Lambda[last_index[0]][last_index[0]], children[1]->Lambda[last_index[1]][last_index[1]]); } else { P.set(children[0]->Lambda[last_index[0]][last_index[0]]); } // cerr << "Lambda[0] = " << children[0]->Lambda[last_index[0]][last_index[0]] << endl; // cerr << "Lambda[1] = " << children[1]->Lambda[last_index[1]][last_index[1]] << endl; #ifdef PSIM_TEST { fMat U1(6,6), V1T(6,6), U2(6,6), V2T(6,6); fVec sigma1(6), sigma2(6); children[0]->Lambda[last_index[0]][last_index[0]].svd(U1, sigma1, V1T); children[1]->Lambda[last_index[1]][last_index[1]].svd(U2, sigma2, V2T); double s1 = sigma1.length(), s2 = sigma2.length(); if(s1 > 1e-8 && s2 > 1e-8) { double ratio = (s1 < s2) ? s2/s1 : s1/s2; if(max_sigma_ratio < 0.0 || ratio > max_sigma_ratio) { max_sigma_ratio = ratio; max_sigma_ratio_joint = last_joint; } sigma_ratios(last_joint->i_dof) = ratio; // cerr << last_joint->name << ": " << s1 << ", " << s2 << " -> " << ratio << endl; } } #endif if(children[0] == children[1]) { P -= children[0]->Lambda[last_index[0]][last_index[1]]; P -= children[0]->Lambda[last_index[1]][last_index[0]]; } // P should be symmetric // P += tran(P); // P *= 0.5; P.symmetric(); #ifndef USE_DCA // Gamma if(n_const > 0) { for(i=0; i<n_const; i++) { for(j=0; j<n_const; j++) Gamma(i, j) = P(const_index[i], const_index[j]); } if(children[0] != children[1]) { // Gamma is symmetric, positive-definite if(Gamma_inv.inv_posv(Gamma)) Gamma_inv.inv_svd(Gamma); // Gamma_inv.inv_porfs(Gamma); #ifdef PSIM_TEST fMat U(n_const, n_const), VT(n_const, n_const); fVec sigma(n_const); Gamma.svd(U, sigma, VT); double cn = sigma(0) / sigma(n_const-1); if(max_condition_number < 0.0 || cn > max_condition_number) { max_condition_number = cn; max_condition_number_joint = last_joint; } condition_numbers(last_joint->i_dof) = cn; // cerr << "condition_number = " << cn << endl; // fMat Gamma_inv2(n_const, n_const); // Gamma_inv2.inv_svd(Gamma, 2000); // cerr << last_joint->name << ": " << cn << endl; // fMat I(n_const, n_const); // I.identity(); // cerr << last_joint->name << ": " << I - Gamma*Gamma_inv << endl; // cerr << last_joint->name << ": " << Gamma_inv - Gamma_inv2 << endl; #endif } else { // Gamma may be singular Gamma_inv.inv_svd(Gamma); // cerr << Gamma_inv * Gamma << endl; } } // W, IW W.zero(); for(i=0; i<n_const; i++) { for(int j=0; j<n_const; j++) { W(const_index[i], const_index[j]) = -Gamma_inv(i, j); } } #else // #ifndef USE_DCA static fMat SV, VSV; SV.resize(n_dof, 6); VSV.resize(n_dof, 6); Vhat.inv_posv(P); if(n_dof > 0) { for(i=0; i<n_dof; i++) { for(int j=0; j<n_dof; j++) { SVS(i,j) = Vhat(joint_index[i], joint_index[j]); } for(int j=0; j<6; j++) { SV(i,j) = Vhat(joint_index[i], j); } } // cerr << "SVS = " << SVS << endl; VSV.lineq(SVS, SV); // cerr << "VSV = " << VSV << endl; W.mul(tran(SV), VSV); // W *= -1.0; } else { W.zero(); } W -= Vhat; #endif // cerr << "P = " << P << endl; // cerr << "W = " << W << endl; IW.mul(P, W); for(i=0; i<6; i++) { IW(i, i) += 1.0; } // cerr << "IW = " << IW << endl; // Lambda if(n_const == 0) { for(i=0; i<n_outer_joints; i++) { int org_i = outer_joints_origin[i]; int index_i = outer_joints_index[i]; for(j=i; j<n_outer_joints; j++) { int org_j = outer_joints_origin[j]; int index_j = outer_joints_index[j]; if(children[org_i] == children[org_j]) { Lambda[i][j].set(children[org_i]->Lambda[index_i][index_j]); } if(i != j) { Lambda[j][i].tran(Lambda[i][j]); } } } } else { for(i=0; i<n_outer_joints; i++) { int org_i = outer_joints_origin[i]; int index_i = outer_joints_index[i]; fMat& Lambda_i = children[org_i]->Lambda[index_i][last_index[org_i]]; #ifndef USE_DCA int m, n; static fMat LKi, KLj, GKLj; LKi.resize(6, n_const); KLj.resize(n_const, 6); GKLj.resize(n_const, 6); for(m=0; m<6; m++) { for(n=0; n<n_const; n++) LKi(m, n) = Lambda_i(m, const_index[n]); } for(j=i; j<n_outer_joints; j++) { int org_j = outer_joints_origin[j]; int index_j = outer_joints_index[j]; fMat& Lambda_j = children[org_j]->Lambda[last_index[org_j]][index_j]; for(m=0; m<n_const; m++) { for(n=0; n<6; n++) KLj(m, n) = Lambda_j(const_index[m], n); } GKLj.mul(Gamma_inv, KLj); // GKLj.lineq_posv(Gamma, KLj); Lambda[i][j].mul(LKi, GKLj); if(children[org_i] == children[org_j]) { Lambda[i][j] -= children[org_i]->Lambda[index_i][index_j]; Lambda[i][j] *= -1.0; } if(i != j) { Lambda[j][i].tran(Lambda[i][j]); } else { Lambda[i][j].symmetric(); } } #else // #ifndef USE_DCA for(j=i; j<n_outer_joints; j++) { int org_j = outer_joints_origin[j]; int index_j = outer_joints_index[j]; fMat& Lambda_j = children[org_j]->Lambda[last_index[org_j]][index_j]; static fMat WL(6,6); WL.mul(W, Lambda_j); WL *= -1.0; Lambda[i][j].mul(Lambda_i, WL); if(children[org_i] == children[org_j]) { Lambda[i][j] -= children[org_i]->Lambda[index_i][index_j]; Lambda[i][j] *= -1.0; } if(i != j) { Lambda[j][i].tran(Lambda[i][j]); } else { Lambda[i][j].symmetric(); } } #endif } } #ifdef USE_MPI if(parent && sim->rank != parent->rank) { // cerr << sim->rank << ": joint (" << last_joint->name << "): send_inertia to " << parent->rank << endl; send_inertia(parent->rank); } #endif }
int ri_inter (void) { /* This is the shortest version of the interpreter, containing only those RASL operators which * are produced by the REFAL compiler. */ /* July, 27, 1985. D.T. */ /* Some macros have been expanded because the PC compiler can't handle too many macros. (its stack overflows.) * DT July 1 1986. */ /* Some other macros have been replaced by functions to reduce the size of object module. March 7 1987. DT. */ register short n; int error; char c, ins = 0; long mdig, bifnum; char *arg; /* short m;*/ error = 0; restart: while (error == 0) { ins = *p; # if MDEBUG if (dump_toggle) printf ("%lx: %d\n", p, ins); # endif switch (ins) { case ACT1: ASGN_CHARP (++p, arg); p += sizeof (char *); act1 (arg); curk ++; break; case BL: p++; bl; break; case BLR: p++; ri_blr (); break; case BR: p++; br; break; case CL: p++; cl; break; case SYM: c = (unsigned char) * ++p; p++; sym (c); break; case SYMR: c = (unsigned char) * ++p; p++; symr (c); break; case EMP: p++; emp; break; case EST: curk --; est; p = break0; break; case MULE: /* n = * ++p; ++p; mule ((int) n); */ ASGN_LONG (++p, mdig); p += sizeof (long); mule (mdig); break; case MULS: /*n = * ++p; muls (n); p++; break;*/ ASGN_LONG (++p, mdig); p += sizeof (long); muls (mdig); break; case PLEN: p++; plen; p++; break; case PLENS: p++; plens; break; case PLENP: p++; plenp; break; case PS: ++p; ps; break; case PSR: ++p; psr; break; case OEXP: n = (unsigned char) * ++p; ++p; oexp (n); break; case OEXPR: n = (unsigned char) * ++p; ++p; oexpr (n); break; case OVSYM: n = (unsigned char) * ++p; ovsym (n); ++p; break; case OVSYMR: n = (unsigned char) * ++p; ovsymr (n); p++; break; case TERM: p++; term; break; case TERMR: p++; termr; break; case RDY: n = (unsigned char) * ++p; ++p; rdy (n); break; case SETB: /* n = (unsigned char) * ++p; m = (unsigned char) * ++p; ++p; setb (n,m); break; */ { long l_n, l_m; ASGN_LONG (++p, l_n); p += sizeof (long); ASGN_LONG (p, l_m); p += sizeof (long); setb (l_n, l_m); } break; case LEN: p++; len; break; case LENS: c = (unsigned char) *++p; p++; lens (c); break; case LENP: ++p; lenp; break; case SYMS: n = (unsigned char) * ++p; p++; syms (n); break; case SYMSR: n = (unsigned char) * ++p; p++; symsr (n) break; case TEXT: n = (unsigned char) * ++p; p++; text (n); break; case NS: c = (unsigned char) * ++p; ++p; ns (c); break; case TPLE: /* n = * ++p; p++; tple (n); break; */ ASGN_LONG (++p, mdig); p += sizeof (long); tple (mdig); break; case TPLS: /* n = * ++p; p++; tpls (n); break; */ ASGN_LONG (++p, mdig); p += sizeof (long); tpls (mdig); break; case TRAN: ASGN_CHARP (++p, arg); p += sizeof (char *); tran (arg); break; case VSYM: p++; vsym; break; case VSYMR: ++p; vsymr; break; case OUTEST: curk --; out (2); est; p = break0; break; case ECOND: if (tel - te + nel + 100 >= size_table_element) { if (fp_debugInfo != NULL) ri_print_error_code(fp_debugInfo,13); ri_error (13); } ASGN_CHARP (++p, arg); b = st[sp].b1; b = st[sp].b1; act1 (arg); tel += (teoff = nel); est; p = break0; break; case POPVF: ++p; tel -= teoff; nel = teoff + 3; sp = stoff-1; teoff = st[sp].nel; stoff = (long) st[sp].b2; break; case PUSHVF: if (sp + 20 >= size_local_stack) { if (fp_debugInfo != NULL) ri_print_error_code(fp_debugInfo,14); ri_error (14); } ++p; b = tbel (2) -> prec; blr; pushst (b->prec,b,NULL,NULL); sp++; pushst (b,stoff,teoff, IMP_); b = b -> prec; stoff = sp + 1; break; case STLEN: ++p; sp = stoff; break; case CSYM: ASGN_CHARP (++p, arg); p += sizeof (char *); csym (arg); break; case CSYMR: ASGN_CHARP (++p, arg); p += sizeof (char *); csymr (arg); break; case NSYM: ASGN_LONG (++p, mdig); p += sizeof (long); nsym (mdig); break; case NSYMR: ASGN_LONG (++p, mdig); p += sizeof (long); nsymr (mdig); break; case NCS: ASGN_CHARP (++p, arg); p += sizeof (char *); ncs (arg); break; case NNS: ASGN_LONG (++p, mdig); p += sizeof (long); nns (mdig); break; /* builtin functions: R.N. - 20 Jul 85 */ case BUILT_IN: /* a call to a built in function no arguments. */ curk --; ASGN_LONG (p+1, bifnum); error = ri_bif (bifnum,NULL); p = break0; break; /* builtin functions with one argument: D.T. - July 27, 1985. */ case BUILT_IN1: /* a call to a function with one argument. */ /* Arguments are stored before function address. */ curk --; ASGN_CHARP(++p, arg); ASGN_LONG (p + (sizeof (char *)), bifnum); error = ri_bif (bifnum, arg); p = break0; break; default: ri_default (ins, &error); break; } } if (error != 0) { fprintf (stderr,"RASL instruction: %4d at address: %lx\n", *p, (unsigned long) p); if (fp_debugInfo != NULL) fprintf (fp_debugInfo,"RASL instruction: %4d at address: %lx\n", *p, (unsigned long) p); ri_error(4); } return 0; }
int main(void) { stldata newgun; stldata part; stldata j0, j1, j2, j3, j4, j5, j6; if (loadstl("45.STL", &newgun) != 0) printf("load 45 stl error\n"); if (loadstl("qian.STL", &part) != 0) printf("load qian stl error!\n"); if (loadstl("robot_stl/J0.STL", &j0) != 0) printf("load newgun stl error\n"); if (loadstl("robot_stl/J1.STL", &j1) != 0) printf("load newgun stl error\n"); if (loadstl("robot_stl/J2.STL", &j2) != 0) printf("load newgun stl error\n"); if (loadstl("robot_stl/J3.STL", &j3) != 0) printf("load newgun stl error\n"); if (loadstl("robot_stl/J4.STL", &j4) != 0) printf("load newgun stl error\n"); if (loadstl("robot_stl/J5.STL", &j5) != 0) printf("load newgun stl error\n"); if (loadstl("robot_stl/J6.STL", &j6) != 0) printf("load newgun stl error\n"); printf("newgun: %s, %d triangles\n", newgun.modelname, newgun.num); printf("part: %s, %d tirangles\n", part.modelname, part.num); printf("j0: %s, %d triangles\n", j0.modelname, j0.num); printf("j1: %s, %d triangles\n", j1.modelname, j1.num); printf("j2: %s, %d triangles\n", j2.modelname, j2.num); printf("j3: %s, %d triangles\n", j3.modelname, j3.num); printf("j4: %s, %d triangles\n", j4.modelname, j4.num); printf("j5: %s, %d triangles\n", j5.modelname, j5.num); printf("j6: %s, %d triangles\n", j6.modelname, j6.num); JAngle robotangle(0.0, -25.00, 65.00, 0.00, 0.00, 0.00); JAngle exangle(0.00, 0.00, 0.00, 0.00, 0.00, 0.00); TRANS j0_trans = Transform::getTransWorldToBase(exangle); TRANS j1_trans, j2_trans, j3_trans, j4_trans, j5_trans, j6_trans; TRANS part_trans, newgun_trans; Transform::getTransBaseToJoints(robotangle, j1_trans, j2_trans, j3_trans, j4_trans, j5_trans, j6_trans); newgun_trans = Transform::getTrans6ToGun(); j1_trans = j0_trans * j1_trans; j2_trans = j0_trans * j2_trans; j3_trans = j0_trans * j3_trans; j4_trans = j0_trans * j4_trans; j5_trans = j0_trans * j5_trans; j6_trans = j0_trans * j6_trans; newgun_trans = j6_trans * newgun_trans; part_trans = Transform::getTransWorldToWorkpiece(exangle); stldata newgunbuffer, partbuffer, j0buffer, j1buffer, j2buffer, j3buffer, j4buffer, j5buffer, j6buffer; strcpy(newgunbuffer.modelname, newgun.modelname); strcpy(partbuffer.modelname, part.modelname); strcpy(j0buffer.modelname, j0.modelname); strcpy(j1buffer.modelname, j1.modelname); strcpy(j2buffer.modelname, j2.modelname); strcpy(j3buffer.modelname, j3.modelname); strcpy(j4buffer.modelname, j4.modelname); strcpy(j5buffer.modelname, j5.modelname); strcpy(j6buffer.modelname, j6.modelname); newgunbuffer.num = newgun.num; partbuffer.num = part.num; j0buffer.num = j0.num; j1buffer.num = j1.num; j2buffer.num = j2.num; j3buffer.num = j3.num; j4buffer.num = j4.num; j5buffer.num = j5.num; j6buffer.num = j6.num; newgunbuffer.ptriangle = (triangle *)malloc(newgun.num * sizeof(triangle)); partbuffer.ptriangle = (triangle *)malloc(part.num * sizeof(triangle)); j0buffer.ptriangle = (triangle *)malloc(j0.num * sizeof(triangle)); j1buffer.ptriangle = (triangle *)malloc(j1.num * sizeof(triangle)); j2buffer.ptriangle = (triangle *)malloc(j2.num * sizeof(triangle)); j3buffer.ptriangle = (triangle *)malloc(j3.num * sizeof(triangle)); j4buffer.ptriangle = (triangle *)malloc(j4.num * sizeof(triangle)); j5buffer.ptriangle = (triangle *)malloc(j5.num * sizeof(triangle)); j6buffer.ptriangle = (triangle *)malloc(j6.num * sizeof(triangle)); /* newgun_trans.rot.mem[0][0] = -0.31028574744121573; */ /* newgun_trans.rot.mem[0][1] = -0.76055620150283443; */ /* newgun_trans.rot.mem[0][2] = 0.57033062278859459; */ /* newgun_trans.rot.mem[1][0] = -0.20326345994589520; */ /* newgun_trans.rot.mem[1][1] = 0.63914569443991687; */ /* newgun_trans.rot.mem[1][2] = 0.74173900202816612; */ /* newgun_trans.rot.mem[2][0] = -0.92865855985161161; */ /* newgun_trans.rot.mem[2][1] = 0.11422366494950395; */ /* newgun_trans.rot.mem[2][2] = -0.35291108452389802; */ /* newgun_trans.pos.dx = 94.771302128496586; */ /* newgun_trans.pos.dy = -505.20287976357167; */ /* newgun_trans.pos.dz = 1222.0426991063437; */ newgun_trans.rot.mem[0][0] = -0.036801385144649992; newgun_trans.rot.mem[0][1] = -0.74802231932451657; newgun_trans.rot.mem[0][2] = 0.66265244875711904; newgun_trans.rot.mem[1][0] = 0.73624785273584337; newgun_trans.rot.mem[1][1] = 0.42807339281869838; newgun_trans.rot.mem[1][2] = 0.52411093263024766; newgun_trans.rot.mem[2][0] = -0.67571055740849195; newgun_trans.rot.mem[2][1] = 0.50716445079782491; newgun_trans.rot.mem[2][2] = 0.53497613260186283; newgun_trans.pos.dx = 159.55751427696521; newgun_trans.pos.dy = 700.79742899056282; newgun_trans.pos.dz = 2790.4503015644741; part_trans.rot.mem[0][0] = -5.1036340138841535e-012; part_trans.rot.mem[0][1] = 1.0000000000000000; part_trans.rot.mem[0][2] = -5.1036340138841535e-012; part_trans.rot.mem[1][0] = -1.0000000000000000; part_trans.rot.mem[1][1] = -5.1036340138581062e-012; part_trans.rot.mem[1][2] = -5.1036340139102000e-012; part_trans.rot.mem[2][0] = -5.1036340138841527e-012; part_trans.rot.mem[2][1] = -5.1036340139102008e-012; part_trans.rot.mem[2][2] = 1.0000000000000000; part_trans.pos.dx = -600.0000000000; part_trans.pos.dy = 429.99999998934874; part_trans.pos.dz = 2087.0000000021946; tran(&newgun_trans, &newgun, &newgunbuffer); tran(&part_trans, &part, &partbuffer); tran(&j0_trans, &j0, &j0buffer); tran(&j1_trans, &j1, &j1buffer); tran(&j2_trans, &j2, &j2buffer); tran(&j3_trans, &j3, &j3buffer); tran(&j4_trans, &j4, &j4buffer); tran(&j5_trans, &j5, &j5buffer); tran(&j6_trans, &j6, &j6buffer); if (writestl("mystl/45.STL", &newgunbuffer)) printf("stl 45.STL write error!\n"); if (writestl("mystl/qian.STL", &partbuffer)) printf("stl part write error!\n"); if (writestl("mystl/j0.STL", &j0buffer)) printf("stl j0 write error!\n"); if (writestl("mystl/j1.STL", &j1buffer)) printf("stl j1 write error!\n"); if (writestl("mystl/j2.STL", &j2buffer)) printf("stl j2 write error!\n"); if (writestl("mystl/j3.STL", &j3buffer)) printf("stl j3 write error!\n"); if (writestl("mystl/j4.STL", &j4buffer)) printf("stl j4 write error!\n"); if (writestl("mystl/j5.STL", &j5buffer)) printf("stl j5 write error!\n"); if (writestl("mystl/j6.STL", &j6buffer)) printf("stl j6 write error!\n"); /* for (i = 0; i < newgun.num; ++i) { */ /* printf("Point %d: (%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f)\n", */ /* i, newgun.ptriangle[i].normalvector.x, newgun.ptriangle[i].normalvector.y, */ /* newgun.ptriangle[i].normalvector.z, newgun.ptriangle[i].vertex1.x, */ /* newgun.ptriangle[i].vertex1.y, newgun.ptriangle[i].vertex1.z, */ /* newgun.ptriangle[i].vertex2.x, newgun.ptriangle[i].vertex2.y, */ /* newgun.ptriangle[i].vertex2.z, newgun.ptriangle[i].vertex3.x, */ /* newgun.ptriangle[i].vertex3.y, newgun.ptriangle[i].vertex3.z); */ /* } */ /* for (i = 0; i < newgun.num; ++i) { */ /* printf("distance %d: %f %f\n", i, distance(&newgun.ptriangle[i].vertex1, &newgun.ptriangle[i].vertex2), distance(&newgunbuffer.ptriangle[i].vertex1, &newgunbuffer.ptriangle[i].vertex2)); */ /* } */ /* printf("part\n"); */ /* for (i = 0; i < part.num; ++i) { */ /* printf("distance %d: %f %f\n", i, distance(&part.ptriangle[i].vertex1, &part.ptriangle[i].vertex2), distance(&partbuffer.ptriangle[i].vertex1, &partbuffer.ptriangle[i].vertex2)); */ /* } */ free(newgun.ptriangle); free(part.ptriangle); free(j0.ptriangle); free(j1.ptriangle); free(j2.ptriangle); free(j3.ptriangle); free(j4.ptriangle); free(j5.ptriangle); free(j6.ptriangle); free(newgunbuffer.ptriangle); free(partbuffer.ptriangle); free(j0buffer.ptriangle); free(j1buffer.ptriangle); free(j2buffer.ptriangle); free(j3buffer.ptriangle); free(j4buffer.ptriangle); free(j5buffer.ptriangle); free(j6buffer.ptriangle); return 0; }
//${HSMs::QHsmTst::SM::s::s1} ................................................ Q_STATE_DEF(QHsmTst, s1) { QP::QState status_; switch (e->sig) { //${HSMs::QHsmTst::SM::s::s1} case Q_ENTRY_SIG: { BSP_display("s1-ENTRY;"); status_ = Q_RET_HANDLED; break; } //${HSMs::QHsmTst::SM::s::s1} case Q_EXIT_SIG: { BSP_display("s1-EXIT;"); status_ = Q_RET_HANDLED; break; } //${HSMs::QHsmTst::SM::s::s1::initial} case Q_INIT_SIG: { BSP_display("s1-INIT;"); status_ = tran(&s11); break; } //${HSMs::QHsmTst::SM::s::s1::I} case I_SIG: { BSP_display("s1-I;"); status_ = Q_RET_HANDLED; break; } //${HSMs::QHsmTst::SM::s::s1::D} case D_SIG: { //${HSMs::QHsmTst::SM::s::s1::D::[!m_foo]} if (!m_foo) { m_foo = true; BSP_display("s1-D;"); status_ = tran(&s); } else { status_ = Q_RET_UNHANDLED; } break; } //${HSMs::QHsmTst::SM::s::s1::A} case A_SIG: { BSP_display("s1-A;"); status_ = tran(&s1); break; } //${HSMs::QHsmTst::SM::s::s1::B} case B_SIG: { BSP_display("s1-B;"); status_ = tran(&s11); break; } //${HSMs::QHsmTst::SM::s::s1::F} case F_SIG: { BSP_display("s1-F;"); status_ = tran(&s211); break; } //${HSMs::QHsmTst::SM::s::s1::C} case C_SIG: { BSP_display("s1-C;"); status_ = tran(&s2); break; } default: { status_ = super(&s); break; } } return status_; }
MachineStatus MTSMSMachine::machineRunState1(int state,const L3Frame*frame,const L3Message*l3msg, const SIP::DialogMessage*sipmsg) { // Step 1 Network->MS CP-DATA containing RP-DATA with message // Step 2 MS->Network CP-ACK // 4.11 6.2.2 State wait-to-send-RP-ACK, timer TR2M // Step 3 MS->Network CP-DATA containing RP-ACK or RP-Error // Step 4 Network->MS CP-ACK // Network->SIP response. PROCLOG2(DEBUG,state)<<LOGVAR(l3msg)<<LOGVAR(sipmsg)<<LOGVAR2("imsi",tran()->subscriber()); switch(state) { case stateStart: { // There is no dialog for a SMS initiated on this BTS. if (getDialog() && getDialog()->isFinished()) { // SIP side closed already. // We can no longer inform the SIP side whether we succeed or not. // Should we continue and deliver the message to the MS or not? return MachineStatus::QuitTran(TermCause::Local(L3Cause::SMS_Timeout)); // could be a sip internal error? } timerStart(TR2M,TR2Mms,TimerAbortTran); // Allocate Transaction Identifier unsigned l3ti = channel()->chanGetContext(true)->mmGetNextTI(); tran()->setL3TI(l3ti); setGSMState(CCState::SMSDelivering); this->mRpduRef = random() % 255; gReports.incr("OpenBTS.GSM.SMS.MTSMS.Start"); // pat 6-2014. We just send the ESTABLISH_REQUEST no matter what now. // The LAPDm will respond with ESTABLISH_INDICATION immediately if SAPI_t sap = getSmsSap(); //L3LogicalChannel *smschan = getSmsChannel(); //if (smschan->multiframeMode(3)) { goto step1; } // If already established. // if (channel()->multiframeMode(sap)) { goto step1; } // If already established. // Start ABM in SAP3. //smschan->l3sendp(GSM::L3_ESTABLISH_REQUEST,SAPI3); channel()->l3sendp(GSM::L3_ESTABLISH_REQUEST,sap); // Wait for SAP3 ABM to connect. // The next read on SAP3 should be the ESTABLISH primitive. // This won't return NULL. It will throw an exception if it fails. // (pat) WARNING: Previous code waited for a return ESTABLISH, // but I think the l3sendp(ESTABLISH) will hang until this happens so it is now a no-op. // delete getFrameSMS(LCH,GSM::ESTABLISH); LOG(DEBUG) << "case start returning, after sending ESTABLISH"; return MachineStatusOK; // Wait for the ESTABLISH on the uplink. } // We use ESTABLISH_INDICATION instead of ESTABLISH_CONFIRM to indicate establishment. // We would have to accept both ESTABLISH_CONFIRM and ESTABLISH_INDICATION here anyway in case // SABM was started by us and handset simultaneously, so we just dont bother with making ESTABLISH_CONFIRM separate. case L3CASE_PRIMITIVE(L3_ESTABLISH_INDICATION): case L3CASE_PRIMITIVE(L3_ESTABLISH_CONFIRM): { // Step 1 // Send the first message. // CP-DATA, containing RP-DATA. RPData rp_data; int l3ti = getL3TI(); if (! createRPData(rp_data)) { // NULL can be returned l3sendSms(CPData(l3ti,RPError(95,this->mRpduRef))); // TODO: Is this correct? // TODO: Make sure MachineStatusQuitTran sends a failure code to SIP. if (getDialog()) getDialog()->MTSMSReply(400, "Bad Request"); return MachineStatus::QuitTran(TermCause::Local(L3Cause::SMS_Error)); } CPData deliver(l3ti,rp_data); PROCLOG(INFO) << "sending " << deliver; // WORKING: MS Does not respond to this message. // (pat) FIXME: The MS may send a DELIVER_REPORT which is discarded by parseTPDU. l3sendSms(deliver); LOG(DEBUG) << "case ESTABLISH returning, after receiving ESTABLISH"; return MachineStatusOK; // Wait for CP-ACK message. } // Step 2 // Get the CP-ACK. case L3CASE_SMS(ACK): { // FIXME -- Check reference and check for RPError. return MachineStatusOK; // Now we are waiting for CP-DATA. } // Step 3 // Get CP-DATA containing RP-ACK and message reference. case L3CASE_SMS(DATA): { timerStop(TR2M); PROCLOG(DEBUG) << "MTSMS: data from MS " << *l3msg; // FIXME -- Check L3 TI. // Parse to check for RP-ACK. // We already called parsel3 on the message. //CPData data; //try { // data.parse(*CM); // LOG(DEBUG) << "CPData " << data; //} //catch (SMSReadError) { // LOG(WARNING) << "SMS parsing failed (above L3)"; // // Cause 95, "semantically incorrect message". // LCH->l2sendf(CPError(L3TI,95),3); // throw UnexpectedMessage(); //} //catch (GSM::L3ReadError) { // LOG(WARNING) << "SMS parsing failed (in L3)"; // throw UnsupportedMessage(); //} //delete CM; const CPData *cpdata = dynamic_cast<typeof(cpdata)>(l3msg); // FIXME -- Check SMS reference. bool success = true; if (cpdata->RPDU().MTI()!=RPMessage::Ack) { PROCLOG(WARNING) << "unexpected RPDU " << cpdata->RPDU(); success = false; } gReports.incr("OpenBTS.GSM.SMS.MTSMS.Complete"); // Step 4 // Send CP-ACK to the MS. PROCLOG(INFO) << "MTSMS: sending CPAck"; l3sendSms(CPAck(getL3TI())); // Ack in SIP domain. if (!getDialog()) { LOG(DEBUG) << "No dialog found for MTSMS; could be welcome message, CLI SMS, or Dialog pre-destroyed error"; } else if (success) { getDialog()->MTSMSReply(200,"OK"); } else { getDialog()->MTSMSReply(400, "Bad Request"); } LOG(DEBUG) << "case DATA returning"; return MachineStatus::QuitTran(TermCause::Local(L3Cause::SMS_Success)); // Finished. } default: return unexpectedState(state,l3msg); } }
// see: Control::MOSMSController MachineStatus MOSMSMachine::machineRunState(int state, const GSM::L3Message *l3msg, const SIP::DialogMessage *sipmsg) { // See GSM 04.11 Arrow Diagram A5 for the transaction (pat) NO, A5 is for GPRS. Closest diagram is F1. // SIP->Network message. // Step 1 MS->Network CP-DATA containing RP-DATA with message // Step 2 Network->MS CP-ACK // 4.11 6.2.2 State wait-for-RP-ACK, timer TR1M // Step 3 Network->MS CP-DATA containing RP-ACK or RP-Error // Step 4 MS->Network CP-ACK // LAPDm operation, from GSM 04.11, Annex F: // """ // Case A: Mobile originating short message transfer, no parallel call: // The mobile station side will initiate SAPI 3 establishment by a SABM command // on the DCCH after the cipher mode has been set. If no hand over occurs, the // SAPI 3 link will stay up until the last CP-ACK is received by the MSC, and // the clearing procedure is invoked. // """ WATCHF("MOSMS state=%x\n",state); PROCLOG2(DEBUG,state)<<LOGVAR(l3msg)<<LOGVAR(sipmsg)<<LOGVAR2("imsi",tran()->subscriber()); switch (state) { case L3CASE_MM(CMServiceRequest): { timerStart(TCancel,30*1000,TimerAbortTran); // Just in case. // This is both the start state and a request to start a new MO SMS when one is already in progress, as per GSM 4.11 5.4 const L3CMServiceRequest *req = dynamic_cast<typeof(req)>(l3msg); const GSM::L3MobileIdentity &mobileID = req->mobileID(); // Reference ok - the SM is going to copy it. // FIXME: We only identify this the FIRST time. // The L3IdentifySM can check the MM state and just return. // FIXME: check provisioning return machPush(new L3IdentifyMachine(tran(),mobileID, &mIdentifyResult), stateIdentResult); } case stateIdentResult: { if (! mIdentifyResult) { //const L3CMServiceReject reject = L3CMServiceReject(L3RejectCause::Invalid_Mandatory_Information); // (pat 6-2014) I think this is wrong, based on comment below, so changing it to the main channel: // l3sendSms(L3CMServiceReject(L3RejectCause::Invalid_Mandatory_Information),SAPI0); MMRejectCause rejectCause = L3RejectCause::Invalid_Mandatory_Information; channel()->l3sendm(L3CMServiceReject(rejectCause),L3_DATA,SAPI0); return MachineStatus::QuitTran(TermCause::Local(rejectCause)); } // Let the phone know we're going ahead with the transaction. // The CMServiceReject is on SAPI 0, not SAPI 3. PROCLOG(DEBUG) << "sending CMServiceAccept"; // Update 8-6-2013: The nokia does not accept this message on SACCH SAPI 0 for in-call SMS; // so I am trying moving it to the main channel. //l3sendSms(GSM::L3CMServiceAccept(),SAPI0); channel()->l3sendm(GSM::L3CMServiceAccept(),L3_DATA,SAPI0); gReports.incr("OpenBTS.GSM.SMS.MOSMS.Start"); return MachineStatusOK; } #if FIXME case L3CASE_ERROR: { // (pat) TODO: Call this on parsel3 error... // TODO: Also send an error code to the sip side, if any. l3sendSms(CPError(getL3TI())); return MachineStatusQuitTran; } #endif case L3CASE_SMS(DATA): { timerStop(TCancel); timerStart(TR1M,TR1Mms,TimerAbortTran); // Step 0: Wait for SAP3 to connect. // The first read on SAP3 is the ESTABLISH primitive. // That was done by our caller. //delete getFrameSMS(LCH,GSM::ESTABLISH); // Step 1: This is the first message: CP-DATA, containing RP-DATA. unsigned L3TI = l3msg->TI() | 0x08; tran()->setL3TI(L3TI); const CPData *cpdata = dynamic_cast<typeof(cpdata)>(l3msg); if (cpdata == NULL) { // Currently this is impossible, but maybe someone will change the code later. l3sendSms(CPError(L3TI)); return MachineStatus::QuitTran(TermCause::Local(L3Cause::SMS_Error)); } // Step 2: Respond with CP-ACK. // This just means that we got the message and could parse it. PROCLOG(DEBUG) << "sending CPAck"; l3sendSms(CPAck(L3TI)); // (pat) The SMS message has already been through L3Message:parseL3, which called SMS::parseSMS(source), which manufactured // a CPMessage::CPData and called L3Message::parse() which called CPData::parseBody which called L3Message::parseLV, // which called CPUserData::parseV to leave the result in L3Message::CPMessage::CPData::mData. // As the mathemetician said after filling 3 blackboards with formulas: It is obvious! // FIXME -- We need to set the message ref correctly, even if the parsing fails. // The compiler gives a warning here. Let it. It will remind someone to fix it. // (pat) Update: If we cant parse far enough to get the ref we send a CPError that does not need the ref. #if 0 unsigned ref; bool success = false; try { // (pat) hierarchy is L3Message::CPMessage::CPData; L3Message::parse calls CPData::parseBody. CPData data; data.parse(*CM); LOG(INFO) << "CPData " << data; // Transfer out the RPDU -> TPDU -> delivery. ref = data.RPDU().reference(); // This handler invokes higher-layer parsers, too. success = handleRPDU(transaction,data.RPDU()); } catch (SMSReadError) { LOG(WARNING) << "SMS parsing failed (above L3)"; // Cause 95, "semantically incorrect message". LCH->l3sendf(CPData(L3TI,RPError(95,ref)),3); if you ever use this, it should call l3sendSms delete CM; throw UnexpectedMessage(); } catch (GSM::L3ReadError) { LOG(WARNING) << "SMS parsing failed (in L3)"; delete CM; throw UnsupportedMessage(); } delete CM; #endif // Step 3 // Send CP-DATA containing message ref and either RP-ACK or RP-Error. // If we cant parse the message, we send RP-Error immeidately, otherwise we wait for the dialog to finish one way or the other. const RLFrame &rpdu = cpdata->data().RPDU(); this->mRpduRef = rpdu.reference(); bool success = false; try { // This creates the outgoing SipDialog to send the message. success = handleRPDU(rpdu); } catch (...) { LOG(WARNING) << "SMS parsing failed (above L3)"; } if (! success) { PROCLOG(INFO) << "sending RPError in CPData"; // Cause 95 is "semantically incorrect message" l3sendSms(CPData(L3TI,RPError(95,mRpduRef))); } mSmsState = MoSmsWaitForAck; LOG(DEBUG) << "case DATA returning"; return MachineStatusOK; } case L3CASE_SIP(dialogBye): { // SIPDialog sends this when the MESSAGE clears. PROCLOG(INFO) << "SMS peer did not respond properly to dialog message; sending RPAck in CPData"; l3sendSms(CPData(getL3TI(),RPAck(mRpduRef))); LOG(DEBUG) << "case dialogBye returning"; } case L3CASE_SIP(dialogFail): { PROCLOG(INFO) << "sending RPError in CPData"; // TODO: Map the dialog failure state to an RPError state. // Cause 127 is "internetworking error, unspecified". // See GSM 04.11 8.2.5.4 Table 8.4. l3sendSms(CPData(getL3TI(),RPError(127,mRpduRef))); LOG(DEBUG) << "case dialogFail returning"; } case L3CASE_SMS(ACK): { timerStop(TR1M); // Step 4: Get CP-ACK from the MS. const CPAck *cpack = dynamic_cast<typeof(cpack)>(l3msg); PROCLOG(INFO) << "CPAck " << cpack; gReports.incr("OpenBTS.GSM.SMS.MOSMS.Complete"); /* MOSMS RLLP request */ //if (gConfig.getBool("Control.SMS.QueryRRLP")) { // Query for RRLP //if (!sendRRLP(mobileID, LCH)) { // LOG(INFO) << "RRLP request failed"; //} //} // Done. mSmsState = MoSmsMMConnection; // TODO: if (set) set->mmCallFinished(); LOG(DEBUG) << "case ACK returning"; // This attach causes any pending MT transactions to start now. gMMLayer.mmAttachByImsi(channel(),tran()->subscriberIMSI()); return MachineStatus::QuitTran(TermCause::Local(L3Cause::SMS_Success)); } default: LOG(DEBUG) << "unexpected state"; return unexpectedState(state,l3msg); } }
int main() { int a,b,c,i,temp,temp1,temp2,result; double k,z,y1,k1,k2; FILE *fin = fopen ("fence9.in", "r"); FILE *fout = fopen ("fence9.out", "w"); fscanf(fin,"%d %d %d",&a,&b,&c); result=0; if(c==a) { k=tran((double)b,(double)a); for(i=1;i<a;i++) { y1=k*(double)i; temp=(int)y1; if((double)temp>y1) temp--; if(y1-(double)temp<0.0001) temp--; result+=temp; } } else if(c>a) { k=tran((double)b,(double)a); for(i=1;i<=a;i++) { y1=k*(double)i; temp=(int)y1; if((double)temp>y1) temp--; if(y1-(double)temp<0.0001) temp--; result+=temp; } k=tran((double)b,(double)(a-c)); z=tran((double)(b*c),(double)(-a+c)); for(;i<c;i++) { y1=k*(double)i+z; temp=(int)y1; if((double)temp>y1) temp--; if(y1-(double)temp<0.0001) temp--; result+=temp; } } else { k1=tran((double)b,(double)a); for(i=1;i<c;i++) { y1=k1*(double)i; temp1=(int)y1; if((double)temp1>y1) temp1--; if(y1-(double)temp1<0.0001) temp1--; result+=temp1; } k2=tran((double)b,(double)(a-c)); z=tran((double)(b*c),(double)(-a+c)); for(;i<a;i++) { y1=k1*(double)i; temp1=(int)y1; if((double)temp1>y1) temp1--; if(y1-(double)temp1<0.0001) temp1--; y1=k2*(double)i+z; temp2=(int)y1; if((double)temp2<y1) temp2++; if((double)temp2-y1<0.0001) temp2++; result+=temp1-temp2+1; } } fprintf(fout,"%d\n",result); return 0; }
//${AOs::Table::SM::active::serving} ......................................... Q_STATE_DEF(Table, serving) { QP::QState status_; switch (e->sig) { //${AOs::Table::SM::active::serving} case Q_ENTRY_SIG: { for (uint8_t n = 0U; n < N_PHILO; ++n) { // give permissions to eat... if (m_isHungry[n] && (m_fork[LEFT(n)] == FREE) && (m_fork[n] == FREE)) { m_fork[LEFT(n)] = USED; m_fork[n] = USED; QP::QF::PUBLISH(Q_NEW(TableEvt, EAT_SIG, n), this); m_isHungry[n] = false; BSP_displayPhilStat(n, EATING); } } status_ = Q_RET_HANDLED; break; } //${AOs::Table::SM::active::serving::HUNGRY} case HUNGRY_SIG: { uint8_t n = Q_EVT_CAST(TableEvt)->philoNum; // phil ID must be in range and he must be not hungry Q_ASSERT((n < N_PHILO) && (!m_isHungry[n])); BSP_displayPhilStat(n, HUNGRY); uint8_t m = LEFT(n); //${AOs::Table::SM::active::serving::HUNGRY::[bothfree]} if ((m_fork[m] == FREE) && (m_fork[n] == FREE)) { m_fork[m] = USED; m_fork[n] = USED; QP::QF::PUBLISH(Q_NEW(TableEvt, EAT_SIG, n), this); BSP_displayPhilStat(n, EATING); status_ = Q_RET_HANDLED; } //${AOs::Table::SM::active::serving::HUNGRY::[else]} else { m_isHungry[n] = true; status_ = Q_RET_HANDLED; } break; } //${AOs::Table::SM::active::serving::DONE} case DONE_SIG: { uint8_t n = Q_EVT_CAST(TableEvt)->philoNum; // phil ID must be in range and he must be not hungry Q_ASSERT((n < N_PHILO) && (!m_isHungry[n])); BSP_displayPhilStat(n, THINKING); uint8_t m = LEFT(n); // both forks of Phil[n] must be used Q_ASSERT((m_fork[n] == USED) && (m_fork[m] == USED)); m_fork[m] = FREE; m_fork[n] = FREE; m = RIGHT(n); // check the right neighbor if (m_isHungry[m] && (m_fork[m] == FREE)) { m_fork[n] = USED; m_fork[m] = USED; m_isHungry[m] = false; QP::QF::PUBLISH(Q_NEW(TableEvt, EAT_SIG, m), this); BSP_displayPhilStat(m, EATING); } m = LEFT(n); // check the left neighbor n = LEFT(m); // left fork of the left neighbor if (m_isHungry[m] && (m_fork[n] == FREE)) { m_fork[m] = USED; m_fork[n] = USED; m_isHungry[m] = false; QP::QF::PUBLISH(Q_NEW(TableEvt, EAT_SIG, m), this); BSP_displayPhilStat(m, EATING); } status_ = Q_RET_HANDLED; break; } //${AOs::Table::SM::active::serving::EAT} case EAT_SIG: { Q_ERROR(); status_ = Q_RET_HANDLED; break; } //${AOs::Table::SM::active::serving::PAUSE} case PAUSE_SIG: { status_ = tran(&paused); break; } default: { status_ = super(&active); break; } } return status_; }
std::vector<int> deal(char s[]) { std::vector<int> r; int sz = strlen(s); int flag = 2 , sign = 1;//0 digit,-1 flag, 1 int sum = 0; for(int i=0; i<sz; i++) { if(flag == 1 || flag == -1) { sign = flag; sum = 0; if(dig(s[i])) { sum *= 10; sum += (sign*(s[i]-'0')); // printf("%d\n",sum); flag = 0; } else { if(flag == 1) { r.push_back('+'); } else r.push_back('-'); if(s[i] == '+') flag = 1; else if(s[i] == '-') flag = -1; else { flag = 2; r.push_back(tran(s[i])); } } } else if(flag == 0) { if(dig(s[i])) { sum *= 10; sum += (sign*(s[i]-'0')); flag = 0; } else if(ltr(s[i])) { sum -= MAX; r.push_back(sum); sum = 0; sign = 1; flag = 2; r.push_back(tran(s[i])); } else if(s[i] == '+') { flag = 2; sum -= MAX; r.push_back(sum); sum = 0; sign = 1; r.push_back('+'); } else if(s[i] == '-') { flag = 2; r.push_back(sum); sum =0; sign = 1; //printf("%d\n",'-'); r.push_back('-'); } } else if(flag == 2) { sum = 0; if(dig(s[i])) { sign = 1; sum *= 10; sum += (sign*(s[i]-'0')); // printf("%dhi",sum); flag = 0; } else if(ltr(s[i])) { r.push_back(tran(s[i])); flag = 2; } else { if(s[i] == '+') { flag = 1; } else if(s[i] == '-') { flag = -1; } sum = 0; } sign = 1; } } // printf("%d %d\n",flag,sum); if(flag == 0) { /* printf("hello"); for(int k=0;k<r.size();k++) printf("hello kk %d\n",r[k]); printf("\n");*/ sum -= MAX; r.push_back(sum); } else if(flag == 1 || flag == -1) { if(flag == 1) r.push_back('+'); else r.push_back('-'); } return r; }
void pSubChain::disassembly_body() { // for space if(!children[1]) return; #ifdef VERBOSE update_log << "disassembly_body" << endl; #endif #ifdef USE_MPI if(sim->rank != rank) return; if(parent && sim->rank != parent->rank) { #ifdef TIMING_CHECK cerr << "[" << sim->rank << "] " << last_joint->name << ": recv force from " << parent->last_joint->name << " [" << parent->rank << "] t = " << MPI_Wtime()-update_start_time << endl; #endif parent->recv_force(); } #endif int i; #ifdef TIMING_CHECK if(children[1] && children[0] != children[1] && sim->rank != children[1]->rank) cerr << "[" << sim->rank << "] " << last_joint->name << " enter disassembly t = " << MPI_Wtime()-update_start_time << endl; #endif // compute final constraint force static fVec KLf, Lf(6), Lf_temp[2], v(6), f, f_final(6); KLf.resize(n_const); Lf_temp[0].resize(6); Lf_temp[1].resize(6); f.resize(n_const); Lf_temp[0].zero(); Lf_temp[1].zero(); for(i=0; i<n_outer_joints; i++) { int org = outer_joints_origin[i]; int index = outer_joints_index[i]; fMat& Lambda_i = children[org]->Lambda[last_index[org]][index]; // first multiply and increment // v.mul(Lambda_i, children[org]->outer_joints[index]->f_final); v.mul(Lambda_i, outer_joints[i]->f_final); #ifdef VERBOSE // update_log << "children[" << org << "]->Lambda[" << last_index[org] << "][" << index << "] = " << Lambda_i << endl; update_log << outer_joints[i]->joint->name << ": f_final[" << i << "] = " << tran(outer_joints[i]->f_final) << endl; #endif Lf_temp[org] += v; } Lf.sub(Lf_temp[0], Lf_temp[1]); // update_log << "Lf_temp[0] = " << tran(Lf_temp[0]) << endl; // update_log << "Lf_temp[1] = " << tran(Lf_temp[1]) << endl; // all test codes removed on 02/09/2007 static fVec pp(6); #ifndef USE_DCA // new formulation pp.add(da6, Lf); f_final.mul(W, pp); for(i=0; i<n_dof; i++) f_final(joint_index[i]) += tau(i); last_pjoints[0]->f_final.set(f_final); last_pjoints[1]->f_final.neg(f_final); v.mul(IW, pp); for(i=0; i<n_dof; i++) { acc_final(i) = v(joint_index[i]); } last_joint->joint_f.set(fVec3(f_final(0), f_final(1), f_final(2))); last_joint->joint_n.set(fVec3(f_final(3), f_final(4), f_final(5))); #else // #ifndef USE_DCA (DCA test) static fVec vp(6), svp; svp.resize(n_dof); pp.set(da6); pp += Lf; vp.mul(Vhat, pp); for(i=0; i<n_dof; i++) { svp(i) = tau(i) + vp(joint_index[i]); } acc_final.lineq_posv(SVS, svp); // cerr << "SVS = " << SVS << endl; // cerr << "svp = " << tran(svp) << endl; // cerr << "acc_final = " << tran(acc_final) << endl; v.zero(); switch(last_joint->j_type) { case JROTATE: case JSLIDE: v(axis) = acc_final(0); break; case JSPHERE: v(3) = acc_final(0); v(4) = acc_final(1); v(5) = acc_final(2); break; case JFREE: v.set(acc_final); break; } pp -= v; f_final.mul(Vhat, pp); last_pjoints[0]->f_final.neg(f_final); last_pjoints[1]->f_final.set(f_final); #endif #ifndef USE_MPI if(last_joint->t_given) { switch(last_joint->j_type) { case JROTATE: case JSLIDE: last_joint->SetJointAcc(v(axis)); // cerr << last_joint->name << ": " << v(axis) << endl; break; case JSPHERE: last_joint->SetJointAcc(v(3), v(4), v(5)); break; case JFREE: last_joint->SetJointAcc(v(0), v(1), v(2), v(3), v(4), v(5)); #ifdef VERBOSE update_log << last_joint->name << ": " << tran(v) << endl; #endif break; default: break; } } #endif #ifdef USE_MPI if(children[0] && sim->rank != children[0]->rank) { #ifdef TIMING_CHECK cerr << "[" << sim->rank << "] " << last_joint->name << ": send force to " << children[0]->last_joint->name << " [" << children[0]->rank << "] t = " << MPI_Wtime()-update_start_time << endl; #endif send_force(children[0]->rank); } if(children[1] && children[0] != children[1] && sim->rank != children[1]->rank) { #ifdef TIMING_CHECK cerr << "[" << sim->rank << "] " << last_joint->name << ": send force to " << children[1]->last_joint->name << " [" << children[1]->rank << "] t = " << MPI_Wtime()-update_start_time << endl; #endif send_force(children[1]->rank); } #endif }
void plfill_soft(short *x, short *y, PLINT n) { PLINT i, j; PLINT xp1, yp1, xp2, yp2, xp3, yp3; PLINT k, dinc; PLFLT ci, si; double temp; buffersize = 2 * BINC; buffer = (PLINT *) malloc((size_t) buffersize * sizeof(PLINT)); if ( ! buffer) { plabort("plfill: Out of memory"); return; } /* Loop over sets of lines in pattern */ for (k = 0; k < plsc->nps; k++) { bufferleng = 0; temp = DTOR * plsc->inclin[k] * 0.1; si = sin(temp) * plsc->ypmm; ci = cos(temp) * plsc->xpmm; /* normalize: 1 = si*si + ci*ci */ temp = sqrt((double) (si*si + ci*ci)); si /= temp; ci /= temp; dinc = plsc->delta[k] * SSQR(plsc->ypmm * ABS(ci), plsc->xpmm * ABS(si)) / 1000.; if (dinc < 0) dinc = -dinc; if (dinc == 0) dinc = 1; xp1 = x[n-2]; yp1 = y[n-2]; tran(&xp1, &yp1, (PLFLT) ci, (PLFLT) si); xp2 = x[n-1]; yp2 = y[n-1]; tran(&xp2, &yp2, (PLFLT) ci, (PLFLT) si); /* Loop over points in polygon */ for (i = 0; i < n; i++) { xp3 = x[i]; yp3 = y[i]; tran(&xp3, &yp3, (PLFLT) ci, (PLFLT) si); buildlist(xp1, yp1, xp2, yp2, xp3, yp3, dinc); xp1 = xp2; yp1 = yp2; xp2 = xp3; yp2 = yp3; } /* Sort list by y then x */ qsort((void *) buffer, (size_t) bufferleng / 2, (size_t) sizeof(struct point), compar); /* OK, now do the hatching */ i = 0; while (i < bufferleng) { xp1 = buffer[i]; yp1 = buffer[i + 1]; i += 2; xp2 = xp1; yp2 = yp1; tran(&xp1, &yp1, (PLFLT) ci, (PLFLT) (-si)); plP_movphy(xp1, yp1); xp1 = buffer[i]; yp1 = buffer[i + 1]; i += 2; if (yp2 != yp1) { fprintf(stderr, "plfill: oh oh we are lost\n"); for (j = 0; j < bufferleng; j+=2) { fprintf(stderr, "plfill: %d %d\n", (int) buffer[j], (int) buffer[j+1]); } continue; /* Uh oh we're lost */ } tran(&xp1, &yp1, (PLFLT) ci, (PLFLT) (-si)); plP_draphy(xp1, yp1); } } free((void *) buffer); }
/******************************************************** Main Function **************************************************/ int main (int argc, char **argv) { //inputs FILE *f_src; //source file pointer FILE *f_src_ctr; //source center file //outputs FILE *f_cid; //cluster-id file pointer FILE *f_mfi; //added April 16, 2009 char name_string[LINE_LEN]; //for name use int time_id=-1; long file_Len=0; long num_clust=0; long num_dm=0; long norm_used=0; long dist_used=0; long i=0; long j=0; long *cluster_id; long *IDmapping; //this is to keep the original populationID of the center.txt double kmean_term=0; double **cluster_center; double **orig_data; double **normalized_data; /* _strtime( tmpbuf ); printf( "Starting time:\t\t\t\t%s\n", tmpbuf ); _strdate( tmpbuf ); printf( "Starting date:\t\t\t\t%s\n", tmpbuf ); */ if (argc!=3) { //modified on July 23, 2010 fprintf(stderr, "usage: cent_adjust input_center input_data_file\n"); abort(); } f_src_ctr=fopen(argv[1],"r"); //read source data f_src=fopen(argv[2],"r"); getfileinfo(f_src, &file_Len, &num_dm, name_string, &time_id); //get the filelength, number of dimensions, and num/name of parameters rewind(f_src); //reset data file pointer orig_data = (double **)malloc(sizeof(double*)*file_Len); memset(orig_data,0,sizeof(double*)*file_Len); for (i=0;i<file_Len;i++) { orig_data[i]=(double *)malloc(sizeof(double)*num_dm); memset(orig_data[i],0,sizeof(double)*num_dm); } readsource(f_src, file_Len, num_dm, orig_data, time_id); //read the data; fclose(f_src); ///////////////////////////////////////////////////////////////////////////// getctrfileinfo(f_src_ctr, &num_clust); //get how many populations norm_used=0; dist_used=0; kmean_term=3; //modified on Oct 16, 2009: changed kmean_term=1 to kmean_term=2 rewind(f_src_ctr); //reset center file pointer //read population center cluster_center=(double **)malloc(sizeof(double*)*num_clust); memset(cluster_center,0,sizeof(double*)*num_clust); for (i=0;i<num_clust;i++) { cluster_center[i]=(double*)malloc(sizeof(double)*num_dm); memset(cluster_center[i],0,sizeof(double)*num_dm); } for (i=0;i<num_clust;i++) for (j=0;j<num_dm;j++) cluster_center[i][j]=0; IDmapping=(long *)malloc(sizeof(long)*num_clust); memset(IDmapping,0,sizeof(long)*num_clust); readcenter(f_src_ctr,num_clust,num_dm,cluster_center,IDmapping); //read population center fclose(f_src_ctr); ///////////////////////////////////////////////////////////////////////////// normalized_data=(double **)malloc(sizeof(double*)*file_Len); memset(normalized_data,0,sizeof(double*)*file_Len); for (i=0;i<file_Len;i++) { normalized_data[i]=(double *)malloc(sizeof(double)*num_dm); memset(normalized_data[i],0,sizeof(double)*num_dm); } tran(orig_data, file_Len, num_dm, norm_used, normalized_data); /************************************************* Compute number of clusters *************************************************/ cluster_id=(long*)malloc(sizeof(long)*file_Len); memset(cluster_id,0,sizeof(long)*file_Len); assign_event(normalized_data,num_clust,dist_used,kmean_term,file_Len,num_dm,cluster_id,cluster_center,0); //show(orig_data,cluster_id,file_Len,num_clust,num_dm,show_data,num_disp,name_string); show(orig_data, cluster_id, file_Len, num_clust, num_dm, name_string, IDmapping); f_cid=fopen("population_id.txt","w"); for (i=0;i<file_Len;i++) fprintf(f_cid,"%d\n",IDmapping[cluster_id[i]]); fclose(f_cid); //added April 16, 2009 f_mfi=fopen("MFI.txt","w"); for (i=0;i<num_clust;i++) { fprintf(f_mfi,"%d\t",IDmapping[i]); for (j=0;j<num_dm;j++) { if (j==num_dm-1) fprintf(f_mfi,"%.0f\n",cluster_center[i][j]); else fprintf(f_mfi,"%.0f\t",cluster_center[i][j]); } } fclose(f_mfi); //ended April 16, 2009 for (i=0;i<num_clust;i++) free(cluster_center[i]); free(cluster_center); /********************************************** Release memory ******************************************/ for (i=0;i<file_Len;i++) { free(orig_data[i]); free(normalized_data[i]); } free(orig_data); free(normalized_data); free(cluster_id); free(IDmapping); /* _strtime( tmpbuf ); printf( "Ending time:\t\t\t\t%s\n", tmpbuf ); _strdate( tmpbuf ); printf( "Ending date:\t\t\t\t%s\n", tmpbuf ); */ }