Exemplo n.º 1
0
BOOL CBypassQueue::SingleJob(CZigbeeWorker * pWorker, BITEM *pItem)
{
	TIMETICK  tmNow;
	int		nElapse, nError;
	BYTE	nAttr;

    GetTimeTick(&tmNow);
	nElapse = GetTimeInterval(&pItem->invokeTime, &tmNow);

    // IF4 Forwarding을 한다
	CIF4Invoke  invoke(m_szFepServer, m_nFepPort, DEFAULT_TIMEOUT);
    invoke.AddParamFormat("1.14", VARSMI_EUI64, &pItem->id, sizeof(EUI64));    // Source ID
    invoke.AddParam("1.6", pItem->trSeq);    // Transaction Sequence
    invoke.AddParam("1.4", pItem->nSeq);     // Message Sequence
    invoke.AddParam("1.5", pItem->nLength);  // Message Length
    invoke.AddParamFormat("1.12", VARSMI_STREAM, pItem->szData, pItem->nLength); // Message
#ifdef _WIN32
    invoke.AddParam("1.6", (UINT)pItem->invokeTime.t);    // Invoke Time
#else
    invoke.AddParam("1.6", (UINT)pItem->invokeTime.t.tv_sec);    // Invoke Time
#endif
    invoke.AddParam("1.6", (UINT)nElapse);               // Waiting Delay

	nAttr  = IF4_CMDATTR_REQUEST | IF4_CMDATTR_RESPONSE;
	nError = IF4API_Command(invoke.GetHandle(), "111.1", nAttr);

    if(nError == IF4ERR_NOERROR)
    {
        pItem->bSent = TRUE;
    }
    else
    {
        char szGUID[17];
        EUI64ToStr(&pItem->id,szGUID);
        XDEBUG("Bypass Fail %s : %s(%d)\r\n", szGUID, IF4API_GetErrorMessage(nError), nError);
    }

    return TRUE;
}
Exemplo n.º 2
0
bool PowerStats::Intel_GetTimeInterval(double &interval){
  return GetTimeInterval(&interval) != 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
#ifndef _WIN32
    struct  sigaction   handler;
#endif
	HANDLE	codi;
	int		nError;
    int     nDebugMode = 1;
    int     nPermit=-1, nPowerMode=-1;
    int     nListSerial = 0;
    signed char    nRfPower=254;
    int    opt;
    char    *pDevicePath = NULL;

#ifndef _WIN32
	// 보편적인 시그널 핸들러를 설치한다.
	handler.sa_handler = signal_handler;
    sigfillset(&handler.sa_mask);
    sigaction(SIGINT, &handler, 0);
    sigaction(SIGTERM, &handler, 0);
    sigaction(SIGCHLD, &handler, 0);
#endif

#ifndef _WIN32
    while((opt=getopt(argc, argv, "dp:q:G:")) != -1) {
#else
    while((opt=getopt(argc, argv, "d")) != -1) {
#endif
        switch(opt) {
            case 'd': 
                nDebugMode = 0;
                break;
            case 'l': 
                nListSerial = 1;
                break;
            case 'q': 
                nPermit = (int)strtol(optarg,(char **)NULL,10) == 0 ? 0 : 255;
                break;
            case 'G': 
                nPowerMode = (int)strtol(optarg,(char **)NULL,10);
                break;
            case 'p': 
                nRfPower = (signed char)strtol(optarg,(char **)NULL,10);
                break;
            case 'h':
            default :
                Usage(argv[0]);
                return (1);
        }
    }

    if((argc - optind) < 1) {
        Usage(argv[0]);
        return (2);
    }

	// 디버깅 화면 출력(0), 해제(1)	
    SET_DEBUG_FILE(stderr);
	SET_DEBUG_MODE(nDebugMode);

    pDevicePath = strdup(argv[optind]);
    memset(g_szCodiId, 0, sizeof(g_szCodiId));

    memset(codiDevice.szDevice, 0, sizeof(codiDevice.szDevice));
    strncpy(codiDevice.szDevice, pDevicePath, MIN(strlen(pDevicePath), sizeof(codiDevice.szDevice)-1));

	// CODIAPI를 초기화 한다.
	nError = codiInit();
	if (nError != CODIERR_NOERROR)
	{
		ReportError(NULL, nError);
		return (3);
	}

	// 새로운 Coordinator 장치를 등록한다.
	nError = codiRegister(&codi, &codiDevice);
	if (nError != CODIERR_NOERROR)
	{
		ReportError(NULL, nError);
		codiExit();
		return (3);
	}

	// Coordinator 서비스를 시작 시킨다.
	nError = codiStartup(codi);
	if (nError != CODIERR_NOERROR)
	{
		ReportError(NULL, nError);
		codiUnregister(codi);
		codiExit();
		return (3);
	}

	// 사용자 프로그램을 여기에 코딩한다.
	MainProcedure(codi, nPermit, nRfPower, nPowerMode);

	// Coordinator 서비스를 종료한다.
	nError = codiShutdown(codi);
	if (nError != CODIERR_NOERROR)
		ReportError(NULL, nError);

	// 등록된 디바이스를 해제한다.
	nError = codiUnregister(codi);
	if (nError != CODIERR_NOERROR)
		ReportError(NULL, nError);

	// API를 종료한다.
	codiExit();
	return (0);
}

const char *GetStateMessage(int nState)
{
	switch(nState) {
	  case CODISTATE_NORMAL :			return "Normal";
	  case CODISTATE_NOT_STARTED :		return "Coordinator not started";
	  case CODISTATE_NOT_CONNECTED :	return "Coordinator not connected";
	  case CODISTATE_STACK_NOT_READY :	return "Coordinator Stack not ready";
	  case CODISTATE_STACK_DOWN :		return "Coordinator Stack down";
	  case CODISTATE_JOIN_FAIL :		return "Coordinator Join Fail";
	  case CODISTATE_NO_RESPONSE :		return "Coordinator No Response";
	  case CODISTATE_ERROR :			return "Coordinator Error";
	}
	return "Unknown State";
}

#define STATE_INIT					0
#define STATE_READY					1
#define STATE_PERMIT				17
#define STATE_SET_PERMIT			40
#define STATE_RF_POWER				41
#define STATE_POWER_MODE			42
#define STATE_RESET					55
#define STATE_WAIT					100

void MainProcedure(HANDLE codi, int nPermit, signed char nRfPower, int nPowerMode)
{
	TIMETICK	start, prev, cur;
	//BYTE	szBuffer[1024];
	int		nError = CODIERR_NOERROR, nLength;
	int		nState, nElapse;
    BOOL    bSet;
    CODI_PERMIT_PAYLOAD     permit;
    CODI_NETWORK_PAYLOAD    network;

    GetTimeTick(&start);
	for(nState=STATE_INIT; !m_bCodiExitPending;)
	{
        GetTimeTick(&prev);
        //nError = codiGetState(codi);
        //XDEBUG("CODINATOR STATE(%d) = %s\r\n", nError, GetStateMessage(nError));

        //XDEBUG("m_bCodiExitPending %d\r\n", m_bCodiExitPending);
		switch(nState) {
		  case STATE_INIT :
               nState = STATE_READY;
               break;

          case STATE_READY :        
               nError = codiGetState(codi);
               XDEBUG("CODINATOR STATE(%d) = %s\r\n", nError, GetStateMessage(nError));

               if (nError != CODISTATE_NORMAL)
               {
                   nState = STATE_RESET;
                   break;           
               }
               nState = STATE_SET_PERMIT;
               break;               

		  case STATE_RESET :
			   nError = codiReset(codi);
			   if (nError != CODIERR_NOERROR) ReportError(NULL, nError);
               USLEEP(10000000); 
			   nState = STATE_READY;
			   break;

          case STATE_SET_PERMIT:
#ifdef __FN_RFSET__
               if(nPermit >=0 && nPermit <= 255)
               {
                    memset(&permit, 0, sizeof(CODI_CMD_PERMIT));
                    permit.permit_time = (BYTE)(nPermit & 0xFF);
                    nError = codiSetProperty(codi, CODI_CMD_PERMIT, (BYTE *)&permit, 
                        sizeof(CODI_PERMIT_PAYLOAD), 3000);
			        if (nError != CODIERR_NOERROR) ReportError(NULL, nError);
               }
#endif
               nState = STATE_PERMIT;
               break;

		  case STATE_PERMIT :
               memset(&permit, 0, sizeof(CODI_PERMIT_PAYLOAD));
			   nError = codiGetProperty(codi, CODI_CMD_PERMIT, (BYTE *)&permit, &nLength, 5000);
			   if (nError != CODIERR_NOERROR) 
               {
                   ReportError(NULL, nError);
               }
#ifdef __FN_RFSET__
               else 
               {
                    PRINT("OUT:PERMIT:%d\n", permit.permit_time);
               }
#endif
			   nState = STATE_RF_POWER;
			   break;

		  case STATE_RF_POWER :
               bSet = FALSE;
               memset(&network, 0, sizeof(CODI_NETWORK_PAYLOAD));
			   nError = codiGetProperty(codi, CODI_CMD_NETWORK_PARAM, (BYTE *)&network, &nLength, 5000);
			   if (nError != CODIERR_NOERROR) 
               {
                   ReportError(NULL, nError);
               }
#ifdef __FN_RFSET__
               else 
               {
                    if(nRfPower != 254)
                    {
                        network.power = nRfPower;
                        bSet = TRUE;
                    }
                    if(nPowerMode >= 0)
                    {
                        network.txpowermode = (BYTE)nPowerMode;
                        bSet = TRUE;
                    }
                    if(bSet) 
                    {
                        nError = codiSetProperty(codi, CODI_CMD_NETWORK_PARAM, (BYTE *)&network, nLength, 3000);
                    }
                    PRINT("OUT:CINFO:%d,%d,%d\n", network.channel, network.panid, network.power);
               }
#endif
			   nState = STATE_WAIT;
			   break;
		
		  case STATE_WAIT :
               GetTimeTick(&cur);
			   nElapse = GetTimeInterval(&start, &cur);

			   USLEEP(30000000);
			   nState = STATE_WAIT;
			   break;
		}

        GetTimeTick(&cur);
	    nElapse = GetTimeInterval(&prev, &cur);
	    //XDEBUG("Elapse=%d ms\r\n", nElapse);
	}
}
void Z_DC_Spread_Policy::OnNewFutureMD(MarketDataField* pMD)
{
	if(IsCallAuction(pMD)){
		return;
	}
	UpdateMD(pMD);
	if(m_bStopOnClose && m_MyTradeA.m_nLongPos<1 && m_MyTradeA.m_nShortPos<1 && m_MyTradeB.m_nLongPos<1 && m_MyTradeB.m_nShortPos<1){
		m_nCurrentStage = 0;
		m_nPositiveAddedFlag = 0;
		m_nPositiveAddEnableFlag = 0;
		m_nNegativeAddedFlag = 0;
		m_nNegativeAddEnableFlag = 0;
		m_MyTradeA.m_fBasePrice = 0;
		m_MyTradeB.m_fBasePrice = 0;
		m_nTotalAddTimes = 0;
		m_nTotalSubTimes = 0;
		SetAttr("totalAddtimes",m_nTotalAddTimes);
		SetAttr("totalSubTimes",m_nTotalSubTimes);
		SetAttr("current_stage",m_nCurrentStage);
		SetAttr("Padded_flag",m_nPositiveAddedFlag);
		SetAttr("Nadded_flag",m_nNegativeAddedFlag);
		SetAttr("Paddenable_flag",m_nPositiveAddEnableFlag);
		SetAttr("Naddenable_flag",m_nNegativeAddEnableFlag);
		SetAttr("base_price_a",0);
		SetAttr("base_price_b",0);
		Stop();
		ShowInfo(&m_MyTradeA,"Close stop.",0);
		return;
	}
	//if(m_MyTradeA.m_pLastMD != NULL && m_MyTradeB.m_pLastMD !=NULL){
		//m_fCurrentPriceDisparity = abs( m_MyTradeA.m_pLastMD->LastPrice - m_MyTradeB.m_pLastMD->LastPrice);
	//}
	if(!m_bStopOnClose && m_MyTradeA.m_pLastMD != NULL && m_MyTradeB.m_pLastMD !=NULL){
	/*	if(strcmp(pMD->InstrumentID, m_MyTradeA.m_InstrumentID)==0){	//For Test
			cout<<m_MyTradeA.m_pLastMD->UpdateTime<<" "<<m_MyTradeB.m_pLastMD->UpdateTime<<endl;
		}*/
		//cout<<(strcmp(pMD->InstrumentID, m_MyTradeA.m_InstrumentID) == 0)<<" "<<GetTimeInterval(m_MyTradeA.m_pLastMD->UpdateTime,m_MyTradeB.m_pLastMD->UpdateTime)<<" "<<m_nCurrentStage<<" "<<m_MyTradeA.m_nLongPos<<" "<<m_MyTradeB.m_nShortPos<<endl;
		if(strcmp(pMD->InstrumentID, m_MyTradeA.m_InstrumentID)==0 && GetTimeInterval(m_MyTradeA.m_pLastMD->UpdateTime,m_MyTradeB.m_pLastMD->UpdateTime)){
			if(m_nCurrentStage == 0 && m_MyTradeA.m_nLongPos==0 && m_MyTradeB.m_nShortPos == 0 && !IsTradeLimit(true)){//m_nCurrentStage == 0 &&
				ShowInfo(&m_MyTradeA,"Set Up Base Pos!",0);
				OpenLong(&m_MyTradeA);
				OpenShort(&m_MyTradeB);
				m_MyTradeA.m_fBasePrice = m_MyTradeA.m_pLastMD->LastPrice;
				m_MyTradeB.m_fBasePrice = m_MyTradeB.m_pLastMD->LastPrice;
				m_nCurrentStage = 1;

				SetBaseFlag(&m_MyTradeA);
				SetAttr("base_price_a",m_MyTradeA.m_fBasePrice);
				SetAttr("base_price_b",m_MyTradeB.m_fBasePrice);
				SetAttr("current_stage",m_nCurrentStage);
			}

			//判断当前盈利状况
			if(!this->GetBarCloseFlag(m_MyTradeA.m_pSeries,pMD,5)){//收盘前五秒没有买卖信号判断
				ManageRateSingal();
			}
			//if(m_MyTradeA.m_pLastMD!=NULL && m_MyTradeB.m_pLastMD!=NULL){
			CalProfit();
			//}
		}
	}

}
Exemplo n.º 5
0
void MainProcedure(HANDLE codi)
{
	TIMETICK start, prev, cur;
	char	szFileName[256] = "";
	BYTE	szBuffer[1024];
	int		nError, nLength;
	int		nState, nElapse;

	strcpy(szFileName, "/app/sw/ZNet3_Coordinator_v10_B16.ebl");
    GetTimeTick(&start);
	for(nState=STATE_INIT; !m_bCodiExitPending && (nState!=STATE_DONE);)
	{
        GetTimeTick(&prev);
        nError = codiGetState(codi);
        printf("CODINATOR STATE(%d) = %s\r\n", nError, GetStateMessage(nError));

		switch(nState) {
		  case STATE_INIT :
               nState = STATE_READY;
               break;

          case STATE_READY :        
               nError = codiGetState(codi);
               printf("CODINATOR STATE(%d) = %s\r\n", nError, GetStateMessage(nError));

               if (nError != CODISTATE_NORMAL)
               {
                   USLEEP(1000000); 
                   break;           
               }
               nState = STATE_MODULE_PARAM;
               break;               

		  case STATE_MODULE_PARAM :
			   codiSync(codi, 3);
               GetTimeTick(&start);
			   nError = codiGetProperty(codi, CODI_CMD_MODULE_PARAM, (BYTE *)szBuffer, &nLength, 5000);
			   if (nError != CODIERR_NOERROR) ReportError(NULL, nError);
			   nState = STATE_NETWORK_PARAM;
			   break;

		  case STATE_NETWORK_PARAM :
			   nError = codiGetProperty(codi, CODI_CMD_NETWORK_PARAM, (BYTE *)szBuffer, &nLength, 5000);
			   if (nError != CODIERR_NOERROR) ReportError(NULL, nError);
			   nState = STATE_SECURITY_PARAM;
			   break;

		  case STATE_SECURITY_PARAM :
			   nError = codiGetProperty(codi, CODI_CMD_SECURITY_PARAM, (BYTE *)szBuffer, &nLength, 5000);
			   if (nError != CODIERR_NOERROR) ReportError(NULL, nError);
			   nState = STATE_PERMIT;
			   break;

		  case STATE_PERMIT :
			   nError = codiGetProperty(codi, CODI_CMD_PERMIT, (BYTE *)szBuffer, &nLength, 5000);
			   if (nError != CODIERR_NOERROR) ReportError(NULL, nError);
			   nState = STATE_DOWNLOAD;
			   break;
		
		  case STATE_DOWNLOAD :
			   nError = codiDownload(codi, CODI_MODEMTYPE_XMODEM, szFileName, "ebl");
			   if (nError != CODIERR_NOERROR) ReportError(NULL, nError);
			   USLEEP(3000000);
			   nState = STATE_WAIT;
			   break;

		  case STATE_WAIT :
               GetTimeTick(&cur);
			   nElapse = GetTimeInterval(&start, &cur);
			   printf("\r\n");
			   printf("-----------------------------------------------------\r\n");
			   printf(" TOTAL Elapse Time = %d ms\r\n", nElapse);
			   printf("-----------------------------------------------------\r\n");
			   nState = STATE_DONE;
			   break;
		}

        GetTimeTick(&cur);
	    nElapse = GetTimeInterval(&prev, &cur);
		printf("Elapse=%d ms\r\n", nElapse);
	}
}