Beispiel #1
0
main(void)
{
    printf("\nFile name to read > ");               /* ask for file by name */
    scanf(" %s",fName);                               /* read name supplied */
    handle = OpenCFSFile(fName,   /* attempt to open named file as CFS V2.0 */
                         0,                           /* open for read only */
                         1);          /* store data section table in memory */
    if (handle<0)                       /* if not sucessful report and fail */
    {
        printf("\nError %d File not opened",handle); 
        return 0;
    }
                                         /* Report general file information */
    ret = DisplayFileInfo(handle);  /* identify file by its CFS file handle */
    if (ret == 0)
        return 0;                                          /* fail if error */

    MyDelay(4000);
    for (i = 0;i < fileVars;i ++)
    {
         ret = DisplayVar(handle,i,FILEVAR,0);
         if (ret == 0) 
             return 0;
    }
    MyDelay(4000);
                                                   /* For each data section */
                                    /* Report on each data section variable */
    for (DSLoop = 1;DSLoop <= dataSections;DSLoop ++)
    {
        printf("\nData Section %3d\n",DSLoop);
                                             /* display data section number */
        for (i = 0;i < DSVars;i ++)
        {        
             ret = DisplayVar(handle,i,DSVAR,DSLoop);
             if (ret == 0)
                 return 0;                                 /* fail if error */
        };
       /* Report an all channel info including 1st 40 value of each channel */      
        for (i = 0;i < channels;i ++)
        {     
             ret = DisplayChan(handle,i,DSLoop);
             if (ret == 0)
                 return 0;                                 /* fail if error */
        };
        DSFlags(handle,DSLoop,(short)0,&flagSet);  /* get DS flags if exist */
        for (i = 0;i <= 15 ;i ++)
            if ((flagSet & DSFlagValue(i)) != 0) /* if valid flag, print it */
                printf("\nFlag exists %u \n",(flagSet & DSFlagValue(i)));
        MyDelay(4000);
    };

    ret = CloseCFSFile(handle);       /* Close CFS file and realease handle */
    if (ret != 0)
        printf("\nError. File closing failed\n");
    return 0;
};
Beispiel #2
0
uint32_t SystemInit(void)
{
    uint32_t result;
    uint32_t unixTime;
        
    SetRebootFlag();
    LedInit();   
    //DisplayStart();   
    RTC_WDT_Init();
    InitNetwork();
    GateInit();
    InitBuff();
    BattADC_Init();

    /* Enable global interrupts */
    CyGlobalIntEnable;
   
    /*sync real time*/
    unixTime = DS1307_GetUnixTime();
//    unixTime = 1485184625 ;
    if(unixTime > 0)
    {      
        RTC_SetUnixTime(unixTime);
        result = DataBaseStart();
        if(result == DB_NO_ERROR)
        {
            Display("System init...");
            result = NO_ERROR;
        }
        else
        {
            Display("Please insert SD");
            result = ERROR;
            SendFinStatus(FIN_NO_READY);
            MyDelay(300);
        }
    }
    else
    {
        Display("Error sync time");
        result = ERROR;
        SendFinStatus(FIN_NO_READY);
        MyDelay(500);
    }
    
    return result;    
}
Beispiel #3
0
int main()
{    
    DisplayStart(); 
    while(SystemInit() == ERROR);
    BLE_start();
    currentState = TIME_SYNC;
    
    for(;;)
    {
        switch (currentState)
        {
            case TIME_SYNC:
            {
                result = TimeSynchronize();
                if(result == TIME_SYNC_OK)
                {
                    currentState = READY;
                }
                break;
            }
            case READY:
            {
                result = CheckReady();
                if(result == NO_ERROR)
                {
                    currentState = CHECK_GATE;
                }
                else if(result == REBOOT)  
                {
                    currentState = TIME_SYNC;
                }
                break;
            }
            case CHECK_GATE:
            {
                result = CheckGate();
                if(result == GATE_OPEN)
                {
                    currentState = SAVE_RESULT;
                }
                else
                {
                    currentState = READY;
                }
                break;
            }
            case SAVE_RESULT:
            {
                SaveResult();
                currentState = READY;
                break;
            }            
        }
        MyDelay(TIMEOUT_DELAY);
    }
}
Beispiel #4
0
void SaveResult(void)
{
    uint64_t finUnixTime;
    uint32_t finRecentMs;
    
    SendFinStatus(FIN_READY);
    LedBlink(FREQ_INIT_BLINK);
    Display("Save data");
    MyDelay(TIMEOUT_USER_READ_INFO);
    
    /*write time in fifo*/
    GetFinTime(&finUnixTime, &finRecentMs);
    WriteFinishTime(finUnixTime,finRecentMs);
    
    FifoPushLastFinished();
    
    /*print time result last skier finished*/
    DisplayLastSkierTime(LastSecTimeOnWay(),LastMillsTimeOnWay());/*LastTimeOnWaySecs(), LastTimeOnWayMillis()*/
    MyDelay(2*TIMEOUT_USER_READ_INFO);
}
Beispiel #5
0
static void PostListens( void )
{
    int         i;

    for( i = NUM_REC_BUFFS-1; i >= 0; --i ) {
        if( !InUse( RecECB[i] ) ) {
            PostAListen( i );
        }
    }
    MyDelay( TICKS_PER_SEC / 5 );
}
Beispiel #6
0
uint32_t TimeSynchronize(void)
{
    uint32_t result;
    
    LedBlink(FREQ_INIT_BLINK);
    
    /* network connect */
    if(NetworkStatus() == NETWORK_DISCONNECT)
    {
        Display("Network conn...");
        //MyDelay(TIMEOUT_DELAY);
    }
    else
    {  
        /* time sync */
        Display("Sync time...");
        if(NTPsync() == TIME_SYNC_OK)
        {
            Display("Sync ok");
            ClearRebootFlag();
            BLE_sendSystemStatus(STATUS_OK);
            ResetTimerForTimeSync();
            
            MyDelay(4 * TIMEOUT_USER_READ_INFO);
            
            result = TIME_SYNC_OK;
        }
        else
        {
            Display("Sync time error");
            SetRebootFlag();
            BLE_sendSystemStatus(STATUS_ERROR);
            MyDelay(4 * TIMEOUT_USER_READ_INFO);
            
            result = TIME_SYNC_ERR;
        }
    }
    
    return result;
}
Beispiel #7
0
/*
 * tempMatch - show a temporary match
 */
static void tempMatch( i_mark *pos )
{
    SaveCurrentFilePos();
    GoToLineNoRelCurs( pos->line );
    GoToColumnOK( pos->column );
#ifdef __WIN__
    DCDisplayAllLines();
    DCUpdate();

    SetWindowCursorForReal();
    MyDelay( 150 );
    RestoreCurrentFilePos();

    DCDisplayAllLines();
    DCUpdate();
#else
    MyDelay( 150 );
    RestoreCurrentFilePos();
    DCDisplayAllLines();
#endif

} /* tempMatch */
Beispiel #8
0
int NoiseFloorFetchWait(int *nfc, int *nfe, int nfn, int timeout)
{
	unsigned int mask;
	int it;
	unsigned int address;
	int high, low;
	int ip;
	unsigned int ready;
	//
	// noise floor values are signed. this computes a mask to extend the sign bit
	// it assumes that all the values are the same length.
	//
	mask=0;
	if(FieldFind("BB_cca_b0.minCCApwr_0", &address, &low, &high))
	{
		for(it=high-low+1; it<32; it++)
		{
			mask |= (1<<it);
		}
	}
	for(ip=0; ip<timeout; ip++)
	{
		//
		// wait for noise floor calibration to finish
		//
		FieldRead("BB_agc_control.do_noisefloor",&ready);
		if(ready==0)
		{
			NoiseFloorFetch(nfc, nfe, nfn);
			break;
		}
		else
		{
			UserPrint(".");
			MyDelay(1);
		}
	}
	if(ip>=timeout)
	{
		UserPrint("timeout.");
		nfc[0]=0;
		nfc[1]=0;
		nfc[2]=0;
		nfe[0]=0;
		nfe[1]=0;
		nfe[2]=0;
		return -1;
	}
	return 0;
}
Beispiel #9
0
uint32_t CheckGate(void)
{
    uint32_t result;
    
    SetLedState(LED_ENABLE);
    result = GateIsOpen();/*IsGateOpen(), CheckGateStatus()*/
    
    if(result == GATE_OPEN)
    {
        Display("Skier Finished");
        MyDelay(TIMEOUT_USER_READ_INFO);
    }
    else
    {
        AllowNextSkier();
    }
    
    return result;  
}
Beispiel #10
0
int Ar9300TemperatureGetOld(void)
{
	unsigned int temperature=0;
    unsigned int AnalogTemp=0;
	unsigned int stuck=0;
    unsigned int currentTime;
    unsigned int endTime;
    int i;

    currentTime = TimeMillisecond();
    endTime = savedTime+5000;

    if((endTime>savedTime && (currentTime>endTime || currentTime<savedTime)) || (endTime<savedTime && currentTime>endTime && currentTime<savedTime))
    {
	    if(TemperatureAddress==0)
	    {
		    Ar9300TemperatureFieldLookup();
	    }
        for(i = 0; i<MSTUCK; i++) {
            MyDelay(1);
            MyFieldRead(TemperatureAddress,TemperatureLow,TemperatureHigh,&temperature);
	        MyFieldRead(TemperatureDoneAddress,TemperatureDoneLow,TemperatureDoneHigh,&stuck);
            MyFieldRead(AnalogTempAddress, AnalogTempLow, AnalogTempHigh, &AnalogTemp);
            UserPrint("Stuck = %d   ", stuck);
            if (stuck == 1){
               break;
            }
        }
        //UserPrint("\n");
        if((stuck==0)) 
	    {
		    TemperatureRestart();
	    }
	    else
	    {
            savedTemp = temperature;
	    }
    	UserPrint("\nctemp=%d stemp=%d alogTemp = %d, ctime=%d stime=%d stuck=%d\n",
                    temperature,savedTemp,AnalogTemp,currentTime, savedTime, stuck);
        savedTime = currentTime;
    }
    return (int)savedTemp;
}
Beispiel #11
0
void RemoteDisco( void )
{
    int         i;

    _DBG_IPX(("RemoteDisco\r\n"));
    /* make sure last packet gets sent out */
    MyDelay( TICKS_PER_SEC/2 );

    Listening = 0;
    _INITSPXECB( Conn, 1, 0, 0 );
    CSPXTerminateConnection( Connection, &ConnECB );
    for( i = NUM_REC_BUFFS-1; i >= 0; --i ) {
        if( InUse( RecECB[i] ) ) {
            SPXCancelEvent( &RecECB[i] );
        }
    }
    SPXCancelEvent( &SendECB );
    for( i = NUM_REC_BUFFS-1; i >= 0; --i ) {
        RecECB[i].status = 0;
    }
}
Beispiel #12
0
DEVICEDLLSPEC void RfBbTestPointStart(int frequency, int ht40, int bandwidth, int antennapair, unsigned char chainnum,
                       int mbgain, int rfgain, int coex, int sharedrx, int switchtable, unsigned char AnaOutEn,
                       int (*ison)(), int (*done)())
{	
	int it;

	DeviceRfBbTestPoint(frequency, ht40, bandwidth, antennapair, chainnum, mbgain, rfgain, coex, sharedrx, switchtable, AnaOutEn);

	if(ison!=0)
	{
		(*ison)();
	}

	for(it = 0; ; it++) 
	{
		//
		// check for message from cart telling us to stop
		// this is the normal terminating condition
		//
		if(done!=0)
		{
			if((*done)())
			{
				UserPrint("Stop message received.\n");
				break;
			}
		}
		//
		// sleep every other time, need to keep up with fast rates
		//
		if (it % 100 == 0)
		{
			UserPrint(".");
		}
	    MyDelay(100);
    } 
}
Beispiel #13
0
uint32_t CheckReady(void)
{
    uint32_t result;   
 
    /*sise FIFO*/
    if ((FifoGetSize() >= MAX_SKIERS_ON_BUF/*main_db_buffer) */)&& (FifoGetSize() <= MAX_FIFO_SIZE)/*reserv, max_fifo rec*/)
    {
        /*skier finish successful*/
        Display("Error SD Card!");
        SendFinStatus(FIN_NO_READY); 
        
        if (SkierOnWay() != 0)
        {
            /*if skiers on way*/
            result = NO_ERROR;
        }
        else
        {
            /*if not skiers on way*/
            result = ERROR;
        }        
    }
    else if(FifoGetSize() > MAX_FIFO_SIZE)
    {
        /*skier finish no successful*/
        Display("Error SD Card!");
        SendFinStatus(FIN_NO_READY); 
        
        result = ERROR;                
    }
    else if(SkierOnWay() >= MAX_SKIERS_ON_WAY/*MAX_COUNT, TRACK_OVERFLOW*/)
    {
        /*max skier on way*/
     
        Display("Max skier on way");
        SendFinStatus(FIN_NO_READY);
        MyDelay(TIMEOUT_USER_READ_INFO);
        
        result = NO_ERROR;      
    }
    else if(SkierOnWay() == 0)
    {
        Display("Finish Ready");
        SendFinStatus(FIN_READY);
        SetLedState(LED_DISABLE);        
        
        result = ERROR;      
    }
    else
    {
        /*finish ready*/
        SendFinStatus(FIN_READY);
        Display("Finish Ready");
        
        result = NO_ERROR;
    }
    
    //if(ReadRebootStartFlag() == REBOOT/*IS*/)
    if(IsRebootStartFlag() == REBOOT)
    {
        result = REBOOT;
    }
    
    /*if  admin , read skier time from SD card and send bluetooth*/
    if(BLE_getFlagAdminOnly() != 0)
    {
        ReadSkierResultAndSendBLE();
    }
    
    if(ChekTimerForTimeSync() == SYNC_REQUIRES)
    {
        SetRebootFlag();
    }
           
    return result;
}
Beispiel #14
0
static A_INT32 socketConnect
(
 	char *target_hostname, 
	int target_port_num, 
	A_UINT32 *ip_addr
)
{
	A_INT32		sockfd;
	A_INT32		res;
	struct sockaddr_in	sin;
	struct hostent *hostent;
	A_INT32		i;
	A_INT32		j;

	sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (sockfd == -1) {
		q_uiPrintf("ERROR::socket failed: %s\n", strerror(errno));
		return -1;
   	}

	/* Allow immediate reuse of port */
    q_uiPrintf("setsockopt SO_REUSEADDR start\n");
    i = 1;
    res = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof(i));
    if (res != 0) {
        uiPrintf("ERROR::socketConnect: setsockopt SO_REUSEADDR failed: %d\n",strerror(errno));
		close(sockfd);
	     return -1;
 	}
    q_uiPrintf("setsockopt SO_REUSEADDR end\n");


	/* Set TCP Nodelay */
    q_uiPrintf("setsockopt TCP_NODELAY start\n");
	i = 1;
    j = sizeof(i);
    res = setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (A_INT8 *)&i, j);
   	if (res == -1) {
		uiPrintf("ERROR::setsockopt failed: %s\n", strerror(errno));
		close(sockfd);
		return -1;
   	}	
	q_uiPrintf("setsockopt TCP_NODELAY end\n");


	q_uiPrintf("gethostbyname start\n");
    q_uiPrintf("socket_connect: target_hostname = '%s'\n", target_hostname);
    hostent = gethostbyname(target_hostname);
    q_uiPrintf("gethostbyname end\n");
    if (!hostent) {
        uiPrintf("ERROR::socketConnect: gethostbyname failed: %d\n",strerror(errno));
		close(sockfd);
	    return -1;
    }

	memcpy(ip_addr, hostent->h_addr_list[0], hostent->h_length);
	*ip_addr = ntohl(*ip_addr);
					
   	sin.sin_family = AF_INET;
	memcpy(&sin.sin_addr.s_addr, hostent->h_addr_list[0], hostent->h_length);
	sin.sin_port = htons((short)target_port_num);


	for (i = 0; i < 20; i++) {
		q_uiPrintf("connect start %d\n", i);
	   	res = connect(sockfd, (struct sockaddr *) &sin, sizeof(sin));
		q_uiPrintf("connect end %d\n", i);
        if (res == 0) {
            break;
        }
        MyDelay(1000);
    }
	
    if (i == 20) {
        uiPrintf("ERROR::connect failed completely\n");
		close(sockfd);
        return -1;
    }
		
   	return sockfd;
}