Пример #1
0
int main(int argc, char *argv[])
{
	char password[DISCUZ_PASSWD_LENGTH];
	int salt;
	int i;
	char md5password[MD5LEN];
	char md5hexpasswd[DISCUZ_PASSWD_LENGTH+1];  // 32 is defined in discuz and add \0 at the end

	if(argc != 3)
	{
		printf("Usage: discuzgenpasswd <salt> <input_password>\n");
		exit(0);
	}
	strcpy(password, argv[2]);
	salt = atoi(argv[1]);
	genpasswd(md5password, salt, password);
	if(ascii2hex(md5password, md5hexpasswd) == -1)
	{
		printf("convert password error \n");
		exit(0);
	}
	for(i=0; i<DISCUZ_PASSWD_LENGTH; i++)
		printf("%c",md5hexpasswd[i]);
	return 1;
}
Пример #2
0
int main(int argc, char **argv) {
    unsigned char value[0x100], mask[0x100];
    short len = 0;
    short e = 0;
    char *h = NULL;

    if(argc < 2) {
        fprintf(stderr, "usage: %s <hex> [<path> [...]]\n", *argv);
        e = 1;
    } else {
        h = argv[1];
        int v0, v1;
        while(e == 0 && *h && len < 0x100) {
            if(*h != '.') {
                while(*h == ' ') h++;
                if((v0 = ascii2hex(h++)) > -1) {
                    while(*h == ' ') h++;
                    if((v1 = ascii2hex(h++)) > -1) {
                        value[len] = (v0 << 4) | v1;
                        mask[len++] = 0xFF;
                    } else e = 2;
                } else e = 2;
            } else {
                value[len] = mask[len] = 0;
                len++;
                h += 1;
            }
        }
    }

    if(e == 0) {
        if (argc < 3)
            searchfile("stdin", 0, value, mask, len);
        else {
            int c = 2;
            while(c < argc)
                recurse(argv[c++], value, mask, len);
        }
    } else {
        if(!len) e = 2;
        else if(len % 2 == 1) e = 3;
        else if(*h) e = 4;
        fprintf(stderr, "ERROR: %s\n", errors[e-1]);
    }

    return e;
}
Пример #3
0
uint32_t ascii2int(uint8_t *SourceBuffer, uint8_t size) {
	uint32_t val = 0;
	volatile uint32_t ind = 0;
	volatile int ret = 0;
	uint32_t mul = 1;

	while (ret != -1) {
		ret = ascii2hex(SourceBuffer[ind++]);
	}
	ind--;
	while (ind) {
		ind--;
		ret = ascii2hex(SourceBuffer[ind]);
		val = val + (ret * mul);
		mul *= 10;
	}
	return val;
}
Пример #4
0
quint32 ascii2int(quint8 *SourceBuffer, quint8 size){
	quint32 val = 0;
	quint8 ind=0;
	int ret = 0;
	quint32 mul=1;


	while(ret != -1){
		ret = ascii2hex(SourceBuffer[ind++]);
	}
	ind--;
	while(ind){
		ind--;
		ret = ascii2hex(SourceBuffer[ind]);
		val = val + (ret*mul);
		mul*=10;
	}
	return val;
}
Пример #5
0
quint32 ascii2ID_Rev(quint8 *SourceBuffer, quint8 idCount){
	quint32 idTmp=0;
	quint8 tmp=0,i=0;
	for(i=0;i<idCount;i++){
		tmp=ascii2hex(SourceBuffer[i]);
		if(tmp!=-1){
			idTmp=idTmp<<4;
			idTmp |= tmp;
		}
	}
	return idTmp;
}
Пример #6
0
uint32_t ascii2MASK(uint8_t *SourceBuffer, uint8_t Spec) {
	uint32_t maskTmp = 0,i = 0;
	uint8_t tmp = 0;

	if (Spec == 'A') {
		for (i = 0; i < 3; i++) {
			tmp = ascii2hex(SourceBuffer[i]);
			if (tmp != -1) {
				maskTmp = maskTmp << 4;
				maskTmp |= tmp;
			}
		}
	} else if (Spec == 'B') {
		for (i = 0; i < 8; i++) {
			tmp = ascii2hex(SourceBuffer[i]);
			if (tmp != -1) {
				maskTmp = maskTmp << 4;
				maskTmp |= tmp;
			}
		}
	}
	return maskTmp;
}
Пример #7
0
uint32_t ascii2ID_Rev(uint8_t *SourceBuffer, uint8_t idCount) {
	uint32_t idTmp = 0,i = 0;
	uint8_t tmp = 0;

	for (i = 0; i < idCount; i++) {
		tmp = ascii2hex(SourceBuffer[i]);
		if (tmp != -1) {
			idTmp = idTmp << 4;
			idTmp |= tmp;
		}
	}

	return idTmp;
}
Пример #8
0
uint32_t ascii2ID(uint8_t *SourceBuffer, uint8_t Spec) {
	uint32_t idTmp = 0,i = 0;
	uint8_t tmp = 0;

	if (Spec == 'A') {
		for (i = 0; i < 3; i++) {
			tmp = ascii2hex(SourceBuffer[i]);
			if (tmp != -1) {
				idTmp = idTmp << 4;
				idTmp |= tmp;
			}
		}
	} else if (Spec == 'B') {
		for (i = 0; i < 8; i++) {
			tmp = ascii2hex(SourceBuffer[i]);
			if (tmp != -1) {
				idTmp = idTmp << 4;
				idTmp |= tmp;
			}
		}
	}
	return idTmp;
}
Пример #9
0
char *
dvalue(char *ptr)
{
	char *modv, *str, *sb;
	int len;

	/* if cleartext return NULL (error!) */
	if (TRUE == is_cleartext(ptr))
		return (NULL);

	sb = strchr(ptr, '}');
	sb++;
	len = strlen(sb);
	str = ascii2hex(sb, &len);
	modv = modvalue(str, len, NULL);
	free(str);
	str = NULL;
	return (modv);
}
Пример #10
0
int srec_read(const char *filename,
              void *code, unsigned int code_len,
              void *data, unsigned int data_len)
{
    FILE *pfile;
    char line[512];
    int rc = SREC_NO_ERROR;
    pfile = fopen(filename, "r");
    if (NULL == pfile)
    {
        fprintf(stderr, "Unable to open file \"%s\"\n", filename);
        return SREC_IO_ERROR;
    }
    rewind(pfile);
    while (!feof(pfile))
    {
        if (NULL == fgets(line, sizeof line, pfile))
        {
            if (ferror(pfile))
            {
                fprintf(stderr, "Unable to read file \"%s\"\n", filename);
                rc = SREC_IO_ERROR;
            }
            break;
        }
        const size_t len = strlen(line);
        if (0 == len || '\n' != line[len - 1])
        {
            fprintf(stderr, "Unable to parse file: line is too long\n");
            rc = SREC_IO_ERROR;
        }
        if (4 <= verbose_level)
        {
            printf("srec: %s\n", line);
        }
        if ('S' != line[0])
        {
            fprintf(stderr, "File format error (\"%s\")\n", line);
            rc = SREC_FORMAT_ERROR;
            break;
        }
        // Ignore non-data frames
        const unsigned int record_type = ascii2hex(&line[1], 1);
        if (1 != record_type
            && 2 != record_type
            && 3 != record_type)
        {
            if (4 <= verbose_level)
            {
                printf("Record with no data (S%u)\n", record_type);
            }
            continue;
        }
        const int address_length = (record_type + 1) * 2; // in symbols
        unsigned int address = ascii2hex(&line[4], address_length);
        const int data_length = ascii2hex(&line[2], 2) - address_length / 2 - 1; // in bytes
        const char *data_p = line + 4 + address_length;
        unsigned char *memory;

        if ((CODE_OFFSET + code_len) >= (address + data_length))
        {
            if (NULL == code)
            {
                continue;
            }
            memory = (unsigned char*)code;
            address -= CODE_OFFSET;
            if (4 <= verbose_level)
            {
                printf("srec_code (%06X) : ", address);
            }
        }
        else if (DATA_OFFSET <= address
            && (DATA_OFFSET + data_len) >= (address + data_length))
        {
            if (NULL == data)
            {
                continue;
            }
            memory = (unsigned char*)data;
            address -= DATA_OFFSET;
            if (4 <= verbose_level)
            {
                printf("srec_data (%06X) : ", address);
            }
        }
        else
        {
            rc = SREC_MEMORY_ERROR;
            break;
        }
        unsigned int i = data_length;
        for(; 0 < i; --i)
        {
            memory[address] = ascii2hex(data_p, 2);
            if (4 <= verbose_level)
            {
                printf("%02X ", memory[address]);
            }
            ++address;
            data_p += 2;
        }
        if (4 <= verbose_level)
        {
            printf("\n");
        }
    }
    fclose(pfile);
    return rc;
}
int usart_main(int argc, char *argv[])
{
	cli();
	local::system_init();
	usart0_init(57600UL);
	usart1_init(57600UL);
	sei();

	PORTD = 0xFF;
	_delay_ms(100);
	PORTD = 0x00;

	while (1)
	{
		if (!usart0_is_empty())
		{
/*
#if 0
			uint8_t hex = usart0_top_char();
			usart0_pop_char();
#else
			uint8_t ascii = usart0_top_char();
			usart0_pop_char();
			uint8_t hex = ascii2hex(ascii);
#endif
			uint16_t num = 0xABCD;
			usart1_push_char(hex2ascii((num >> 12) & 0x0F));
			usart1_push_char(hex2ascii((num >> 8) & 0x0F));
			usart1_push_char(hex2ascii((num >> 4) & 0x0F));
			usart1_push_char(hex2ascii(num & 0x0F));
*/
			uint8_t ascii = usart0_top_char();
			usart0_pop_char();
			uint8_t hex = ascii2hex(ascii);

			PORTA = hex;

			usart0_push_char(ascii);
		}

		if (!usart1_is_empty())
		{
/*
#if 0
			uint8_t hex = usart1_top_char();
			usart1_pop_char();
#else
			uint8_t ascii = usart1_top_char();
			usart1_pop_char();
			uint8_t hex = ascii2hex(ascii);
#endif
			uint16_t num = 0xABCD;
			usart1_push_char(hex2ascii((num >> 12) & 0x0F));
			usart1_push_char(hex2ascii((num >> 8) & 0x0F));
			usart1_push_char(hex2ascii((num >> 4) & 0x0F));
			usart1_push_char(hex2ascii(num & 0x0F));

*/
			uint8_t ascii = usart1_top_char();
			usart1_pop_char();
			uint8_t hex = ascii2hex(ascii);

			PORTA = hex;

			usart1_push_char(ascii);
		}

		//sleep_mode();
	}

	return 0;
}
Пример #12
0
int main(int argc, char *argv[])
{
	// stir depth and nonce length
	ub4 dep, sdep = MAXM, lnce = NLEN;
	ub4 rounds = 7;
	#ifdef MOTE-REPO
	enum CSPRNG rng = MOTE8;
	enum CSPRNG hasher = BB512;
	#else
	#ifdef BB-REPO
	enum CSPRNG rng = BB128;
	enum CSPRNG hasher = MOTE32;	
	#else
	enum CSPRNG rng = MOTE32;
	enum CSPRNG hasher = BB512;
	#endif
	#endif
	enum ciphermode cmode   = cmNone;
	enum ciphertype ctype	= ctNone;
	enum outputform oform	= ofASC;
	// input: message & key-phrase
	char msg[MAXM] = ""; 
	char key[MAXM] = "";
	// ciphertext & plaintext
	char ctx[MAXM], ptx[MAXM];
	// derived & stretched key
	char kdf[MAXK] = "";
	// IV/nonce
	char nce[MAXK] = "";
	// check the command line
	if (argc >= 5) {
		if ((argc>=2) && strlen(argv[1])<MAXM) strcpy(msg,argv[1]);
		if ((argc>=3) && strlen(argv[1])<MAXK) strcpy(key,argv[2]);
		if (argc>=4)
			if ((strcmp(argv[3],"d")==0) || (strcmp(argv[3],"D")==0))
				 cmode = cmDecipher; else
			if ((strcmp(argv[3],"e")==0) || (strcmp(argv[3],"E")==0)) 
				 cmode = cmEncipher; else cmode = cmNone;
		if (argc>=5)
			#ifdef NEVER
			if ((strcmp(argv[4],"v")==0) || (strcmp(argv[4],"V")==0))
				 ctype = ctVernam; else
			#endif
			if ((strcmp(argv[4],"c")==0) || (strcmp(argv[4],"C")==0))
				 ctype = ctCaesar; else
			if ((strcmp(argv[4],"m")==0) || (strcmp(argv[4],"M")==0)) 
				ctype = ctCaesarM; else ctype = ctNone;
		if (argc>=6) 
			if ((strcmp(argv[5],"a")==0) || (strcmp(argv[5],"A")==0))
				oform = ofASC; else oform = ofHEX;
		if (argc>=7) rng = (enum CSPRNG)(atoi(argv[6]) % 7);
	}
	// sanity checks
	if (TRUE) {
		if ((strlen(msg)<MINM) || (strlen(key)<MINK)) { info(); exit(0); }
		if ((cmode==cmNone) || (ctype==ctNone))       { info(); exit(0); }
		// only hex output available for Vernam
		if (ctype==ctVernam) oform=ofHEX;
		// output mode MOD 26? (not possible with Vernam)
		if ((oform==ofASC) && (ctype!=ctVernam)) { MOD=26; START='A'; }
		// no nonce scrambling or mixing available with hex output
		if (oform==ofHEX) SCRAMBLER=NONCE=MIX=FALSE;
	}
	// B E G I N  P R E P A R A T I O N
	// preliminary seeding
	rSeedAll(key,rounds);
	
	if (SCRAMBLER) {
		sdep = SetDepth(rng,strlen(key));
		#ifdef LOG
		char tmp[12]=""; sprintf(tmp,"%d",sdep);
		log_add("RNG",rName(rng));
		log_add("HSH",rName(hasher));
		log_add("DEP",tmp);
		#endif
	}
	
	if (NONCE) {
		// obtain nonce/IV hash of fixed or random length
		strcpy(nce,rNonce(hasher,FALSE));
		// note nonce length for later
		lnce = strlen(nce);
	}

	// Key-derivation starts:
	if (TRUE) {
		// 1) seed MOTE with a key-derived hash
		strcpy(kdf,rHash(hasher,key,rStateSize(rng)*4));
		rSeed(rng,kdf,rounds);
		// 2) calculate stir-depth
		dep = rDepth(rng,kdf);
		// 3) warm up MOTE with <dep> rounds
		rStir(rng,dep); 
	}
	#ifdef TEST
		#ifdef LOG
		log_add("DKY",leftstr(kdf,LINE));
		#endif
	#endif
	// Key-derivation ends.
	
	if (SCRAMBLER) {
		// prepare scrambler's random pool
		RandPool_Fill(rng);
	}
	// E N D  P R E P A R A T I O N.
	
	// B E G I N  M A I N  C I P H E R  S E Q U E N C E
	// Mode: Encipher
	if (cmode==cmEncipher) {
		// pre-process message if output is mod 26
		if (oform==ofASC) strcpy(msg, PreProcessText(msg));
			#ifdef LOG
			if (oform==ofASC) log_add("MSG",msg);
			#endif
		// Encrypt: Vernam XOR
		if (ctype==ctVernam)  strcpy(ctx, Vernam(rng,msg));
		// Encrypt: Caesar MOD
		if (ctype==ctCaesar)  strcpy(ctx, rCaesarStr(rng, cmEncipher, msg, MOD, START));
		// Encrypt: Caesar MIX
		if (ctype==ctCaesarM) strcpy(ctx, rmCaesarStr(rng, cmEncipher, msg, MOD, START));
		// convert to hexadecimal as appropriate
		if (oform==ofHEX) strcpy(ctx,ascii2hex(ctx));
			#ifdef LOG
			log_add(" CT",ctx);
			#endif
		if (MIX) {
			// Mix: Vigenere-cipher the ciphertext on the nonce
			strcpy(ctx,Vig(rng,cmode,ctx,nce,MOD,START,FALSE));
				#ifdef LOG
				log_add("NCE",nce);
				log_add("VCT",ctx);
				#endif
		}
		if (NONCE) {
			// append ciphertext to nonce
			strcat(nce,ctx); strcpy(ctx,nce);
				#ifdef LOG
				log_add("NCT",ctx);
				#endif
		}
		if (SCRAMBLER) {
			// prepare scrambler context & scramble ciphertext
			InitRandPairs(rng,sdep,strlen(ctx));
			strcpy(ctx,Scrambled(ctx,sdep));
				#ifdef LOG
				log_add("SCT",ctx);
				#endif
		}
	}
	// Mode: Decipher
	if (cmode==cmDecipher) {
		// Convert hexadecimal ciphertext to ASCII (not in mod 26)
		if (oform==ofHEX) strcpy(ctx, hex2ascii(msg)); else strcpy(ctx, msg);
		if (SCRAMBLER) {
				#ifdef LOG
				log_add("SCT",ctx);
				#endif
			// prepare scrambler context & unscramble ciphertext
			InitRandPairs(rng,sdep,strlen(ctx));
			strcpy(ctx,unScrambled(ctx,sdep));
				#ifdef LOG
				log_add("UST",ctx);
				#endif
		}
		if (NONCE) {
			// detach ciphertext from nonce
			strcpy(nce,leftstr(ctx,lnce));
			strcpy(ctx,rightstr(ctx,strlen(msg)-lnce));
				#ifdef LOG
				log_add("VCT",ctx);
				log_add("NCE",nce);
				#endif
		}
		if (MIX) {
			// Un-mix: Vigenere-decipher the ciphertext on the nonce
			strcpy(ctx,Vig(rng,cmode,ctx,nce,MOD,START,FALSE));
				#ifdef LOG
				log_add("UVC",ctx);
				#endif
		}
		// Decrypt: Vernam XOR
		if (ctype==ctVernam) strcpy(ptx, Vernam(rng,ctx));
		// Decrypt: Caesar MOD
		if (ctype==ctCaesar)  strcpy(ptx, rCaesarStr(rng, cmDecipher, ctx, MOD, START));
		// Decrypt: Caesar MIX
		if (ctype==ctCaesarM) strcpy(ptx, rmCaesarStr(rng, cmDecipher,ctx, MOD, START));
		// post-process plaintext if output is mod 26
		if (oform==ofASC) strcpy(ptx, PostProcessText(ptx));
	}  
	// E N D  M A I N  C I P H E R  S E Q U E N C E .
	#ifdef LOG
	log_show ();
	log_clear();
	#endif
	// P R O G R A M  O U T P U T
	if ((strcmp(ptx,"") != 0) || (strcmp(ctx,"") != 0)) {
		// Mode: Encipher
		if (cmode==cmEncipher) puts(ctx);
		// Mode: Decipher
		if (cmode==cmDecipher) puts(ptx);
		
		// belt'n'braces memory wipe
		if (TRUE) {
			rResetAll(); rResetAll();
			memset(msg,0,sizeof(msg));memset(msg,0xFF,sizeof(msg));memset(msg,0,sizeof(msg));
			memset(key,0,sizeof(key));memset(key,0xFF,sizeof(key));memset(key,0,sizeof(key));
			memset(kdf,0,sizeof(kdf));memset(kdf,0xFF,sizeof(kdf));memset(kdf,0,sizeof(kdf));
			memset(ctx,0,sizeof(ctx));memset(ctx,0xFF,sizeof(ctx));memset(ctx,0,sizeof(ctx));
			memset(ptx,0,sizeof(ptx));memset(ptx,0xFF,sizeof(ptx));memset(ptx,0,sizeof(ctx));
			dep=0;
		}
		
	} else info();

	return 0;
}
Пример #13
0
static void send_pass_through_command_text_reply ( const int fd, const char * const text )
{
  const std::string text_hex = ascii2hex( text );
  put_str_packet( fd, &text_hex );
}
Пример #14
0
uint32_t SetCANTxBuffer(uint8_t *ch, uint32_t size) {


	uint32_t ind = 0;
	uint32_t idCount;
	uint32_t idTmp = 0;
	uint8_t IDTMP[8];
	uint32_t i;
	uint8_t tmp;
	uint8_t dataTmp = 0;

	tx_tmp_msg.mode_id = 0;


	if(ch[ind] == STD_DAT){
		tx_tmp_msg.mode_id |= CAN_MSGOBJ_STD;
		tx_tmp_msg.mode_id |= CAN_MSGOBJ_DAT;
		idCount = 3;
	}else if(ch[ind] == STD_RET){
		tx_tmp_msg.mode_id |= CAN_MSGOBJ_STD;
		tx_tmp_msg.mode_id |= CAN_MSGOBJ_RTR;
		idCount = 3;

	}else if(ch[ind] == EXT_DAT){
		tx_tmp_msg.mode_id |= CAN_MSGOBJ_EXT;
		tx_tmp_msg.mode_id |= CAN_MSGOBJ_DAT;
		idCount = 8;
	}else if(ch[ind] == EXT_RET){
		tx_tmp_msg.mode_id |= CAN_MSGOBJ_EXT;
		tx_tmp_msg.mode_id |= CAN_MSGOBJ_RTR;
		idCount = 8;
	}else{
		return 0;
	}


	for (i = 1; i <= idCount; i++) {
		IDTMP[i - 1] = ch[i];
		ind++;
	}
	idTmp = ascii2ID_Rev(IDTMP, idCount);
	tx_tmp_msg.mode_id |= idTmp;


	ind = idCount+1;

	tmp = ascii2hex(ch[ind++]);
	if (tmp != -1)
		tx_tmp_msg.dlc = tmp;
	else
		return 0;

	if (!(tx_tmp_msg.mode_id & CAN_MSGOBJ_RTR)) {

		for (i = 0; i < (tmp * 2); i++) {
			if (i % 2) {
				dataTmp |= ascii2hex(ch[(i + ind)]);
				tx_tmp_msg.data[i / 2] = dataTmp;
			} else {
				dataTmp = ascii2hex(ch[i + ind]);
				dataTmp = dataTmp << 4;

			}
		}

	}

	tx_tmp_msg.mask = 0x0UL;
	tx_tmp_msg.msgobj = (tx_can_count % MAX_CAN_TX_MESSAGEOBJECT)+24;
	//tx_tmp_msg.msgobj =0;

	tx_can_msg[TX_CAN_BUFFER_POINT] = tx_tmp_msg;

	tx_can_count++;
	return 1;
}
Пример #15
0
TEST(UTIL, ascii2hex) {
  EXPECT_EQ(0x0, ascii2hex('0'));
  EXPECT_EQ(0x9, ascii2hex('9'));
  EXPECT_EQ(0xA, ascii2hex('A'));
  EXPECT_EQ(0xF, ascii2hex('F'));
}
Пример #16
0
/*******************************************************************
 *  FUNCTION: CommandParse
 *  AUTHOR 		= 	TRAMPAS STERN
 *  FILE 		=	command.c	
 *  DATE		=   1/25/2004  4:03:03 PM
 *
 *  PARAMETERS: Takes the command line string	
 *
 *  DESCRIPTION: parses the command line and returns Command ID
 *
 *  RETURNS: Command ID, and 
 *
 *
 *******************************************************************/
UINT CommandParse(CHAR *str)
{
	CHAR *ptr;
	CHAR *ptr2;
	UINT i;
	CHAR cmd[MAX_STRING];
	CHAR buff[MAX_CMD_LENGTH];
	CHAR argv[MAX_ARGS][MAX_ARG_LENGTH];
	//CHAR *ptrArgv[MAX_ARGS];
	UINT numArgs;

	//first we need find command and arguments	
	ptr=strchr(str,' '); //find first char

	if (ptr==0)
	{
		//we have two options, frist whole thing is command
		//second bad command
		if(strlen(str)>0)
			ptr=str+strlen(str); 
		else
			return 0; //bad command
	}

	//copy string to command buffer. 
	i=0;
	ptr2=str; 
	while(ptr!=0 && ptr!=ptr2 && i<(MAX_CMD_LENGTH-1))
	{
		buff[i++]=*ptr2++; 
	}
	buff[i]=0;

	//now buff contains the command let's get the args
	numArgs=0;
	while(*ptr!=0 && *ptr==' ')
		ptr++; //increment pointer past ' '
	if (*ptr!=0)
	{ 	
		ptr2=strchr(ptr,' ');
		if (ptr2==0)
		{
			//we have two options, frist whole thing is command
			//second bad command
			if(strlen(ptr)>0)
				ptr2=ptr+strlen(ptr); 
		}
		while(ptr2!=0 && numArgs<MAX_ARGS)
		{
			int j;
			j=0;
			while (ptr2!=ptr && j<(MAX_ARG_LENGTH-1))
			{
				argv[numArgs][j++]=*ptr++;
			}
			argv[numArgs][j++]=0;
			numArgs++;
			ptr2=0;
			if (*ptr!=0)
			{
				while(*ptr!=0 && *ptr==' ')
					ptr++; //increment pointer past ' '
				ptr2=strchr(ptr,' ');
				if (ptr2==0)
				{
					//we have two options, frist whole thing is command
					//second bad command
					if(strlen(ptr)>0)
						ptr2=ptr+strlen(ptr); 
				}
			}
		}
	}
/*
	for(i=0; i<MAX_ARGS; i++)
	{
		ptrArgv[i]=argv[i];
	}
	
	//now let's parse the command
	for(i=1; i<NUM_COMMANDS; i++)
	{
		if (strcmp((const char *)buff,(const char *)strCommands[i])==0)
			return (*ptrCommands[i])(numArgs,ptrArgv);
	}
*/
	sprintf(cmd,"exit");
	if (strcmp(buff,cmd)==0)
	{
		CommandExit=1;
	}

	sprintf(cmd,"ver");
	if (strcmp(buff,cmd)==0)
	{
	   printf("software v%d.%02d",VER_MAJOR,VER_MINOR); 
	}	
	sprintf(cmd,"hwver");
	if (strcmp(buff,cmd)==0)
	{
	   printf("hardware v%d",HW_VER); 
	}	
	sprintf(cmd,"logb");
	if (strcmp(buff,cmd)==0)
	{
		datalog_bin();

	}	
	sprintf(cmd,"vpwmon");
	if (strcmp(buff,cmd)==0)
	{
	   vpw_montior(); 
	}	
	sprintf(cmd,"log");
	if (strcmp(buff,cmd)==0)
	{
		datalog();
	}
	sprintf(cmd,"pwmhigh");
	if (strcmp(buff,cmd)==0)
	{
		output_high(PIN_F5);
	} 

	sprintf(cmd,"pwmlow");
	if (strcmp(buff,cmd)==0)
	{
		output_low(PIN_F5);
	}	

	sprintf(cmd,"pwmmon");
	if (strcmp(buff,cmd)==0)
	{
		pwm_monitor();
	}
	sprintf(cmd,"pwmread");
	if (strcmp(buff,cmd)==0)
	{
		while(!kbhit())
		{
			printf("PWM bus=%d\n\r",PWM_IN);
		}
		getch2();
	}	
		 
	sprintf(cmd,"5baud");
	if (strcmp(buff,cmd)==0)
	{
	    UBYTE keys[2];
		printf("%lu ",iso_5baud(keys,2,0x33));
		printf("%X %X\n\r",keys[0],keys[1]);
	}
   		sprintf(cmd,"crc");
	if (strcmp(buff,cmd)==0)
	{
		UBYTE data[20];
		UBYTE temp;
		for (i=0; i<numArgs; i++)
		{
			//we need to parse ASCII
			temp=ascii2hex(argv[i]);
			data[i]=temp;
		}
		for (temp=0; temp<numArgs; temp++)
		{
			printf("%X ",data[temp]);
		}
		printf("\n\r");
		fprintf(STDIN,"CRC %X\n\r",crc(data,numArgs));
	}

	sprintf(cmd,"csum");
	if (strcmp(buff,cmd)==0)
	{
		UBYTE data[20];
		UBYTE temp;
		for (i=0; i<numArgs; i++)
		{
			//we need to parse ASCII
			temp=ascii2hex(argv[i]);
			data[i]=temp;
		}
		for (temp=0; temp<numArgs; temp++)
		{
			printf("%X ",data[temp]);
		}
		printf("\n\r");
		fprintf(STDIN,"CheckSum %X\n\r",checksum(data,numArgs));
	}
	
	sprintf(cmd, "vagcom");
	if (strcmp(buff,cmd)==0)
	{
		//we need to monitor the serial port
		// when port goes high drive k-line accordingly
	}

	sprintf(cmd, "vag");
	if (strcmp(buff,cmd)==0)
	{
		UBYTE data[60];
		UBYTE resp[20];
		UBYTE ret;
		UBYTE i;
		UBYTE block;

		//first lets init communications
		ret=iso_5baud(data,2,0x01);
  
		data[2]=0;

		while(data[2]!=0x09)
		{
		    //get block from ECM
		    ret=vagGetBlock(data,60);
			for(i=0; i<ret; i++)
			{
				printf("%X ",data[i]);
			}
			printf("\n\r");
		    //now build ack
			block=data[1]+1;
		    resp[0]=data[1]+1;
		    resp[1]=0x09;
		    vagPutBlock(resp,2);
			block++;
		}
		ret=vagGetBlock(data,60);
		for(i=0; i<ret; i++)
		{
			printf("%X ",data[i]);
		}
		printf("\n\r");
		block=data[1]+1;

		printf("Test block ");	
		for(i=0; i<numArgs; i++)
		{
			resp[i+1]=ascii2hex(argv[i]);
			printf("%X ",resp[i+1]);
		}	
		printf("\n\r");

		//now lets see what happens if we send a block request for block 02
		resp[0]=block;
		//resp[1]=code;
		vagPutBlock(resp,numArgs+1);
		data[2]=0;

		while(data[2]!=0x09)
		{
		    //get block from ECM
		    ret=vagGetBlock(data,60);
			for(i=0; i<ret; i++)
			{
				printf("%X ",data[i]);
			}
			printf("\n\r");
		    //now build ack
			block=data[1]+1;
		    resp[0]=data[1]+1;
		    resp[1]=0x09;
		    vagPutBlock(resp,2);
			block++;
		}



	 }

	sprintf(cmd,"isosend");
	if (strcmp(buff,cmd)==0)
	{
	    UBYTE data[60];
		UBYTE resp[20];
		UBYTE i;
		UBYTE temp;
		
		printf("hit key to stop\n\r");
		//we need to copy args to data
		for (i=0; i<numArgs; i++)
		{
			//we need to parse ASCII
			temp=ascii2hex(argv[i]);
			data[i]=temp;
		}
		//printf("\n\r");
		while(!kbhit())
		{
			temp=iso_send(resp, 60, data, numArgs,0x33);	
			printf("response %u\n\r",temp); 
			for (i=0; i<temp; i++)
			{
				printf("%X ",resp[i]);
			}
			printf("\n\r");	
		}
		while(kbhit())
			getch2();		
	}
	

	sprintf(cmd,"pwmsend");
	if (strcmp(buff,cmd)==0)
	{
	    UBYTE data[60];
		UBYTE resp[20];
		UBYTE i;
		UBYTE temp;
		
		printf("hit key to stop\n\r");
		//we need to copy args to data
		for (i=0; i<numArgs; i++)
		{
			//we need to parse ASCII
			temp=ascii2hex(argv[i]);
			data[i]=temp;
			//printf("args %x %s\n\r",temp,argv[i]);
		}
		//printf("\n\r");
		while(!kbhit())
		{
			temp=pwm_send(resp, 60, data, numArgs);	
			printf("response %u\n\r",temp); 
			for (i=0; i<temp; i++)
			{
				printf("%X ",resp[i]);
			}
			printf("\n\r");	
		}
		while(kbhit())
			getch2();		
	}
/*
	sprintf(cmd,"flashread");
	if (strcmp(buff,cmd)==0)
	{
		UDWORD addr;
		
		addr=atoi32(argv[0]);
		printf("*%lu=%X\n\r",addr,flash_read(addr));	    		
	}

	sprintf(cmd,"flashbufread");
	if (strcmp(buff,cmd)==0)
	{
		UDWORD addr;
		
		addr=atoi32(argv[0]);
		printf("*%lu=%X\n\r",addr,flash_buf_read(addr));	    		
	}
*/
	sprintf(cmd,"flasherase");
	if (strcmp(buff,cmd)==0)
	{
		flash_erase();
		printf("Done\n\r");    		
	}

/*
	sprintf(cmd,"flashput");
	if (strcmp(buff,cmd)==0)
	{
		UDWORD addr;
		UBYTE data;
		
		addr=atoi32(argv[0]);
		data=atoi(argv[1]);
		printf("Putting *%lu=%X\n\r",addr,data);
		data=flash_put(addr,data);
		printf("returned %x\n\r",data);	    		
	}
*/

	sprintf(cmd,"vpwsend");
	if (strcmp(buff,cmd)==0)
	{
	    UBYTE data[60];
		UBYTE resp[20];
		UBYTE i;
		UBYTE temp;
		
		printf("hit key to stop\n\r");
		//we need to copy args to data
		for (i=0; i<numArgs; i++)
		{
			//we need to parse ASCII
			temp=ascii2hex(argv[i]);
			data[i]=temp;
		}
		//printf("\n\r");
		while(!kbhit())
		{
			temp=vpw_send(resp, 60, data, numArgs);	
			printf("response %u\n\r",temp); 
			for (i=0; i<temp; i++)
			{
				printf("%X ",resp[i]);
			}
			printf("\n\r");	
		}
		while(kbhit())
			getch2();		
	}

	sprintf(cmd,"isomon");
	if (strcmp(buff,cmd)==0)
	{
		while (!kbhit())
		   iso_monitor(); 
			
		while(kbhit())
			getch2();

	}

	sprintf(cmd,"isoput");
	if (strcmp(buff,cmd)==0)
	{
		UBYTE temp;
		printf("ISO Put test\n\r");
		printf("press any key to stop\n\r");
		temp=0x03;
		while (!kbhit())
			iso_put(&temp,1,20);  
			
		while(kbhit())
			getch2();
	}

	sprintf(cmd,"vpwhigh");
	if (strcmp(buff,cmd)==0)
	{
		UBYTE temp;
		printf("VPW high test\n\r");
		printf("press any key to stop\n\r");
		temp=0x03;
		output_high(VPW_OUT);
		while (!kbhit()){
			printf("VPW_IN=%u\n\r",VPW_IN);
		}	  
			
		while(kbhit())
			getch2();
		output_low(VPW_OUT);

	}

	sprintf(cmd,"isohigh");
	if (strcmp(buff,cmd)==0)
	{
		UBYTE temp;
		printf("ISO high test\n\r");
		printf("press any key to stop\n\r");
		temp=0x03;
		K_HIGH;
		while (!kbhit()){
			printf("ISO_IN=%u\n\r",K_IN);
		}	  
			
		while(kbhit())
			getch2();
		K_LOW;

	}

	sprintf(cmd,"isolow");
	if (strcmp(buff,cmd)==0)
	{
		UBYTE temp;
		printf("ISO low test\n\r");
		printf("press any key to stop\n\r");
		temp=0x03;
		K_LOW;
		while (!kbhit()){
			printf("ISO_IN=%u\n\r",K_IN);
		}	  
			
		while(kbhit())
			getch2();
		K_HIGH;

	}



	sprintf(cmd,"vpwlow");
	if (strcmp(buff,cmd)==0)
	{
		UBYTE temp;
		printf("VPW low test\n\r");
		printf("press any key to stop\n\r");
		temp=0x03;
		output_low(VPW_OUT);
		while (!kbhit()){
			printf("VPW_IN=%u\n\r",VPW_IN);
		}	  
			
		while(kbhit())
			getch2();
		output_low(VPW_OUT);

	}

	sprintf(cmd,"flashpgm");
	if (strcmp(buff,cmd)==0)
	{
		//UBYTE ret;
		printf("Start Xmodem download to unit of flash");
		delay_ms(250);
		Flash_serial_program(0);
	}
	 
	sprintf(cmd,"flashpcodes");
	if (strcmp(buff,cmd)==0)
	{
		//UBYTE ret;
		printf("Start Xmodem download to unit of P codes");
		delay_ms(250);
		Flash_serial_program(PCODE_FLASH_START);
	}

	sprintf(cmd,"flashccodes");
	if (strcmp(buff,cmd)==0)
	{
		//UBYTE ret;
		printf("Start Xmodem download to unit of C codes");
		delay_ms(250);
		Flash_serial_program(CCODE_FLASH_START);
	}
	sprintf(cmd,"flashbcodes");
	if (strcmp(buff,cmd)==0)
	{
		//UBYTE ret;
		printf("Start Xmodem download to unit of B codes");
		delay_ms(250);
		Flash_serial_program(BCODE_FLASH_START);
	}
	sprintf(cmd,"flashucodes");
	if (strcmp(buff,cmd)==0)
	{
		//UBYTE ret;
		printf("Start Xmodem download to unit of U codes");
		delay_ms(250);
		Flash_serial_program(UCODE_FLASH_START);
	}

	sprintf(cmd,"flashfirm");
	if (strcmp(buff,cmd)==0)
	{
		UWORD i;
		printf("Erasing Firmware\n\r");
		for(i=(FIRM_FLASH_START>>8); i<(FLASH_MAX_PAGES>>8); i++)
		{
			//sprintf(temp,"%lu",i);
			//LCD_print2(temp,2);
			//printf("Erasing Page %lu\n\r",i);
			if (flash_erase_page(i)!=0)
				return 1;
		}

		printf("Start Xmodem download to unit of Firmware");
		delay_ms(250);
		Flash_serial_program(FIRM_FLASH_START);
		delay_ms(250);
		printf("Checking Firmware\n\r");

		if (FirmwareCheck(FIRM_FLASH_START)==0)
		{
			printf("Updating Firmware\n\r");
			FirmwareUpdate(FIRM_FLASH_START);
		}else
		{
			printf("Firmware not correct, try reloading\n\r");
		}

	}
Пример #17
0
TEST(UTIL, ascii2hex_out_of_range) {
  EXPECT_EQ(0x0, ascii2hex('*'));
}