コード例 #1
0
inline std::string
Unescape(std::string const & aText)
{
  if (!aText.empty()) {
    std::string unescaped;
    size_t len = aText.length();
    for (size_t i = 0; i < len; i++) {
      if (i+2 < len && 
          aText[i] == '%' && 
          isHex(aText[i+1]) && 
          isHex(aText[i+2]))
      {
        unescaped.push_back((char)
                ((hexValue(aText[i+1]) << 4) | hexValue(aText[i+2])));
        i += 2;
      }
      else if (aText[i] == '+')
        unescaped.push_back(' ');
      else
        unescaped.push_back(aText[i]);
    }
    return unescaped;
  }
  return aText;
}
コード例 #2
0
ファイル: qurlrecode.cpp プロジェクト: LonelyPale/goqt
// if the sequence at input is 2*HEXDIG, returns its decoding
// returns -1 if it isn't.
// assumes that the range has been checked already
static inline ushort decodePercentEncoding(const ushort *input)
{
    ushort c1 = input[1];
    ushort c2 = input[2];
    if (!isHex(c1) || !isHex(c2))
        return ushort(-1);
    return decodeNibble(c1) << 4 | decodeNibble(c2);
}
コード例 #3
0
ファイル: utils.c プロジェクト: CODECOMMUNITY/libcss
/**
 * Parse a hash colour (#rgb or #rrggbb)
 *
 * \param data    Pointer to colour string
 * \param result  Pointer to location to receive result (AARRGGBB)
 * \return CSS_OK      on success,
 *         CSS_INVALID if the input is invalid
 */
css_error css__parse_hash_colour(lwc_string *data, uint32_t *result)
{
	uint8_t r = 0, g = 0, b = 0, a = 0xff;
	size_t len = lwc_string_length(data);
	const char *input = lwc_string_data(data);

	if (len == 3 &&	isHex(input[0]) && isHex(input[1]) &&
			isHex(input[2])) {
		r = charToHex(input[0]);
		g = charToHex(input[1]);
		b = charToHex(input[2]);

		r |= (r << 4);
		g |= (g << 4);
		b |= (b << 4);
	} else if (len == 6 && isHex(input[0]) && isHex(input[1]) &&
			isHex(input[2]) && isHex(input[3]) &&
			isHex(input[4]) && isHex(input[5])) {
		r = (charToHex(input[0]) << 4);
		r |= charToHex(input[1]);
		g = (charToHex(input[2]) << 4);
		g |= charToHex(input[3]);
		b = (charToHex(input[4]) << 4);
		b |= charToHex(input[5]);
	} else
		return CSS_INVALID;

	*result = (a << 24) | (r << 16) | (g << 8) | b;

	return CSS_OK;
}
コード例 #4
0
ファイル: Encode.cpp プロジェクト: Qarterd/Honeycomb
Bytes hex_decode(const String& string)
{
    Bytes ret;
    ret.reserve(string.length()/2);
    
    for (auto i: range(0, (string.length()/2)*2, 2))
    {
        if (!isHex(string[i]) || !isHex(string[i+1])) break;
        ret.push_back((fromHex(string[i]) << 4) | fromHex(string[i+1]));
    }
    return ret;
}
コード例 #5
0
ファイル: mktables.c プロジェクト: AlexSnet/libz80
char* nextToken(char* cur, byte* val, TokenType* ttype)
{
	*ttype = TT_END;
	while (*cur)
	{
		if (*cur == ' ')
		{
			cur++;
			continue;
		}
		else if (isHex(*cur) && isHex(*(cur+1)))
		{
			*val = (hexVal(*cur) << 4) | hexVal(*(cur+1));
			*ttype = TT_OPCODE;
			cur += 2;
			break;
		}
		else if (*cur == 'd')
		{
			*ttype = TT_D;	
			cur++;
			break;
		}
		else if (*cur == 'e')
		{
			*ttype = TT_E;
			cur++;
			break;
		}
		else if ((*cur == 'n') && (*(cur+1) == 'n'))
		{
			*ttype = TT_NN;
			cur += 2;
			break;
		}
		else if (*cur == 'n')
		{
			*ttype = TT_N;
			cur++;
			break;
		}
		else
		{
			fatal2("Unknown char	at ", cur);
		}
	};
	
	return cur;
}
コード例 #6
0
/*!
   Process WEP key validation. Following keys are allowed:
   
   HEX: 
   - 64 bit: allowed key length = 10
   - 128 bit: allowed key length = 26
   
   ASCII:
   - 64 bit: allowed key length = 5   
   - 128 bit: allowed key length = 13
   
   @param [in] key WEP Key to be validated
   
   @return Following values are possible
   - KeyStatusOk
   - KeyStatusIllegalCharacters
   - KeyStatusWepInvalidLength
 */
WlanWizardUtils::KeyStatus WlanWizardUtils::validateWepKey(const QString &key)
{
    OstTraceFunctionEntry0( WLANWIZARDUTILS_VALIDATEWEPKEY_ENTRY );
#ifdef OST_TRACE_COMPILER_IN_USE
    TPtrC tmp(key.utf16(),key.length() );
    OstTraceExt1( TRACE_NORMAL, WLANWIZARDUTILS_VALIDATEWEPKEY, 
        "WlanWizardUtils::validateWepKey;key=%S", tmp );
#endif
    
    int length = key.length();
    KeyStatus ret = KeyStatusOk;
    
    if (length == WepHex64BitMaxLength || length == WepHex128BitMaxLength) {
        ret = isHex(key);
    } else if (length == WepAscii64BitMaxLength || length == WepAscii128BitMaxLength) {
        ret = isAscii(key);
    } else {
        ret = KeyStatusWepInvalidLength;
    }

    OstTrace1( 
        TRACE_NORMAL, WLANWIZARDUTILS_VALIDATEWEPKEY_RETURN, 
        "WlanWizardUtils::validateWepKey - Return;ret=%{KeyStatus}", ret );
    
    OstTraceFunctionExit0( WLANWIZARDUTILS_VALIDATEWEPKEY_EXIT );
    return ret;
}
コード例 #7
0
ファイル: Transaction.cpp プロジェクト: Criptomonedas/rippled
bool Transaction::isHexTxID(const std::string& txid)
{
	if (txid.size() != 64) return false;
	for (int i = 0; i < 64; ++i)
		if (!isHex(txid[i])) return false;
	return true;
}
コード例 #8
0
int ParseProfLine(const char *pchIn, long *plAddress, int *piSamples, float *pfPercentage)
{
  char chVal[128], *pchOut;
  
  /* skip any initial whitespace */
  while (isSpace(*pchIn)) pchIn++;
  if (!isHex(*pchIn)) return 0;
  
  /* parse hexadecimal address value */
  pchOut = chVal;
  while (isHex(*pchIn)) *pchOut++ = *pchIn++;
  *pchOut = 0;
  if (!isSpace(*pchIn)) return 0;
  *plAddress = strtol(chVal, NULL, 16);
  
  /* skip more whitespace */
  while (isSpace(*pchIn)) pchIn++;
  if (!isNum(*pchIn)) return 0;
  
  /* parse decimal sample count value */
  pchOut = chVal;
  while (isNum(*pchIn)) *pchOut++ = *pchIn++;
  *pchOut = 0;
  if (!isSpace(*pchIn)) return 0;
  *piSamples = atoi(chVal);
  
  /* skip more whitespace */
  while (isSpace(*pchIn)) pchIn++;
  if (!isFloat(*pchIn)) return 0;
  
  /* parse floating-point percentage value */
  pchOut = chVal;
  while (isFloat(*pchIn)) *pchOut++ = *pchIn++;
  *pchOut = 0;
  if (!isSpace(*pchIn) && *pchIn != '\r' && *pchIn != '\n' && *pchIn != 0) return 0;
  *pfPercentage = atof(chVal);

  /* if this isn't the end of the line, it's not a valid sample point */
  while (isSpace(*pchIn)) pchIn++;
  if (*pchIn != '\r' && *pchIn != '\n' && *pchIn != 0) return 0;
 
  return 1;
}
コード例 #9
0
string Operand::toHex() {
    string ret = "";
    if (isHex() || type == OperandType::XBYTES || type == OperandType::XLITERAL){
        return operand;
    } else if (type == OperandType::CBYTES || type == OperandType::CLITERAL) {
        for(char c : operand) {
            ret += autalities::toByte((int) c);
        }
    } else if (isNumber()) {
        return autalities::toWord(operand);
    }
    return ret;
}
コード例 #10
0
int verifyInstallationId(const char* id) {
    int i;
    if (strlen(id) != 36) return 0;
    for (i = 0 ; i < 36; i++) {
        if (i == 8 || i == 13 || i == 18 || i == 23) {
            if (id[i] != '-') return 0;
        } else {
            if (!isHex(id[i])) return 0;
        }
    }

    return 1;
}
コード例 #11
0
ファイル: HexBin.cpp プロジェクト: gitrider/wxsj2
bool HexBin::isArrayByteHex(const XMLCh* const hexData)
{
    if ( !isInitialized )
        init();

    if (( hexData == 0 ) || ( *hexData == 0 )) // zero length
        return true;

    int strLen = XMLString::stringLen(hexData);
    if ( strLen%2 != 0 )
        return false;

    for ( int i = 0; i < strLen; i++ )
        if( !isHex(hexData[i]) )
            return false;

    return true;
}
コード例 #12
0
ファイル: calc.c プロジェクト: QuiteTheChoi/C
/* Will take in both numbers to validate that the numbers are entered correctly.
 * Will run the numbers to other functions based on the type specified by user. 
 * Returns a 1 if number entered is found to be an invalid format.*/
int validateToken(char* num) {
	char tempType;
	char* tempNum;
	
	if (num[0] == '-' && strlen(num) <= 2) {         	//to have a negative sign means you must have at least a '-', a type (b,o,x,d) 
		return 1;										// and at least one digit.
	}
	else if (num[0] == '-') {
		tempType = num[1];
		tempNum = strdup(&num[2]);
	}
	else if (strlen(num) <= 1) {						//string must contain a type and at least one digit
		return 1;
	}
	else {
		tempType = num[0];
		tempNum = strdup(&num[1]);
	}

	if (tempType == 'b' || tempType == 'B')								//determination of type and whether number entered is valid. 
	{
		return isBinary(tempNum);
	}
	else if (tempType == 'o'|| tempType == 'O')
	{
		return isOctal(tempNum);
	}
	else if (tempType == 'x' || tempType == 'X')
	{
		return isHex(tempNum);
	}
	else if (tempType == 'd' || tempType == 'D')
	{
		curr_State = mightBeDecFirstNum;
		return isDecimal(tempNum);		
	}
	curr_State = undetermined;
	free(tempNum);
	return 1;
}
コード例 #13
0
ファイル: m_libcbase.c プロジェクト: Zekom/valgrind
Bool VG_(parse_Addr) ( const HChar** ppc, Addr* result )
{
   Int used, limit = 2 * sizeof(Addr);
   if (**ppc != '0')
      return False;
   (*ppc)++;
   if (**ppc != 'x')
      return False;
   (*ppc)++;
   *result = 0;
   used = 0;
   while (isHex(**ppc)) {
      // ??? need to vg_assert(d < fromHex(**ppc));
      *result = ((*result) << 4) | fromHex(**ppc);
      (*ppc)++;
      used++;
      if (used > limit) return False;
   }
   if (used == 0)
      return False;
   return True;
}
コード例 #14
0
//
// ----------------------------------------------------------------------------
//
bool CMemoryIniFile::Update( char* szSection, char* szName, DWORD& dwValue, bool bWrite)
{
	bool bRC;
	std::string strValue;

	if (bWrite) str::sprintf(strValue,"%u", dwValue); 
	bRC = Update(  szSection,  szName, strValue, bWrite) == TRUE;
	
	if (bRC && !bWrite)
	{		
        str::Trim(strValue);
        if (isHex(strValue))
        {
            str::ToLower(strValue);
            sscanf(strValue.c_str(), "%x", &dwValue);
        }
        else
        {
            dwValue = atol(strValue.c_str());
        }					
	}
	return bRC;
}
コード例 #15
0
//
// ----------------------------------------------------------------------------
//
bool CMemoryIniFile::Update( char* szSection, char* szName, LONGLONG&  nlValue, bool bWrite)
{
	bool bRC;
    std::string strValue;
    
	if (bWrite) str::sprintf(strValue,"%I64d", nlValue);
	bRC = Update(  szSection,  szName, strValue, bWrite);

	if (bRC && !bWrite)
	{		
        str::Trim(strValue);
		if (isHex(strValue))
		{
			str::ToLower(strValue);
			sscanf(strValue.c_str(), "%I64x", &nlValue);
		}
		else
		{
			nlValue = _atoi64(strValue.c_str());
		}		
	}
	return bRC;
}
コード例 #16
0
ファイル: rx-debug.c プロジェクト: ssalenik/machine
void check_debug_uart(void) {
	static uint8_t inputbuf[RX_LINE_SIZE], inputptr = 0;
	uint8_t i, recv;
	int16_t ticks;
	
	while(uart_available(DEBUG)) {
		recv = uart_get(DEBUG);
		
		if(recv == '\r') {
			fprintf(&debug, "\r\n");
			
			if(inputptr) {
				switch(inputbuf[0]) {
					case '?': // print drive command list
					fprintf_P(&debug, PSTR("stop() ........................ | p00\r\n"));
					fprintf_P(&debug, PSTR("fwd_both(speed) ............... | p0300, p0400, p15 u8\r\n"));
					fprintf_P(&debug, PSTR("rev_both(speed) ............... | p0301, p0401, p15 u8\r\n"));
					fprintf_P(&debug, PSTR("forward(Lspeed, Rspeed) ....... | p0300, p0400, p11 u8, p12 u8\r\n"));
					fprintf_P(&debug, PSTR("reverse(Lspeed, Rspeed) ....... | p0301, p0401, p11 u8, p12 u8\r\n"));
					fprintf_P(&debug, PSTR("turnCCW(Lspeed, Rspeed) ....... | p0301, p0400, p11 u8, p12 u8\r\n"));
					fprintf_P(&debug, PSTR("turnCW (Lspeed, Rspeed) ....... | p0300, p0401, p11 u8, p12 u8\r\n"));
					fprintf_P(&debug, PSTR("set_abs_pos(pos) .............. | p1a s16\r\n"));
					fprintf_P(&debug, PSTR("set_rel_pos(sect, pos) ........ | p1b u8 u8\r\n"));
					fprintf_P(&debug, PSTR("pos_corr_on() ................. | p1f01\r\n"));
					fprintf_P(&debug, PSTR("pos_corr_off() ................ | p1f00\r\n"));
					fprintf_P(&debug, PSTR("nav_abs_pos(speed, pos) ....... | p31 u8 s16\r\n"));
					fprintf_P(&debug, PSTR("nav_rel_pos(speed, sect, pos) . | p32 u8 u8 u8\r\n"));
					break;
					
					case 'p': // passthrough to DRIVE MCU
					for(i = 1; i < inputptr; i++) { uart_put(DRIVE, inputbuf[i]); }
					uart_put(DRIVE, '\r');
					break;
					
					case 'r': // toggle reverse passthrough from DRIVE MCU
					rev_passthru ^= 1;
					break;
					
					case 'd': // local dump on/off
					local_dump ^= 1;
					break;
					
					case 's': // start/stop main thread
					run_main ^= 1;
					if(run_main) { fprintf_P(&debug, PSTR("Main thread started!\r\n")); }
					else         { fprintf_P(&debug, PSTR("Main thread stopped!\r\n")); stop(); }
					break;
					
					case 't': // start/stop test thread
					if(inputptr != 2) { cmd_err(); break; }
					run_test = htoa(0, inputbuf[1]);
					if(!run_test) { fprintf_P(&debug, PSTR("All test sequences stopped!\r\n")); stop(); }
					else { fprintf_P(&debug, PSTR("Started test sequence %u!\r\n"), run_test); }
					break;
					
					case ' ': // stop all motors
					run_main = 0;
					run_test = 0;
					pid_on = 0;
					stop();
					set_speed_3(0);
					set_speed_4(0);
					break;
					
					case 'u':
					fprintf_P(&debug, PSTR("%lu\r\n"), uptime());
					break;
					
					case 'b':
					#define VBAT_FACTOR 0.0044336
					fprintf_P(&debug, PSTR("4 x %1.2fV\r\n"), (float)read_adc(VSENS) * VBAT_FACTOR);
					break;
                    
					case 'm': // servo power
					if(inputptr != 2 || (inputbuf[1] & ~1) != '0') { cmd_err(); break; }
					inputbuf[1] == '0' ? clr_bit(SPWR) : set_bit(SPWR);
					break;
					
					case '9': // magnets
					if(inputptr != 2 || (inputbuf[1] & ~1) != '0') { cmd_err(); break; }
					if(inputbuf[1] == '0') { clr_bit(FET1); clr_bit(FET2); fprintf_P(&debug, PSTR("Magnets off!\r\n")); }
					else                   { set_bit(FET1); set_bit(FET2); fprintf_P(&debug, PSTR("Magnets on!\r\n"));  }
					break;
					
					case '1': // PID on/off
					if(inputptr != 2 || (inputbuf[1] & ~1) != '0') { cmd_err(); break; }
					if(inputbuf[1] == '0') { pid_on = 0; fprintf_P(&debug, PSTR("PID off!\r\n")); }
					else                   { pid_on = 1; fprintf_P(&debug, PSTR("PID on!\r\n")); reset_pid(); }
					break;
					
					case '3': // turn motor commands
					if(!isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; }
					switch(inputbuf[1]) {
						case '0': // forward (uint8_t speed)
						if(inputptr != 4) { cmd_err(); break; }
						motor3_fwd();
						set_speed_3(htoa(inputbuf[2], inputbuf[3]) * 40);
						break;
						
						case '1': // reverse (uint8_t speed)
						if(inputptr != 4) { cmd_err(); break; }
						motor3_rev();
						set_speed_3(htoa(inputbuf[2], inputbuf[3]) * 40);
						break;
						
						case '2': // set reference target (int16_t ticks)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						pid_target[MOTOR3] = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '3': // set reference speed (int16_t ticks)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						pid_speed[MOTOR3] = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '4': // set P (int16_t factor)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						//ENC3_P = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '5': // set I (int16_t factor)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						//ENC3_I = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '6': // set D (int16_t factor)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						//ENC3_D = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '7': // set noise gate (int16_t level)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						//ENC3_NOISE_GATE = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case 'f': // set reference angle
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						ticks = deg2ticks(htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]));
						cli();
						V_encoder = ticks;
						sei();
						reset_pid();
						break;
						
						default:
						cmd_err();
					}
					break;
					
					case '4': // lift motor commands
					if(!isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; }
					switch(inputbuf[1]) {
						case '0': // up (uint8_t speed)
						if(inputptr != 4) { cmd_err(); break; }
						motor4_fwd();
						set_speed_4(htoa(inputbuf[2], inputbuf[3]) * 40);
						break;
						
						case '1': // down (uint8_t speed)
						if(inputptr != 4) { cmd_err(); break; }
						motor4_rev();
						set_speed_4(htoa(inputbuf[2], inputbuf[3]) * 40);
						break;
						
						case '2': // set reference target (int16_t ticks)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						pid_target[MOTOR4] = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '3': // set reference speed (int16_t ticks)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						pid_speed[MOTOR4] = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '4': // set P (int16_t factor)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						//ACTU_P = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '5': // set I (int16_t factor)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						//ACTU_I = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '6': // set D (int16_t factor)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						//ACTU_D = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						case '7': // set noise gate (int16_t level)
						if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
						//ACTU_NOISE_GATE = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
						break;
						
						default:
						cmd_err();
					}
					break;
					
					case '5': // servo5 commands
					if(inputptr != 4 || !isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; }
					servo5(htoa(inputbuf[2], inputbuf[3]));
					//OCR0A = htoa(inputbuf[1], inputbuf[2]);
					break;
					
					case '6': // servo6 commands
					if(inputptr != 4 || !isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; }
					servo6(htoa(inputbuf[2], inputbuf[3]));
					//OCR0B = htoa(inputbuf[1], inputbuf[2]);
					break;
					
					case '7': // servo7 commands
					if(inputptr != 4 || !isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; }
					servo7(htoa(inputbuf[2], inputbuf[3]));
					//OCR2A = htoa(inputbuf[1], inputbuf[2]);
					break;
					
					case '8': // servo8 commands
					if(inputptr != 4 || !isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; }
					servo8(htoa(inputbuf[2], inputbuf[3]));
					//OCR2B = htoa(inputbuf[1], inputbuf[2]);
					break;
					
					case 'x':
					if(!isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; }
					switch(inputbuf[1]) {					
						case '1': // set reference angle
							if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
							param1 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
							break;
						case '2': // set reference angle
							if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
							param2 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
							break;
						case '3': // set reference angle
							if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
							param3 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
							break;
						case '4': // set reference angle
							if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
							param4 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
							break;
						case '5': // set reference angle
							if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; }
							param5 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]);
							break;
					}
					break;
					
					default:
					cmd_err();
				}
				
				inputptr = 0;
			}
		}
		else if(recv == 0x7f) {
			if(!inputptr) { uart_put(DEBUG, '\a'); }
			else {
				fprintf(&debug, "\b\e[K");
				inputptr--;
			}
		}
		else {
			if(inputptr == RX_LINE_SIZE) { uart_put(DEBUG, '\a'); }
			else {
				uart_put(DEBUG, recv);
				inputbuf[inputptr] = recv;
				inputptr++;
			}
		}
	}
コード例 #17
0
ファイル: MyOs.c プロジェクト: AngryHacker/OS_Lab
void call21h()
{
	/*
	 * 对21h 中的功能号进行测试
	 */
	while(1)
	{
		cls();
		print("\r\n         Now, you can run some commands to test the 21h:\n\n\r");
		print("        1.ouch  -- to ouch          2.upper -- change the letter to upper\n\r");
		print("        3.lower         -- change the letter to lower\n\r"); 
		print("        4.to_digit      -- change the string to digit\r\n"); 
		print("        5.to_string     -- change the digit to string\r\n"); 
		print("        6.display_where -- you can assign where to display\r\n");
		print("        7.to_deci      -- change the Hex to a decimal digit\r\n"); 
		print("        8.reverse      -- to reverse your string\r\n"); 
		print("        9.strlen      --  get the length of your string\r\n"); 
		print("        10.quit          -- just to quit\r\n\r\n"); 
		print("Please input your choice:"); 
		getline(input,20);
	    if(strcmp(input,"1") || strcmp(input,"ouch"))
		{
			/*
			 * 测试 0 号功能
			 */
			to_OUCH();
		}
	    else if(strcmp(input,"2") || strcmp(input,"upper"))
		{
			/*
			 * 测试 1 号功能
			 */
			while(1)
			{
				print("\r\nPlease input a sentence or quit to back:");
				getline(input,30);
				if(strcmp(input,"quit")) break;
				upper(input);
				print("\r\nThe upper case is:");
				print(input);
				print("\r\n");
			}
		}
	    else if(strcmp(input,"3") || strcmp(input,"lower"))
		{
			/*
			 * 测试 2 号功能
			 */
		    while(1)
			{
				print("\r\nPlease input a sentence or quit to back:");
				getline(input,30);
				if(strcmp(input,"quit")) break;
				lower(input);
				print("\r\nThe lower case is:");
				print(input);
				print("\r\n");
			}
		}
	    else if(strcmp(input,"4") || strcmp(input,"to_digit"))
		{
			/*
			 * 测试 3 号功能
			 */
			print("\r\nDo you want to continue? Y | N :");
			getline(input,2);
			while(1)
			{
				int t1,t2,t3;
				t1 = 0;t2 = 0;
				if(strcmp(input,"n") || strcmp(input,"N")) break;
				print("\r\nPlease input the first digit:");
				getline(input,4);
				if(isDigit(input))
				{
				    t1 = digital(input);
				}
				else 
				{
					print("\r\nInvalid digit!We assume it is 12\n\r");
					t1 = 12;
				}
				print("\r\nPlease input the second digit:");
				getline(input,4);
				if(isDigit(input))
				{
					t2 = digital(input);
				}
				else 
				{
					print("\r\nInvalid digit!We assume it is 21\n\r");
					t2 = 21;
				}
				print("\r\nThe sum of the them is:");
				t3 = t1 + t2;
				printInt(t3);
				print("\r\n");
				print("\r\nDo you want to continue? Y | N :");
				getline(input,2);
			}
		}
	    else if(strcmp(input,"5") || strcmp(input,"to_string"))
		{
			/*
			 * 测试 4 号功能
			 */
			print("\r\nDo you want to continue? Y | N: ");
			getline(input,2);
			while(1)
			{
				char *cht;
				int tt = rand();
				if(strcmp(input,"n") || strcmp(input,"N")) break;
				cht = convertToString(tt);
				print("\r\nI am a string: ");
				print(cht);
				print("\r\n");
				print("\r\nDo you want to continue? Y | N: ");
				getline(input,2);
			}
		}
	    else if(strcmp(input,"6") || strcmp(input,"display_where"))
		{
			/*
			 * 测试 5 号功能
			 */
			int row,col;
			print("\r\nPlease input the row:");
			getline(input,3);
			if(isDigit(input))
			{
				row = digital(input);
			}
			else 
			{
				print("\r\nInvalid digit!We assume it is 12\n\r");
			    row = 12;
			}
			print("\r\nPlease input column:");
			getline(input,3);
			if(isDigit(input))
			{
				col = digital(input);
			}
			else 
			{
				print("\r\nInvalid digit!We assume it is 40\n\r");
			    col = 40;
			}
			print("\r\nPlease input the string:");
			getline(input,30);
			display(row,col,input);
		}
		else if(strcmp(input,"7") || strcmp(input,"to_dec"))
		{
			/*
			 * 测试 6 号功能
			 */
			print("\r\nDo you want to continue? Y | N :");
			getline(input,2);
			while(1)
			{
				int t1;
				t1 = 0;
				if(strcmp(input,"n") || strcmp(input,"N")) break;
				print("\r\nPlease input the hex digit:");
				getline(input,3);
				if(isHex(input))
				{
				    t1 = convertHexToDec(input);
				}
				else 
				{
					print("\r\nInvalid Hex!We assume it is 12\n\r");
					t1 = 12;
				}
				print("\r\nThe decimal form is:");
				printInt(t1);
				print("\r\n");
				print("\r\nDo you want to continue? Y | N :");
				getline(input,2);
			}
		}
		else if(strcmp(input,"8") || strcmp(input,"reverse"))
		{
			/*
			 * 测试 7 号功能
			 */
			print("\r\nDo you want to continue? Y | N :");
			getline(input,2);
			while(1)
			{
				if(strcmp(input,"n") || strcmp(input,"N")) break;
				print("\r\nPlease input the your string:");
				getline(input,30);
				reverse(input,strlen(input));
				print("\r\nThe string after reverse is:");
				print(input);
				print("\r\n");
				print("\r\nDo you want to continue? Y | N :");
				getline(input,2);
			}
		}
		else if(strcmp(input,"9") || strcmp(input,"strlen"))
		{
			/*
			 * 测试 8 号功能
			 */
			print("\r\nDo you want to continue? Y | N :");
			getline(input,2);
			while(1)
			{
				int t;
				if(strcmp(input,"n") || strcmp(input,"N")) break;
				print("\r\nPlease input the your string:");
				getline(input,30);
				t = strlen(input);
				print("\r\nThe length of the string is:");
				printInt(t);
				print("\r\n");
				print("\r\nDo you want to continue? Y | N :");
				getline(input,2);
			}
		}
	    else if(strcmp(input,"10") || strcmp(input,"quit"))
		{
			/*
			 * 退出
			 */
			break;
		}
	}
}
コード例 #18
0
ファイル: URLEncode.cpp プロジェクト: boboding/Boboding
// strURL: URL to decode.
CString CURLEncode::Decode(CString strURL)
{
	int i=strURL.Find(_T('%'));
	TCHAR tc1=0, tc2=0;
	BYTE b=0;
	BOOL bFound=FALSE;
	while (i>-1)
	{
		tc1=strURL.GetAt(i+1);
		tc2=strURL.GetAt(i+2);

		if (isHex(tc1) && isHex(tc2))
		{
			b=hexToDec(tc1, tc2);

			// first deal with 1-byte unprintable characters
			if (b<0x1F || b==0x7F) {
				strURL.SetAt(i, b);
				strURL.Delete(i+1, 2);
			} else {
				// Then deal with 1-byte unsafe/reserved characters
				// We are reading for those static LPCTSTR strings,
				// so we have nice support for Unicode
				bFound=FALSE;
				for (int ii=0; ii<m_iUnsafeLen && !bFound; ii++)
				{
					if (__toascii(m_lpszUnsafeString[ii])==b)
					{
						strURL.SetAt(i, m_lpszUnsafeString[ii]);
						strURL.Delete(i+1, 2);
						bFound=TRUE;
					}
				}
				for (int ii=0; ii<m_iReservedLen && !bFound; ii++)
				{
					if (__toascii(m_lpszReservedString[ii])==b)
					{
						strURL.SetAt(i, m_lpszReservedString[ii]);
						strURL.Delete(i+1, 2);
						bFound=TRUE;
					}
				}
				// Then deal with UTF-8 (2-bytes) characters
				if (!bFound)
				{
					// We need to have 2 bytes for decoding
					if (strURL.GetAt(i+3)==_T('%'))
					{
						tc1=strURL.GetAt(i+4);
						tc2=strURL.GetAt(i+5);

						if (isHex(tc1) && isHex(tc2))
						{
							BYTE b2=hexToDec(tc1, tc2);
							strURL.SetAt(i, fromUTF8(MAKEWORD(b2, b)));
							strURL.Delete(i+1, 5);
						}
					}
				}
			}
		}

		i=strURL.Find(_T('%'), i+1);
	}

	return strURL;
}
コード例 #19
0
ファイル: chars.c プロジェクト: blipvert/latex2rtf
/******************************************************************************
 purpose: 
        code = 0, handles \char'35 or \char"35 or \char35 or \char`b
        code = 1, handles \symbol{\'22} or \symbol{\"22}
 ******************************************************************************/
void CmdSymbol(int code)
{
    char c, *s, *t;
    int n, base;

    if (code == 0) {
    
        char num[4];
        int i;
    
        c = getNonSpace();
        base = identifyBase(c);
        
        if (base == 0) {
            diagnostics(1,"malformed \\char construction");
            fprintRTF("%c",c);
            return;
        }
            
        if (base == -1) {
            c = getTexChar();   /* \char`b case */
            CmdChar((int) c);
            return;
        }
        
        if (base == 10) 
            ungetTexChar(c);
        
        /* read sequence of digits */
        for (i=0; i<4; i++) {
            num[i] = getTexChar();
            if (base == 10 && ! isdigit(num[i]) ) break;
            if (base == 8  && ! isOctal(num[i]) ) break;
            if (base == 16 && ! isHex  (num[i]) ) break;
         }
        ungetTexChar(num[i]);
        num[i] = '\0';
        
        n = (int) strtol(num,&s,base);
        CmdChar(n);
        
    } else {

        s = getBraceParam();
        t = strdup_noendblanks(s);
        free(s);
        
        base = identifyBase(*t);
        
        if (base == 0)
            return;
            
        if (base == -1) {
            CmdChar((int) *(t+1));   /* \char`b case */
            return;
        }

        n = (int) strtol(t+1,&s,base);
        CmdChar(n);
        free(t);
    }
    
}
コード例 #20
0
ファイル: athtestcmd.c プロジェクト: Ar3kkusu/AR6kSDK.3.1
int main (int argc, char **argv)
{
    void (*reportCB)(void *) = NULL;
    void (*cmdRespCB)(void *) = cmdReplyFunc_readThermal;
#endif /* ATHTESTCMD_LIB */
    int c, s=-1;
    char ifname[IFNAMSIZ];
    unsigned int cmd = 0;
    progname = argv[0];
    struct ifreq ifr;
    char buf[2048];
    TCMD_CONT_TX *txCmd = (TCMD_CONT_TX *)((A_UINT32 *)buf + 1); /* first 32-bit is XIOCTL_CMD */
    TCMD_CONT_RX *rxCmd   = (TCMD_CONT_RX *)((A_UINT32 *)buf + 1);
    TCMD_PM *pmCmd = (TCMD_PM *)((A_UINT32 *)buf + 1);
    WMI_SET_LPREAMBLE_CMD *setLpreambleCmd = (WMI_SET_LPREAMBLE_CMD *)((A_UINT32 *)buf + 1);
    TCMD_SET_REG *setRegCmd = (TCMD_SET_REG *)((A_UINT32 *)buf + 1);
    TC_CMDS  *tCmds = (TC_CMDS *)((A_UINT32 *)buf + 1);
    A_BOOL needRxReport = FALSE;    
#ifndef ATHTESTCMD_LIB
    A_UINT16 efuse_begin = 0, efuse_end = (VENUS_OTP_SIZE - 1);
    A_UINT8  efuseBuf[VENUS_OTP_SIZE];
    A_UINT8  efuseWriteBuf[VENUS_OTP_SIZE];
    A_UINT16 data_length = 0;
#endif
    txCmd->numPackets = 0;
    txCmd->wlanMode = TCMD_WLAN_MODE_NOHT;
    txCmd->tpcm = TPC_TX_PWR;
/* default to tx power */
    rxCmd->u.para.wlanMode = TCMD_WLAN_MODE_NOHT;
#ifdef ATHTESTCMD_LIB
    if (setjmp(*jbuf)!=0) {
        if (s>=0)
            close(s);
        return -1;
    }
#endif 

    if (argc == 1) {
        usage();
    }

    memset(buf, 0, sizeof(buf));
    memset(ifname, '\0', IFNAMSIZ);
    strcpy(ifname, "eth1");
    s = socket(AF_INET, SOCK_DGRAM, 0);
    if (s < 0) {
        A_ERR(1, "socket");
    }

    while (1) {
        int option_index = 0;
        static struct option long_options[] = {
            {"version", 0, NULL, 'v'},
            {"interface", 1, NULL, 'i'},
            {"tx", 1, NULL, 't'},
            {"txfreq", 1, NULL, 'f'},
            {"txrate", 1, NULL, 'g'},
            {"txpwr", 1, NULL, 'h'},
            {"tgtpwr", 0, NULL, 'H'},
            {"pcdac", 1, NULL, 'I'},
            {"txantenna", 1, NULL, 'j'},
            {"txpktsz", 1, NULL, 'z'},
            {"txpattern", 1, NULL, 'e'},
            {"rx", 1, NULL, 'r'},
            {"rxfreq", 1, NULL, 'p'},
            {"rxantenna", 1, NULL, 'q'},
            {"pm", 1, NULL, 'x'},
            {"setmac", 1, NULL, 's'},
            {"ani", 0, NULL, 'a'},
            {"scrambleroff", 0, NULL, 'o'},
            {"aifsn", 1, NULL, 'u'},
            {"SetAntSwitchTable", 1, NULL, 'S'},
            {"shortguard", 0, NULL, 'G'},
            {"numpackets", 1, NULL, 'n'},
            {"mode", 1, NULL, 'M'},
            {"setlongpreamble", 1, NULL, 'l'},
            {"setreg", 1, NULL, 'R'},                  
            {"regval", 1, NULL, 'V'},                
            {"flag", 1, NULL, 'F'},     
            {"writeotp", 0, NULL, 'w'},  	
            {"otpregdmn", 1, NULL, 'E'},		
#ifndef ATHTESTCMD_LIB
            {"efusedump", 0, NULL, 'm'},
            {"efusewrite", 0, NULL, 'W'},
            {"start", 1, NULL, 'A'},
            {"end", 1, NULL, 'L'},
            {"data", 1, NULL, 'U'},
            {"otpwrite", 0, NULL, 'O'},
            {"otpdump", 0, NULL, 'P'},
#endif
            {"btaddr", 1, NULL, 'B'},			
            {"therm", 0, NULL, 'c'},
            {0, 0, 0, 0}
        };

        c = getopt_long(argc, argv, "vi:t:f:g:h:HI:r:p:q:x:u:ao:M:A:L:mU:WOP",
                         long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
        case 'i':
            memset(ifname, '\0', 8);
            strcpy(ifname, optarg);
            break;
        case 't':
            cmd = TESTMODE_CONT_TX;
			txCmd->testCmdId = TCMD_CONT_TX_ID;
            if (!strcmp(optarg, "sine")) {
                txCmd->mode = TCMD_CONT_TX_SINE;
            } else if (!strcmp(optarg, "frame")) {
                txCmd->mode = TCMD_CONT_TX_FRAME;
            } else if (!strcmp(optarg, "tx99")) {
                txCmd->mode = TCMD_CONT_TX_TX99;
            } else if (!strcmp(optarg, "tx100")) {
                txCmd->mode = TCMD_CONT_TX_TX100;
            } else if (!strcmp(optarg, "off")) {
                txCmd->mode = TCMD_CONT_TX_OFF;
            }else {
                cmd = 0;
            }
            break;
        case 'f':
            txCmd->freq = freqValid(atoi(optarg));
            break;
        case 'G':
            txCmd->shortGuard = 1;
            break;
        case 'M':
            if(cmd == TESTMODE_CONT_TX) {
                if (!strcmp(optarg, "ht20")) {
                    txCmd->wlanMode = TCMD_WLAN_MODE_HT20;
                } else if (!strcmp(optarg, "ht40plus")) {
                    txCmd->wlanMode = TCMD_WLAN_MODE_HT40PLUS;
                } else if (!strcmp(optarg, "ht40minus")) {
                    txCmd->wlanMode = TCMD_WLAN_MODE_HT40MINUS;
                }
            } else if(cmd == TESTMODE_CONT_RX) {
                if (!strcmp(optarg, "ht20")) {
                    rxCmd->u.para.wlanMode = TCMD_WLAN_MODE_HT20;
                } else if (!strcmp(optarg, "ht40plus")) {
                    rxCmd->u.para.wlanMode = TCMD_WLAN_MODE_HT40PLUS;
                } else if (!strcmp(optarg, "ht40minus")) {
                    rxCmd->u.para.wlanMode = TCMD_WLAN_MODE_HT40MINUS;
                }
            }
            break;
        case 'n':
            txCmd->numPackets = atoi(optarg);
            break;
        case 'g':
            /* let user input index of rateTable instead of string parse */
            txCmd->dataRate = rateValid(atoi(optarg), txCmd->freq);
            break;
        case 'h':
        {
            int txPowerAsInt;
            /* Get tx power from user.  This is given in the form of a number
             * that's supposed to be either an integer, or an integer + 0.5
             */
            double txPowerIndBm = atof(optarg);

            /*
             * Check to make sure that the number given is either an integer
             * or an integer + 0.5
             */
            txPowerAsInt = (int)txPowerIndBm;
            if (((txPowerIndBm - (double)txPowerAsInt) == 0) ||
                (((txPowerIndBm - (double)txPowerAsInt)) == 0.5) ||
                (((txPowerIndBm - (double)txPowerAsInt)) == -0.5)) {
                if (txCmd->mode != TCMD_CONT_TX_SINE) {
                    txCmd->txPwr = txPowerIndBm * 2;
                } else {
                    txCmd->txPwr = txPowerIndBm;
                }
           } else {
                printf("Bad argument to --txpwr, must be in steps of 0.5 dBm\n");
                cmd = 0;
           }
             
            txCmd->tpcm = TPC_TX_PWR;
        }
            break;
        case 'H':
            txCmd->tpcm = TPC_TGT_PWR;
            break;
        case 'I':
            txCmd->tpcm = TPC_FORCED_GAIN;
            txCmd->txPwr = atof(optarg);
            break;
        case 'j':
            txCmd->antenna = antValid(atoi(optarg));
            break;       
        case 'z':
            txCmd->pktSz = pktSzValid(atoi(optarg));
            break;
        case 'e':
            txCmd->txPattern = atoi(optarg);
            break;
        case 'r':
            cmd = TESTMODE_CONT_RX;
			rxCmd->testCmdId = TCMD_CONT_RX_ID;
            if (!strcmp(optarg, "promis")) {
                rxCmd->act = TCMD_CONT_RX_PROMIS;
			 	printf(" Its cont Rx promis mode \n");
            } else if (!strcmp(optarg, "filter")) {
                rxCmd->act = TCMD_CONT_RX_FILTER;
				printf(" Its cont Rx  filter  mode \n");
            } else if (!strcmp(optarg, "report")) {
				 printf(" Its cont Rx report  mode \n");
                rxCmd->act = TCMD_CONT_RX_REPORT;
                needRxReport = TRUE;
            } else {
                cmd = 0;
            }
            break;
        case 'p':
            rxCmd->u.para.freq = freqValid(atoi(optarg));
            break;
        case 'q':
            rxCmd->u.para.antenna = antValid(atoi(optarg));
            break;
        case 'x':
            cmd = TESTMODE_PM;
			pmCmd->testCmdId = TCMD_PM_ID;
            if (!strcmp(optarg, "wakeup")) {
                pmCmd->mode = TCMD_PM_WAKEUP;
            } else if (!strcmp(optarg, "sleep")) {
                pmCmd->mode = TCMD_PM_SLEEP;
            } else if (!strcmp(optarg, "deepsleep")) {
                pmCmd->mode = TCMD_PM_DEEPSLEEP;
            } else {
                cmd = 0;
            }
            break;
        case 's':
            {
                A_UINT8 mac[ATH_MAC_LEN];

                cmd = TESTMODE_CONT_RX;
                rxCmd->testCmdId = TCMD_CONT_RX_ID;
                rxCmd->act = TCMD_CONT_RX_SETMAC;
                if (ath_ether_aton(optarg, mac) != A_OK) {
                    A_ERR(-1, "Invalid mac address format! \n");
                }
                memcpy(rxCmd->u.mac.addr, mac, ATH_MAC_LEN);
#ifdef TCMD_DEBUG
                printf("JLU: tcmd: setmac 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", 
                        mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
#endif
                break;
            }
        case 'u':
            {
                txCmd->aifsn = atoi(optarg) & 0xff;
                printf("AIFS:%d\n", txCmd->aifsn);
            }
            break;
        case 'a':
            if(cmd == TESTMODE_CONT_TX) {
                txCmd->enANI = TRUE;
            } else if(cmd == TESTMODE_CONT_RX) {
                rxCmd->enANI = TRUE;
            }
            break;
        case 'o':
            txCmd->scramblerOff = TRUE;
            break;
        case 'S':
            if (argc < 4)
                usage();
            cmd = TESTMODE_CONT_RX;
            rxCmd->testCmdId = TCMD_CONT_RX_ID;		
            rxCmd->act = TCMD_CONT_RX_SET_ANT_SWITCH_TABLE;				
            rxCmd->u.antswitchtable.antswitch1 = strtoul(argv[2], (char **)NULL,0);
            rxCmd->u.antswitchtable.antswitch2 = strtoul(argv[3], (char **)NULL,0);
            break;
        case 'l':
            cmd = TESTMODE_SETLPREAMBLE;
            setLpreambleCmd->status = atoi(optarg);
            break;
        case 'R':
            if (argc < 5) {
                printf("usage:athtestcmd -i eth0 --setreg 0x1234 --regval 0x01 --flag 0\n");
            }
            cmd = TESTMODE_SETREG;
            setRegCmd->testCmdId = TCMD_SET_REG_ID;
            setRegCmd->regAddr   = strtoul(optarg, (char **)NULL, 0);//atoi(optarg);
            break; 
        case 'V':
            setRegCmd->val = strtoul(optarg, (char **)NULL, 0);
            break;            
        case 'F':
            setRegCmd->flag = atoi(optarg);
            break;                       
        case 'w':
            rxCmd->u.mac.otpWriteFlag = 1;	
            break;		
        case 'E':
            rxCmd->u.mac.regDmn[0] = 0xffff&(strtoul(optarg, (char **)NULL, 0));
            rxCmd->u.mac.regDmn[1] = 0xffff&(strtoul(optarg, (char **)NULL, 0)>>16);		
            break;		
        case 'B':
            {    				           
                A_UINT8 btaddr[ATH_MAC_LEN];
                if (ath_ether_aton(optarg, btaddr) != A_OK) {
                    A_ERR(-1, "Invalid mac address format! \n");
                } 
                memcpy(rxCmd->u.mac.btaddr, btaddr, ATH_MAC_LEN);
#ifdef TCMD_DEBUG
                printf("JLU: tcmd: setbtaddr 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", 
                        btaddr[0], btaddr[1], btaddr[2], btaddr[3], btaddr[4], btaddr[5]);
#endif		
            }
            break;		
        case 'c':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId = TC_CMDS_ID;
            {
                tCmds->hdr.u.parm.length = (A_UINT16)0;    
                tCmds->hdr.u.parm.version = TC_CMDS_VERSION_TS;    
                tCmds->hdr.act = TC_CMDS_READTHERMAL;//TC_CMDS_CAL_THERMALVOLT;
            }
            break;
	
#ifndef ATHTESTCMD_LIB
        case 'A':
            efuse_begin = atoi(optarg);
            break;

        case 'L':
            efuse_end = atoi(optarg);
            break;

        case 'U':
            {
                A_UINT8* pucArg = (A_UINT8*)optarg;
                A_UINT8  c;
                A_UINT8  strBuf[256];
                A_UINT8  pos = 0;
                A_UINT16 length = 0;
                A_UINT32  data;

                /* Sweep string to end */
                while (1) {
                    c = *pucArg++;
                    if (isHex(c)) {
                        strBuf[pos++] = c;
                    } else {
                        strBuf[pos] = '\0';
                        pos = 0;
                        sscanf(((char *)&strBuf), "%x", &data);
                        efuseWriteBuf[length++] = (data & 0xFF);

                        /* End of arg string */
                        if (c == '\0') {
                            break;
                        }
                    }
                }

                data_length = length;
            }
            break;

        case 'm':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId      = TC_CMDS_ID;
            tCmds->hdr.act            = TC_CMDS_EFUSEDUMP;
            cmdRespCB = cmdReplyFunc;
            break;

        case 'W':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId      = TC_CMDS_ID;
            tCmds->hdr.act            = TC_CMDS_EFUSEWRITE;
            cmdRespCB = cmdReplyFunc;
            break;

        case 'O':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId      = TC_CMDS_ID;
            tCmds->hdr.act            = TC_CMDS_OTPSTREAMWRITE;
            cmdRespCB = cmdReplyFunc;
            break;

        case 'P':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId      = TC_CMDS_ID;
            tCmds->hdr.act            = TC_CMDS_OTPDUMP;
            cmdRespCB = cmdReplyFunc;
            break;
#endif		
        default:
            usage();
        }
    }

    strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

    switch (cmd) {
    case TESTMODE_CONT_TX:
#ifdef CONFIG_HOST_TCMD_SUPPORT
        *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_CONT_TX;

        txPwrValid(txCmd);

        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            A_ERR(1, "%s", ifr.ifr_name);
        }
#endif /* CONFIG_HOST_TCMD_SUPPORT */
        break;
    case TESTMODE_CONT_RX:
#ifdef CONFIG_HOST_TCMD_SUPPORT
        *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_CONT_RX;

        if (rxCmd->act == TCMD_CONT_RX_PROMIS ||
             rxCmd->act == TCMD_CONT_RX_FILTER) {
            if (rxCmd->u.para.freq == 0)
                rxCmd->u.para.freq = 2412;
        }

        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            A_ERR(1, "%s", ifr.ifr_name);
        }
        if (reportCB) {
            reportCB(ifr.ifr_data);
        }
        if (needRxReport) {
            rxReport(ifr.ifr_data);
            needRxReport = FALSE;
        }
#endif /* CONFIG_HOST_TCMD_SUPPORT */
        break;
    case TESTMODE_PM:
#ifdef CONFIG_HOST_TCMD_SUPPORT
        *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_PM;
        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            A_ERR(1, "%s", ifr.ifr_name);
        }
#endif /* CONFIG_HOST_TCMD_SUPPORT */
        break;
    case TESTMODE_SETLPREAMBLE:
        *(A_UINT32 *)buf = AR6000_XIOCTL_WMI_SET_LPREAMBLE;
        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            A_ERR(1, "%s", ifr.ifr_name);
        }   
        break;   
    case TESTMODE_SETREG:
        *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_SETREG;
        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            printf("%s", ifr.ifr_name);
        }   
        break;
#ifndef ATHTESTCMD_LIB              
    case TESTMODE_CMDS:
        if (tCmds->hdr.act == TC_CMDS_EFUSEDUMP) {
            int i, k;
            int blkNum;
            A_UINT16 efuseEnd   = efuse_end;
            A_UINT16 efuseBegin = efuse_begin;
            A_UINT16 efusePrintAnkor;
            A_UINT16 numPlaceHolder;

            /* Input check */
            if (efuseEnd > (VENUS_OTP_SIZE - 1)) {
                efuseEnd = (VENUS_OTP_SIZE - 1);
            }

            if (efuseBegin > efuseEnd) {
                efuseBegin = efuseEnd;
            }

            efusePrintAnkor = efuseBegin;

            blkNum = ((efuseEnd - efuseBegin) / TC_CMDS_SIZE_MAX) + 1;

            /* Request data in several trys */
            for (i = 0; i < blkNum; i++) {
                tCmds->hdr.testCmdId      = TC_CMDS_ID;
                tCmds->hdr.act            = TC_CMDS_EFUSEDUMP;
                tCmds->hdr.u.parm.length  = 4;    
                tCmds->hdr.u.parm.version = TC_CMDS_VERSION_TS;  

                tCmds->buf[0] = (efuseBegin & 0xFF);
                tCmds->buf[1] = (efuseBegin >> 8) & 0xFF;
                tCmds->buf[2] = (efuseEnd & 0xFF);
                tCmds->buf[3] = (efuseEnd >> 8) & 0xFF;      

                *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_CMDS;

                ifr.ifr_data = (void *)buf;

                if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
                    A_ERR(1,"%s", ifr.ifr_name);
                }

                if (cmdRespCB) {
                    cmdRespCB(ifr.ifr_data);
                }

                /* Last block? */
                if ((efuseEnd - efuseBegin + 1) < TC_CMDS_SIZE_MAX) {
                    memcpy((void*)(efuseBuf + efuseBegin), (void*)&(sTcCmds.buf[0]), (efuseEnd - efuseBegin + 1));
                } else {
                    memcpy((void*)(efuseBuf + efuseBegin), (void*)&(sTcCmds.buf[0]), TC_CMDS_SIZE_MAX);
                }

                /* Adjust the efuseBegin but keep efuseEnd unchanged */
                efuseBegin += TC_CMDS_SIZE_MAX;
            }

            /* Output Dump */
            printf("------------------- eFuse Dump ----------------------");
            for (i = efusePrintAnkor; i <= efuseEnd; i++) {
                /* Cosmetics */
                if (i == efusePrintAnkor) {
                    numPlaceHolder = (efusePrintAnkor & 0x0F);
                    printf("\n%04X:", (efusePrintAnkor & 0xFFF0));
                    for (k = 0; k < numPlaceHolder; k++) {
                        printf("   ");
                    }
                } else if ((i & 0x0F) == 0) {
                    printf("\n%04X:", i);
                }

                printf(" %02X", efuseBuf[i]);
            }
            printf("\n\n");
        } else if (tCmds->hdr.act == TC_CMDS_EFUSEWRITE) {
コード例 #21
0
ファイル: debuggersp.cpp プロジェクト: Plombo/fceux
/**
* Parses a line from a NL file.
* @param line The line to parse
* @param n The name structure to write the information to
*
* @return 0 if everything went OK. Otherwise an error code is returned.
**/
int parseLine(char* line, Name* n)
{
	char* pos;
	int llen;

	// Check parameters
	
	if (!line)
	{
		MessageBox(0, "Invalid parameter \"line\" in function parseLine", "Error", MB_OK | MB_ICONERROR);
		return 1;
	}
	
	if (!n)
	{
		MessageBox(0, "Invalid parameter \"n\" in function parseLine", "Error", MB_OK | MB_ICONERROR);
		return 2;
	}
	
	// Allow empty lines
	if (*line == '\r' || *line == '\n')
	{
		return -1;
	}
	
	// Attempt to tokenize the given line
	
	pos = strstr(line, delimiterChar);

	if (!pos)
	{
		// Found an invalid line
		return 3;
	}
	
	// Check if the first tokenized part (the offset) is valid
	
	*pos = 0;
	
	llen = (int)strlen(line);
	
	if (llen == 5) // Offset size of normal lines of the form $XXXX
	{
		if (line[0] != '$'
			|| !isHex(line[1])
			|| !isHex(line[2])
			|| !isHex(line[3])
			|| !isHex(line[4])
		)
		{
			return 4;
		}
	}
	else if (llen >= 7) // Offset size of array definition lines of the form $XXXX/YY
	{
		int i;
		if (line[0] != '$'
			|| !isHex(line[1])
			|| !isHex(line[2])
			|| !isHex(line[3])
			|| !isHex(line[4])
			|| line[5] != '/'
		)
		{
			return 5;
		}
		
		for (i=6;line[i];i++)
		{
			if (!isHex(line[i]))
			{
				return 6;
			}
		}
	}
	else // Lines that have an invalid size
	{
		return 7;
	}
	
	
	// TODO: Validate if the offset is in the correct NL file.

	// After validating the offset it's OK to store it
	n->offset = (char*)malloc(strlen(line) + 1);
	strcpy(n->offset, line);
	line = pos + 1;
	
	// Attempt to tokenize the string again to find the name of the address

	pos = strstr(line, delimiterChar);

	if (!pos)
	{
		// Found an invalid line
		return 8;
	}

	*pos = 0;
	
	if (*line)
	{
		if (strlen(line) > NL_MAX_NAME_LEN)
			line[NL_MAX_NAME_LEN + 1] = 0;
		n->name = (char*)malloc(strlen(line) + 1);
		strcpy(n->name, line);
	}
	else
	{
		// Properly initialize zero-length names too
		n->name = 0;
	}
	
	// Now it's clear that the line was valid. The rest of the line is the comment
	// that belongs to that line. Once again a real string is required though.
	
	line = pos + 1;

	if (*line > 0x0D)
	{
		if (strlen(line) > NL_MAX_MULTILINE_COMMENT_LEN)
			line[NL_MAX_MULTILINE_COMMENT_LEN + 1] = 0;
		// remove all backslashes after \r\n
		char* crlf_pos = strstr(line, "\r\n\\");
		while (crlf_pos)
		{
			strcpy(crlf_pos + 2, crlf_pos + 3);
			crlf_pos = strstr(crlf_pos + 2, "\r\n\\");
		}

		n->comment = (char*)malloc(strlen(line) + 1);
		strcpy(n->comment, line);
	}
	else
	{
		// Properly initialize zero-length comments too
		n->comment = 0;
	}
	
	// Everything went fine.
	return 0;
}
コード例 #22
0
ファイル: monitor.cpp プロジェクト: BigMacStorm/NES_machine
BOOL updateResults(HWND hwndDlg, int rule)
{
	char buff[0x100];
	char buff2[0x100];
	char input_buff[8] = { 0 };
	
	int chosen_rules[NUMBER_OF_RULES] = { 0 };
	unsigned int values[NUMBER_OF_RULES] = { 0 };
	
	for (int i=0;i<sizeof(chosen_rules) && i <= rule;i++)
	{
		chosen_rules[i] = SendDlgItemMessage(hwndDlg, RULE_BOX_1 + i, CB_GETCURSEL, 0, 0);
		
		if ( chosen_rules[i] == RULE_EXACT || chosen_rules[i] == RULE_EXACT_NOT )
		{
			SendDlgItemMessage( hwndDlg, RULE_INPUT_1 + i, WM_GETTEXT, sizeof(buff) - 1, (LPARAM) input_buff );
			
			unsigned int len = strlen(input_buff);
			
			for (unsigned int j=0;j<len;j++)
			{
				if (isHex(input_buff[j]) == FALSE)
				{
					return FALSE;
				}
			}
			
			if (sscanf(input_buff, "%X", &values[i]) != 1)
			{
				return FALSE;
			}
		}
	}

	for (int i=0;i<SIZE_OF_RAM;i++)
	{
		snapshots[rule][i] = GetMem(i);
	}
	
	SendDlgItemMessage( hwndDlg, RESULTS_BOX, LB_RESETCONTENT, 0, 0 );
	
	for (int i=0;i<SIZE_OF_RAM;i++)
	{
		BOOL all_valid = TRUE;
	
		for (int current_rule=0;current_rule<=rule && all_valid;current_rule++)
		{
			all_valid = all_valid & verify_rule(current_rule, chosen_rules[current_rule], i, values[current_rule]);
		}
		
		if ( all_valid )
		{
			sprintf(buff, "%04X: %02X", i, snapshots[0][i]);
			
			for (int j=1;j<=rule;j++)
			{
				sprintf(buff2, " -> %02X", snapshots[j][i]);
				strcat(buff, buff2);
			}
			
			SendDlgItemMessage(hwndDlg, RESULTS_BOX, LB_ADDSTRING, 0, (LPARAM) buff);
		}
	}
	
	UpdateControls(hwndDlg, rule);
	
	return TRUE;
}
コード例 #23
0
/* main */
int main(int argc, void *argv[])
{
  long lOpStart, lOpEnd;
  int flength, oplistlength, totaltime, proflistlength;
  int samp_unknown, samp_blockend, samp_notcompiled, samp_wrappers, samp_flush;
  int i, j;
  FILE *pfIn;
  r4300op *pOpAddrTable;
  profilehit *pProfTable;
  char *pch, *pchSampleData;

  /* check arguments */
  if (argc < 3)
  {
    printf("Usage: r4300prof r4300addr.dat x86profile.txt\n\n");
    printf("r4300addr.dat  - binary table of r4300 opcodes and corresponding x86 starting addresses\n");
    printf("x86profile.txt - text file containing a list of profile sample counts by x86 address on the heap\n\n");
    return 1;
  }

  /* open r4300 opcode/x86 address table generated from emulator run */
  printf("Loading %s...\n", argv[1]);
  pfIn = fopen(argv[1], "rb");
  if (pfIn == NULL)
  {
    printf("Couldn't open input file: %s\n", argv[1]);
    return 2;
  }

  /* get file length and calculate number of r4300op table entries */
  fseek(pfIn, 0L, SEEK_END);
  flength = (int) ftell(pfIn);
  fseek(pfIn, 0L, SEEK_SET);
  oplistlength = flength / sizeof(r4300op);
  
  /* read the file */
  pOpAddrTable = (r4300op *) malloc(flength);
  if (pOpAddrTable == NULL)
  {
    printf("Failed to allocate %i bytes for OpAddrTable!\n", flength);
    fclose(pfIn);
    return 3;
  }
  fread(pOpAddrTable, 1, flength, pfIn);
  fclose(pfIn);
  printf("%i r4300 instruction locations read.\n", oplistlength);

  /* sort the opcode/address table according to x86addr */
  qsort(pOpAddrTable, oplistlength, sizeof(r4300op), AddrCompare);

  /* remove any 0-length r4300 instructions */
  i = 0;
  j = 0;
  while (i < oplistlength)
  {
    pOpAddrTable[j].mipsop = pOpAddrTable[i].mipsop;
    pOpAddrTable[j].x86addr = pOpAddrTable[i].x86addr;
    i++;
    if (pOpAddrTable[j].x86addr != pOpAddrTable[i].x86addr)
      j++;
  }
  oplistlength = j;
  printf("%i non-empty MIPS instructions.\n", oplistlength);

  /* convert each r4300 opcode to an instruction type index */
  for (i = 0; i < oplistlength; i++)
    if (pOpAddrTable[i].mipsop > 0 || pOpAddrTable[i].mipsop < -16)
      pOpAddrTable[i].mipsop = GetInstrType(pOpAddrTable[i].mipsop);

  /* open the profiling sample data file */
  printf("Loading %s...\n", argv[2]);
  pfIn = fopen(argv[2], "rb");
  if (pfIn == NULL)
  {
    printf("Couldn't open input file: %s\n", argv[2]);
    free(pOpAddrTable);
    return 4;
  }

  /* load it */
  fseek(pfIn, 0L, SEEK_END);
  flength = (int) ftell(pfIn);
  fseek(pfIn, 0L, SEEK_SET);
  pchSampleData = (char *) malloc(flength + 16);
  if (pchSampleData == NULL)
  {
    printf("Failed to allocate %i bytes for pchSampleData!\n", flength + 16);
    fclose(pfIn);
    free(pOpAddrTable);
    return 5;
  }
  fread(pchSampleData, 1, flength, pfIn);
  pchSampleData[flength] = 0;
  fclose(pfIn);
  
  /* count the number of newlines in the ascii-formatted sample data file */
  proflistlength = 1;
  pch = pchSampleData;
  while (pch = strchr(pch, '\n'))
  {
    proflistlength++;
    pch++;
  }
  printf("%i lines in sample data file.\n", proflistlength);
  
  /* extract text data into binary table */
  pProfTable = (profilehit *) malloc(proflistlength * sizeof(profilehit));
  if (pProfTable == NULL)
  {
    printf("Failed to allocate %i bytes for pProfTable!\n", proflistlength * sizeof(profilehit));
    free(pOpAddrTable);
    free(pchSampleData);
    return 6;
  }
  pch = pchSampleData;
  j = 0;
  long long llOffset = 0;
  while (j < proflistlength)
  {
    long lAddress;
    int iSamples;
    float fPercentage;
    char *pchNext = strchr(pch, '\n');
    if (pchNext != NULL) *pchNext++ = 0; // null-terminate this line
    if (strstr(pch, "range:0x") != NULL) // search for offset change
    {
      pch = strstr(pch, "range:0x") + 8; // extract hex value and update our offset
      char *pch2 = pch;
      while (isHex(*pch2)) pch2++;
      *pch2 = 0;
      llOffset = strtoll(pch, NULL, 16);
    }
    else // parse line for sample point
    {
      int rval = ParseProfLine(pch, &lAddress, &iSamples, &fPercentage);
      if (rval != 0)
      {
        pProfTable[j].x86addr = (unsigned long) (lAddress + llOffset);
        pProfTable[j].samples = iSamples;
        j++;
      }
    }
    pch = pchNext;
    if (pch == NULL) break;
  }
  free(pchSampleData);
  proflistlength = j;
  printf("Found %i profile hits.\n", proflistlength);

  /* clear r4300 instruction sample data table */
  for (i = 0; i < 132; i++)
    instr_samples[i] = 0;
    
  /* calculate r4300 instruction profiling data by merging the tables */
  samp_unknown  = 0;
  samp_blockend = 0;
  samp_notcompiled = 0;
  samp_wrappers = 0;
  samp_flush = 0;
  i = 0; // i == OpAddrTable index
  lOpStart = pOpAddrTable[0].x86addr;
  lOpEnd   = pOpAddrTable[1].x86addr;
  for (j = 0; j < proflistlength; j++) // j == pProfTable index
  {
    long lOpx86addr = pProfTable[j].x86addr;
    if (lOpx86addr >= lOpStart && lOpx86addr <= lOpEnd) /* these profile samples lie within current r4300 instruction */
    {
      int instr = pOpAddrTable[i].mipsop;
      if (instr == -1) printf("%lx sample point lies between %i/%lx and %i/%lx\n", lOpx86addr, instr, lOpStart, pOpAddrTable[i+1].mipsop, lOpEnd);

      if (instr == -1)
        samp_unknown += pProfTable[j].samples;
      else if (instr == -2)
        samp_notcompiled += pProfTable[j].samples;
      else if (instr == -3)
        samp_blockend += pProfTable[j].samples;
      else if (instr == -4)
        samp_wrappers += pProfTable[j].samples;
      else if (instr == -5)
        samp_flush += pProfTable[j].samples;
      else
        instr_samples[instr] += pProfTable[j].samples;
      continue;
    }
    if (lOpx86addr < pOpAddrTable[0].x86addr || lOpx86addr >= pOpAddrTable[oplistlength-1].x86addr)
    { /* outside the range of all recompiled instructions */
      samp_unknown += pProfTable[j].samples;
      continue;
    } 
    if (lOpx86addr < lOpStart) /* discontinuity in profile list, go back to start */
    {
      i = 0;
      lOpStart = pOpAddrTable[0].x86addr;
      lOpEnd   = pOpAddrTable[1].x86addr;
      j--;
      continue;
    }
    /* this profile point is ahead of current r4300 instruction */
    do  /* race ahead in r4300 opcode list until we hit this profile sample point */
    {
      i++;
    } while (i+1 < oplistlength && lOpx86addr > pOpAddrTable[i+1].x86addr);
    lOpStart = pOpAddrTable[i].x86addr;
    lOpEnd   = pOpAddrTable[i+1].x86addr;
    if (lOpx86addr < lOpStart || lOpx86addr > lOpEnd)
    {
      printf("Error: lOpx86addr = %lx but lOpStart, lOpEnd = %lx, %lx\n", lOpx86addr, lOpStart, lOpEnd);
      return 7;
    }
    /* we have found the correct r4300 instruction corresponding to this profile point */
    j--;
  }

  /* print the results */
  unsigned int iTypeCount[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  printf("\nInstruction time (samples):\n");
  totaltime = 0;
  for (i = 0; i < 131; i++)
  {
    printf("%8s: %08i  ", instr_name[i], instr_samples[i]);
    if (i % 5 == 4) printf("\n");
    iTypeCount[instr_type[i]] += instr_samples[i];
    totaltime += instr_samples[i];
  }
  int special = samp_flush + samp_wrappers + samp_notcompiled + samp_blockend;
  printf("\n\nSpecial code samples:\n");
  printf("  Regcache flushing: %i\n", samp_flush);
  printf("  Jump wrappers: %i\n", samp_wrappers);
  printf("  NOTCOMPILED: %i\n", samp_notcompiled);
  printf("  block postfix & link samples: %i\n", samp_blockend);

  printf("\nUnaccounted samples: %i\n", samp_unknown);
  printf("Total accounted instruction samples: %i\n", totaltime + special);
  for (i = 0; i < 11; i++)
  {
    printf("%20s: %04.1f%% (%i)\n", instr_typename[i], (float) iTypeCount[i] * 100.0 / totaltime, iTypeCount[i]);
  }

  free(pOpAddrTable);
  free(pProfTable);
  return 0;
}
void XQAccessPointManagerPrivate::storeWEPDataL(const TInt aIapId, const TDesC& aPresharedKey)
{
    CCommsDbTableView* wLanServiceTable;

    CApUtils* apUtils = CApUtils::NewLC(*ipCommsDB);
    TUint32 iapId = apUtils->IapIdFromWapIdL(aIapId);
    CleanupStack::PopAndDestroy(apUtils);

    TUint32 serviceId;

    CCommsDbTableView* iapTable = ipCommsDB->OpenViewMatchingUintLC(TPtrC(IAP),
                                                                    TPtrC(COMMDB_ID),
                                                                    iapId);
                            
    User::LeaveIfError(iapTable->GotoFirstRecord());
    iapTable->ReadUintL(TPtrC(IAP_SERVICE), serviceId);
    CleanupStack::PopAndDestroy(iapTable);

    wLanServiceTable = ipCommsDB->OpenViewMatchingUintLC(TPtrC(XQ_WLAN_SERVICE),
                                                         TPtrC(XQ_WLAN_SERVICE_ID),
                                                         serviceId);
    TInt errorCode = wLanServiceTable->GotoFirstRecord();
    if (errorCode == KErrNone) {
        User::LeaveIfError(wLanServiceTable->UpdateRecord());
    }
    else {
        TUint32 dummyUid = 0;
        User::LeaveIfError(wLanServiceTable->InsertRecord(dummyUid));
        wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_SERVICE_ID), aIapId);
    }
    
    CleanupCancelPushL(*wLanServiceTable);

    // Save index of key in use
    TUint32 keyInUse(KFirstWepKey);
    wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_INDEX), keyInUse);

    // Save authentication mode
    TUint32 auth(0); // set to open... 
    if (isS60VersionGreaterThan3_1()) {  
        //TODO: wLanServiceTable->WriteUintL(TPtrC(NU_WLAN_AUTHENTICATION_MODE), auth);
    } else {
        wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_AUTHENTICATION_MODE), auth);
    }
    // not we need to convert the key.... to 8bit and to hex... and again detect the required bits..
    TBuf8<KMaxWepKeyLen> key;
    
    //convert to 8 bit
    key.Copy(aPresharedKey);

    TBool useHex(EFalse);
    TWepKeyLength keyLength;
    TBool validKey = validWepKeyLength(aPresharedKey, useHex, keyLength);
    
    if (!useHex) {
        // Must be converted to hexa and stored as a hexa
        // Ascii key is half the length of Hex
        HBufC8* buf8Conv = HBufC8::NewLC(key.Length() * 2);
        asciiToHex(key, buf8Conv);
        
        if (isS60VersionGreaterThan3_1()) {  
            wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_HEX_WEP_KEY1), buf8Conv->Des());
        } else {
            wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY1), buf8Conv->Des());
        }
        CleanupStack::PopAndDestroy(buf8Conv);
    } else if (isHex(aPresharedKey)) {
        //already in hexa format
        if (isS60VersionGreaterThan3_1()) {  
            wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_HEX_WEP_KEY1), key);
        } else {
            wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY1), key);
        }
    }
  
    wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_KEY1_FORMAT), useHex);
  
    key.Zero();
    // write default values to the rest of the columns
    if (isS60VersionGreaterThan3_1()) {  
        wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_HEX_WEP_KEY2), 
                                     key);
    } else { 
        wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY2), 
                                     key );
    }
    // Save third WEP key
    if (isS60VersionGreaterThan3_1()) {  
        wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_HEX_WEP_KEY3), 
                                     key);
    } else { 
        wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY3), 
                                     key);
    }
    // Save fourth WEP key
    if (isS60VersionGreaterThan3_1()) {  
        //TODO: wLanServiceTable->WriteTextL(TPtrC(NU_WLAN_WEP_KEY4), 
        //                             key);
    } else {
        wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY4), 
                                     key);
    }
    wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_KEY2_FORMAT), 
                                 (TUint32&)useHex);

    wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_KEY3_FORMAT), 
                                 (TUint32&)useHex);

    wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_KEY4_FORMAT), 
                                 (TUint32&)useHex);
 
    wLanServiceTable->PutRecordChanges();

    CleanupStack::Pop(wLanServiceTable); // table rollback...
    CleanupStack::PopAndDestroy(wLanServiceTable);
}