Esempio n. 1
0
void Uart::do_uart_cycle()
{
	for (std::vector<wbchars*>::iterator it=wbuffer.begin();it != wbuffer.end();){
		wbchars* tmp = *it;
		char todisplay[50];
		char * p_display=todisplay;
		memset(p_display,0,50*sizeof(char));
		ByteToHexStr((const unsigned char*)tmp->buffer,p_display,tmp->length);
		std::cout<<p_display<<std::endl;
		for (int j=0; j < tmp->length; j++){
			write(*fd,tmp->buffer+j,1);
			tcflush(*fd,TCOFLUSH);
		}
		usleep(1000);
		for (int j=0; j < tmp->length; j++){
			write(*fd,tmp->buffer+j,1);
			tcflush(*fd,TCOFLUSH);
		}
		//clean buffer
		delete tmp->buffer;
		delete tmp;
		it = wbuffer.erase(it);
		usleep(60000);
	}
}
Esempio n. 2
0
void transmit::HexToOut(int length, char* buffer)
{
    char *p_display = (char *)malloc(sizeof(char) * length);
    memset(p_display, 0 ,sizeof(char) * length);
    ByteToHexStr((const unsigned char*)buffer,p_display,length);
    printf("Hex out: %s \n",p_display);
}
Esempio n. 3
0
int main()
{
	int u;
	u = InitSerial();
	if( u == -1 )
	{
		fprintf(stderr,"InitSerial Error!\n");
		return -1;
	}
	char *buffer = (char*)malloc(8*sizeof(char));
	*buffer = 0xff;
	*(buffer+1) = 0xff;
	*(buffer+2) = 0xfe;//broadcast
	*(buffer+3) = 0x04;
	*(buffer+4) = 0x03;//write data
	*(buffer+5) = 0x04;
	*(buffer+6) = 0x01;
	int sum;
	sum = 0xfe;
	sum += 0x04;
	sum += 0x03;
	sum += 0x04+1;
	sum = sum&0xff;
	sum = ~sum;
	char *chsum = (char*)malloc(sizeof(char));
	memcpy(chsum,&sum,sizeof(char));
	*(buffer+7) = *chsum;//checksum
	char todisplay[50];
	char * p_display=todisplay;
	memset(p_display,0,50*sizeof(char));
	ByteToHexStr(buffer,p_display,8*sizeof(char));
	printf("Sending:\n %s \n",p_display);
	UART_Send(u,buffer,8*sizeof(char));
	free(buffer);
	close(u);
}
Esempio n. 4
0
/**	Verify checksum
 *	The function will return FALSE if verification fails or if any errors occur,
 *
 *	@param	signed_file		URL containing the file to be verified. MUST be loaded,
 *							which can be accomplished with signed_file.QuickLoad(TRUE)
 *	@param	checksum		Base64 encoded checksum
 *
 *	@param  alg				Algorithm used to calculate checksum. Default SSL_SHA
 *
 *	@return TRUE if the verification succeded, FALSE if there was any error.
 */
BOOL VerifyChecksum(URL &signed_file, const OpStringC8 &checksum, SSL_HashAlgorithmType alg)
{

    if(signed_file.IsEmpty() || (URLStatus) signed_file.GetAttribute(URL::KLoadStatus) != URL_LOADED)
        return FALSE;

    // Get The raw data
    OpAutoPtr<URL_DataDescriptor> desc(signed_file.GetDescriptor(NULL, TRUE, TRUE, TRUE));
    if(!desc.get())
        return FALSE;

    BOOL more = FALSE;
    unsigned long buf_len;

    if(desc->RetrieveData(more) == 0 || desc->GetBuffer() == NULL)
        return FALSE;

    if(desc->GetBufSize() == 0)
        return FALSE;

    SSL_Hash_Pointer digester(alg);
    if(digester.Error())
        return FALSE;

    digester->InitHash();

    do {
        more = FALSE;
        buf_len = desc->RetrieveData(more);

        digester->CalculateHash((unsigned char *)desc->GetBuffer(), buf_len);

        desc->ConsumeData(buf_len);
    } while(more);

    SSL_varvector32 signature_out;

    digester->ExtractHash(signature_out);

    if(digester->Error() || signature_out.Error())
        return FALSE;

#ifdef _DEBUG
    OpString8 s8;
    OP_STATUS retval = ByteToHexStr(signature_out.GetDirect(), signature_out.GetLength(), s8);
    OP_ASSERT(retval == OpStatus::OK);
#endif

    byte* byte_buffer = NULL;
    unsigned int buffer_len = 0;
    OP_STATUS ret = HexStrToByte(checksum, byte_buffer, buffer_len);
    if(OpStatus::IsError(ret))
        return FALSE;

    SSL_varvector32 signature_in;
    signature_in.Set(byte_buffer, buffer_len);

    OP_DELETEA(byte_buffer);

    return signature_in == signature_out;
}