示例#1
0
void MasterSystem::UIVarChanged(byte uivn, int val) {
  DEBUG_PRINT_S(" MAS:UIV-");
  DEBUG_PRINT_I(uivn);
  DEBUG_PRINT_S("=");
  DEBUG_PRINT_I(val);
  DEBUG_PRINT_S(".");

  switch (uivn) {
    case UIVM_STRENGTH_DIFFICULTY:
      initcharge.setTargetPercent(10 * val);
      break;
  }
}
示例#2
0
int Add_Category()
{
	int ret, ret_val=0, svcGroup;

	char        fname[FILESIZE], *env;
	DLinkedList head, tail, *node;

	st_CategoryInfo		stCat;
	DESTIP_DATA	DestIP, *pDestIP;
	DESTIP_KEY	DestIPKey1, DestIPKey2;

	DESTPORT_DATA	DestPort, *pDestPort;
	DESTPORT_KEY	DestPortKey1, DestPortKey2;

	int	found, iPrefix;
	unsigned int	uiIP, uiNetMask;

	if ((env = getenv(IV_HOME)) == NULL){
		sprintf( trcBuf, "getenv error! \n" );
		trclib_writeLogErr (FL,trcBuf);
		return -1;
	}

	sprintf (fname, "%s/%s", env, SERVICE_TYPE_FILE);

	set_head_tail(&head, &tail);
	if(make_conf_list(fname, &head) < 0){
		sprintf (trcBuf, "make linked list fail; err=%d(%s)\n", errno, strerror(errno));
		trclib_writeLogErr (FL,trcBuf);
	 	return -1;
	 }


	// add & update
	node = &head;
	while( node->next ) {
		node = node->next;
		if(node->item.gubun != TOK_CONF_LINE) continue;

DEBUG_PRINT_A(node->item.line);
		memset( &stCat, 0x00, sizeof(st_CategoryInfo) );

		load_svc_group(node->item.columns, &stCat);

		svcGroup = stCat.ucGroup >> 4;
DEBUG_PRINT_I(svcGroup);
		switch( svcGroup ){
			case 1:		/* DESTIP */

				memset( &DestIP, 0x00, sizeof(DESTIP_DATA) );

				DestIP.key.ucFlag = 'D';
				uiIP = inet_addr( stCat.szCon[0] );
				iPrefix = atoi( stCat.szCon[1] );
				if( iPrefix < 0 || iPrefix > 32)
				{
					ret_val = -1;
					sprintf(trcBuf, "DESTIP iPrefix[%d] GroupID:%d", 
					iPrefix, svcGroup);
					trclib_writeLogErr (FL,trcBuf);
					break;
				}
				if( strcmp(stCat.szCon[0], "255.255.255.255") !=0 && 
				uiIP == (in_addr_t)-1 )
				{
					ret_val = -1;
					sprintf(trcBuf, "DESTIP NET[%s:%d] GroupID:%d", 
						stCat.szCon[0], uiIP, svcGroup);
					trclib_writeLogErr (FL,trcBuf);
					break;
				}
				uiNetMask = 0xffffffff << (32 - iPrefix);

				/* input error handling */
				uiIP = htonl(uiIP) | ~uiNetMask;
				DestIP.key.uiIP = ntohl(uiIP);

				DestIP.uiNetmask = uiNetMask;
				DestIP.usCatID = stCat.usCategory;
				DestIP.ucGroupID = stCat.ucGroup;
				/* Sequence */
				DestIP.ucSerial = stCat.szServiceID[0];
				DestIP.ucFilterOut = stCat.ucFilterOut;

				//Obsolete
				//DestIP.ucLayer = stCat.ucLayer;
				// 21 - including retransmission
				DestIP.ucLayer = 21;

				DestIP.ucURLChar = stCat.ucMode;
				DestIP.ucSvcBlk = stCat.ucSvcBlk;
				DestIP.ucCDRIPFlag = stCat.szReserved[0];
				DestIP.ucUDRFlag = stCat.szReserved[1]; // add by helca

DEBUG_MEM(DestIP.key, (sizeof(DestIP.key)));

				pDestIP = Search_DESTIP( &DestIP.key );
				if( pDestIP == 0 ){	/* not exist */
					ret = Insert_DESTIP( &DestIP );
DEBUG_PRINT("SVC type 1 Insert_DESTIP");
				}else{
					ret = Update_DESTIP( pDestIP, &DestIP );
DEBUG_PRINT("SVC type 1 Update_DESTIP");
                }
				if( ret < 0 )
				{
					ret_val = -1;
					sprintf(trcBuf, "pDestIP[%p] GroupID:%d ret[%d]", 
						pDestIP, svcGroup, ret);
					trclib_writeLogErr (FL,trcBuf);
					break;
				}
				break;

			case 2:		/* DESTIP+TCP PORT */
			case 3:		/* DESTIP+UDP PORT */
				uiIP = inet_addr( stCat.szCon[0] );
				iPrefix = atoi( stCat.szCon[1] );
				if( iPrefix < 0 || iPrefix > 32)
				{
					ret_val = -1;
					sprintf(trcBuf, "DESTPORT iPrefix[%d] GroupID:%d", 
					iPrefix, svcGroup);
					trclib_writeLogErr (FL,trcBuf);
					break;
				}

				if( strcmp(stCat.szCon[0], "255.255.255.255") !=0 && 
					uiIP == (in_addr_t)-1 )
				{
					ret_val = -1;
					sprintf(trcBuf, "DESTPORT NET[%s:%d] GroupID:%d", 
					stCat.szCon[0], uiIP, svcGroup);
					trclib_writeLogErr (FL,trcBuf);
					break;
				}

				uiNetMask = 0xffffffff << (32 - iPrefix);

				memset( &DestPort, 0x00, sizeof(DESTPORT_DATA) );
				uiIP = htonl(uiIP) | ~uiNetMask;
				DestPort.key.uiDestIP = ntohl(uiIP);
				if( svcGroup == 2 )
					DestPort.key.ucProtocol = 6;	/* TCP */
				else
					DestPort.key.ucProtocol = 17;	/* UDP */

				DestPort.key.usDestPort = atoi( stCat.szCon[2] );

				DestPort.uiNetmask = uiNetMask;
				DestPort.usCatID = stCat.usCategory;
				DestPort.ucGroupID = stCat.ucGroup;
				DestPort.ucSerial = stCat.szServiceID[0]; // sequence
				DestPort.ucFilterOut = stCat.ucFilterOut;
				//Obsolete
				//DestPort.ucLayer = stCat.ucLayer;
				// 21 means including retransmission.
				DestPort.ucLayer = 21;

				DestPort.ucURLChar = stCat.ucMode;       /* 040429 added by js */
				DestPort.ucSvcBlk = stCat.ucSvcBlk;
				DestPort.ucCDRIPFlag = stCat.szReserved[0];
				DestPort.ucUDRFlag = stCat.szReserved[1]; // add by helca

				pDestPort = Search_DESTPORT( &DestPort.key );

DEBUG_MEM(DestPort.key, (sizeof(DestPort.key)));
				if( pDestPort == 0 ){	/* not exist */
					ret = Insert_DESTPORT( &DestPort );
DEBUG_PRINT("SVC type 2(3) Insert_DESTIP");
				}else{
					ret = Update_DESTPORT( pDestPort, &DestPort );
DEBUG_PRINT("SVC type 2(3) Update_DESTIP");
                }
				if( ret < 0 )
				{
					ret_val = -1;
					sprintf(trcBuf, "pDestPort[%p] GroupID:%d ret[%d]", 
					pDestPort, svcGroup, ret);
					trclib_writeLogErr (FL,trcBuf);
					break;
				}

				break;

			default:
				sprintf(trcBuf, "Undefined GroupID:%d", svcGroup );
				trclib_writeLogErr (FL,trcBuf);
				break;
		}
	}

	// delete
	if( ret_val == 0 )
	{
		// destip delete
		memset( &DestIPKey1, 0x00, sizeof(DESTIP_KEY) );
		DestIPKey1.ucFlag = 'D';

		memset( &DestIPKey2, 0xff, sizeof(DESTIP_KEY) );
		DestIPKey2.ucFlag = 'D';

		while( 1 )
		{
			pDestIP = Select_DESTIP( &DestIPKey1, &DestIPKey2 );
			if( pDestIP == 0 || pDestIP->key.ucFlag != 'D')
				break;

			memcpy( &DestIPKey1, &pDestIP->key, sizeof(DESTIP_KEY) );

			// convert key if needed
			memcpy( &DestIP, pDestIP, sizeof(DESTIP_DATA) );
			DestIP.key.uiIP = htonl(DestIP.key.uiIP);
			found = 0;
			node = &head;
			while( node->next )
			{
				node = node->next;
				if(node->item.gubun != TOK_CONF_LINE) continue;

				memset( &stCat, 0x00, sizeof(st_CategoryInfo) );
				load_svc_group(node->item.columns, &stCat);

				svcGroup = stCat.ucGroup >> 4;
				if( svcGroup != 1 )
					continue;

				uiIP = inet_addr( stCat.szCon[0] );
// inet_addr return Network byter ordered IP Addr
				uiIP = htonl(uiIP);
				iPrefix = atoi( stCat.szCon[1] );
				uiNetMask = 0xffffffff << (32-iPrefix);
				
DEBUG_MEM(DestIP.key.uiIP, (sizeof(DestIP.key.uiIP)));
DEBUG_MEM(uiIP, (sizeof(uiIP)));
DEBUG_MEM(DestIP.uiNetmask, (sizeof(DestIP.uiNetmask)));
DEBUG_MEM(uiNetMask, (sizeof(uiNetMask)));

				if( (DestIP.key.uiIP & DestIP.uiNetmask) == (uiIP & DestIP.uiNetmask) 
						&& DestIP.uiNetmask == uiNetMask )
				{
					found = 1;
					break;
				}
			}

			if( !found )
			{
DEBUG_PRINT("Delete_DESTIP");
				ret = Delete_DESTIP( &DestIPKey1 );
				if( ret < 0 )
					ret_val = -1;
			}
		}

		// destport delete
		memset( &DestPortKey1, 0x00, sizeof(DESTPORT_KEY) );
		memset( &DestPortKey2, 0xff, sizeof(DESTPORT_KEY) );

		while( 1 )
		{
			pDestPort = Select_DESTPORT( &DestPortKey1, &DestPortKey2 );
			if( pDestPort == 0 ) 
				break;

			memcpy( &DestPortKey1, &pDestPort->key, sizeof(DESTPORT_KEY) );

			// convert key if needed
			memcpy( &DestPort, pDestPort, sizeof(DESTPORT_DATA) );
			DestPort.key.uiDestIP = htonl(DestPort.key.uiDestIP);
			found = 0;
			node = &head;
			while( node->next )
			{
				node = node->next;
				if(node->item.gubun != TOK_CONF_LINE) continue;

				memset( &stCat, 0x00, sizeof(st_CategoryInfo) );
				load_svc_group(node->item.columns, &stCat);

				svcGroup = stCat.ucGroup >> 4;

				switch( DestPort.key.ucProtocol )
				{
					case 6 : // TCP
						if( svcGroup == 2 )  // 
							break;
						continue;
					case 17 : // UDP
						if( svcGroup ==3 )   //
							break;
						continue;
					default :
							continue;
				}
						
				uiIP = inet_addr( stCat.szCon[0] );
//  inet_addr returns network byte orderd IP Address
				uiIP = htonl(uiIP);
				iPrefix = atoi( stCat.szCon[1] );
				uiNetMask = 0xffffffff << (32-iPrefix);

DEBUG_MEM(DestPort.key.uiDestIP, (sizeof(DestPort.key.uiDestIP)));
DEBUG_MEM(uiIP, (sizeof(uiIP)));
DEBUG_MEM(DestPort.uiNetmask, (sizeof(DestPort.uiNetmask)));
DEBUG_MEM(uiNetMask, (sizeof(uiNetMask)));
					
				// 2003/09/25 edit by hwh
				if( (DestPort.key.uiDestIP & DestPort.uiNetmask) == 
					(uiIP & DestPort.uiNetmask) && 
					DestPort.uiNetmask == uiNetMask && 
					DestPort.key.usDestPort == atoi(stCat.szCon[2]) )
				{
					found = 1;
					break;
				}
			}

			if( !found )
			{
DEBUG_PRINT("Delete_DESTPORT");
				ret = Delete_DESTPORT( &DestPortKey1 );
				if( ret < 0 )
					ret_val = -1;
			}
		}
	}
示例#3
0
/* MasterSystem loop
 *  This function is called from the main loop
 *  1. Read PushBackSonar and Air pressure in main push back system
 *  2. If the sonar value is > CHARGE_DISTANCE_TRIP (390), ui.goStrengthPosthit - which just updates the screen display
 *  3. If the pressure in the tank is > CHARGE_PRESSURE_TRIP  (400) ,  which goes into ui.goStrengthPosthit which just updates the display
*/
void MasterSystem::loop() {
//  Serial.println("Master loop started");
//  Serial.print("lastUIstate: "); Serial.println(master.lastUIState);
//  Serial.print("last ready state: "); Serial.println(master.lastReadyState);
//  Serial.print("last tow state: "); Serial.println(master.lastTowSwitch);
  pushBackAve();
  outriggerLooseAve();
  outriggerTightAve();

  if (strengthChargeTimeoutMillis > 0) {
    // read sonar and pushback pressure
    //int son  = halReadSonar_Pushback(2);
    int son = getPushbackSonarAve();
    int pres = analogRead(aiAchievedPin);
    
    Serial.print("Sonar PUSHBACK READING: "); Serial.println(son);
    Serial.print("Pressure in PUSHBACK: "); Serial.println(pres);
//    Serial.println("waiting for debug button");
//    //while(pulseIn(ioTight_ball_sonar, HIGH) > 300);  Serial.println("continue");
    
    
    DEBUG_PRINT_S("#");
    DEBUG_PRINT_I(millis());
    DEBUG_PRINT_S("\t");  DEBUG_PRINT_I(son);
    DEBUG_PRINT_S("\t");  DEBUG_PRINT_I(pres);
    DEBUG_PRINT_S("\t");  DEBUG_PRINT_I(
      strengthChargeTimeoutMillis >  32767L ?  32767 :
      strengthChargeTimeoutMillis < -32768L ? -32768 :
      strengthChargeTimeoutMillis);
    DEBUG_PRINT_S("\n");

    // check sonar distance
//    Serial.print("Pushback Sonar Value: "); Serial.println(son);
//    Serial.print("Pushback Air Pressure: "); Serial.println(pres);
//    Serial.println("waiting for debug button");
//    //while(pulseIn(ioTight_ball_sonar, HIGH) > 300);  Serial.println("continue");
    
    if (son > CHARGE_DISTANCE_TRIP) { //#define CHARGE_DISTANCE_TRIP  390   // if sonar over this, shutdown
      // if sonar too high,
      strengthChargeTimeoutMillis = 0;
      ui.goStrengthPosthit(UISPH_TOO_HIGH, son - CHARGE_DISTANCE_TRIP);//this just updates the lcd screen display
      return;
    }

    // check sonar speed
    //  long sonarMillis = millis();
    //  if (???) {
    //    // if sonar increasing too fast,
    //    strengthChargeTimeoutMillis = 0;
    //    ui.goStrengthPosthit(UISPH_TOO_FAST, 0);
    //    return;
    //  }
    //  lastSonarDistance = son;
    //  lastSonarMillis   = sonarMillis;

    // check pushback pressure
    if (pres > CHARGE_PRESSURE_TRIP) {  //#define CHARGE_PRESSURE_TRIP  400   // if pressure over this, shutdown (400 means approx. 30 lbs)
      // if pushback pressure too much,
      strengthChargeTimeoutMillis = 0;
      ui.goStrengthPosthit(UISPH_TOO_MUCH, pres - CHARGE_PRESSURE_TRIP);
      return;
    }
/* Code Added by Trevor and Zach
 *  The code below, keeps track of the timer for the strength charge push, which after they hold this for a certain 
 *  time, the sled is released, and it can be pushed. The sled push length is handled by anothter timer.
 *  Rollover is taken into account here.
*/
    // check for Duration timeout
     long m = millis();
     long elapsedMillis = 0;
    if (m > lastMillis)
        elapsedMillis = m - lastMillis;
    else
        elapsedMillis = m - lastMillis + MILLIS_MAX; //rollover
    lastMillis = m; 
    strengthChargeTimeoutMillis -= elapsedMillis;
    if (strengthChargeTimeoutMillis < 0) {
      strengthChargeTimeoutMillis = 0;
      digitalWrite(oSuccess, HIGH); //allow for the sled to move
      successStartTime = millis();
      ui.goStrengthPosthit(UISPH_SUCCESS, 0);//changes the screen to display success
      accustat.saveHiddenPeak();
    }
  } // end if (strengthChargeTimeoutMillis > 0)
}// end master loop