Esempio n. 1
0
void annealing(TSP *tsp)
{
    Path   p;
    int    i, j, pathchg;
    int    numOnPath, numNotOnPath;
    DTYPE    pathlen;
    int    n = tsp->n;
    double energyChange, T;

    pathlen = pathLength (tsp); 

    for (T = T_INIT; T > FINAL_T; T *= COOLING)  /* annealing schedule */
    {
        pathchg = 0;
        for (j = 0; j < TRIES_PER_T; j++)
        {
            do {
                p[0] = unifRand (n);
                p[1] = unifRand (n);
                /* non-empty path */
                if (p[0] == p[1]) p[1] = MOD(p[0]+1,n);
                numOnPath = MOD(p[1]-p[0],n) + 1;
                numNotOnPath = n - numOnPath;
            } while (numOnPath < 2 || numNotOnPath < 2); /* non-empty path */
            
            if (RANDOM() % 2) /*  threeWay */
            {
                do {
                    p[2] = MOD(unifRand (numNotOnPath)+p[1]+1,n);
                } while (p[0] == MOD(p[2]+1,n)); /* avoids a non-change */

                energyChange = getThreeWayCost (tsp, p);
                if (energyChange < 0 || RREAL < exp(-energyChange/T) )
                {
                    pathchg++;
                    pathlen += energyChange;
                    doThreeWay (tsp, p);
                }
            }
            else            /* path Reverse */
            {
                energyChange = getReverseCost (tsp, p);
                if (energyChange < 0 || RREAL < exp(-energyChange/T))
                {
                    pathchg++;
                    pathlen += energyChange;
                    doReverse(tsp, p); 
                }
            }
            // if the new length is better than best then save it as best
            if (pathlen < tsp->bestlen) {
                tsp->bestlen = pathlen;
                for (i=0; i<tsp->n; i++) tsp->border[i] = tsp->iorder[i];
            }
            if (pathchg > IMPROVED_PATH_PER_T) break; /* finish early */
        }   
        DBG("T:%f L:%f B:%f C:%d", T, pathlen, tsp->bestlen, pathchg);
        if (pathchg == 0) break;   /* if no change then quit */
    }
}
Esempio n. 2
0
int F846302(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
//	ret=pAccTrans->checkCfgUpdate();
//	if(ret)
//		return ret;
	des2src(pAccTrans->trans.opercode,rPack->semp);
	pAccTrans->trans.transcode=TC_CARDOPENREV;
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;			
	TRANS& trans=pAccTrans->trans;
	char authrightflag=rPack->sstatus2[0];
	des2src(trans.chkopercode,rPack->semp_no);
	if('1'==authrightflag)
	{
		ret=chk_oper_pwd(trans.chkopercode,rPack->scust_limit);
		if(ret)
			return ret;
	}
	ST_CPACK aPack;
	ST_PACK *outPack = &(aPack.pack);

	ResetNormalCPack(&aPack,0,1);
		

	char oldaccdate[9]="";
	des2src(oldaccdate,rPack->sdate3);
	int oldtermid=rPack->lwithdraw_flag;
	int oldtermseqno=rPack->lserial1;
	trans.dpscnt=rPack->lvol5;
	trans.paycnt=rPack->lvol6;
	trans.cardbefbal=rPack->lvol7;
	des2src(trans.cardphyid,rPack->sstation1);
	if(trans.dpscnt>1||trans.paycnt>0)
		return E_CARD_USED;
	if(strlen(oldaccdate)<1)
		return E_INPUTNULL_ACCDATE;
	if(oldtermid<1)
		return E_INPUTNULL_TERMID;
	if(oldtermseqno<1)
		return E_INPUTNULL_TERMSEQNO;
	SetCol(handle,F_LVOL0,F_LVOL8,F_SDATE3,F_SEMP,F_LSERIAL1,F_SSTATION0,F_VSMESS,F_STIME3,0);	
	ret=doReverse(oldaccdate,oldtermid,oldtermseqno,outPack->sstation0);
	if(ret)
		return ret;
	outPack->lvol0=pAccTrans->trans.cardno;
	outPack->lvol8=0;
	des2src(outPack->sdate3,pAccTrans->trans.accdate);
	des2src(outPack->stime3,pAccTrans->trans.acctime);
	des2src(outPack->semp,pAccTrans->trans.opercode);
	outPack->lserial1=pAccTrans->trans.termseqno;
	strcpy(outPack->vsmess,"开户冲正成功");
	strcat(outPack->vsmess,pAccTrans->remark.c_str());
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}
Esempio n. 3
0
List ReverseList (List L)
{
    List newHead;

    doReverse (&L, &newHead);

    L->next = NULL;

    return newHead;

}
Esempio n. 4
0
void doReverse (List *L, List *newHead)
{
    if (!(*L)->next) {
        *newHead = *L;
        return;
    }

    doReverse(&(*L)->next, newHead);

    (*L)->next->next = *L;

    return;
}
Esempio n. 5
0
int F846315(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	ST_CPACK aPack;
	ST_PACK *outPack = &(aPack.pack);

	ResetNormalCPack(&aPack,0,1);
		

	char oldaccdate[9]="";
	des2src(oldaccdate,rPack->sdate3);
	int oldtermid=rPack->lwithdraw_flag;
	int oldtermseqno=rPack->lserial1;
	
	char authrightflag=rPack->sstatus2[0];

	if(strlen(oldaccdate)<1)
		return E_INPUTNULL_ACCDATE;
	if(oldtermid<1)
		return E_INPUTNULL_TERMID;
	if(oldtermseqno<1)
		return E_INPUTNULL_TERMSEQNO;

	if('1'==authrightflag)
	{
		ret=chk_oper_pwd(rPack->semp_no,rPack->scust_limit);
		if(ret)
			return ret;
	}
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	ret=pAccTrans->checkCfgUpdate();
	if(ret)
		return ret;
	pAccTrans->clear();
	GetCpackDataString(rPack,pAccTrans->cpackdata);
	pAccTrans->trans.transcode=TC_TRANSREV;
	ret=pAccTrans->addOperDtl(rPack->semp);
	if(ret)
		return ret;	
	ret=doReverse(authrightflag,oldaccdate,oldtermid,oldtermseqno);
	if(ret)
		return ret;
	SetCol(handle,F_LVOL0,F_LVOL8,F_SDATE3,F_SEMP,F_LSERIAL1,F_VSMESS,0);	
	outPack->lvol0=pAccTrans->trans.cardno;
	outPack->lvol8=0;
	des2src(outPack->sdate3,pAccTrans->trans.accdate);
	des2src(outPack->semp,pAccTrans->trans.opercode);
	outPack->lserial1=pAccTrans->trans.termseqno;
	strcpy(outPack->vsmess,pAccTrans->remark.c_str());
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
task main ()
{
	ubyte type;
	ubyte ID;
	ubyte state;
	ubyte value;
	string dataString;
	string tmpString;

	// initialise the port, etc
	RS485initLib();

	StartTask(updateScreen);

	// Disconnect if already connected
	N2WDisconnect();
	N2WchillOut();
	wait1Msec(1000);
  if (!N2WCustomExist())
  {
    StopTask(updateScreen);
    wait1Msec(50);
    eraseDisplay();
    PlaySound(soundException);
    nxtDisplayCenteredBigTextLine(1, "ERROR");
    nxtDisplayTextLine(3, "No custom profile");
    nxtDisplayTextLine(4, "configured!!");
    while(true) EndTimeSlice();
  }

  N2WLoad();

	wait1Msec(100);

	N2WConnect(true);
	connStatus = "connecting";

	while (!N2WConnected()) wait1Msec(100);
	wait1Msec(1000);

	connStatus = "connected";
	PlaySound(soundBeepBeep);

	wait1Msec(3000);
	N2WgetIP(IPaddress);

	wait1Msec(1000);
	//                123456789012345
	dataStrings[0] = "Tch | Snr | Clr";
	//                on  | 011 |   1"
	while (true)
	{
		if (N2WreadWS(type, ID, state, value))
		{
			writeDebugStreamLine("btn: %d, state: %d", ID, state);
			switch (ID)
			{
			case 1: doStraight(state); break;
			case 3: doRight(state); break;
			case 4: doStop(state); break;
			case 5: doLeft(state); break;
			case 7: doReverse(state); break;
			case 9: doAction(state); break;
			case 11: handleColour(state); break;
			default: break;
			}
		}

		// All values are only updated when they've changed.
		// This cuts backs drastically on the number of messages
		// that have to be sent to the NXT2WIFI

		// Fetch the state of the Touch Sensor
		// This value is displayed by field 0 (in0) on the page
		currTouchState = SensorBoolean[TOUCH];
		if (currTouchState != prevTouchState)
		{
		  memset(data, 0, sizeof(data));
			data[0] = (currTouchState) ? '1' : '0';
			N2WwriteWS(1, 0, data, 2);
			prevTouchState = currTouchState;
			N2WchillOut();
		}

		// Fetch the currently detected colour.
		// This value is displayed by field 1 (in1) on the page
		currDetectedColour = SensorValue[COLOUR];
		if (currDetectedColour != prevDetectedColour)
		{
			sprintf(dataString, "%d", currDetectedColour);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 1, data, strlen(dataString));
			prevDetectedColour = currDetectedColour;
			N2WchillOut();
		}

		// Fetch the distance detected by the sonar sensor
		// This value is displayed by field 2 (in2) on the page
		currSonarDistance = SensorValue[SONAR];
		if (currSonarDistance != prevSonarDistance)
		{
			sprintf(dataString, "%d", currSonarDistance);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 2, data, strlen(dataString));
			prevSonarDistance = currSonarDistance;
			N2WchillOut();
		}

		// Fetch the tacho count for motor A
		// This value is displayed by field 3 (in3) on the page
		currEncMotorA = nMotorEncoder[MOT_ACTION];
		if (currEncMotorA != prevEncMotorA)
		{
			sprintf(dataString, "%d", currEncMotorA);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 3, data, strlen(dataString));
			prevEncMotorA = currEncMotorA;
			N2WchillOut();
		}

		// Fetch the tacho count for motor B
		// This value is displayed by field 4 (in4) on the page
		//currEncMotorB = nMotorEncoder[MOT_LEFT];
		if (currEncMotorB != prevEncMotorB)
		{
			sprintf(dataString, "%d", currEncMotorB);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 4, data, strlen(dataString));
			prevEncMotorB = currEncMotorB;
			N2WchillOut();
		}

		// Fetch the tacho count for motor C
		// This value is displayed by field 5 (in5) on the page
		currEncMotorC = nMotorEncoder[MOT_RIGHT];
		if (currEncMotorC != prevEncMotorC)
		{
			sprintf(dataString, "%d", currEncMotorC);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 5, data, strlen(dataString));
			prevEncMotorC = currEncMotorC;
			N2WchillOut();
		}

		// Fetch the current voltage level.  The average one
		// works best, the other one jumps around too much.
		// This value is displayed by field 6 (in6) on the page

		currBatteryLevel = nAvgBatteryLevel;
		if (currBatteryLevel != prevBatteryLevel)
		{
			sprintf(dataString, "%d", currBatteryLevel);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 6, data, strlen(dataString));
			prevBatteryLevel = currBatteryLevel;
			N2WchillOut();
		}

		sprintf(dataStrings[2], "A: %d", currEncMotorA);
		sprintf(dataStrings[3], "B: %d", currEncMotorB);
		sprintf(dataStrings[4], "C: %d", currEncMotorC);
	  sprintf(tmpString, "%s | %3d", (currTouchState == 0) ? "off" : "on ", currSonarDistance);
		sprintf(dataStrings[1], "%s | %3d", tmpString, currDetectedColour);
	}
}
Esempio n. 7
0
int F950053(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	ret=pAccTrans->CheckCfgUpdate();
	if(ret)
		return ret;
	int lastdevseqno=rPack->lvol4;
	char devphyid[31]="";
	des2src(devphyid,rPack->sdate1);
	T_t_transdtl transdtl;

	memset(&transdtl,0,sizeof(transdtl));
	ret=DB_t_transdtl_read_by_transdate_and_devphyid_and_devseqno(trans.transdate,devphyid,lastdevseqno,&transdtl);
	if(ret)
	{
		writelog(LOG_ERR,"transdate[%s]devphyid[%s]devseqno[%d]",trans.transdate,devphyid,lastdevseqno);
		if(DB_NOTFOUND==ret)
			return 0;
		else
			return E_DB_TRANSDTL_R;

	}
	if(transdtl.revflag[0]=='1')
	{
		return 0;
	}
	ret=GetDevIdByDevPhyId(&(trans.termid),devphyid);
	if(ret)
	{
		return ret;
	}
 	pAccTrans->GetTermSeqno();
	if(transdtl.transcode==TC_POSDEPOSIT)
		pAccTrans->trans.transcode=TC_POSDEPOSITREV;
	else if(transdtl.transcode==TC_SHOPPOSDEPOSIT)
		pAccTrans->trans.transcode=TC_SHOPPOSDEPOSITREV;
	else
		return E_TRANSCODE_NOT_SAVING;
	ret=doReverse(transdtl.accdate,transdtl.termid,transdtl.termseqno);
	if(ret)
		return ret;
	
	ST_CPACK aPack;
	ST_PACK *outPack = &(aPack.pack);

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL5,F_LVOL10,F_LCERT_CODE,0);
	
	outPack->lvol5 = transdtl.cardno;
	outPack->lvol10 = (int)D4U5(transdtl.cardaftbal*100,0);
	outPack->lcert_code = transdtl.termseqno;
	
//	outPack->lvol0=pAccTrans->trans.cardno;
//	outPack->lvol8=D4U5(pAccTrans->trans.cardaftbal*100,0);
//	des2src(outPack->sdate3,pAccTrans->sysPara.sSettleDate);
//	des2src(outPack->semp,pAccTrans->trans.opercode);
//	outPack->lserial1=pAccTrans->trans.termseqno;
	sprintf(outPack->vsmess,"冲正金额%.2lf 卡余额%.2lf",trans.transamt,trans.cardaftbal);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
} 
task main ()
{
	ubyte type;
	ubyte ID;
	ubyte state;
	ubyte value;
	string dataString;
	string tmpString;

	// initialise the port, etc
	RS485initLib();

	StartTask(updateScreen);

	// Disconnect if already connected
	N2WDisconnect();
	N2WchillOut();
	wait1Msec(1000);
	// enable DHCP
	N2WsetDHCP(true);
	wait1Msec(100);
	// Disable adhoc
	N2WsetAdHoc(false);
	wait1Msec(100);

	// Network Configuration
	N2WsetMask("255.255.255.0");
	wait1Msec(100);
	N2WsetGateway("10.0.0.138");
	wait1Msec(100);
	N2WsetDNS1("8.8.8.8");
	wait1Msec(100);
	N2WsetDNS2("8.8.4.4");
	wait1Msec(100);
	N2WsetNetbiosName("NXT2WIFI1");
	wait1Msec(100);

	// SSID to connect to
	N2WsetSSID("test");
	wait1Msec(100);
	// The passphrase to use
	N2WSecurityWPA2Passphrase("pwasde08");
	wait1Msec(100);
	// Save this profile to the custom profile
	N2WSave();
	wait1Msec(500);
	// Load the custom profile
	N2WLoad();
	wait1Msec(100);

	N2WConnect(true);
	connStatus = "connecting";

	while (!N2WConnected()) wait1Msec(100);
	wait1Msec(1000);

	connStatus = "connected";
	PlaySound(soundBeepBeep);

	wait1Msec(3000);
	N2WgetIP(IPaddress);

	wait1Msec(1000);
	//                123456789012345
	dataStrings[0] = "Tch | Snr | Clr";
	//                on  | 011 |   1"
	while (true)
	{
		if (N2WreadWS(type, ID, state, value))
		{
			writeDebugStreamLine("btn: %d, state: %d", ID, state);
			switch (ID)
			{
			case 1: doStraight(state); break;
			case 3: doRight(state); break;
			case 4: doStop(state); break;
			case 5: doLeft(state); break;
			case 7: doReverse(state); break;
			case 9: doAction(state); break;
			case 11: handleColour(state); break;
			default: break;
			}
		}

		// All values are only updated when they've changed.
		// This cuts backs drastically on the number of messages
		// that have to be sent to the NXT2WIFI

		// Fetch the state of the Touch Sensor
		// This value is displayed by field 0 (in0) on the page
		currTouchState = SensorValue[TOUCH];
		if (currTouchState != prevTouchState)
		{
			sprintf(dataString, "%d", currTouchState);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 0, data, strlen(&data));
			prevTouchState = currTouchState;
			N2WchillOut();
		}

		// Fetch the currently detected colour.
		// This value is displayed by field 1 (in1) on the page
		currDetectedColour = SensorValue[COLOUR];
		if (currDetectedColour != prevDetectedColour)
		{
			sprintf(dataString, "%d", currDetectedColour);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 1, data, strlen(dataString));
			prevDetectedColour = currDetectedColour;
			N2WchillOut();
		}

		// Fetch the distance detected by the sonar sensor
		// This value is displayed by field 2 (in2) on the page
		currSonarDistance = SensorValue[SONAR];
		if (currSonarDistance != prevSonarDistance)
		{
			sprintf(dataString, "%d", currSonarDistance);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 2, data, strlen(dataString));
			prevSonarDistance = currSonarDistance;
			N2WchillOut();
		}

		// Fetch the tacho count for motor A
		// This value is displayed by field 3 (in3) on the page
		currEncMotorA = nMotorEncoder[MOT_ACTION];
		if (currEncMotorA != prevEncMotorA)
		{
			sprintf(dataString, "%d", currEncMotorA);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 3, data, strlen(dataString));
			prevEncMotorA = currEncMotorA;
			N2WchillOut();
		}

		// Fetch the tacho count for motor B
		// This value is displayed by field 4 (in4) on the page
		currEncMotorB = nMotorEncoder[MOT_LEFT];
		if (currEncMotorB != prevEncMotorB)
		{
			sprintf(dataString, "%d", currEncMotorB);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 4, data, strlen(dataString));
			prevEncMotorB = currEncMotorB;
			N2WchillOut();
		}

		// Fetch the tacho count for motor C
		// This value is displayed by field 5 (in5) on the page
		currEncMotorC = nMotorEncoder[MOT_RIGHT];
		if (currEncMotorC != prevEncMotorC)
		{
			sprintf(dataString, "%d", currEncMotorC);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 5, data, strlen(dataString));
			prevEncMotorC = currEncMotorC;
			N2WchillOut();
		}

		// Fetch the current voltage level.  The average one
		// works best, the other one jumps around too much.
		// This value is displayed by field 6 (in6) on the page

		currBatteryLevel = nAvgBatteryLevel;
		if (currBatteryLevel != prevBatteryLevel)
		{
			sprintf(dataString, "%d", currBatteryLevel);
			memcpy(data, dataString, strlen(dataString));
			N2WwriteWS(1, 6, data, strlen(dataString));
			prevBatteryLevel = currBatteryLevel;
			N2WchillOut();
		}

		sprintf(dataStrings[2], "A: %d", currEncMotorA);
		sprintf(dataStrings[3], "B: %d", currEncMotorB);
		sprintf(dataStrings[4], "C: %d", currEncMotorC);
	sprintf(tmpString, "%s | %3d", (currTouchState == 0) ? "off" : "on ", currSonarDistance);
		sprintf(dataStrings[1], "%s | %3d", tmpString, currDetectedColour);
	}
}
Esempio n. 9
0
void
TSP::annealing() {
    Path   p;
    size_t    numOnPath, numNotOnPath;

    double pathCost(dist.pathCost(iorder));
    const double T_INIT = 100.0;
    const double FINAL_T = 0.1;
    const double COOLING = 0.9; /* to lower down T (< 1) */
    const size_t TRIES_PER_T(500 * n);
    const size_t IMPROVED_PATH_PER_T = 60 * n;

    /* annealing schedule */
    for (double T = T_INIT; FINAL_T < T; T *= COOLING) {
        size_t pathchg = 0;
        for (size_t j = 0; j < TRIES_PER_T; j++) {
            do {
                p[0] = rand(n);
                p[1] = rand(n);
                /* non-empty path */
                if (p[0] == p[1]) 
                    p[1] = MOD(p[0] + 1, n);

                numOnPath = MOD(p[1] - p[0], n) + 1;
                numNotOnPath = n - numOnPath;
            } while (numOnPath < 2 || numNotOnPath < 2); /* non-empty path */

            if (rand(2)) {
                /*  threeWay */
                do {
                    p[2] = MOD(rand(numNotOnPath) + p[1] + 1, n);
                } while (p[0] == MOD(p[2] + 1, n)); /* avoids a non-change */

                auto energyChange = getThreeWayCost(p);
                // if (energyChange < 0 || RREAL < exp(-energyChange / T) )
                if (energyChange < 0 || std::rand() < exp(-energyChange / static_cast<double>(T)) ) {
                    pathchg++;
                    pathCost += energyChange;
                    doThreeWay(p);
                }

            } else {
                /* path Reverse */
                auto energyChange = getReverseCost(p);
                if (energyChange < 0 || std::rand() < exp(-energyChange / static_cast<double>(T)) ) {
                    pathchg++;
                    pathCost += energyChange;
                    doReverse(p); 
                }
            }
            // if the new length is better than best then save it as best
            update(iorder);
#if 0
            if (pathlen < tsp->bestlen) {
                tsp->bestlen = pathlen;
                for (i=0; i<tsp->n; i++) tsp->border[i] = tsp->iorder[i];
            }
#endif
            if (pathchg > IMPROVED_PATH_PER_T) break; /* finish early */
        }   
        // PGR_DBG("T:%f L:%f B:%f C:%d", T, pathlen, tsp->bestlen, pathchg);
        if (pathchg == 0) break;   /* if no change then quit */
    }
}
Esempio n. 10
0
int F846317(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg) {
    int ret=0;
    char oldaccdate[9]="";
    des2src(oldaccdate,rPack->sdate3);
    int oldtermid=rPack->lwithdraw_flag;
    int oldtermseqno=rPack->lserial1;
    CAccTrans *pAccTrans=CAccTrans::getInstance();
    TRANS& trans=pAccTrans->trans;
    des2src(pAccTrans->trans.opercode,rPack->semp);
    pAccTrans->trans.transcode=TC_POSDRAWREV;
    des2src(trans.refno,rPack->sphone3);
    if(14==strlen(trans.refno)) {
        trans.termid=rPack->lwithdraw_flag;
        T_t_refno tRefno;

        memset(&tRefno,0,sizeof(tRefno));

        ret=DB_t_refno_read_by_refno(trans.refno,&tRefno);
        if(ret) {
            if(DB_NOTFOUND==ret)
                return 0;
            else
                return E_DB_REFNO_R;
        }
        if(strncmp(tRefno.mac,rPack->saddr,8)!=0) {
            ERRTIP("交易参考号MAC校验错误");
            return E_COMMON_ERR;
        }
        if(RS_SUCC!=tRefno.status) {
            return E_TRANS_REVERSED;
        }
        des2src(oldaccdate,tRefno.accdate);
        oldtermid=tRefno.termid;
        oldtermseqno=tRefno.termseqno;
    } else {
        des2src(trans.chkopercode,rPack->semp_no);
        ret=chk_oper_pwd(trans.chkopercode,rPack->scust_limit);
        if(ret)
            return ret;
    }
    if(strlen(oldaccdate)<1)
        return E_INPUTNULL_ACCDATE;
    if(oldtermid<1)
        return E_INPUTNULL_TERMID;
    if(oldtermseqno<1)
        return E_INPUTNULL_TERMSEQNO;

    ret=pAccTrans->InitTrans();
    if(ret)
        return ret;

    ST_CPACK aPack;
    ST_PACK *outPack = &(aPack.pack);

    ResetNormalCPack(&aPack,0,1);

    SetCol(handle,F_LVOL0,F_LVOL8,F_SDATE3,F_SEMP,F_LSERIAL1,F_SSTATION0,F_VSMESS,F_STIME3,0);
    trans.cardflag=1;
    trans.usecardflag=1;
    trans.cardno = rPack->lvol0;
    pAccTrans->SetCardCntAndCardBal(rPack->lvol5,rPack->lvol6,rPack->lvol7);
    trans.aftdpscnt++;
    ret=doReverse(oldaccdate,oldtermid,oldtermseqno);
    if(ret)
        return ret;
    ret=SaveCardTransInfo();
    if(ret) {
        writelog(LOG_ERR,"SaveCardTransInfo ret=%d",ret);
    }
    outPack->lvol0=pAccTrans->trans.cardno;
    outPack->lvol8=D4U5(pAccTrans->trans.cardaftbal*100,0);
    des2src(outPack->sdate3,pAccTrans->trans.accdate);
    des2src(outPack->stime3,pAccTrans->trans.acctime);
    des2src(outPack->semp,pAccTrans->trans.opercode);
    outPack->lserial1=pAccTrans->trans.termseqno;
    sprintf(outPack->vsmess,"冲正金额%.2lf 卡余额%.2lf元",pAccTrans->trans.transamt,pAccTrans->trans.cardaftbal);
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}