Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example #7

Closed
petertest22 opened this issue Sep 28, 2022 · 5 comments
Closed

example #7

petertest22 opened this issue Sep 28, 2022 · 5 comments

Comments

@petertest22
Copy link

hello do you have a example how to use this i am new into php thanks

@meetanthony
Copy link
Owner

I added an example in the last commit today.
Best regards, Anthony.

@petertest22
Copy link
Author

thank you very much for your time and help you are great! I will test it.

@petertest22
Copy link
Author

petertest22 commented Oct 2, 2022

Sorry to disturb you again, the example works fine but i want to use it inside a class and i can't get it working i tried 3 days to sort this, can you help me? I want to pay you. thanks, this is the code, i think must call inside a class? I want to retrieve some bytes (string) from a uploaded bin file and calculate the cs of it. I don't have php expenrience but with some exampe codes it will help me a lot. thanks again!

`<?php

require_once "../utils.php";
include "../crcphp/crc8.php";

class test {

public function read_only(){
return false;
}

public function accept_size($size){
	return $size == 2048;
}



public function get_data($data){

$crc8 = new Crc8();
$algoParams = $CRC_8_;
$algoName = $algoParams->Name;
echo "Name: ".$algoName."<br/>";
$check = $algoParams->Check;
print "Check:  0x".dechex($check)."<br/>";

	
		$test = ((ord($data[0x02]) & 0xFF) << 16)
			+ ((ord($data[0x01]) & 0xFF) << 8)
			+ ((ord($data[0x00]) & 0xFF) );
	$test = intval($test);


	
	$array = array();
	$array['TEST'] =round($test);
	return $array;
}

public function set_test($data, $test2){

if (isset($_POST['swap2'])) {

     $data = swap($data);

} else {

;
}
if($test2 < 0){
$test2 = 0;
} else if ($test2 > 999999){
$test2 = 999999;
}

 for($n = 0x00; $n < 0x80; $n+=16){

		$data[$n+0] = chr(($test2) & 0xFF);
		$data[$n+1] = chr(($test2 >> 8) & 0xFF);
	    $data[$n+2] = chr($test2 >>16 & 0xFF);
		

	}	

if (isset($_POST['swap2'])) {

     $data = swap($data);

} else {
;

}

	return $data;
}

}

?>
`

@meetanthony
Copy link
Owner

It's not good practice, but you can use it as a global variable.

$algoParams = $GLOBALS['CRC_8_'];

@meetanthony
Copy link
Owner

It's not good practice, but you can use it as a global variable.

$algoParams = $GLOBALS['CRC_8_'];

https://stackoverflow.com/questions/1877136/access-global-variable-from-within-a-class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants