コード例 #1
0
// Take a line of the input file and make a gateOrWire struct from it.
struct gateOrWire *processGateLineRTL(randctx *globalIsaacContext, char *line, struct gateOrWire **circuit, unsigned char *R, int idOffset, int numInputs1)
{
	int strIndex = 0, idNum, i;
	int numInputWires, purposelessNumber;
	int *inputIDs;

	numInputWires = getIntFromString(line, strIndex);

	// As of yet unsure of the purpose of this number. Ask Nigel? Otherwise we just ignore it.
	purposelessNumber = getIntFromString(line, strIndex);

	inputIDs = (int*) calloc(numInputWires, sizeof(int));
	for(i = 0; i < numInputWires; i ++)
	{
		idNum = getIntFromString(line, strIndex);
		if(idNum >= numInputs1)
		{
			inputIDs[i] = idNum + idOffset;
		}
		else
		{
			inputIDs[i] = idNum;
		}
	}

	idNum = getIntFromString(line, strIndex) + idOffset;

	return processGateOrWireRTL(globalIsaacContext, idNum, inputIDs, numInputWires, line[strIndex], circuit, R, numInputs1);
}
コード例 #2
0
	// ---------------------------------------------------------------------------------------
	// Decode OregonScientific V2 protocol for specific
	// Oregon Devices
	//
	// Support :
	// - THGR122NX : Temp + Humidity
	//				 OSV2 1A2D1002 502060552A4C
	//               In correct order :
	//					OSV2 A 1D20 1 20 0 502 0 655 2A 4C
	//					OSV2 => decoding header
	//						 A => Sync header
	//						   1D20	=> THGR122NX ID
	// - THN132N : Temp
	//				OSV2 EA4C20809822D013
	//				In correct order :
	//				   OSV2 A EC40 2 08 8 922 D0 13
	//
	// ------------------------------------------------------------------------------------------
	bool OregonSensorV2::decode( char * _str ) {
		char * pt = & _str[5];
		int  len = strlen(_str);
		char sensorId[5]; int isensorId;

		// Proceed the right sensor
		if ( len > 11 ) {
			sensorId[0] = pt[0];sensorId[1] = pt[3];sensorId[2] = pt[2];sensorId[3] = pt[5];sensorId[4]='\0';
			isensorId = getIntFromString(sensorId);
#ifdef SENSORDEBUG
			printf("OSV2 - decode : id(%s)(0x%4X)\n",sensorId, isensorId);
#endif

			switch (isensorId) {
			case 0x1D20:
				this->sensorType=0x1D20;
				return decode_THGR122NX(pt); break;
			case 0xEC40:
				this->sensorType=0xEC40;
				return decode_THN132N(pt); break;
			default:
				return false;

			}

		}
		return false;
	}
コード例 #3
0
// devuelve la propiedad como entero
int XmlNodo::getPropiedadInt(const std::string& nombre) {
	std::string aux = getPropiedad(nombre);

	if (aux.size())
		return getIntFromString (aux);
	else {
		return -1;
		// aca puede devolver -1 o nada porque el usuario ya sabe
	}
}
コード例 #4
0
int16_t
parse_cmd_rfm12_ask_2272_send (char *cmd, char *output, uint16_t len)
{
  (void) output;
  (void) len;

  uint8_t command[3];
  uint8_t delay = 74;
  uint8_t cnt = 10;
#ifdef TEENSY_SUPPORT
  while (*cmd == ' ')
    cmd++;
  command[0] = getIntFromString (cmd);
  while (*cmd != ',')
    cmd++;
  cmd++;
  command[1] = getIntFromString (cmd);
  while (*cmd != ',')
    cmd++;
  cmd++;
  command[2] = getIntFromString (cmd);
  while (*cmd != ' ')
    cmd++;
  cmd++;
  delay = getIntFromString (cmd);
  while (*cmd != ' ')
    cmd++;
  cmd++;
  cnt = getIntFromString (cmd);
  int ret = 5;
#else
  int ret = sscanf_P (cmd, PSTR ("%hhu,%hhu,%hhu %hhu %hhu"), &(command[0]),
		      &(command[1]), &(command[2]), &delay, &cnt);
#endif
  RFM12_DEBUG ("ps cmd %u,%u,%u d %u s %u", command[0], command[1],
	       command[2], delay, cnt);
  if (ret < 3)
    return ECMD_ERR_PARSE_ERROR;

  rfm12_ask_2272_send (command, delay, cnt);
  return ECMD_FINAL_OK;
}
コード例 #5
0
// devuelve el contenido como entero
int XmlNodo::getContenidoInt() {
	if ( !this->nodo )
		throw new NullNodeExc();

	std::string aux = getContenido();

	if ( aux.size() == 0)
		throw new ContenidoIntVacioExc( this->getNombre() );

	return getIntFromString (aux);
}
コード例 #6
0
ファイル: number.cpp プロジェクト: ThQ/memc
char
parseIntNumber (std::string str, int& nb)
{
   nb = 0;
   // FIXME This is so ugly it hurts...
   if (getCharFromString(str.c_str(), nb))
   {
      return 'c';
   }
   else if (getShortFromString(str.c_str(), nb))
   {
      return 's';
   }
   else if (getIntFromString(str.c_str(), nb))
   {
      return 'i';
   }
   return '\0';
}
コード例 #7
0
ファイル: stdio.c プロジェクト: tcolloca/loco-mouseOS
static int getIntFromString(char c, int * dest, int * i, int base, const char * src, int * j) {
	if( c == cut ) {
		return 1;
	} else if( !validNum(c, base) ) {
		return 0;
	}

	char chr = src[(*j)++];
	int ret = getIntFromString(chr, dest, i, base, src, j);
	
	if( isdigit(c) )
		*dest += (c - '0') * pow(base, (*i)++); 
	else if( isupper(c) )
		*dest += (c - 'A' + 10) * pow(base, (*i)++); 
	else
		*dest += (c - 'a' + 10) * pow(base, (*i)++); 
	
	return ret;
}
コード例 #8
0
	// ---------------------------------------------------------------------------------------
	// Decode OregonScientific V2 protocol for specific
	// Oregon Devices
	// - THGR122NX : Temp + Humidity
	//				 1A2D1002502060552A4C
	//			     1A2D1002300638042BB7 		=> -6°C
	//				 A 1D20 1 20 0 360 8 340 2BB7
	//               In correct order :
	//					A 1D20 1 20 0 502 0 655 2A 4C
	//						 A => Sync header
	//						   1D20	=> THGR122NX ID
	//                              1 => Channel ( 1 | 2 | 4 )
	//                                20 => rolling (random value def @ reset)
	//                                   0 => battery flag & 0x4
	//										XXX => temperature BCD to be read left from right
	//                                          0 => temperature sign 0 = positive
	//                                            XX (X) => hummidity BCD to be read L from R
	//                                                      last digit unclear as it is not a BCD when > 75%
	//                                                2A => checksum from ID to Humid (8b sum)
	//													4C => CRC8 from ID to Humid w/o rolling
	//														  init : 0x43 CRCPoly : 0x07
	// ------------------------------------------------------------------------------------------
	bool OregonSensorV2::decode_THGR122NX(char * pt) {

		char channel; int ichannel;				// values 1,2,4
		char rolling[3]; int irolling;
		char battery; int ibattery;				// value & 0x4
		char temp[4]; double dtemp;				// Temp in BCD
		char tempS;	int itempS;					// Sign 0 = positif
		char humid[4]; double dhumid;				// Humid in BCD
		char checksum[3]; int ichecksum;
		char crc[3]; int icrc;
		int  len = strlen(pt);

		if ( len == 20 ) {
			channel = pt[4];
			rolling[0]=pt[7]; rolling[1]=pt[6]; rolling[2]='\0';
			battery = pt[9];
			temp[0] = pt[10] ; temp[1] = pt[11] ; temp[2] = pt[8] ; temp[3] = '\0';
			tempS = pt[13];
// BugFix	humid[0] = pt[15] ; humid[1] = pt[12]; humid[2] = pt[14] ; humid[3] = '\0'; /* when humid >75% pt[14] = 0xD ... */
			humid[0] = pt[15] ; humid[1] = pt[12]; humid[2] = '0' ; humid[3] = '\0';
			checksum[0] = pt[16];	checksum[1] = pt[17]; checksum[2] = '\0';
			crc[0] = pt[18] ; crc[1] = pt[19] ; crc[2] = '\0';

#ifdef SENSORDEBUG
			printf("OSV2 - decode : id(%s) ch(%c) bat(%c) temp(%s) sign(%c) humid(%s) cksum(%s) crc(%s)\n",
			                        "1D20",channel,battery,temp,tempS,humid, checksum, crc);
#endif

			// Conversion to int value
			ichannel = getIntFromChar(channel);
			irolling = getIntFromString(rolling);
			ibattery = getIntFromChar(battery);
			itempS = getIntFromChar(tempS) & 0x08;
			ichecksum = getIntFromString(checksum);
			icrc = getIntFromString(crc);
			dtemp = getDoubleFromString(temp);
			dhumid = getDoubleFromString(humid);

#ifdef SENSORDEBUG
			printf("OSV2 - decode : id(0x%04X) ch(%d) bat(%d) temp(%f) sign(%d) humid(%f) cksum(0x%02X) crc(0x%02X)\n",
			                        0x1D20,ichannel,ibattery,dtemp,itempS,dhumid, ichecksum, icrc);
#endif

			// Check SUM & CRC
			if ( validate(pt,16,icrc,ichecksum) == true ) {

				// now we can decode the important flag and fill the object
				this->haveChannel = true;
				this->channel = (ichannel != 4)?ichannel:3;

				this->haveBattery = true;
				this->battery = (ibattery & 0x4);

				this->haveTemperature = true;
				this->temperature = (itempS == 0)?dtemp:-dtemp;

				this->haveHumidity = true;
				this->humidity = dhumid;

				return true;
			} else return false;

		}
		return false;
	}
コード例 #9
0
	// ---------------------------------------------------------------------------------------
	// Decode OregonScientific V2 protocol for specific
	// Oregon Devices
	// - THN132N : Temp
	//				OSV2 EA4C2080 9822 D013		22.8°C
	//              OSV2 EA4C2080 5208 F813		08.5°C
	//			    OSV2 EA4C2080 0201 B082
	//				OSV2 EA4C2080 7202 3053
	//				OSV2 EA4C2080 2204 0073
	//			    OSV2 EA4C2080 6206 6063
	//				OSV2 EA4C2080 9210 40C3
	//			    OSV2 EA4C2080 4211 0033
	//			    OSV2 EA4C2080 1212 E002
	//				OSV2 EA4C2080 6234 70C3		34.6°C
	//			    OSV2 EA4C2080 5231 3043		31.5°C
	//				OSV2 EA4C2080 9207 28F4		// negatif autour de -7 ?
	//			    OSV2 EA4C2080 0213 68A3		// negatif -13
	//				OSV2 EA4C2080 7019 9043
	//				In correct order :
	//				   OSV2 A EC40 2 08 8 922 0 3D 1
	//	     				A => Sync header
	//						  EC40	=> THN132N ID
	//                             2 => Channel ( 1 | 2 | 4 )
	//                               08 => rolling (random value def @ reset)
	//                                  8 => battery flag & 0x4 other unknown
	//										could be : 0x2 => rising
	//												   0x8 => decreasing, to be analysed
	//									  XXX => temperature BCD to be read left from right
	//											0 => Sign 0 = + ; 8 = -
	//											  3D => CheckSum ( from EC40 to Sign)
	// ------------------------------------------------------------------------------------------
	bool OregonSensorV2::decode_THN132N(char * pt) {

		char channel; int ichannel;				// values 1,2,4
		char rolling[3]; int irolling;
		char battery; int ibattery;				// value & 0x4
		char temp[4]; double dtemp;				// Temp in BCD
		char tempS;	int itempS;					// Sign 0 = positif
		char checksum[3]; int ichecksum;
		int  len = strlen(pt);

		if ( len == 16 ) {
			channel = pt[4];
			rolling[0]=pt[7]; rolling[1]=pt[6]; rolling[2]='\0';
			battery = pt[9];
			temp[0] = pt[10] ; temp[1] = pt[11] ; temp[2] = pt[8] ; temp[3] = '\0';
			tempS = pt[13];
			checksum[0] = pt[15];	checksum[1] = pt[12]; checksum[2] = '\0';

#ifdef SENSORDEBUG
			printf("OSV2 - decode : id(%s) ch(%c) bat(%c) temp(%s) sign(%c) cksum(%s) \n",
			                        "EC040",channel,battery,temp,tempS, checksum);
#endif

			// Conversion to int value
			ichannel = getIntFromChar(channel);
			irolling = getIntFromString(rolling);
			ibattery = getIntFromChar(battery) & 0x04;
			itempS = getIntFromChar(tempS) & 0x08;
			ichecksum = getIntFromString(checksum);
			dtemp = getDoubleFromString(temp);

			// Check SUM
			int _sum = getIntFromChar(pt[0]);
			for ( int i = 2 ; i <= 11 ; i++ ) _sum += getIntFromChar(pt[i]);
			_sum += getIntFromChar(pt[13]);


#ifdef SENSORDEBUG
			printf("OSV2 - decode : id(0x%04X) ch(%d) bat(%d) temp(%f) sign(%d) cksum(0x%02X) _chksum(0x%02X)\n",
			                        0xEC40,ichannel,ibattery,dtemp,itempS, ichecksum, _sum);
#endif

			if ( _sum == ichecksum ){

				// now we can decode the important flag and fill the object
				this->haveChannel = true;
				this->channel = (ichannel != 4)?ichannel:3;

				this->haveBattery = true;
				this->battery = (ibattery != 0);

				this->haveTemperature = true;
				this->temperature = (itempS == 0)?dtemp:-dtemp;

				this->haveHumidity = false;

				return true;
			} else return false;

		}
		return false;
	}
コード例 #10
0
ファイル: stdio.c プロジェクト: tcolloca/loco-mouseOS
int vsscanf(const char * src, const char * fmt, va_list args) {

	int read = 0, i = 0, j = 0, type, state = CHAR;
	int sign, hasSign, base;
	char * str, * sdest;	
	char c;
	while( fmt[i] != 0 ) {
		switch( state ) {
			case CHAR:
				switch( fmt[i] ) {
					case '%':
						state = PERCENTAGE;
						break;
					case ' ':
					default:
						c = src[j++];
						if( c != fmt[i] )
							return read;
				}
				i++;
				break;
			case PERCENTAGE:
				switch( fmt[i] ) {
					case '%':
						state = CHAR;
						c = src[j++];
						if( c != fmt[i] )
							return read;
						i++;
						break;
					case 'd':
						state = GETINT;
						type = DEC;
						break;
					case 'h':
					case 'x':
						state = GETINT;
						type = HEX;
						break;
					case 'o':
						state = GETINT;
						type = OCT;
						break;
					case 'c':
						state = GETCHAR;
						break;
					case 's':
						state = GETSTRING;
						break;
					default:
						return -1; //TODO: ERROR
				}
				break;
			case GETINT:
				base = 10;
				hasSign = 0;
				sign = 1;
				i++;
				cut = fmt[i++];
				state = CHAR;
				c = src[j++];
				switch( c ) {
					case '-':
						sign = -1;
					case '+':
						c = src[j++];
						hasSign = 1;
						break;
				}

				if( hasSign && c == cut ) {
					return read;
				} else if( !hasSign && c == cut ) {					
					break;
				}
 
				if( type == OCT || type == HEX) {
					if( c != '0' ) {
						return read;
					}
					c = src[j++];
			
					if( type == HEX ) {
						if( c != 'x' )
							return read;
						c = src[j++];
						base = 16;
					} else
						base = 8;
					
				}
				
				if( !validNum(c, base) ) {
					return read;
				} else {
					int * dest = va_arg(args, int *);
					int k = 0;
					int ret;
					*dest = 0;
					ret = getIntFromString(c, dest, &k, base, src, &j);
					*dest *= sign;
					read++;
					if( !ret ) {
						return read;
					} 
				}
				break;
			case GETCHAR:
				state = CHAR;
				c = src[j++];
				if( !isgraph(c) )
					return read;
				*va_arg(args, char *) = c;
				i++;
				read++;
				break;
			case GETSTRING:	
				i++;		
				cut = fmt[i++];
				state = CHAR;
				c = src[j++];
				sdest = va_arg(args, char *);
				str = sdest;	
					
				while( c != cut && isgraph(c) ) {
					*(sdest++) = c;
					c = src[j++];					
				}	
				*sdest = 0;
					
				if( (*str) )
					read++;

				if( c != cut )
					return read;
				
				break;		
		}
	}
	return read;
}