Exemplo n.º 1
0
TmEcode DecodePcapFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq)
{
    SCEnter();
    DecodeThreadVars *dtv = (DecodeThreadVars *)data;

    /* XXX HACK: flow timeout can call us for injected pseudo packets
     *           see bug: https://redmine.openinfosecfoundation.org/issues/1107 */
    if (p->flags & PKT_PSEUDO_STREAM_END)
        return TM_ECODE_OK;

    /* update counters */
    DecodeUpdatePacketCounters(tv, dtv, p);

    double curr_ts = p->ts.tv_sec + p->ts.tv_usec / 1000.0;
    if (curr_ts < prev_signaled_ts || (curr_ts - prev_signaled_ts) > 60.0) {
        prev_signaled_ts = curr_ts;
        FlowWakeupFlowManagerThread();
    }

    /* update the engine time representation based on the timestamp
     * of the packet. */
    TimeSet(&p->ts);

    /* call the decoder */
    pcap_g.Decoder(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);

#ifdef DEBUG
    BUG_ON(p->pkt_src != PKT_SRC_WIRE && p->pkt_src != PKT_SRC_FFR);
#endif

    PacketDecodeFinalize(tv, dtv, p);

    SCReturnInt(TM_ECODE_OK);
}
Exemplo n.º 2
0
void OnButtonClicked_time(WM_MESSAGE * pMsg)
{

	#ifndef WIN_SIM
	TimeSet(pMsg);
	#endif
}
Exemplo n.º 3
0
TmEcode DecodePcapFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq)
{
    SCEnter();
    DecodeThreadVars *dtv = (DecodeThreadVars *)data;

    /* update counters */
    SCPerfCounterIncr(dtv->counter_pkts, tv->sc_perf_pca);
    SCPerfCounterIncr(dtv->counter_pkts_per_sec, tv->sc_perf_pca);

    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, GET_PKT_LEN(p));
#if 0
    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, GET_PKT_LEN(p));
    SCPerfCounterAddDouble(dtv->counter_mbit_per_sec, tv->sc_perf_pca,
                           (GET_PKT_LEN(p) * 8)/1000000.0 );
#endif
    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));

    double curr_ts = p->ts.tv_sec + p->ts.tv_usec / 1000.0;
    if (curr_ts < prev_signaled_ts || (curr_ts - prev_signaled_ts) > 60.0) {
        prev_signaled_ts = curr_ts;
        FlowWakeupFlowManagerThread();
    }

    /* update the engine time representation based on the timestamp
     * of the packet. */
    TimeSet(&p->ts);

    /* call the decoder */
    pcap_g.Decoder(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);

    SCReturnInt(TM_ECODE_OK);
}
Exemplo n.º 4
0
// we need to parse GLL as well because it can mark the start of a new quantum data
// followed by values with no data, ex. altitude, vario, etc.
BOOL NMEAParser::GLL(TCHAR *String, TCHAR **params, size_t nparams, NMEA_INFO *GPS_INFO)
{

  gpsValid = !NAVWarn(params[5][0]);

  if (!activeGPS) return TRUE;

  if (ReplayLogger::IsEnabled()) {
    // block actual GPS signal
	InterfaceTimeoutReset();
	return TRUE;
  }
  
  GPS_INFO->NAVWarning = !gpsValid;
  
  // use valid time with invalid fix
  double glltime = StrToDouble(params[4],NULL);
  if (glltime>0) {
	#ifdef NEWTRIGGERGPS
	double ThisTime = TimeConvert(glltime, GPS_INFO); // 091208
	#else
	double ThisTime = TimeModify(glltime, GPS_INFO);
	#endif

	#ifndef NEWTRIGGERGPS
	if (!TimeHasAdvanced(ThisTime, GPS_INFO)) return FALSE; // 091208
	#endif

	#ifdef NEWTRIGGERGPS
	// is time advanced to a new quantum?
	if (ThisTime >NmeaTime) {
		// yes so lets trigger the gps event
		TriggerGPSUpdate();
		Sleep(50); // 091208
		NmeaTime=ThisTime;
		TimeSet(GPS_INFO); // 091208
		TimeHasAdvanced(ThisTime,GPS_INFO); // 091208
		//StartupStore(_T(".............. trigger from GLL\n"));
	}
	#endif
  }
  if (!gpsValid) return FALSE;  // 091108 addon BUGFIX GLL time with no valid signal
  
  double tmplat;
  double tmplon;
  
  tmplat = MixedFormatToDegrees(StrToDouble(params[0], NULL));
  tmplat = NorthOrSouth(tmplat, params[1][0]);
  
  tmplon = MixedFormatToDegrees(StrToDouble(params[2], NULL));
  tmplon = EastOrWest(tmplon,params[3][0]);
  
  if (!((tmplat == 0.0) && (tmplon == 0.0))) {
	GPS_INFO->Latitude = tmplat;
	GPS_INFO->Longitude = tmplon;
  } else {
    
  }
  return TRUE;
}
Exemplo n.º 5
0
Arquivo: time.c Projeto: x893/OpenBLT
/************************************************************************************//**
** \brief     Initializes the timer.
** \return    none.
**
****************************************************************************************/
void TimeInit(void)
{
  /* configure the SysTick timer for 1 ms period */
  SysTickPeriodSet((unsigned long)SysCtlClockGet() / 1000);
  SysTickEnable();
  SysTickIntEnable();
  /* reset the millisecond counter */
  TimeSet(0);
} /*** end of TimeInit ***/
Exemplo n.º 6
0
/** \brief set the time to "gettimeofday" meant for testing */
void TimeSetToCurrentTime(void)
{
    struct timeval tv;
    memset(&tv, 0x00, sizeof(tv));

    gettimeofday(&tv, NULL);

    TimeSet(&tv);
}
Exemplo n.º 7
0
/** \brief increment the time in the engine
 *  \param tv_sec seconds to increment the time with */
void TimeSetIncrementTime(uint32_t tv_sec)
{
    struct timeval tv;
    memset(&tv, 0x00, sizeof(tv));
    TimeGet(&tv);

    tv.tv_sec += tv_sec;

    TimeSet(&tv);
}
Exemplo n.º 8
0
Float SampleTime(int sampnum)
{
  Float window, jitter = 0.0, res;

  if (Options.shutterspeed <= 0.)
	return Options.framestart;
  if (Options.jitter)
	jitter = nrand();
  window = Options.shutterspeed / Sampling.totsamples;
  res = Options.framestart + window * (sampnum + jitter);
  TimeSet(res);
  return res;
}
Exemplo n.º 9
0
void TimeDelayTest(void *param)
{
    u8 year, month, day, week,hour, min, sec;
    u8 FH_Value = 0;
    
    u8 *temp = NULL;
    u8 *humi = NULL;
    
    IIC_InitPort();
  
    TimeSet();
    vTaskDelay(1000);
    while(1)
    {
             
        TimeGet(&year, &month, &day, &week,&hour, &min, &sec);
        
        vTaskDelay(2000);

    }                    
}
Exemplo n.º 10
0
void CRuleManager::ReadFromFile(const TDesC8& aFile,TInt aPos,CRule* aRule)
	{
	CDesC8Array *array = CCommonUtils::SplitText(aFile.Left(aPos),KCharRuleSymbolSplit);
	if (array->Count() == 6)
		{
		CRule* rule = aRule;
		
		HBufC* name = CCommonUtils::ConvertToUnicodeFromUTF8((*array)[0]);
		rule->SetName(name->Des());
		delete name;
		
		TInt uid = CCommonUtils::StrToInt((*array)[1]);
		rule->SetUid(TUid::Uid(uid));
		
		TInt type = CCommonUtils::StrToInt((*array)[2]);
		rule->SetType(type);
		
		if (type == 0)
			{
			TInt countdown = CCommonUtils::StrToInt((*array)[3]);
			rule->SetCountDown(countdown);
			}
		else
			{
			TTime time;
			TBuf<8> timetxt;
			timetxt.Copy((*array)[3]);
			TimeSet(timetxt,time);
			rule->SetClock(time);
			}
		
		HBufC* rulename = CCommonUtils::ConvertToUnicodeFromUTF8((*array)[4]);
		rule->SetRuleName(rulename->Des());
		delete rulename;
		
		TInt lunch = CCommonUtils::StrToInt((*array)[5]);
		rule->SetLunchRun(lunch);
		}
	delete array;
	}
Exemplo n.º 11
0
/**
 * @brief  解析一帧报文
 * @param  参数名 参数说明  
 * @param  [in] rxBuf 串口接收缓冲数据指针
 * @retval 该帧报文的长度
 * @par 使用全局变量 \n
 * @note ● 执行时间: \n
 *       ● 调用周期: 4ms, 被UartDecode调用 \n
 *       ● 可否打断: 可以 \n
 *
 * @par  注意:
 *       ● 无 \n
 */
static u8 msgDec(u8 *rxBuf)
{
    u8 length = 0, command = 0, verify = 0, readOrWrite = 0;
	u8 i;
	STR_Time timeSetBLE;
    u8 data[20];
    extern u16 temperature;
	
	command = rxBuf[1];
	readOrWrite = rxBuf[2];
	length = rxBuf[3];
	
	for(i = 1; i < (length - 1); i++)
	{
		verify += rxBuf[i];
	}
	
	if(verify != rxBuf[length - 1])
		return 0;
	
	switch(command)
	{
		//时间
		case 0x01:
			if(readOrWrite == 1)
			{
				timeSetBLE.year 	=	rxBuf[4];
				timeSetBLE.month 	= 	rxBuf[5];
				timeSetBLE.date 	=	rxBuf[6];
				timeSetBLE.hour 	=	rxBuf[7];
				timeSetBLE.min 	    = 	rxBuf[8];
				timeSetBLE.sec 	    = 	rxBuf[9];
				timeSetBLE.week     =	rxBuf[10];
				TimeSet(&timeSetBLE);
			}
			break;
		//关屏时间
		case 0x02:
			//写
			if(readOrWrite == 1)
			{
				Sys.secSleep = rxBuf[4];
			}
			//读
			else if(readOrWrite == 0)
			{
				data[0] = 0x7f;
                data[1] = 0x02;
                data[2] = 0x00;
                data[3] = 0x06;
                data[4] = Sys.secSleep;
                data[5] = data[1] + data[2] + data[3] + data[4];
                PushSendBuf(data, 6);
			}
			break;
		//系统状态
		case 0x03:
            if (readOrWrite == 0)
            {
                data[0] = 0x7f;
                data[1] = 0x03;
                data[2] = 0x00;
                data[3] = 0x0C;
                data[4] = Bat.stt.bit.chrg;         // 是否充电中
                data[5] = Bat.vol - 200;            // 电池电压
                data[6] = Bat.lvl;                  // 电池电量等级
                data[7] = Led.light.delaySec / 60;  // 照明延时时间
                data[8] = SW_VERSION;               // 固件版本
                data[9] = Temp.val >> 8;            // 温度
                data[10] = Temp.val;                // 温度
                data[11] = 0;
                for (i = 1; i < 11; i++)
                {
                    data[11] += data[i];
                }
                PushSendBuf(data, 12);
            }
			break;
		//LED
		case 0x04:
			//写
			if(readOrWrite == 1)
			{				
                u8 delay = rxBuf[5];
                u8 mode = rxBuf[4];
                u16 pwmW = rxBuf[6] * 10;             // 照明亮度
                u8 breath = rxBuf[7];                 // 呼吸灯使能
                u16 pwmR = rxBuf[8] * 10;             // 红灯亮度
                u16 pwmG = rxBuf[9] * 10;             // 绿灯亮度
                u16 pwmB = rxBuf[10] * 10;            // 蓝灯亮度
               
                // 照明模式
                if (0 == mode)
                {
                    SetLight(pwmW, delay * 60);
                }
                // 彩灯模式
                else
                {
                    SetColor(pwmR, pwmG, pwmB, breath);
                }                
			}
			
            //读
			else if(readOrWrite == 0)
			{
				data[0] = 0x7f;
                data[1] = 0x04;
                data[2] = 0x00;
                data[3] = 0x0c;
                data[4] = Led.mode;                         // 模式
                data[5] = (Led.light.delaySec + 59) / 60;   // 延时时间
                data[6] = Led.light.pwmW / 10;                   // 照明亮度
                data[7] = Led.color.breath;                 // 呼吸灯
                data[8] = Led.color.pwmR / 10;                   // 红灯亮度
                data[9] = Led.color.pwmG / 10;                   // 绿灯亮度
                data[10] = Led.color.pwmB / 10;                  // 蓝灯亮度
                data[11] = 0;
                for (i = 1; i < 11; i++)
                {
                    data[11] += data[i];
                }
                PushSendBuf(data, 12);
			}
			break;
		
		default:
			break;
	}
Exemplo n.º 12
0
BOOL NMEAParser::GGA(TCHAR *String, TCHAR **params, size_t nparams, NMEA_INFO *GPS_INFO)
{

  if (ReplayLogger::IsEnabled()) {
        return TRUE;
  }

  GGAAvailable = TRUE;
  GPSCONNECT = TRUE;     // 091208

  // this will force gps invalid but will NOT assume gps valid!
  nSatellites = (int)(min(16.0, StrToDouble(params[6], NULL)));
  if (nSatellites==0) {
	gpsValid = false;
  }

  double ggafix = StrToDouble(params[5],NULL);
  if ( ggafix==0 || ggafix>5 ) {
	#ifdef DEBUG_GPS
	if (ggafix>5) StartupStore(_T("------ GGA DEAD RECKON fix skipped%s"),NEWLINE);
	#endif
	gpsValid=false;
  } else {
	gpsValid=true;
  }

  // don't set any GPS_INFO if not activeGPS!!
  if (!activeGPS) return TRUE;

  GPS_INFO->SatellitesUsed = nSatellites; // 091208
  GPS_INFO->NAVWarning = !gpsValid; // 091208

//  // GPS_INFO->SatellitesUsed = (int)(min(16,StrToDouble(params[6], NULL))); 091205 091208 moved up
//  GPS_INFO->SatellitesUsed = nSatellites; // 091205

  double ggatime=StrToDouble(params[0],NULL);
  // Even with invalid fix, we might still have valid time
  // I assume that 0 is invalid, and I am very sorry for UTC time 00:00 ( missing a second a midnight).
  // is better than risking using 0 as valid, since many gps do not respect any real nmea standard
  if (ggatime>0) { 
	#ifdef NEWTRIGGERGPS
	double ThisTime = TimeConvert(ggatime, GPS_INFO);
	#else
	double ThisTime = TimeModify(ggatime, GPS_INFO);
	#endif

	#ifndef NEWTRIGGERGPS
	if (!TimeHasAdvanced(ThisTime, GPS_INFO))
		return FALSE;
	#endif

	#ifdef NEWTRIGGERGPS
		// is time advanced to a new quantum?
		if (ThisTime >NmeaTime) {
			// yes so lets trigger the gps event
			TriggerGPSUpdate();
			Sleep(50); // 091208
			NmeaTime=ThisTime;
			TimeSet(GPS_INFO); // 091208
			TimeHasAdvanced(ThisTime, GPS_INFO); // 091208
			StartupStore(_T(".............. trigger from GGA\n"));
		}
	#endif
  }
  if (gpsValid) {
	double tmplat;
	double tmplon;
	tmplat = MixedFormatToDegrees(StrToDouble(params[1], NULL));
	tmplat = NorthOrSouth(tmplat, params[2][0]);
	tmplon = MixedFormatToDegrees(StrToDouble(params[3], NULL));
	tmplon = EastOrWest(tmplon,params[4][0]);
	if (!((tmplat == 0.0) && (tmplon == 0.0))) {
		GPS_INFO->Latitude = tmplat;
		GPS_INFO->Longitude = tmplon;
	} 
	else {
		#ifdef DEBUG_GPS
		StartupStore(_T("++++++ GGA gpsValid with invalid posfix!%s"),NEWLINE);
		#endif
		gpsValid=false;
	}
  }
 
  // GGA is marking now triggering end of data, so OK to use baro
  // Even with invalid fix we might have valid baro data of course

  // any NMEA sentence with time can now trigger gps update: the first to detect new time will make trigger.
  // we assume also that any sentence with no time belongs to current time.
  // note that if no time from gps, no use of vario and baro data, but also no fix available.. so no problems
  if(RMZAvailable) {
	GPS_INFO->BaroAltitudeAvailable = true;
	GPS_INFO->BaroAltitude = RMZAltitude;
  }
  else if(RMAAvailable) {
	GPS_INFO->BaroAltitudeAvailable = true;
	GPS_INFO->BaroAltitude = RMAAltitude;
  }

#ifndef NEWTRIGGERGPS
  if (!gpsValid) { // 091108 addon BUGFIX GCA
	// in old mode, GGA had priority over RMC for triggering, so this was needed in case of no signal 
	TriggerGPSUpdate(); // 091205 TESTFIX
	return FALSE; // 091108 addon BUGFIX GCA
  }
#endif

  // "Altitude" should always be GPS Altitude.
  GPS_INFO->Altitude = ParseAltitude(params[8], params[9]);
  GPS_INFO->Altitude += (GPSAltitudeOffset/1000); // BUGFIX 100429
  
  double GeoidSeparation;

  if (_tcslen(params[10])>0) {
    // No real need to parse this value,
    // but we do assume that no correction is required in this case
    GeoidSeparation = ParseAltitude(params[10], params[11]);
  } else {
	if (UseGeoidSeparation) {
		GeoidSeparation = LookupGeoidSeparation(GPS_INFO->Latitude, GPS_INFO->Longitude);
		GPS_INFO->Altitude -= GeoidSeparation;
	}
  }

#ifndef NEWTRIGGERGPS
  // if RMC would be Triggering update, we loose the relative altitude, which is coming AFTER rmc! 
  // This was causing old altitude recorded in new pos fix.
  TriggerGPSUpdate(); 
#endif
  return TRUE;
}
Exemplo n.º 13
0
int main(void)
{
    u08 i,j,g,sel,rm;

    //Key 
    PORTD=0x00;
    DDRD=0xff;

    sbi(DDRD,5);
    cbi(DDRD,2);
    cbi(DDRD,3);
    cbi(DDRD,4);
    sbi(PORTD,6);
    cbi(PORTD,5);


    cbi(PORTA,RST);
    LCDINI();

    Page0:
    LCDGOTOXY(1,0);

    /// draws smart home picture
    for(i=0;i<=62;i++)
        for(j=0;j<=7;j++)
            spi_write(Welup[i][j]);

    for(i=0;i<10;i++)
        _delay_ms(200);

     cbi(PORTA,RST);

     Mainmenu:
    sbi(PORTA,RST);
    LCDBRD();/// draws border
    LCDCLR();// clear lcd


    //displays date and time
    LCDSTR(date,1,1,0);
    LCDSTR(time,8,2,0);
    LCDMEN("H O M E",4,4);

    //waiting for key
    Page:
    if(getKey()!=KEY_OK) goto Page;

//MENU Page 0 // menu list 
    Menulist:
    pos=0;             //pos=highlighted position //all  room names and total no of rooms
    LCDCLR();
    for(i=0;i<T_1;i++)
       ri[i]=i;   
    rmdisp(T_1,0,0);
   
    while(1)
    {
        g=getKey();
        if(g==KEY_DOWN || g==KEY_UP)
            rmdisp(T_1,g,0);
        else if (g==KEY_BACK)
        goto Mainmenu;
        else if(g==KEY_OK) 
        break;
    }   


sel=ri[pos];

   if ( sel == 3)// set time - time syncronize with central server(cordinator) date time()
   {
       TimeSet();
       goto Menulist;
   }
//   PORTB=sel;
/////////////////////////////////////////////////////////////////////////////////////////////
// 
//ROOMS Disp page 1 pressing of ok
   Roomlist:
   pos=0;
//Page3:
   LCDCLR();

   for(i=0;i<RNO;i++)
    ri[i]=i;   
rmdisp(RNO,0,1);
while(1)
{
    g=getKey();
    if(g==KEY_UP || g==KEY_DOWN)
      rmdisp(RNO,g,1);
  else if(g==KEY_BACK)
      goto Menulist;
  else if(g==KEY_OK) 
   break;
//   delayms(7000);
}
rm=ri[pos]+1;

// selection based values ie room choice->temp ,pressure,control etc
//SENSOR Status Page 2 

pos=0;
if(sel==0) rmdisp(8,0,2);
while(sel==0)
{
 g=getKey();
 if(g==KEY_DOWN || g==KEY_UP)
   rmdisp(10,g,2);
else if (g==KEY_BACK)
    goto Roomlist;
else if(g==KEY_OK) goto Roomlist;
 //      delayms(7000);
}



pos=0;   //////////////////////////////////////control page switch display
if(sel==1)
{

  j=20;
  for(i=0;i<j;i++)
     ri[i]=i;
 swi(j,0,0);
 while(1)
 {
     g=getKey();
     if(g==KEY_UP || g==KEY_DOWN)
       swi(j,g,0);
   else if(g==KEY_STAR) 
   { 
       switc[ri[pos]][6] = switc[ri[pos]][6] ^ 0xff; 
       swi(j,12,0);
   }
   else if(g==KEY_OK)  goto Roomlist;
}
goto Page0;
}
else if(sel==4)
{
   pos=0;
   NameSet(1,rm);
   goto Menulist;
}
else if(sel==5)
{
  j=0;
  for(i=0;i<20;i++)
  {
     rd[j++]=i;
 }

 for(i=0;i<=j;i++)
     ri[i]=i;
 rmdisp(j+1,0,4);
 while(1)
 {
     g=getKey();
     if(g==KEY_DOWN || g==KEY_UP)
       rmdisp(j+1,g,4);
   else if(g==KEY_OK) break;
}

pos=0;
NameSet(0,ri[pos]);
goto Menulist;

}
else if(sel==2)
{
  SchSwitch:

  for(i=0;i<10;i++)
     ri[i]=i;
 swi(10,0,1);
 while(1)
 {
     g=getKey();
     if(g==KEY_DOWN || g==KEY_UP)
       swi(10,g,1);
   else if (g==KEY_STAR)
   {
       sch[ri[pos]][3]  =sch[ri[pos]][3] ^ 0x01;
       swi(10,19,1);
   }
   else if (g==KEY_BACK)
    goto Roomlist;
else if(g==KEY_OK) break;
}
j=ri[pos];
SchDisp:
LCDCLR();
schd(j,0);
pos=0;
while(1)
{
   g=getKey();
   if(g<=KEY_9 || g==KEY_STAR) 
      SchTimeSet(g,j);
  else if(g==KEY_DOWN && pos <16) pos =(pos +1);
  else if(g==KEY_UP && pos>0)   pos = (pos-1); 
  schd(j,0);
  if (g==KEY_BACK)
      goto SchSwitch;
  else
   if(g==KEY_OK)
   {
     g=SchTimeChk(j);
     if(g==1) goto SchDisp;
     else    goto Mainmenu;
 }
}

}

cbi(PORTA,4);

while(1);
return 0;
}
Exemplo n.º 14
0
/**
 * \brief UTHBuildPacketReal is a function that create tcp/udp packets for unittests
 * specifying ip and port sources and destinations (IPV6)
 *
 * \param payload pointer to the payloadd buffer
 * \param payload_len pointer to the length of the payload
 * \param ipproto Protocols allowed atm are IPPROTO_TCP and IPPROTO_UDP
 * \param src pointer to a string containing the ip source
 * \param dst pointer to a string containing the ip destination
 * \param sport pointer to a string containing the port source
 * \param dport pointer to a string containing the port destination
 *
 * \retval Packet pointer to the built in packet
 */
Packet *UTHBuildPacketIPV6Real(uint8_t *payload, uint16_t payload_len,
                           uint8_t ipproto, char *src, char *dst,
                           uint16_t sport, uint16_t dport)
{
    uint32_t in[4];

    Packet *p = PacketGetFromAlloc();
    if (unlikely(p == NULL))
        return NULL;

    TimeSet(&p->ts);

    p->src.family = AF_INET6;
    p->dst.family = AF_INET6;
    p->payload = payload;
    p->payload_len = payload_len;
    p->proto = ipproto;

    p->ip6h = SCMalloc(sizeof(IPV6Hdr));
    if (p->ip6h == NULL)
        goto error;
    memset(p->ip6h, 0, sizeof(IPV6Hdr));
    p->ip6h->s_ip6_nxt = ipproto;
    p->ip6h->s_ip6_plen = htons(payload_len + sizeof(TCPHdr));

    if (inet_pton(AF_INET6, src, &in) != 1)
        goto error;
    p->src.addr_data32[0] = in[0];
    p->src.addr_data32[1] = in[1];
    p->src.addr_data32[2] = in[2];
    p->src.addr_data32[3] = in[3];
    p->sp = sport;
    p->ip6h->s_ip6_src[0] = in[0];
    p->ip6h->s_ip6_src[1] = in[1];
    p->ip6h->s_ip6_src[2] = in[2];
    p->ip6h->s_ip6_src[3] = in[3];

    if (inet_pton(AF_INET6, dst, &in) != 1)
        goto error;
    p->dst.addr_data32[0] = in[0];
    p->dst.addr_data32[1] = in[1];
    p->dst.addr_data32[2] = in[2];
    p->dst.addr_data32[3] = in[3];
    p->dp = dport;
    p->ip6h->s_ip6_dst[0] = in[0];
    p->ip6h->s_ip6_dst[1] = in[1];
    p->ip6h->s_ip6_dst[2] = in[2];
    p->ip6h->s_ip6_dst[3] = in[3];

    p->tcph = SCMalloc(sizeof(TCPHdr));
    if (p->tcph == NULL)
        goto error;
    memset(p->tcph, 0, sizeof(TCPHdr));
    p->tcph->th_sport = htons(sport);
    p->tcph->th_dport = htons(dport);

    SET_PKT_LEN(p, sizeof(IPV6Hdr) + sizeof(TCPHdr) + payload_len);
    return p;

error:
    if (p != NULL) {
        if (p->ip6h != NULL) {
            SCFree(p->ip6h);
        }
        if (p->tcph != NULL) {
            SCFree(p->tcph);
        }
        SCFree(p);
    }
    return NULL;
}
/*
********************************************************************************
*                                                                              *
*   Ponder() is the driver for "pondering" (thinking on the opponent's time.)  *
*   its operation is simple:  find a predicted move by (a) taking the second   *
*   move from the principal variation, or (b) call lookup to see if it finds   *
*   a suggested move from the transposition table.  then, make this move and   *
*   do a search from the resulting position.  while pondering, one of three    *
*   things can happen:  (1) a move is entered, and it matches the predicted    *
*   move.  we then switch from pondering to thinking and search as normal;     *
*   (2) a move is entered, but it does not match the predicted move.  we then  *
*   abort the search, unmake the pondered move, and then restart with the move *
*   entered.  (3) a command is entered.  if it is a simple command, it can be  *
*   done without aborting the search or losing time.  if not, we abort the     *
*   search, execute the command, and then attempt to restart pondering if the  *
*   command didn't make that impossible.                                       *
*                                                                              *
********************************************************************************
*/
int Ponder(int wtm)
{
  int dummy=0, i, *n_ponder_moves, *mv;
/*
 ----------------------------------------------------------
|                                                          |
|   first, let's check to see if pondering is allowed, or  |
|   if we should avoid pondering on this move since it is  |
|   the first move of a game, or if the game is over, or   |
|   "force" mode is active, or there is input in the queue |
|   that needs to be read and processed.                   |
|                                                          |
 ----------------------------------------------------------
*/
  if (!ponder || force || over || CheckInput()) return(0);
/*
 ----------------------------------------------------------
|                                                          |
|   if we don't have a predicted move to ponder, try two   |
|   sources:  (1) look up the current position in the      |
|   transposition table and see if it has a suggested best |
|   move;  (2) do a short tree search to calculate a move  |
|   that we should ponder.                                 |
|                                                          |
 ----------------------------------------------------------
*/
  strcpy(hint,"none");
  if (!ponder_move) {
    (void) LookUp(0,0,wtm,&dummy,&dummy);
    if (hash_move[0]) ponder_move=hash_move[0];
  }
  if (!ponder_move) {
    TimeSet(puzzle);
    if (time_limit < 3) return(0);
    puzzling=1;
    position[1]=position[0];
    printf("              puzzling over a move to ponder.\n");
    last_pv.path_length=0;
    last_pv.path_iteration_depth=0;
    for (i=0;i<MAXPLY;i++) {
      killer_move1[i]=0;
      killer_move2[i]=0;
      killer_count1[i]=0;
      killer_count2[i]=0;
    }
    (void) Iterate(wtm,puzzle,0);
    for (i=0;i<MAXPLY;i++) {
      killer_move1[i]=0;
      killer_move2[i]=0;
      killer_count1[i]=0;
      killer_count2[i]=0;
    }
    puzzling=0;
    if (pv[0].path_length) ponder_move=pv[0].path[1];
    if (!ponder_move) return(0);
    for (i=1;i<(int) pv[0].path_length-1;i++) last_pv.path[i]=pv[0].path[i+1];
    last_pv.path_length=pv[0].path_length-1;
    last_pv.path_iteration_depth=0;
    if (!ValidMove(1,wtm,ponder_move)) {
      ponder_move=0;
      return(0);
    }
  }
/*
 ----------------------------------------------------------
|                                                          |
|   display the move we are going to "ponder".             |
|                                                          |
 ----------------------------------------------------------
*/
  if (wtm)
    printf("White(%d): %s [pondering]\n",
          move_number,OutputMove(&ponder_move,0,wtm));
  else
    printf("Black(%d): %s [pondering]\n",
          move_number,OutputMove(&ponder_move,0,wtm));
  sprintf(hint,"%s",OutputMove(&ponder_move,0,wtm));
  if (post) printf("Hint: %s\n",hint);
/*
 ----------------------------------------------------------
|                                                          |
|   set the ponder move list and eliminate illegal moves.  |
|                                                          |
 ----------------------------------------------------------
*/
  n_ponder_moves=GenerateCaptures(0, wtm, ponder_moves);
  num_ponder_moves=GenerateNonCaptures(0, wtm, n_ponder_moves)-ponder_moves;
  for (mv=ponder_moves;mv<ponder_moves+num_ponder_moves;mv++) {
    MakeMove(0, *mv, wtm);
    if (Check(wtm)) {
      UnMakeMove(0, *mv, wtm);
      *mv=0;
      }
    else UnMakeMove(0, *mv, wtm);
  }
/*
 ----------------------------------------------------------
|                                                          |
|   now, perform an iterated search, but with the special  |
|   "pondering" flag set which changes the time controls   |
|   since there is no need to stop searching until the     |
|   opponent makes a move.                                 |
|                                                          |
 ----------------------------------------------------------
*/
  MakeMove(0,ponder_move,wtm);
  if (Rule50Moves(1)==90 || Rule50Moves(1)==91) ClearHashTables();
  last_opponent_move=ponder_move;
  if (ChangeSide(wtm))
    *rephead_w++=HashKey;
  else
    *rephead_b++=HashKey;
  if (RepetitionDraw(wtm)) printf("game is a draw by repetition\n");
  if (whisper) strcpy(whisper_text,"n/a");
  thinking=0;
  pondering=1;
  (void) Iterate(ChangeSide(wtm),think,0);
  pondering=0;
  thinking=0;
  if (ChangeSide(wtm))
    rephead_w--;
  else
    rephead_b--;
  last_opponent_move=0;
  UnMakeMove(0,ponder_move,wtm);
/*
 ----------------------------------------------------------
|                                                          |
|   search completed. the possible return values are:      |
|                                                          |
|   (0) no pondering was done, period.                     |
|                                                          |
|   (1) pondering was done, opponent made the predicted    |
|       move, and we searched until time ran out in a      |
|       normal manner.                                     |
|                                                          |
|   (2) pondering was done, but the ponder search          |
|       terminated due to either finding a mate, or the    |
|       maximum search depth was reached.  the result of   |
|       this ponder search are valid, but only if the      |
|       opponent makes the correct (predicted) move.       |
|                                                          |
|   (3) pondering was done, but the opponent either made   |
|       a different move, or entered a command that has to |
|       interrupt the pondering search before the command  |
|       (or move) can be processed.  this forces Main() to |
|       avoid reading in a move/command since one has been |
|       read into the command buffer already.              |
|                                                          |
 ----------------------------------------------------------
*/
  if (made_predicted_move) return(1);
  if (abort_search) return(3);
  return(2);
}
Exemplo n.º 16
0
BOOL NMEAParser::RMC(TCHAR *String, TCHAR **params, size_t nparams, NMEA_INFO *GPS_INFO)
{
  TCHAR *Stop;
  static bool logbaddate=true;
  double speed=0;

  gpsValid = !NAVWarn(params[1][0]);

  GPSCONNECT = TRUE;    
  RMCAvailable=true; // 100409

  if (!activeGPS) return TRUE; // 091205 BUGFIX true

  // if no valid fix, we dont get speed either!
  if (gpsValid)
  {
	speed = StrToDouble(params[6], NULL);
	// speed is in knots, 2 = 3.7kmh
	if (speed>2.0) {
		GPS_INFO->MovementDetected = TRUE;
		if (ReplayLogger::IsEnabled()) {
			// stop logger replay if aircraft is actually moving.
			ReplayLogger::Stop();
		}
	} else {
		GPS_INFO->MovementDetected = FALSE;
		if (ReplayLogger::IsEnabled()) {
			// block actual GPS signal if not moving and a log is being replayed
			return TRUE;
		}
	}
  }
  
  GPS_INFO->NAVWarning = !gpsValid;

  // say we are updated every time we get this,
  // so infoboxes get refreshed if GPS connected
  // the RMC sentence marks the start of a new fix, so we force the old data to be saved for calculations
#ifndef NEWTRIGGERGPS
  if (!GGAAvailable) { 
	TriggerGPSUpdate();
  }
#endif

	// Even with no valid position, we let RMC set the time and date if valid
	long gy, gm, gd;
	gy = _tcstol(&params[8][4], &Stop, 10) + 2000;   
	params[8][4] = '\0';
	gm = _tcstol(&params[8][2], &Stop, 10); 
	params[8][2] = '\0';
	gd = _tcstol(&params[8][0], &Stop, 10); 

	// SeeYou PC is sending NMEA sentences with RMC date 2072-02-27
	if ( ((gy > 1980) && (gy <2100) ) && (gm != 0) && (gd != 0) ) { 
		GPS_INFO->Year = gy;
		GPS_INFO->Month = gm;
		GPS_INFO->Day = gd;
#ifdef NEWTRIGGERGPS
		double ThisTime = TimeConvert(StrToDouble(params[0],NULL), GPS_INFO); // 091208
#else
		double ThisTime = TimeModify(StrToDouble(params[0],NULL), GPS_INFO);
#endif

#ifndef NEWTRIGGERGPS
		if (!TimeHasAdvanced(ThisTime, GPS_INFO))
			return FALSE;
#endif
#ifdef NEWTRIGGERGPS
		// is time advanced to a new quantum?
		if (ThisTime >NmeaTime) {
			// yes so lets trigger the gps event
			TriggerGPSUpdate();
			// and only then advance the time in the GPSINFO
			Sleep(50); // 091208
			NmeaTime=ThisTime;
			TimeSet(GPS_INFO); // 091208
			TimeHasAdvanced(ThisTime, GPS_INFO); // 091208
			StartupStore(_T(".............. trigger from RMC\n"));
		}
#endif
			
	}  else {
		if (gpsValid && logbaddate) { // 091115
			StartupStore(_T("------ NMEAParser:RMC Receiving an invalid or null DATE from GPS%s"),NEWLINE);
			StartupStore(_T("------ NMEAParser: Date received is y=%d m=%d d=%d%s"),gy,gm,gd,NEWLINE); // 100422
			StartupStore(_T("------ This message will NOT be repeated.%s"),NEWLINE);
			// DoStatusMessage(_T("WARNING: GPS IS SENDING INVALID DATE, AND PROBABLY WRONG TIME")); // REMOVE FIXV2
			// LKTOKEN 875  WARNING: GPS IS SENDING INVALID DATE, AND PROBABLY WRONG TIME")); 
			DoStatusMessage(gettext(TEXT("_@M875_")));
			logbaddate=false;
		}
	}
//  } // 091108

  if (gpsValid) {   // 091108 BUGFIX set latlon and speed ONLY if valid gpsdata, missing check!
	double tmplat;
	double tmplon;

	tmplat = MixedFormatToDegrees(StrToDouble(params[2], NULL));
	tmplat = NorthOrSouth(tmplat, params[3][0]);
	  
	tmplon = MixedFormatToDegrees(StrToDouble(params[4], NULL));
	tmplon = EastOrWest(tmplon,params[5][0]);
  
	if (!((tmplat == 0.0) && (tmplon == 0.0))) {
		GPS_INFO->Latitude = tmplat;
		GPS_INFO->Longitude = tmplon;
	}
  
	GPS_INFO->Speed = KNOTSTOMETRESSECONDS * speed;
  
	if (GPS_INFO->Speed>1.0) {
		// JMW don't update bearing unless we're moving
		GPS_INFO->TrackBearing = AngleLimit360(StrToDouble(params[7], NULL));
	}
  } // gpsvalid 091108
    
  // Altair doesn't have a battery-backed up realtime clock,
  // so as soon as we get a fix for the first time, set the
  // system clock to the GPS time.
  static bool sysTimeInitialised = false;
  
  if (!GPS_INFO->NAVWarning && (gpsValid)) {
	if (SetSystemTimeFromGPS) {
		if (!sysTimeInitialised) {
			if ( ( GPS_INFO->Year > 1980 && GPS_INFO->Year<2100) && ( GPS_INFO->Month > 0) && ( GPS_INFO->Hour > 0)) {
        
				sysTimeInitialised =true; // Attempting only once
				SYSTEMTIME sysTime;
				// ::GetSystemTime(&sysTime);
				int hours = (int)GPS_INFO->Hour;
				int mins = (int)GPS_INFO->Minute;
				int secs = (int)GPS_INFO->Second;
				sysTime.wYear = (unsigned short)GPS_INFO->Year;
				sysTime.wMonth = (unsigned short)GPS_INFO->Month;
				sysTime.wDay = (unsigned short)GPS_INFO->Day;
				sysTime.wHour = (unsigned short)hours;
				sysTime.wMinute = (unsigned short)mins;
				sysTime.wSecond = (unsigned short)secs;
				sysTime.wMilliseconds = 0;
				::SetSystemTime(&sysTime);
			}
		}
	}
  }

  if (!ReplayLogger::IsEnabled()) {      
	if(RMZAvailable) {
		// JMW changed from Altitude to BaroAltitude
		GPS_INFO->BaroAltitudeAvailable = true;
		GPS_INFO->BaroAltitude = RMZAltitude;
	}
	else if(RMAAvailable) {
	// JMW changed from Altitude to BaroAltitude
		GPS_INFO->BaroAltitudeAvailable = true;
		GPS_INFO->BaroAltitude = RMAAltitude;
	}
  }
  if (!GGAAvailable) {
	// update SatInUse, some GPS receiver dont emmit GGA sentance
	if (!gpsValid) { 
		GPS_INFO->SatellitesUsed = 0;
	} else {
		GPS_INFO->SatellitesUsed = -1;
	}
  }
  
  return TRUE;
}
Exemplo n.º 17
0
/*
 *******************************************************************************
 *                                                                             *
 *   Ponder() is the driver for "pondering" (thinking on the opponent's time.) *
 *   its operation is simple:  Find a predicted move by (a) taking the second  *
 *   move from the principal variation, or (b) call lookup to see if it finds  *
 *   a suggested move from the transposition table.  Then, make this move and  *
 *   do a search from the resulting position.  While pondering, one of three   *
 *   things can happen:  (1) A move is entered, and it matches the predicted   *
 *   move.  We then switch from pondering to thinking and search as normal;    *
 *   (2) A move is entered, but it does not match the predicted move.  We then *
 *   abort the search, unmake the pondered move, and then restart with the     *
 *   move entered.  (3) A command is entered.  If it is a simple command, it   *
 *   can be done without aborting the search or losing time.  If not, we abort *
 *   the search, execute the command, and then attempt to restart pondering if *
 *   the command didn't make that impossible.                                  *
 *                                                                             *
 *******************************************************************************
 */
int Ponder(int wtm) {
  TREE *const tree = block[0];
  int dalpha = -999999, dbeta = 999999, i;
  unsigned *n_ponder_moves, *mv;
  int save_move_number, tlom, value;

/*
 ************************************************************
 *                                                          *
 *  First, let's check to see if pondering is allowed, or   *
 *  if we should avoid pondering on this move since it is   *
 *  the first move of a game, or if the game is over, or    *
 *  "force" mode is active, or there is input in the queue  *
 *  that needs to be read and processed.                    *
 *                                                          *
 ************************************************************
 */
  if (!ponder || force || over || CheckInput())
    return 0;
  save_move_number = move_number;
/*
 ************************************************************
 *                                                          *
 *  Check the ponder move for legality.  If it is not a     *
 *  legal move, we have to take action to find something to *
 *  ponder.                                                 *
 *                                                          *
 ************************************************************
 */
  strcpy(ponder_text, "none");
  if (ponder_move) {
    if (!VerifyMove(tree, 1, wtm, ponder_move)) {
      ponder_move = 0;
      Print(4095, "ERROR.  ponder_move is illegal (1).\n");
      Print(4095, "ERROR.  PV pathl=%d\n", last_pv.pathl);
      Print(4095, "ERROR.  move=%d  %x\n", ponder_move, ponder_move);
    }
  }
/*
 ************************************************************
 *                                                          *
 *  First attempt, do a hash probe.  However, since a hash  *
 *  collision is remotely possible, we still need to verify *
 *  that the transposition/refutation best move is actually *
 *  legal.                                                  *
 *                                                          *
 ************************************************************
 */
  if (!ponder_move) {
    HashProbe(tree, 0, 0, wtm, dalpha, dbeta, &value);
    if (tree->hash_move[0])
      ponder_move = tree->hash_move[0];
    if (ponder_move) {
      if (!VerifyMove(tree, 1, wtm, ponder_move)) {
        Print(4095, "ERROR.  ponder_move is illegal (2).\n");
        Print(4095, "ERROR.  move=%d  %x\n", ponder_move, ponder_move);
        ponder_move = 0;
      }
    }
  }
/*
 ************************************************************
 *                                                          *
 *  Second attempt.  If that didn't work, then we try what  *
 *  I call a "puzzling" search.  Which is simply a shorter  *
 *  time-limit search for the other side, to find something *
 *  to ponder.                                              *
 *                                                          *
 ************************************************************
 */
  if (!ponder_move) {
    TimeSet(puzzle);
    if (time_limit < 20)
      return 0;
    puzzling = 1;
    tree->status[1] = tree->status[0];
    Print(32, "              puzzling over a move to ponder.\n");
    last_pv.pathl = 0;
    last_pv.pathd = 0;
    for (i = 0; i < MAXPLY; i++) {
      tree->killers[i].move1 = 0;
      tree->killers[i].move2 = 0;
    }
    Iterate(wtm, puzzle, 0);
    for (i = 0; i < MAXPLY; i++) {
      tree->killers[i].move1 = 0;
      tree->killers[i].move2 = 0;
    }
    puzzling = 0;
    if (tree->pv[0].pathl)
      ponder_move = tree->pv[0].path[1];
    if (!ponder_move)
      return 0;
    for (i = 1; i < (int) tree->pv[0].pathl; i++)
      last_pv.path[i] = tree->pv[0].path[i + 1];
    last_pv.pathl = tree->pv[0].pathl - 1;
    last_pv.pathd = 0;
    if (!VerifyMove(tree, 1, wtm, ponder_move)) {
      ponder_move = 0;
      Print(4095, "ERROR.  ponder_move is illegal (3).\n");
      Print(4095, "ERROR.  PV pathl=%d\n", last_pv.pathl);
      return 0;
    }
  }
/*
 ************************************************************
 *                                                          *
 *  Display the move we are going to "ponder".              *
 *                                                          *
 ************************************************************
 */
  if (wtm)
    Print(32, "White(%d): %s [pondering]\n", move_number, OutputMove(tree, 0,
            wtm, ponder_move));
  else
    Print(32, "Black(%d): %s [pondering]\n", move_number, OutputMove(tree, 0,
            wtm, ponder_move));
  sprintf(ponder_text, "%s", OutputMove(tree, 0, wtm, ponder_move));
  if (post)
    printf("Hint: %s\n", ponder_text);
/*
 ************************************************************
 *                                                          *
 *  Set the ponder move list and eliminate illegal moves.   *
 *  This list is used to test the move entered while we are *
 *  pondering, since we need a move list for the input      *
 *  screening process.                                      *
 *                                                          *
 ************************************************************
 */
  n_ponder_moves = GenerateCaptures(tree, 0, wtm, ponder_moves);
  num_ponder_moves =
      GenerateNoncaptures(tree, 0, wtm, n_ponder_moves) - ponder_moves;
  for (mv = ponder_moves; mv < ponder_moves + num_ponder_moves; mv++) {
    MakeMove(tree, 0, wtm, *mv);
    if (Check(wtm)) {
      UnmakeMove(tree, 0, wtm, *mv);
      *mv = 0;
    } else
      UnmakeMove(tree, 0, wtm, *mv);
  }
/*
 ************************************************************
 *                                                          *
 *  Now, perform an iterated search, but with the special   *
 *  "pondering" flag set which changes the time controls    *
 *  since there is no need to stop searching until the      *
 *  opponent makes a move.                                  *
 *                                                          *
 ************************************************************
 */
  MakeMove(tree, 0, wtm, ponder_move);
  tree->curmv[0] = ponder_move;
  tree->rep_list[++rep_index] = HashKey;
  tlom = last_opponent_move;
  last_opponent_move = ponder_move;
  if (kibitz)
    strcpy(kibitz_text, "n/a");
  thinking = 0;
  pondering = 1;
  if (!wtm)
    move_number++;
  ponder_value = Iterate(Flip(wtm), think, 0);
  rep_index--;
  move_number = save_move_number;
  pondering = 0;
  thinking = 0;
  last_opponent_move = tlom;
  UnmakeMove(tree, 0, wtm, ponder_move);
/*
 ************************************************************
 *                                                          *
 *  Search completed. the possible return values are:       *
 *                                                          *
 *  (0) No pondering was done, period.                      *
 *                                                          *
 *  (1) Pondering was done, opponent made the predicted     *
 *      move, and we searched until time ran out in a       *
 *      normal manner.                                      *
 *                                                          *
 *  (2) Pondering was done, but the ponder search           *
 *      terminated due to either finding a mate, or the     *
 *      maximum search depth was reached.  The result of    *
 *      this ponder search are valid, but only if the       *
 *      opponent makes the correct (predicted) move.        *
 *                                                          *
 *  (3) Pondering was done, but the opponent either made a  *
 *      different move, or entered a command that has to    *
 *      interrupt the pondering search before the command   *
 *      (or move) can be processed.  This forces Main() to  *
 *      avoid reading in a move/command since one has been  *
 *      read into the command buffer already.               *
 *                                                          *
 ************************************************************
 */
  if (input_status == 1)
    return 1;
  if (input_status == 2)
    return 3;
  return 2;
}
Exemplo n.º 18
0
/*
********************************************************************************
*                                                                              *
*   Ponder() is the driver for "pondering" (thinking on the opponent's time.)  *
*   its operation is simple:  find a predicted move by (a) taking the second   *
*   move from the principal variation, or (b) call lookup to see if it finds   *
*   a suggested move from the transposition table.  then, make this move and   *
*   do a search from the resulting position.  while pondering, one of three    *
*   things can happen:  (1) a move is entered, and it matches the predicted    *
*   move.  we then switch from pondering to thinking and search as normal;     *
*   (2) a move is entered, but it does not match the predicted move.  we then  *
*   abort the search, unmake the pondered move, and then restart with the move *
*   entered.  (3) a command is entered.  if it is a simple command, it can be  *
*   done without aborting the search or losing time.  if not, we abort the     *
*   search, execute the command, and then attempt to restart pondering if the  *
*   command didn't make that impossible.                                       *
*                                                                              *
********************************************************************************
*/
int Ponder(int wtm)
{
  int dummy=0, i, *n_ponder_moves;

/*
 ----------------------------------------------------------
|                                                          |
|   if we don't have a predicted move to ponder, try two   |
|   sources:  (1) look up the current position in the      |
|   transposition table and see if it has a suggested best |
|   move;  (2) do a short tree search to calculate a move  |
|   that we should ponder.                                 |
|                                                          |
 ----------------------------------------------------------
*/
  ponder_completed=0;
  if (!ponder_move) {
    (void) LookUp(0,0,wtm,&dummy,dummy);
    if (hash_move[0]) ponder_move=hash_move[0];
  }
  if (!ponder_move) {
    TimeSet(puzzle);
    if (time_limit < 3) return(0);
    puzzling=1;
    position[1]=position[0];
    Print(2,"              puzzling over a move to ponder.\n");
    last_pv.path_length=0;
    last_pv.path_iteration_depth=0;
    for (i=0;i<MAXPLY;i++) {
      killer_move1[i]=0;
      killer_move2[i]=0;
      killer_count1[i]=0;
      killer_count2[i]=0;
    }
    (void) Iterate(wtm,puzzle);
    for (i=0;i<MAXPLY;i++) {
      killer_move1[i]=0;
      killer_move2[i]=0;
      killer_count1[i]=0;
      killer_count2[i]=0;
    }
    puzzling=0;
    if (pv[0].path_length) ponder_move=pv[0].path[1];
    if (!ponder_move) return(0);
    for (i=1;i<(int) pv[0].path_length-1;i++) last_pv.path[i]=pv[0].path[i+1];
    last_pv.path_length=pv[0].path_length-1;
    last_pv.path_iteration_depth=0;
    if (!ValidMove(1,wtm,ponder_move)) {
      printf("puzzle returned an illegal move!\n");
      DisplayChessMove("move= ",ponder_move);
      ponder_move=0;
      return(0);
    }
  }
  if (!ponder_move) {
    strcpy(hint,"none");
    return(0);
  }
/*
 ----------------------------------------------------------
|                                                          |
|   display the move we are going to "ponder".             |
|                                                          |
 ----------------------------------------------------------
*/
  if (wtm)
    Print(2,"White(%d): %s [pondering]\n",
          move_number,OutputMove(&ponder_move,0,wtm));
  else
    Print(2,"Black(%d): %s [pondering]\n",
          move_number,OutputMove(&ponder_move,0,wtm));
  sprintf(hint,"%s",OutputMove(&ponder_move,0,wtm));
  n_ponder_moves=GenerateCaptures(0, wtm, ponder_moves);
  num_ponder_moves=GenerateNonCaptures(0, wtm, n_ponder_moves)-ponder_moves;
/*
 ----------------------------------------------------------
|                                                          |
|   now, perform an iterated search, but with the special  |
|   "pondering" flag set which changes the time controls   |
|   since there is no need to stop searching until the     |
|   opponent makes a move.                                 |
|                                                          |
 ----------------------------------------------------------
*/
  MakeMove(0,ponder_move,wtm);
  if (Rule50Moves(1)==90 || Rule50Moves(1)==91) ClearHashTables();
  last_opponent_move=ponder_move;
  if (ChangeSide(wtm))
    *rephead_w++=HashKey;
  else
    *rephead_b++=HashKey;
  if (RepetitionDraw(wtm)) Print(0,"game is a draw by repetition\n");
  if (whisper) strcpy(whisper_text,"n/a");
  pondering=1;
  (void) Iterate(ChangeSide(wtm),think);
  pondering=0;
  if (!abort_search) ponder_completed=1;
  if (ChangeSide(wtm))
    rephead_w--;
  else
    rephead_b--;
  last_opponent_move=0;
  UnMakeMove(0,ponder_move,wtm);
/*
 ----------------------------------------------------------
|                                                          |
|   search completed.  there are two possible reasons for  |
|   us to get here.  (1) the opponent made the predicted   |
|   move and we have used enough time on the search, or;   |
|   the operator typed in a command (or not-predicted      |
|   move) that requires the search to abort and restart.   |
|                                                          |
 ----------------------------------------------------------
*/
  if (made_predicted_move) return(1);
  return(0);
}