void applicationTask()
{
    msb = capextend_read_msb_buttons();
    lsb = capextend_read_lsb_buttons();
    ByteToHex(lsb,text);
    mikrobus_logWrite("Hex representation of lsb: ",_LOG_TEXT);
    mikrobus_logWrite(text,_LOG_LINE);
    ByteToHex(msb,text);
    mikrobus_logWrite("Hex representation of msb: ",_LOG_TEXT);
    mikrobus_logWrite(text,_LOG_LINE);
    Delay_ms(1000);
}
Пример #2
0
SYSLIBFUNC(DWORD) BinToHexA(LPBYTE lpData,DWORD dwSize,LPSTR lpStrOut)
{
    DWORD dwStrSize=0;
    do
    {
        if (!SYSLIB_SAFE::CheckParamRead(lpData,dwSize))
            break;

        if (!SYSLIB_SAFE::CheckStrParamA(lpStrOut,(dwSize+1)*2))
            break;

        LPSTR lpPtr=lpStrOut;
        for (DWORD i=0; i < dwSize; i++)
        {
            lpPtr[0]=ByteToHex(lpData[i] >> 0x4);
            lpPtr[1]=ByteToHex(lpData[i]  & 0xF);

            dwStrSize+=2;
            lpPtr+=2;
        }
        *lpPtr=0;
    }
    while (false);
    return dwStrSize;
}
Пример #3
0
BOOL CEditBinDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	SetDlgItemText(IDC_EDT_REGVALUE, m_strValue);
	
	if (m_bIsBinary)
	{
		BYTE sData[512] = {0};
		int len = StringToByte(m_strData,sData,512);
		m_EditBinCtrl.SetData(sData,len);
		char buff[1024] = {0};
		ByteToHex(sData,len,buff);
		m_strData = buff;
	}
	else
	{
		int len = m_strData.GetLength(),i;
		BYTE *pBuff = new BYTE[len+1];
		for (i=0;i<len;i++)
			pBuff[i] = (BYTE)m_strData.GetAt(i);
		m_EditBinCtrl.SetData(pBuff,len);
		delete []pBuff;
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Пример #4
0
//Illegal value in querry frame
void ErrorMessage(uint8_t ErrorCode)
{
char OutputFrame[OFS];   // output frame
char temp[2];
uint8_t FunC;
uint8_t ErrFuncCode;
uint8_t k;

//Clears table
for(k = 0; k<OFS; k++){OutputFrame[k] = '\0';}

//Rewrite first chars
RewritingChars(OutputFrame,0,2);

//Read Function Code from message
temp[0] = word[3];
temp[1] = word[4];
HexToByte(temp, &FunC);

//Calculate Function Code for Message with Error
ErrFuncCode = FunC + 80;
ByteToHex(temp,ErrFuncCode);
OutputFrame[3] = temp[0];
OutputFrame[4] = temp[1];

//Fill Data field with ILLEGAL FUNCTION CODE
ByteToHex(temp,ErrorCode);
OutputFrame[5] = temp[0];
OutputFrame[6] = temp[1];

//* Writes LRC.
ByteToHex(temp,GetLRC(OutputFrame));
OutputFrame[7] = temp[0];
OutputFrame[8] = temp[1];
OutputFrame[9] = 0x0D;
OutputFrame[10] = 0x0A;
OutputFrame[11] = 0x0A;

//sending frame 
UART_SendStr(OutputFrame); 
}
Пример #5
0
//* FC06 This command writes the contents of analog output holding register.
void PresetSingleRegister(void)
{
char OutputFrame[OFS];   
char temp4[4];
char temp2[2];

uint16_t Register = 0;
uint16_t ValueToWrite = 0;
uint8_t k = 0;

//Clears table
for(k = 0; k<OFS; k++){OutputFrame[k] = '\0';}

// rewrites slave's address & number of function
RewritingChars(OutputFrame,0,12);


//* Gets data addres of the register.
temp4[0] = word[5];
temp4[1] = word[6];
temp4[2] = word[7];
temp4[3] = word[8];
HexToByte_4(temp4, &Register);
if(Check_DataAddr_F06(Register) & Check_DataVal())
{
	//* The value to write( FF00 = ON,  0000 = OFF ).
	temp4[0] = word[9];
	temp4[1] = word[10];
	temp4[2] = word[11];
	temp4[3] = word[12];
	HexToByte_4(temp4, &ValueToWrite);

	//* Sets the value.
	Output_Registers[Register] = ValueToWrite;

	//* Writes LRC.
	k = 13;
	ByteToHex(temp2,GetLRC(OutputFrame));
	OutputFrame[k] = temp2[0];
	k++;
	OutputFrame[k] = temp2[1];
	k++;
	OutputFrame[k] = 0x0D;
	k++;
	OutputFrame[k] = 0x0A;
	k++;
	OutputFrame[k] = 0x0A;
	k++;

	//sends frame 
	UART_SendStr(OutputFrame); 
}
}
Пример #6
0
///FC05 *This command writes the contents of discrete coil ///
void ForceSingleCoil(void)
{
char OutputFrame[OFS];   // output frame
char temp4[4];
char temp2[2];

uint16_t Coil = 0;
uint16_t StatusToWrite = 0;
uint8_t k = 0;

//Clears table
for(k = 0; k<OFS; k++){OutputFrame[k] = '\0';}

// rewrites slave's address & number of function
RewritingChars(OutputFrame,0,12);


//* Gets data addres of the coil.
temp4[0] = word[5];
temp4[1] = word[6];
temp4[2] = word[7];
temp4[3] = word[8];
HexToByte_4(temp4, &Coil);
if(Check_DataAddr_F05(Coil))
{
	//* The status to write( FF00 = ON,  0000 = OFF ).
	temp4[0] = word[9];
	temp4[1] = word[10];
	temp4[2] = word[11];
	temp4[3] = word[12];
	HexToByte_4(temp4, &StatusToWrite);

	//* Sets the status.
	SetSingleCoil( &Coil,  &StatusToWrite, Output_Registers);

	//* Writes LRC.
	k = 13;
	ByteToHex(temp2,GetLRC(OutputFrame));
	OutputFrame[k] = temp2[0];
	k++;
	OutputFrame[k] = temp2[1];
	k++;
	OutputFrame[k] = 0x0D;
	k++;
	OutputFrame[k] = 0x0A;
	k++;
	OutputFrame[k] = 0x0A;
	k++;

	//sending frame 
	UART_SendStr(OutputFrame); 
}
}
Пример #7
0
//* This function changes uint16_t to hex char[4].
void ByteToHex_4(char *hexstring, uint16_t byte)
{
	char temp1[2];
	char temp2[2];
	uint16_t D1 = byte >> 8;
  uint16_t D2 = byte & 255;
	uint8_t D1_8 = 0;
	uint8_t D2_8 = 0;
	uint8_t ct = 0;
	
	D1_8 |= D1;
	D2_8 |= D2;
	
	ByteToHex(temp1, D1_8);
	ByteToHex(temp2, D2_8);
	
	hexstring[0] = temp1[0];
	hexstring[1] = temp1[1];
	hexstring[2] = temp2[0];
	hexstring[3] = temp2[1];
		
}
Пример #8
0
char* Encrypt(const char* szSource, const char* szPassWord) // 加密,返回加密结果
{
    if(szSource == NULL || szPassWord == NULL) return NULL;
    unsigned char* ret = new unsigned char[strlen(szSource)];
    int ret_len = 0;
    if(RC4((unsigned char*)szSource,
           (int)strlen(szSource),
           (unsigned char*)szPassWord,
           (int)strlen(szPassWord),
           ret,
           &ret_len) != 0)
        return NULL;
    char* ret2 = ByteToHex(ret, ret_len);
    delete[] ret;
    return ret2;
}
Пример #9
0
//* FC16 This command    writes the contents of  analog output holding registers
void ForceMultipleRegisters()
{
char OutputFrame[OFS];  
uint8_t counter = 0;
uint16_t Value=0;
uint16_t FirstRegister;
uint16_t NumberOfRegs;
uint16_t Coil;
uint8_t NumberOfDataBytes;
char temp[2];
char temp4[4];
uint16_t n = 0;

//Clears table
for(n = 0; n<OFS; n++){OutputFrame[n] = '\0';}

// rewrites slave's address & number of function
RewritingChars(OutputFrame,0,12);
	
//gets number of first coil
temp4[0] = word[5];
temp4[1] = word[6];
temp4[2] = word[7];
temp4[3] = word[8];
HexToByte_4(temp4, &FirstRegister);

//gets number  of coils to written	
temp4[0] = word[9];
temp4[1] = word[10];
temp4[2] = word[11];
temp4[3] = word[12];
HexToByte_4(temp4, &NumberOfRegs);

//gets the number of data bytes to follow
temp[0] = word[13];
temp[1] = word[14];
HexToByte(temp, &NumberOfDataBytes);
if(Check_DataAddr_F03_F04(FirstRegister, NumberOfRegs) & Check_DataVal_F16(NumberOfDataBytes))
{

	counter=15;
	for(n=0; n<(NumberOfDataBytes/2); n++)
	{
		temp4[0] = word[counter];
		counter++;
		temp4[1] = word[counter];
		counter++;
		temp4[2] = word[counter];
		counter++;
		temp4[3] = word[counter];		
		counter++;
	
		HexToByte_4(temp4, &Value);
		Output_Registers[FirstRegister+n] = Value;
	}
	
	//* Writes LRC.
	counter = 13;
	ByteToHex(temp,GetLRC(OutputFrame));
	OutputFrame[counter] = temp[0];
	counter++;
	OutputFrame[counter] = temp[1];
	counter++;
	OutputFrame[counter] = 0x0D;
	counter++;
	OutputFrame[counter] = 0x0A;
	counter++;
	OutputFrame[counter] = 0x0A;
	counter++;

	//sending frame 
	UART_SendStr(OutputFrame); 
}
}
Пример #10
0
///FC03  *This command is requests the content of analog output holding registers///
/// 			*registers => output or input
void ReadHoldingRegisters(uint16_t *registers)
{
char OutputFrame[OFS];    
char temp[4];
char temp2[2];

uint16_t FirstReg = 0;
uint16_t NumberOfRegs = 0;
uint8_t NumberOfBytes = 0 ;
uint8_t ct = 0;
uint8_t k = 0;
uint8_t counter = 0;
uint16_t Content_dec = 0;


//Clears table
for(k = 0; k<OFS; k++){OutputFrame[k] = '\0';}

// rewrites slave's address & number of function
RewritingChars(OutputFrame,0,4);

//gets number of first register
temp[0] = word[5];
temp[1] = word[6];
temp[2] = word[7];
temp[3] = word[8];
HexToByte_4(temp, &FirstReg);

//gets quantity of registers
temp[0] = word[9];
temp[1] = word[10];
temp[2] = word[11];
temp[3] = word[12];
HexToByte_4(temp, &NumberOfRegs);
if(Check_DataAddr_F03_F04(FirstReg, NumberOfRegs) & Check_DataVal())
{
	// calculates the number of data bytes to follow ( n registers * 2 bytes each)
	NumberOfBytes = NumberOfRegs*2;

	//Writes the number of data bytes
	ByteToHex(temp,NumberOfBytes);
	OutputFrame[5] = temp[0];
	OutputFrame[6] = temp[1];

	counter = 7;
	k = FirstReg;


	//Reads the contents from Output_Registers
	for(ct=0;ct<NumberOfRegs;ct++)
	{
		Content_dec = registers[k];
		ByteToHex_4(temp,Content_dec);
		OutputFrame[counter] = temp[0];
		counter++;
		OutputFrame[counter] = temp[1];
		counter++;
		OutputFrame[counter] = temp[2];
		counter++;
		OutputFrame[counter] = temp[3];
		counter++;
		k++;
	}
	
	
	// LRC
	ByteToHex(temp2,GetLRC(OutputFrame));
	OutputFrame[counter] = temp2[0];
	counter++;
	OutputFrame[counter] = temp2[1];
	counter++;
	OutputFrame[counter] = 0x0D;
	counter++;
	OutputFrame[counter] = 0x0A;
	counter++;
	OutputFrame[counter] = 0x0A;
	counter++;


	//sends frame 
	UART_SendStr(OutputFrame); 
}
}
Пример #11
0
//* FC01 This command requests the ON/OFF status of discrete output coils.
void ReadCoilStatus(uint16_t *registers)
{
char OutputFrame[OFS];  
uint8_t counter = 0;
uint8_t TempSum=0;
uint16_t FirstCoil;
uint16_t NumberOfCoils;
uint16_t Coil;
uint8_t NumberOfDataBytes;
char temp[2];
char temp4[4];
uint16_t n = 0;

//Clears table
for(n = 0; n<OFS; n++){OutputFrame[n] = '\0';}

// rewrites slave's address & number of function
RewritingChars(OutputFrame,0,4);
	
//gets number of first coil
temp4[0] = word[5];
temp4[1] = word[6];
temp4[2] = word[7];
temp4[3] = word[8];
HexToByte_4(temp4, &FirstCoil);

//gets quantity of coils
temp4[0] = word[9];
temp4[1] = word[10];
temp4[2] = word[11];
temp4[3] = word[12];
HexToByte_4(temp4, &NumberOfCoils);
if(Check_DataAddr_F01_F02(FirstCoil, NumberOfCoils) & Check_DataVal())
{
	// calculates the number of data bytes
	if((NumberOfCoils%8)!=0)
	{
		NumberOfDataBytes = ( NumberOfCoils/8)+1;
	}
	else
	{
		NumberOfDataBytes = NumberOfCoils/8;
	}

	//Writes the number of data bytes
	ByteToHex(temp,NumberOfDataBytes);
	OutputFrame[5] = temp[0];
	OutputFrame[6] = temp[1];

	// calculates data bits to HEX and writing to frame
	counter = 7; 
	Coil = FirstCoil;
	n = NumberOfCoils;
	while(n>0)
	{
					if(n>=8)                   //    changes 8bits to hex
					{
						uint8_t pwr = 0;
						for(pwr =0; pwr<8; pwr++,Coil++)
						{
							TempSum += (1<<pwr)*StateOfCoil(Coil, registers);   ///////      (9 dec)  1001  =>  1*2^3 + 0*2^2 + 0*2^1 + 1*2^0
							n--;
						}			
						
						ByteToHex(temp,TempSum);
						TempSum = 0;
						OutputFrame[counter] = temp[0];
						counter++;
						OutputFrame[counter] = temp[1];
						counter++;
					}
				
					else                                       //        changing incomplete octet to hex
					{
							uint8_t pwr = 0;
							uint8_t zm = n;
							for(pwr =0; pwr<zm; pwr++,Coil++)
							{
									TempSum += (1<<pwr)*StateOfCoil(Coil, registers);   ///////      (9 dec)  1001  =>  1*2^3 + 0*2^2 + 0*2^1 + 1*2^(
									n--;
							}
							ByteToHex(temp,TempSum);
							TempSum = 0;
							OutputFrame[counter] = temp[0];
							counter++;
							OutputFrame[counter] = temp[1];
							counter++;
					}
	}

	// writes LRC 
	ByteToHex(temp,GetLRC(OutputFrame));
	OutputFrame[counter] = temp[0];
	counter++;
	OutputFrame[counter] = temp[1];
	counter++;
	OutputFrame[counter] = 0x0D;
	counter++;
	OutputFrame[counter] = 0x0A;
	counter++;
	OutputFrame[counter] = 0x0A;
	counter++;

		// sends frame
		UART_SendStr(OutputFrame); 
}
}
Пример #12
0
int main()
{
    int success;

    //HexToValue TEST
    success = 1;
    if( HexToValue( 'd' ) != HexToValue( 'D' ) )
        success = 0;
    if( HexToValue( 'Z' ) != 255 )
        success = 0;
    if( HexToValue( 'b' ) != 11 )
        success = 0;
    if( HexToValue( '4' ) != 4 )
        success = 0;
    evaluate("HEXTOVALUE",success);
    //EOT
    //HEXTOBYTE
    success = 1;
    if( HexToByte( '1', '2' ) != 0x12 )
        success = 0;
    if( HexToByte( 'a', 'B' ) != 0xAB )
        success = 0;
    if( HexToByte( '3', '4' ) != 0x34 )
        success = 0;
    if( HexToByte( '1', '2' ) != 0x12 )
        success = 0;
    evaluate("HEXTOBYTE",success);
    //EOT
    //B64ToValue
    success = 1;
    if( B64ToValue( 'a' ) != 26 )
        success = 0;
    if( B64ToValue( 'B' ) != 1 )
        success = 0;
    if( B64ToValue( '+' ) != 62 )
        success = 0;
    if( B64ToValue( 'Z' ) != 25 )
        success = 0;
    evaluate("B64ToVal",success);
    //EOT
    //ValueToHex
    success = 1;
    if( ValueToHex(3) != '3' )
        success = 0;
    if( ValueToHex(11) != 'B' )
        success = 0;
    if( ValueToHex(18) != -1 )
        success = 0;
    evaluate("ValueToHex",success);
    //EOT
    //ValueToB64
    success = 1;
    if( ValueToB64(3) != 'D' )
        success = 0;
    if( ValueToB64(42) != 'q' )
        success = 0;
    if( ValueToB64(55) != '3' )
        success = 0;
    if( ValueToB64(62) != '+' )
        success = 0;
    if( ValueToB64(63) != '/' )
        success = 0;
    if( ValueToB64(66) != -1 )
        success = 0;
    evaluate("ValueToB64",success);
    //B64ToBytes
    success = 1;

    byte_t *b = malloc(3);
    
    if( ( B64ToBytes( b, "TWlL" ) != 0) )
        success = 0;
    if( b[0] != 0x4D || b[1] != 0x69 || b[2] != 0x4B )
        success = 0;
    
    if( ( B64ToBytes( b, "Z29z" ) != 0) )
        success = 0;
    if( b[0] != 0x67 || b[1] != 0x6F || b[2] != 0x73 )
        success = 0;

    if( ( B64ToBytes( b, "YQ==" ) != 0) )
        success = 0;
    if( b[0] != 0x61 || b[1] != 0x00 || b[2] != 0x00 )
        success = 0;

    if( ( B64ToBytes( b, "YWM=" ) != 0) )
        success = 0;
    if( b[0] != 0x61 || b[1] != 0x63 || b[2] != 0x00 )
        success = 0;
    evaluate("B64ToBytes",success);
    //EOT
    //ByteToHex
    success = 1;
    char b2h[3];
    b2h[2] = '\0';
    ByteToHex( b2h ,0xAF );
    if( b2h[0] != 'A' || b2h[1] != 'F' )
        success = 0;

    ByteToHex( b2h ,0x02 );
    if( b2h[0] != '0' || b2h[1] != '2' )
        success = 0;

    evaluate("ByteToHex",success);
    //EOT
    //BytesToB64
    char b2b[4];
    BytesToB64( b2b, (unsigned char *)"gat", 3);
    if( b2b[0] != 'Z' || b2b[1] != '2' || b2b[2] != 'F' || b2b[3] != '0' )
        success = 0;
    BytesToB64( b2b, (unsigned char *)"pa", 2);
    if( b2b[0] != 'c' || b2b[1] != 'G' || b2b[2] != 'E' || b2b[3] != '=' )
        success = 0;
    BytesToB64( b2b, (unsigned char *)"g", 1);
    if( b2b[0] != 'Z' || b2b[1] != 'w' || b2b[2] != '=' || b2b[3] != '=' )
        success = 0;
    evaluate("BytesToB64",success);
    //EOT
    //HexStringToBytes
    success = 1;

    byte_t *dest;
    int temp = HexStringToBytes( &dest, LOREMHEX );
    char * str;
    BytesToString( &str, dest, (size_t)temp );

    if( strcmp( str, LOREM ) )
        success = 0;
    free(dest);
    free(str);
    evaluate("HexStringToBytes",success);
    //EOT
    //B64StringToBytes
    success = 1;

    temp = B64StringToBytes( &dest, LOREMB64 );
    BytesToString( &str, dest, (size_t)temp );

    if( strcmp( str, LOREM ) )
        success = 0;
    free(dest);
    free(str);
    evaluate("B64StringToBytes",success);
    //EOT
    //BytesToHexString
    success = 1;

    dest = (byte_t *) LOREM;
    BytesToHexString( &str, dest, strlen( LOREM ) );
    if( strcmp( LOREMHEX, str ) )
        success = 0;
    evaluate("BytesToHexString",success);



    //BytesToB64String
    success = 1;
    
    BytesToB64String( &str, (byte_t *)LOREM, strlen(LOREM) );
    
    if( strcmp( LOREMB64, str ) )
        success = 0;

    evaluate("B64StringToBytes",success);
    free(str);


    BytesToB64String( &str, (byte_t *)"A", 1 );
    if( strcmp( str, "QQ==" ) )
        success = 0;
    free(str);


    BytesToB64String( &str, (byte_t *)"AB", 2 );
    if( strcmp( str, "QUI=" ) )
        success = 0;
    free(str);


    BytesToB64String( &str,(byte_t *)"ABC", 3 );
    if( strcmp( str, "QUJD" ) )
        success = 0;
    free(str);

    evaluate("B64StringToBytes",success);
    //eot
    









    return 0;
}
Пример #13
0
hexdigest();return shash;}std::string ROR(std::string blockhash,int iPos,std::
string hash){if(iPos<=(int)hash.length()-(0x1f5b+1342-0x2498)){int asc1=(int)
hash.at(iPos);int rorcount=BitwiseCount(blockhash,iPos);std::string hex=
ByteToHex(asc1+rorcount);return hex;}return"\x30\x30";}std::string CPID::CPID_V2