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

add API to deliver notification messages #3

Open
agalasso opened this issue Aug 3, 2020 · 10 comments
Open

add API to deliver notification messages #3

agalasso opened this issue Aug 3, 2020 · 10 comments

Comments

@agalasso
Copy link
Owner

agalasso commented Aug 3, 2020

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

@AstroAir
Copy link

AstroAir commented Aug 4, 2020

@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

@agalasso
Copy link
Owner Author

agalasso commented Aug 4, 2020

@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.

@AstroAir
Copy link

AstroAir commented Aug 4, 2020

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
Copy link

AstroAir commented Aug 4, 2020

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

@AstroAir
Copy link

AstroAir commented Aug 4, 2020

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";
}

?>`

@agalasso
Copy link
Owner Author

agalasso commented Aug 4, 2020

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

@AstroAir
Copy link

AstroAir commented Aug 5, 2020

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
Copy link

AstroAir commented Aug 5, 2020

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

@AstroAir
Copy link

AstroAir commented Aug 5, 2020

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
Copy link

AstroAir commented Aug 8, 2020

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?

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

No branches or pull requests

2 participants