phd2client icon indicating copy to clipboard operation
phd2client copied to clipboard

add API to deliver notification messages

Open agalasso opened this issue 4 years ago • 10 comments

the client API should provide a way to deliver notification messages such as GuideStep to allow an app to plot PHD2 data.

agalasso avatar Aug 03 '20 02:08 agalasso

@agalasso Today,I tried "php socket"and "php curl",but they didn't work at all.Then I changed the way to connect PHD2.I use telnet and it works very good.There is also a question,Can I communicate with PHD2 by c++?This API (https://github.com/agalasso/phd2client/) could not get useful informations about drawing guding lines on website.I think we can add some outputs to solve this problem. PS:How can I put data in JSON format to the TCP socket? This is telnet's log: log.txt

AstroAir avatar Aug 04 '20 05:08 AstroAir

@AstroAir

Can I communicate with PHD2 by c++?This API (https://github.com/agalasso/phd2client/) could not get useful informations about drawing guding lines on website.

This github issue (#3) was created to track the feature request. When the feature is implemented, the API will include a way for clients to receive event notifications including GuideStep events. At that point you can use the new API plot the data. Until then you'll need to use a direct socket connection to PHD2 to receive the event notification messages.

agalasso avatar Aug 04 '20 05:08 agalasso

No problem.I can use telnet to connect PHD2,and only need to read the log.But I think it is not easy to do .So I hope the new API will come soon.I think maybe I can take a part in developing this API,I kown a little about C++ and C.

AstroAir avatar Aug 04 '20 06:08 AstroAir

Hi.I want to ask a question what is the relation between "RADistanceRaw" and "RADistanceGuide" ?

AstroAir avatar Aug 04 '20 14:08 AstroAir

This is my php demo.

`<?php /* * This a part of AstroAir Web Tools. * This is used to draw guiding line on website * Write on Aug,4,2020 */

//----------Read the log file-----------

$file = 'log.txt';	//open log file
$fp = fopen($file, 'r');
fseek($fp,-1,SEEK_END);		//read last line's informations
$log = '';
while(($c = fgetc($fp)) !== falloge)
{
	if($c == "\n" && $log)
		break;
	$log = $c . $log;
	fseek($fp, -2, SEEK_CUR);	//read next-to-last line's informations
}
fclose($fp);	//close log file

//--------Choose useful informations---------

$log=trim($log);						//delete " "
$log=preg_replace("/\s/","",$log);		//delete "\s"
$log=preg_replace('/"/',"",$log);		//delete ":"
$log=preg_replace("/{/","",$log);		//delete "{"
$log=preg_replace("/}/","",$log);		//delete "}"

//--------get the guide stats----------

$stats=explode(",",$log);
$stats=explode(":",$stats[0]);

//--------judge the guide stats----------

if($stats[1] == "GuideStep")		//Guiding
{
	$dir=explode(",",$log);
	$dir=explode(":",$dir[14]);
	$dir1=explode(",",$log);
	$dir1=explode(":",$dir1[16]);
	if($dir[0] == "StarMass")		//moving direction did not change
	{
		$file=fopen("guiding_ra.txt.txt","r");		//get ra moving direction from data
		$RAdir=trim(fgets($file));
		fclose($file);
		
		$file=fopen("guiding_dec.txt.txt","r");		//get dec moving direction from data
		$DECdir=trim(fgets($file));
		fclose($file);
	}
	else
	{
		if($dir[0] == "RADirection" && $dir1[0] == "DECDirection")		//both RA and DEC moving directions have changed
		{
			if($dir[1] == "East")		//judge RA moving direction
				$RAdir=1;				//RA direction is east
			else
				$RAdir=0;				//RA direction is west
				
			//Write RA moving direction into data 
			$file = fopen("guiding_ra.txt", "w") or die("Unable to open file!");            
			fwrite($file, $RAdir);
			fclose($file);
			
			if($dir1[1] == "North")		//judge DEC moving direction
				$DECdir=1;				//DEC direction is north
			else
				$DECdir=0;				//DEC direction is south
				
			//Write DEC moving direction into data
			$file = fopen("guiding_dec.txt", "w") or die("Unable to open file!");            
			fwrite($file, $DECdir);
			fclose($file);
		}
		else
		{
			if($dir[0] == "RADirection")		//RA moving direction has changed
			{
				if($dir[1] == "East")		//judge RA moving direction
					$RAdir=1;				//RA direction is east
				else
					$RAdir=0;				//RA direction is west
					
				$file = fopen("guiding_ra.txt", "w") or die("Unable to open file!");            
				fwrite($file,$RAdir);
				fclose($file);
				
				$file=fopen("guiding_dec.txt","r");		//get dec moving direction from data
				$DECdir=trim(fgets($file));
				fclose($file);
			}
			else	//DEC moving direction has changed
			{
				if($dir[1] == "North")		//judge DEC moving direction
					$DECdir=1;				//DEC direction is north
				else
					$DECdir=0;				//DEC direction is south
					
				$file = fopen("guiding_dec.txt", "w") or die("Unable to open file!");            
				fwrite($file, $DECdir);
				fclose($file);
				
				$file=fopen("guiding_ra.txt","r");		//get ra moving direction from data
				$RAdir=trim(fgets($file));
				fclose($file);
			}
		}
	}
	
	//calculate RA moving distance
	
	$radis=explode(",",$log);		//get RA distance
	$radis=explode(":",$radis[9]);
	if($RAdir == 0)		//RA moving direction is west
		$radis[1]=0-$radis[1];
		
	//calculate DEC moving distance
	
	$decdis=explode(",",$log);		//get dec distance
	$decdis=explode(":",$decdis[10]);
	if($decdir == 0)		//DEC moving direction is south
		$decdis[1]=0-$decdis[1];
	echo "    DRIFT_DATA:$radis[1] $decdis[1]\n";
	
}
if($stats[1] == "Alert")		//Alert
{
	$alert=explode(",",$log);
	$alert=explode(":",$alert[4]);
	$file = fopen("guiding_alert.txt", "a") or die("Unable to open file!");            
	fwrite($file,$alert[1]);
	fclose($file);
	passthru("php notify_guiding.php");
	echo "AAAAA";
}
if($stats[1] == "GuidingStopped" || $stats[1] == "LoopingExposuresStopped")		//Stopped
{
	$file = fopen("guiding.txt", "a") or die("Unable to open file!");            
	fwrite($file,"Stopped.");
	fclose($file);
	echo "GGGGG";
}
if($stats[0] == "jsonrpc")		//PHD2 Error
{
	$error=explode(",",$log);
	$error = strstr($error[2],"message");
	$file = fopen("guiding_error.txt", "a") or die("Unable to open file!");            
	fwrite($file,"$error\n");
	fclose($file);
	echo "PHD2 Error";
}

?>`

AstroAir avatar Aug 04 '20 18:08 AstroAir

what is the relation between "RADistanceRaw" and "RADistanceGuide"

RADistanceRaw is RA offset of the guide star centroid relative to the lock position RADistanceGuide is the size of the offset that PHD2's selected RA guide algorithm will attempt to correct. In other words, the output of the guide algorithm's calculation.

For plotting purposes, you almost certainly would be more interested in RADistanceRaw

agalasso avatar Aug 04 '20 23:08 agalasso

You are right.I am insterested in RADistanceRaw and DECDistanceRaw.But I am not sure that should I consider adding RADistanceGuide and DECDistanceGuide when plotting.How PHD2 plots its graph and need which informations?

AstroAir avatar Aug 05 '20 00:08 AstroAir

And I also have a question do RADirection and DECDirection affect the size of the data drawn?

AstroAir avatar Aug 05 '20 00:08 AstroAir

I found a question that The DEC curve I drew on the web page is the opposite of that in PHD2.Maybe I should check out my code to find the problem.Can you help todo this ?

AstroAir avatar Aug 05 '20 14:08 AstroAir

I tried to modify the source code of PHD2 and found that guidelog.cpp There is a code to output the data of the guide line, so we add our own code. Is this feasible?

AstroAir avatar Aug 08 '20 06:08 AstroAir