mirror of
https://github.com/eddyem/BTA_utils.git
synced 2026-03-22 01:31:15 +03:00
add 64-bit bta_control_net
This commit is contained in:
14
bta_control_net-x86_64/bta_print/Makefile
Normal file
14
bta_control_net-x86_64/bta_print/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
# run `make DEF=...` to add extra defines
|
||||
PROGRAM := bta_print
|
||||
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all -lcrypt -lm
|
||||
SRCS := bta_print.c bta_shdata.c
|
||||
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
|
||||
CFLAGS += -O2 -Wall -Werror -Wextra -Wno-trampolines -std=gnu99
|
||||
CC = gcc
|
||||
#CXX = g++
|
||||
|
||||
all : $(PROGRAM)
|
||||
|
||||
$(PROGRAM) : $(SRCS)
|
||||
$(CC) $(DEFINES) $(CFLAGS) $(LDFLAGS) $(SRCS) -o $(PROGRAM)
|
||||
|
||||
381
bta_control_net-x86_64/bta_print/bta_print.c
Normal file
381
bta_control_net-x86_64/bta_print/bta_print.c
Normal file
@@ -0,0 +1,381 @@
|
||||
|
||||
/* Print some BTA NewACS data (or write to file)
|
||||
* Usage:
|
||||
* bta_print [time_step] [file_name]
|
||||
* Where:
|
||||
* time_step - writing period in sec., >=1.0
|
||||
* <1.0 - once and exit (default)
|
||||
* file_name - name of file to write to,
|
||||
* "-" - stdout (default)
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
#include <crypt.h>
|
||||
|
||||
//#define SHM_OLD_SIZE
|
||||
#include "bta_shdata.h"
|
||||
|
||||
static double time_step=0.0;
|
||||
|
||||
static char *file_name = "-";
|
||||
|
||||
char *time_asc(double t, char *lin)
|
||||
{
|
||||
int h, min;
|
||||
double sec;
|
||||
h = (int)(t/3600.);
|
||||
min = (int)((t - (double)h*3600.)/60.);
|
||||
sec = t - (double)h*3600. - (double)min*60.;
|
||||
h %= 24;
|
||||
if(sec>59.99) sec=59.99;
|
||||
sprintf(lin, "%02d:%02d:%05.2f", h,min,sec);
|
||||
return lin;
|
||||
}
|
||||
|
||||
char *angle_asc(double a, char *lin)
|
||||
{
|
||||
char s;
|
||||
int d, min;
|
||||
double sec;
|
||||
if (a >= 0.)
|
||||
s = '+';
|
||||
else {
|
||||
s = '-'; a = -a;
|
||||
}
|
||||
d = (int)(a/3600.);
|
||||
min = (int)((a - (double)d*3600.)/60.);
|
||||
sec = a - (double)d*3600. - (double)min*60.;
|
||||
d %= 360;
|
||||
if(sec>59.9) sec=59.9;
|
||||
sprintf (lin, "%c%02d:%02d:%04.1f", s,d,min,sec);
|
||||
return lin;
|
||||
}
|
||||
|
||||
char *angle_fmt(double a, char *format, char *lin)
|
||||
{
|
||||
char s, *p;
|
||||
int d, min, n;
|
||||
double sec, msec;
|
||||
if (a >= 0.)
|
||||
s = '+';
|
||||
else {
|
||||
s = '-'; a = -a;
|
||||
}
|
||||
d = (int)(a/3600.);
|
||||
min = (int)((a - (double)d*3600.)/60.);
|
||||
sec = a - (double)d*3600. - (double)min*60.;
|
||||
d %= 360;
|
||||
if ((p = strchr(format,'.')) == NULL)
|
||||
msec=59.;
|
||||
else if (*(p+2) == 'f' ) {
|
||||
n = *(p+1) - '0';
|
||||
msec = 60. - pow(10.,(double)(-n));
|
||||
} else
|
||||
msec=60.;
|
||||
if(sec>msec) sec=msec;
|
||||
if (strstr(format,"%c"))
|
||||
sprintf (lin, format, s,d,min,sec);
|
||||
else
|
||||
sprintf (lin, format, d,min,sec);
|
||||
return lin;
|
||||
}
|
||||
|
||||
#ifndef PI
|
||||
#define PI 3.14159265358979323846 /* pi */
|
||||
#endif
|
||||
|
||||
#define R2D 180./PI /* rad. to degr. */
|
||||
#define D2R PI/180. /* degr. to rad. */
|
||||
#define R2S 648000./PI /* rad. to sec */
|
||||
#define S2R PI/648000. /* sec. to rad. */
|
||||
#define S360 1296000. /* sec in 360degr */
|
||||
|
||||
const double longitude=149189.175; /* SAO longitude 41 26 29.175 (-2:45:45.945)*/
|
||||
const double Fi=157152.7; /* SAO latitude 43 39 12.7 */
|
||||
const double cos_fi=0.7235272793; /* Cos of SAO latitude */
|
||||
const double sin_fi=0.6902957888; /* Sin --- "" ----- */
|
||||
|
||||
static void calc_AZ(double alpha, double delta, double stime, double *az, double *zd)
|
||||
{
|
||||
double sin_t,cos_t, sin_d,cos_d, cos_z;
|
||||
double t, d, z, a, x, y;
|
||||
|
||||
t = (stime - alpha) * 15.;
|
||||
if (t < 0.)
|
||||
t += S360; /* +360degr */
|
||||
t *= S2R; /* -> rad */
|
||||
d = delta * S2R;
|
||||
sin_t = sin(t);
|
||||
cos_t = cos(t);
|
||||
sin_d = sin(d);
|
||||
cos_d = cos(d);
|
||||
|
||||
cos_z = cos_fi * cos_d * cos_t + sin_fi * sin_d;
|
||||
z = acos(cos_z);
|
||||
|
||||
y = cos_d * sin_t;
|
||||
x = cos_d * sin_fi * cos_t - cos_fi * sin_d;
|
||||
a = atan2(y, x);
|
||||
|
||||
*zd = z * R2S;
|
||||
*az = a * R2S;
|
||||
}
|
||||
|
||||
static double calc_PA(double alpha, double delta, double stime)
|
||||
{
|
||||
double sin_t,cos_t, sin_d,cos_d;
|
||||
double t, d, p, sp, cp;
|
||||
|
||||
t = (stime - alpha) * 15.;
|
||||
if (t < 0.)
|
||||
t += S360; /* +360degr */
|
||||
t *= S2R; /* -> rad */
|
||||
d = delta * S2R;
|
||||
sin_t = sin(t);
|
||||
cos_t = cos(t);
|
||||
sin_d = sin(d);
|
||||
cos_d = cos(d);
|
||||
|
||||
sp = sin_t * cos_fi;
|
||||
cp = sin_fi * cos_d - sin_d * cos_fi * cos_t;
|
||||
p = atan2(sp, cp);
|
||||
if (p < 0.0)
|
||||
p += 2.0*PI;
|
||||
|
||||
return(p * R2S);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void calc_AD(double az, double zd, double stime, double *alpha, double *delta)
|
||||
{
|
||||
double sin_d, sin_a,cos_a, sin_z,cos_z;
|
||||
double t, d, z, a, x, y;
|
||||
a = az * S2R;
|
||||
z = zd * S2R;
|
||||
sin_a = sin(a);
|
||||
cos_a = cos(a);
|
||||
sin_z = sin(z);
|
||||
cos_z = cos(z);
|
||||
|
||||
y = sin_z * sin_a;
|
||||
x = cos_a * sin_fi * sin_z + cos_fi * cos_z;
|
||||
t = atan2(y, x);
|
||||
if (t < 0.0)
|
||||
t += 2.0*PI;
|
||||
|
||||
sin_d = sin_fi * cos_z - cos_fi * cos_a * sin_z;
|
||||
d = asin(sin_d);
|
||||
|
||||
*delta = d * R2S;
|
||||
*alpha = (stime - t * R2S / 15.);
|
||||
if (*alpha < 0.0)
|
||||
*alpha += S360/15.; /* +24h */
|
||||
}
|
||||
#endif
|
||||
|
||||
static void my_sleep(double dt)
|
||||
{
|
||||
int nfd;
|
||||
struct timeval tv;
|
||||
tv.tv_sec = (int)dt;
|
||||
tv.tv_usec = (int)((dt - tv.tv_sec)*1000000.);
|
||||
slipping:
|
||||
nfd = select(0, (fd_set *)NULL,(fd_set *)NULL,(fd_set *)NULL, &tv);
|
||||
if(nfd < 0) {
|
||||
if(errno == EINTR)
|
||||
/*On Linux, timeout is modified to reflect the amount of
|
||||
time not slept; most other implementations DO NOT do this!*/
|
||||
goto slipping;
|
||||
fprintf(stderr,"Error in mydelay(){ select() }. %s\n",strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
FILE *fd;
|
||||
double last;
|
||||
int i,acs_bta;
|
||||
char tmp[80], *value;
|
||||
|
||||
if(argc>1) {
|
||||
if(isdigit(argv[1][0])||argv[1][0]=='.') time_step=atof(argv[1]);
|
||||
else file_name = argv[1];
|
||||
if(argc>2) {
|
||||
if(isdigit(argv[2][0])||argv[2][0]=='.') time_step=atof(argv[2]);
|
||||
else file_name = argv[2];
|
||||
}
|
||||
}
|
||||
if(strcmp(file_name,"-")==0) {
|
||||
fd = stdout;
|
||||
} else if((fd=fopen(file_name,"w"))==NULL) {
|
||||
fprintf(stderr,"Can't write BTA data to file: %s\n",file_name);
|
||||
exit(1);
|
||||
}
|
||||
if(!get_shm_block( &sdat, ClientSide)) return 1;
|
||||
last = M_time;
|
||||
for(i=0;i<50 && fabs(M_time-last)<0.01; i++)
|
||||
my_sleep(0.02);
|
||||
|
||||
do {
|
||||
if(fd != stdout)
|
||||
if((fd=freopen(file_name,"w",fd))==NULL) {
|
||||
fprintf(stderr,"Can't write BTA data to file: %s\n",file_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
acs_bta = ( check_shm_block(&sdat) && fabs(M_time-last)>0.01);
|
||||
value = (acs_bta)? "On" : "Off";
|
||||
fprintf(fd,"ACS_BTA=\"%s\"\n",value);
|
||||
/* Mean Solar Time */
|
||||
fprintf(fd,"M_time=\"%s\"\n",time_asc(M_time+DUT1,tmp));
|
||||
/* Mean Sidereal Time */
|
||||
#ifdef EE_time
|
||||
fprintf(fd,"S_time=\"%s\"\n",time_asc(S_time-EE_time,tmp));
|
||||
//fprintf(fd,"JDate=\"%13.5f\"\n",JDate);
|
||||
fprintf(fd,"JDate=\"%g\"\n",JDate);
|
||||
#else
|
||||
fprintf(fd,"S_time=\"%s\"\n",time_asc(S_time,tmp));
|
||||
#endif
|
||||
if(!acs_bta || Tel_Hardware == Hard_Off) value = "Off";
|
||||
else if(Tel_Mode != Automatic) value = "Manual";
|
||||
else {
|
||||
switch (Sys_Mode) {
|
||||
default:
|
||||
case SysStop : value = "Stopping"; break;
|
||||
case SysWait : value = "Waiting"; break;
|
||||
case SysPointAZ :
|
||||
case SysPointAD : value = "Pointing"; break;
|
||||
case SysTrkStop :
|
||||
case SysTrkStart:
|
||||
case SysTrkMove :
|
||||
case SysTrkSeek : value = "Seeking"; break;
|
||||
case SysTrkOk : value = "Tracking"; break;
|
||||
case SysTrkCorr : value = "Correction";break;
|
||||
case SysTest : value = "Testing"; break;
|
||||
}
|
||||
}
|
||||
fprintf(fd,"Tel_Mode=\"%s\"\n",value);
|
||||
|
||||
switch (Tel_Focus) {
|
||||
default:
|
||||
case Prime : value = "Prime"; break;
|
||||
case Nasmyth1 : value = "Nasmyth1"; break;
|
||||
case Nasmyth2 : value = "Nasmyth2"; break;
|
||||
}
|
||||
fprintf(fd,"Tel_Focus=\"%s\"\n",value);
|
||||
|
||||
switch (Sys_Target) {
|
||||
default:
|
||||
case TagObject : value = "Object"; break;
|
||||
case TagPosition : value = "A/Z-Pos."; break;
|
||||
case TagNest : value = "Nest"; break;
|
||||
case TagZenith : value = "Zenith"; break;
|
||||
case TagHorizon : value = "Horizon"; break;
|
||||
}
|
||||
fprintf(fd,"Tel_Taget=\"%s\"\n",value);
|
||||
|
||||
if(acs_bta && Tel_Hardware == Hard_On)
|
||||
switch (P2_State) {
|
||||
default:
|
||||
case P2_Off : value = "Stop"; break;
|
||||
case P2_On : value = "Track"; break;
|
||||
case P2_Plus : value = "Move+"; break;
|
||||
case P2_Minus : value = "Move-"; break;
|
||||
}
|
||||
else value = "Off";
|
||||
fprintf(fd,"P2_Mode=\"%s\"\n",value);
|
||||
fprintf(fd,"code_KOST=\"0x%04X\"\n",code_KOST);
|
||||
|
||||
fprintf(fd,"CurAlpha=\"%s\"\n", time_asc(CurAlpha,tmp));
|
||||
fprintf(fd,"CurDelta=\"%s\"\n",angle_asc(CurDelta,tmp));
|
||||
fprintf(fd,"SrcAlpha=\"%s\"\n", time_asc(SrcAlpha,tmp));
|
||||
fprintf(fd,"SrcDelta=\"%s\"\n",angle_asc(SrcDelta,tmp));
|
||||
fprintf(fd,"InpAlpha=\"%s\"\n", time_asc(InpAlpha,tmp));
|
||||
fprintf(fd,"InpDelta=\"%s\"\n",angle_asc(InpDelta,tmp));
|
||||
fprintf(fd,"TelAlpha=\"%s\"\n", time_asc(val_Alp,tmp));
|
||||
fprintf(fd,"TelDelta=\"%s\"\n",angle_asc(val_Del,tmp));
|
||||
|
||||
fprintf(fd,"InpAzim=\"%s\"\n",angle_fmt(InpAzim,"%c%03d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"InpZenD=\"%s\"\n",angle_fmt(InpZdist,"%02d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"CurAzim=\"%s\"\n",angle_fmt(tag_A,"%c%03d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"CurZenD=\"%s\"\n",angle_fmt(tag_Z,"%02d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"CurPA=\"%s\"\n",angle_fmt(tag_P,"%03d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"SrcPA=\"%s\"\n",angle_fmt(calc_PA(SrcAlpha,SrcDelta,S_time),"%03d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"InpPA=\"%s\"\n",angle_fmt(calc_PA(InpAlpha,InpDelta,S_time),"%03d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"TelPA=\"%s\"\n",angle_fmt(calc_PA(val_Alp, val_Del, S_time),"%03d:%02d:%04.1f",tmp));
|
||||
|
||||
fprintf(fd,"ValAzim=\"%s\"\n",angle_fmt(val_A,"%c%03d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"ValZenD=\"%s\"\n",angle_fmt(val_Z,"%02d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"ValP2=\"%s\"\n",angle_fmt(val_P,"%03d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"ValDome=\"%s\"\n", angle_fmt(val_D,"%c%03d:%02d:%04.1f",tmp));
|
||||
|
||||
fprintf(fd,"DiffAzim=\"%s\"\n",angle_fmt(Diff_A,"%c%03d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"DiffZenD=\"%s\"\n",angle_fmt(Diff_Z,"%c%02d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"DiffP2=\"%s\"\n",angle_fmt(Diff_P,"%c%03d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"DiffDome=\"%s\"\n",angle_fmt(val_A-val_D,"%c%03d:%02d:%04.1f",tmp));
|
||||
|
||||
fprintf(fd,"VelAzim=\"%s\"\n",angle_fmt(vel_A,"%c%02d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"VelZenD=\"%s\"\n",angle_fmt(vel_Z,"%c%02d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"VelP2=\"%s\"\n",angle_fmt(vel_P,"%c%02d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"VelPA=\"%s\"\n",angle_fmt(vel_objP,"%c%02d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"VelDome=\"%s\"\n",angle_fmt(vel_D,"%c%02d:%02d:%04.1f",tmp));
|
||||
|
||||
if(Sys_Mode==SysTrkSeek||Sys_Mode==SysTrkOk||Sys_Mode==SysTrkCorr) {
|
||||
double curA,curZ,srcA,srcZ;
|
||||
double corAlp,corDel,corA,corZ;
|
||||
corAlp = CurAlpha-SrcAlpha;
|
||||
corDel = CurDelta-SrcDelta;
|
||||
if(corAlp > 23*3600.) corAlp -= 24*3600.;
|
||||
if(corAlp < -23*3600.) corAlp += 24*3600.;
|
||||
calc_AZ(SrcAlpha, SrcDelta, S_time, &srcA, &srcZ);
|
||||
calc_AZ(CurAlpha, CurDelta, S_time, &curA, &curZ);
|
||||
corA=curA-srcA;
|
||||
corZ=curZ-srcZ;
|
||||
fprintf(fd,"CorrAlpha=\"%s\"\n",angle_fmt(corAlp,"%c%01d:%02d:%05.2f",tmp));
|
||||
fprintf(fd,"CorrDelta=\"%s\"\n",angle_fmt(corDel,"%c%01d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"CorrAzim=\"%s\"\n",angle_fmt(corA,"%c%01d:%02d:%04.1f",tmp));
|
||||
fprintf(fd,"CorrZenD=\"%s\"\n",angle_fmt(corZ,"%c%01d:%02d:%04.1f",tmp));
|
||||
} else {
|
||||
fprintf(fd,"CorrAlpha=\"+0:00:00.00\"\n");
|
||||
fprintf(fd,"CorrDelta=\"+0:00:00.0\"\n");
|
||||
fprintf(fd,"CorrAzim=\"+0:00:00.0\"\n");
|
||||
fprintf(fd,"CorrZenD=\"+0:00:00.0\"\n");
|
||||
}
|
||||
fprintf(fd,"ValFoc=\"%0.2f\"\n",val_F);
|
||||
fprintf(fd,"ValTout=\"%+05.1f\"\n",val_T1);
|
||||
fprintf(fd,"ValTind=\"%+05.1f\"\n",val_T2);
|
||||
fprintf(fd,"ValTmir=\"%+05.1f\"\n",val_T3);
|
||||
fprintf(fd,"ValPres=\"%05.1f\"\n",val_B);
|
||||
fprintf(fd,"ValWind=\"%04.1f\"\n",val_Wnd);
|
||||
if(Wnd10_time>0.1 && Wnd10_time<=M_time /*&& M_time-Wnd10_time<24*3600.*/) {
|
||||
fprintf(fd,"Blast10=\"%.1f\"\n",(M_time-Wnd10_time)/60);
|
||||
fprintf(fd,"Blast15=\"%.1f\"\n",(M_time-Wnd15_time)/60);
|
||||
} else {
|
||||
fprintf(fd,"Blast10=\" \"\n");
|
||||
fprintf(fd,"Blast15=\" \"\n");
|
||||
}
|
||||
fprintf(fd,"ValHumd=\"%04.1f\"\n",val_Hmd);
|
||||
if(Precip_time>0.1 && Precip_time<=M_time /*&& M_time-Precip_time<24*3600.*/)
|
||||
fprintf(fd,"Precipt=\"%.1f\"\n",(M_time-Precip_time)/60);
|
||||
else
|
||||
fprintf(fd,"Precipt=\" \"\n");
|
||||
fflush(fd);
|
||||
|
||||
last = M_time;
|
||||
if(time_step>0.9) my_sleep(time_step);
|
||||
|
||||
} while (time_step>0.9); /* else only once */
|
||||
|
||||
exit(0);
|
||||
}
|
||||
356
bta_control_net-x86_64/bta_print/bta_shdata.c
Normal file
356
bta_control_net-x86_64/bta_print/bta_shdata.c
Normal file
@@ -0,0 +1,356 @@
|
||||
// (C) V.S. Shergin, SAO RAS
|
||||
#include <err.h>
|
||||
#include "bta_shdata.h"
|
||||
|
||||
#pragma pack(push, 4)
|
||||
// Main command channel (level 5)
|
||||
struct CMD_Queue mcmd = {{"Mcmd"}, 0200,0,-1,0};
|
||||
// Operator command channel (level 4)
|
||||
struct CMD_Queue ocmd = {{"Ocmd"}, 0200,0,-1,0};
|
||||
// User command channel (level 2/3)
|
||||
struct CMD_Queue ucmd = {{"Ucmd"}, 0200,0,-1,0};
|
||||
|
||||
#define MSGLEN (80)
|
||||
static char msg[MSGLEN];
|
||||
#define WARN(...) warn(__VA_ARGS__)
|
||||
#define PERR(...) do{snprintf(msg, MSGLEN, __VA_ARGS__); perror(msg);} while(0)
|
||||
#ifdef EBUG
|
||||
#define FNAME() fprintf(stderr, "\n%s (%s, line %d)\n", __func__, __FILE__, __LINE__)
|
||||
#define DBG(...) do{fprintf(stderr, "%s (%s, line %d): ", __func__, __FILE__, __LINE__); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
fprintf(stderr, "\n");} while(0)
|
||||
#else
|
||||
#define FNAME() do{}while(0)
|
||||
#define DBG(...) do{}while(0)
|
||||
#endif //EBUG
|
||||
|
||||
|
||||
#ifndef BTA_MODULE
|
||||
volatile struct BTA_Data *sdt;
|
||||
volatile struct BTA_Local *sdtl;
|
||||
|
||||
volatile struct SHM_Block sdat = {
|
||||
{"Sdat"},
|
||||
sizeof(struct BTA_Data),
|
||||
2048,0444,
|
||||
SHM_RDONLY,
|
||||
bta_data_init,
|
||||
bta_data_check,
|
||||
bta_data_close,
|
||||
ClientSide,-1,NULL
|
||||
};
|
||||
|
||||
int snd_id = -1; // client sender ID
|
||||
int cmd_src_pid = 0; // next command source PID
|
||||
uint32_t cmd_src_ip = 0;// next command source IP
|
||||
|
||||
/**
|
||||
* Init data
|
||||
*/
|
||||
void bta_data_init() {
|
||||
sdt = (struct BTA_Data *)sdat.addr;
|
||||
sdtl = (struct BTA_Local *)(sdat.addr+sizeof(struct BTA_Data));
|
||||
if(sdat.side == ClientSide) {
|
||||
if(sdt->magic != sdat.key.code) {
|
||||
WARN("Wrong shared data (maybe server turned off)");
|
||||
}
|
||||
if(sdt->version == 0) {
|
||||
WARN("Null shared data version (maybe server turned off)");
|
||||
}
|
||||
else if(sdt->version != BTA_Data_Ver) {
|
||||
WARN("Wrong shared data version: I'am - %d, but server - %d ...",
|
||||
BTA_Data_Ver, sdt->version );
|
||||
}
|
||||
if(sdt->size != sdat.size) {
|
||||
if(sdt->size > sdat.size) {
|
||||
WARN("Wrong shared area size: I needs - %d, but server - %d ...",
|
||||
sdat.size, sdt->size );
|
||||
} else {
|
||||
WARN("Attention! Too little shared data structure!");
|
||||
WARN("I needs - %d, but server gives only %d ...",
|
||||
sdat.size, sdt->size );
|
||||
WARN("May be server's version too old!?");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
/* ServerSide */
|
||||
if(sdt->magic == sdat.key.code &&
|
||||
sdt->version == BTA_Data_Ver &&
|
||||
sdt->size == sdat.size)
|
||||
return;
|
||||
memset(sdat.addr, 0, sdat.maxsize);
|
||||
sdt->magic = sdat.key.code;
|
||||
sdt->version = BTA_Data_Ver;
|
||||
sdt->size = sdat.size;
|
||||
Tel_Hardware = Hard_On;
|
||||
Pos_Corr = PC_On;
|
||||
TrkOk_Mode = UseDiffVel | UseDiffAZ ;
|
||||
inp_B = 591.;
|
||||
Pressure = 595.;
|
||||
PEP_code_A = 0x002aaa;
|
||||
PEP_code_Z = 0x002aaa;
|
||||
PEP_code_P = 0x002aaa;
|
||||
PEP_code_F = 0x002aaa;
|
||||
PEP_code_D = 0x002aaa;
|
||||
DomeSEW_N = 1;
|
||||
}
|
||||
|
||||
int bta_data_check() {
|
||||
return( (sdt->magic == sdat.key.code) && (sdt->version == BTA_Data_Ver) );
|
||||
}
|
||||
|
||||
void bta_data_close() {
|
||||
if(sdat.side == ServerSide) {
|
||||
sdt->magic = 0;
|
||||
sdt->version = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate shared memory segment
|
||||
*/
|
||||
int get_shm_block(volatile struct SHM_Block *sb, int server) {
|
||||
int getsize = (server)? sb->maxsize : sb->size;
|
||||
// first try to find existing one
|
||||
sb->id = shmget(sb->key.code, getsize, sb->mode);
|
||||
if(sb->id < 0 && errno == ENOENT && server){
|
||||
// if no - try to create a new one
|
||||
int cresize = sb->maxsize;
|
||||
if(sb->size > cresize){
|
||||
WARN("Wrong shm maxsize(%d) < realsize(%d)",sb->maxsize,sb->size);
|
||||
cresize = sb->size;
|
||||
}
|
||||
sb->id = shmget(sb->key.code, cresize, IPC_CREAT|IPC_EXCL|sb->mode);
|
||||
}
|
||||
if(sb->id < 0){
|
||||
if(server)
|
||||
PERR("Can't create shared memory segment '%s'",sb->key.name);
|
||||
else
|
||||
PERR("Can't find shared segment '%s' (maybe no server process) ",sb->key.name);
|
||||
return 0;
|
||||
}
|
||||
// attach it to our memory space
|
||||
sb->addr = (unsigned char *) shmat(sb->id, NULL, sb->atflag);
|
||||
if((long)sb->addr == -1){
|
||||
PERR("Can't attach shared memory segment '%s'",sb->key.name);
|
||||
return 0;
|
||||
}
|
||||
if(server && (shmctl(sb->id, SHM_LOCK, NULL) < 0)){
|
||||
PERR("Can't prevents swapping of shared memory segment '%s'",sb->key.name);
|
||||
return 0;
|
||||
}
|
||||
DBG("Create & attach shared memory segment '%s' %dbytes", sb->key.name, sb->size);
|
||||
sb->side = server;
|
||||
if(sb->init != NULL)
|
||||
sb->init();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int close_shm_block(volatile struct SHM_Block *sb){
|
||||
int ret;
|
||||
if(sb->close != NULL)
|
||||
sb->close();
|
||||
if(sb->side == ServerSide) {
|
||||
// ret = shmctl(sb->id, SHM_UNLOCK, NULL);
|
||||
ret = shmctl(sb->id, IPC_RMID, NULL);
|
||||
}
|
||||
ret = shmdt (sb->addr);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create|Find command queue
|
||||
*/
|
||||
void get_cmd_queue(struct CMD_Queue *cq, int server){
|
||||
if (!server && cq->id >= 0) { //if already in use set current
|
||||
snd_id = cq->id;
|
||||
return;
|
||||
}
|
||||
// first try to find existing one
|
||||
cq->id = msgget(cq->key.code, cq->mode);
|
||||
// if no - try to create a new one
|
||||
if(cq->id<0 && errno == ENOENT && server)
|
||||
cq->id = msgget(cq->key.code, IPC_CREAT|IPC_EXCL|cq->mode);
|
||||
if(cq->id<0){
|
||||
if(server)
|
||||
PERR("Can't create comand queue '%s'",cq->key.name);
|
||||
else
|
||||
PERR("Can't find comand queue '%s' (maybe no server process) ",cq->key.name);
|
||||
return;
|
||||
}
|
||||
cq->side = server;
|
||||
if(server){
|
||||
char buf[120]; /* выбросить все команды из очереди */
|
||||
while(msgrcv(cq->id, (struct msgbuf *)buf, 112, 0, IPC_NOWAIT) > 0);
|
||||
}else
|
||||
snd_id = cq->id;
|
||||
cq->acckey = 0;
|
||||
}
|
||||
|
||||
#endif // BTA_MODULE
|
||||
|
||||
|
||||
int check_shm_block(volatile struct SHM_Block *sb) {
|
||||
if(sb->check)
|
||||
return(sb->check());
|
||||
else return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set access key in current channel
|
||||
*/
|
||||
void set_acckey(uint32_t newkey){
|
||||
if(snd_id < 0) return;
|
||||
if(ucmd.id == snd_id) ucmd.acckey = newkey;
|
||||
else if(ocmd.id == snd_id) ocmd.acckey = newkey;
|
||||
else if(mcmd.id == snd_id) mcmd.acckey = newkey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup source data for one following command if default values
|
||||
* (IP == 0 - local, PID = current) not suits
|
||||
*/
|
||||
void set_cmd_src(uint32_t ip, int pid) {
|
||||
cmd_src_pid = pid;
|
||||
cmd_src_ip = ip;
|
||||
}
|
||||
|
||||
#pragma pack(push, 4)
|
||||
/**
|
||||
* Send client commands to server
|
||||
*/
|
||||
void send_cmd(int cmd_code, char *buf, int size) {
|
||||
struct my_msgbuf mbuf;
|
||||
if(snd_id < 0) return;
|
||||
if(size > 100) size = 100;
|
||||
if(cmd_code > 0)
|
||||
mbuf.mtype = cmd_code;
|
||||
else
|
||||
return;
|
||||
if(ucmd.id == snd_id) mbuf.acckey = ucmd.acckey;
|
||||
else if(ocmd.id == snd_id) mbuf.acckey = ocmd.acckey;
|
||||
else if(mcmd.id == snd_id) mbuf.acckey = mcmd.acckey;
|
||||
|
||||
mbuf.src_pid = cmd_src_pid ? cmd_src_pid : getpid();
|
||||
mbuf.src_ip = cmd_src_ip;
|
||||
cmd_src_pid = cmd_src_ip = 0;
|
||||
|
||||
if(size > 0)
|
||||
memcpy(mbuf.mtext, buf, size);
|
||||
else {
|
||||
mbuf.mtext[0] = 0;
|
||||
size = 1;
|
||||
}
|
||||
msgsnd(snd_id, (struct msgbuf *)&mbuf, size+12, IPC_NOWAIT);
|
||||
}
|
||||
|
||||
void send_cmd_noarg(int cmd_code) {
|
||||
send_cmd(cmd_code, NULL, 0);
|
||||
}
|
||||
void send_cmd_str(int cmd_code, char *arg) {
|
||||
send_cmd(cmd_code, arg, strlen(arg)+1);
|
||||
}
|
||||
void send_cmd_i1(int cmd_code, int32_t arg1) {
|
||||
send_cmd(cmd_code, (char *)&arg1, sizeof(int32_t));
|
||||
}
|
||||
void send_cmd_i2(int cmd_code, int32_t arg1, int32_t arg2) {
|
||||
int32_t ibuf[2];
|
||||
ibuf[0] = arg1;
|
||||
ibuf[1] = arg2;
|
||||
send_cmd(cmd_code, (char *)ibuf, 2*sizeof(int32_t));
|
||||
}
|
||||
void send_cmd_i3(int cmd_code, int32_t arg1, int32_t arg2, int32_t arg3) {
|
||||
int32_t ibuf[3];
|
||||
ibuf[0] = arg1;
|
||||
ibuf[1] = arg2;
|
||||
ibuf[2] = arg3;
|
||||
send_cmd(cmd_code, (char *)ibuf, 3*sizeof(int32_t));
|
||||
}
|
||||
void send_cmd_i4(int cmd_code, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4) {
|
||||
int32_t ibuf[4];
|
||||
ibuf[0] = arg1;
|
||||
ibuf[1] = arg2;
|
||||
ibuf[2] = arg3;
|
||||
ibuf[3] = arg4;
|
||||
send_cmd(cmd_code, (char *)ibuf, 4*sizeof(int32_t));
|
||||
}
|
||||
void send_cmd_d1(int32_t cmd_code, double arg1) {
|
||||
send_cmd(cmd_code, (char *)&arg1, sizeof(double));
|
||||
}
|
||||
void send_cmd_d2(int cmd_code, double arg1, double arg2) {
|
||||
double dbuf[2];
|
||||
dbuf[0] = arg1;
|
||||
dbuf[1] = arg2;
|
||||
send_cmd(cmd_code, (char *)dbuf, 2*sizeof(double));
|
||||
}
|
||||
void send_cmd_i1d1(int cmd_code, int32_t arg1, double arg2) {
|
||||
struct {
|
||||
int32_t ival;
|
||||
double dval;
|
||||
} buf;
|
||||
buf.ival = arg1;
|
||||
buf.dval = arg2;
|
||||
send_cmd(cmd_code, (char *)&buf, sizeof(buf));
|
||||
}
|
||||
void send_cmd_i2d1(int cmd_code, int32_t arg1, int32_t arg2, double arg3) {
|
||||
struct {
|
||||
int32_t ival[2];
|
||||
double dval;
|
||||
} buf;
|
||||
buf.ival[0] = arg1;
|
||||
buf.ival[1] = arg2;
|
||||
buf.dval = arg3;
|
||||
send_cmd(cmd_code, (char *)&buf, sizeof(buf));
|
||||
}
|
||||
void send_cmd_i3d1(int cmd_code, int32_t arg1, int32_t arg2, int32_t arg3, double arg4) {
|
||||
struct {
|
||||
int32_t ival[3];
|
||||
double dval;
|
||||
} buf;
|
||||
buf.ival[0] = arg1;
|
||||
buf.ival[1] = arg2;
|
||||
buf.ival[2] = arg3;
|
||||
buf.dval = arg4;
|
||||
send_cmd(cmd_code, (char *)&buf, sizeof(buf));
|
||||
}
|
||||
|
||||
void encode_lev_passwd(char *passwd, int nlev, uint32_t *keylev, uint32_t *codlev){
|
||||
char salt[4];
|
||||
char *encr;
|
||||
union {
|
||||
uint32_t ui;
|
||||
char c[4];
|
||||
} key, cod;
|
||||
sprintf(salt,"L%1d",nlev);
|
||||
encr = (char *)crypt(passwd, salt);
|
||||
cod.c[0] = encr[2];
|
||||
key.c[0] = encr[3];
|
||||
cod.c[1] = encr[4];
|
||||
key.c[1] = encr[5];
|
||||
cod.c[2] = encr[6];
|
||||
key.c[2] = encr[7];
|
||||
cod.c[3] = encr[8];
|
||||
key.c[3] = encr[9];
|
||||
*keylev = key.ui;
|
||||
*codlev = cod.ui;
|
||||
}
|
||||
|
||||
int find_lev_passwd(char *passwd, uint32_t *keylev, uint32_t *codlev){
|
||||
int nlev;
|
||||
for(nlev = 5; nlev > 0; --nlev){
|
||||
encode_lev_passwd(passwd, nlev, keylev, codlev);
|
||||
if(*codlev == code_Lev(nlev)) break;
|
||||
}
|
||||
return(nlev);
|
||||
}
|
||||
|
||||
int check_lev_passwd(char *passwd){
|
||||
uint32_t keylev,codlev;
|
||||
int nlev;
|
||||
nlev = find_lev_passwd(passwd, &keylev, &codlev);
|
||||
if(nlev > 0) set_acckey(keylev);
|
||||
return(nlev);
|
||||
}
|
||||
|
||||
#pragma pack(pop)
|
||||
851
bta_control_net-x86_64/bta_print/bta_shdata.h
Normal file
851
bta_control_net-x86_64/bta_print/bta_shdata.h
Normal file
@@ -0,0 +1,851 @@
|
||||
// (C) V.S. Shergin, SAO RAS
|
||||
#pragma once
|
||||
#ifndef __BTA_SHDATA_H__
|
||||
#define __BTA_SHDATA_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/msg.h>
|
||||
#include <errno.h>
|
||||
|
||||
#pragma pack(push, 4)
|
||||
/*
|
||||
* Shared memory block
|
||||
*/
|
||||
struct SHM_Block {
|
||||
union {
|
||||
char name[5]; // memory segment identificator
|
||||
key_t code;
|
||||
} key;
|
||||
int32_t size; // size of memory used
|
||||
int32_t maxsize; // size when created
|
||||
int32_t mode; // access mode (rwxrwxrwx)
|
||||
int32_t atflag; // connection mode (SHM_RDONLY or 0)
|
||||
void (*init)(); // init function
|
||||
int32_t (*check)(); // test function
|
||||
void (*close)(); // deinit function
|
||||
int32_t side; // connection type: client/server
|
||||
int32_t id; // connection identificator
|
||||
uint8_t *addr; // connection address
|
||||
};
|
||||
|
||||
extern volatile struct SHM_Block sdat;
|
||||
|
||||
/*
|
||||
* Command queue descriptor
|
||||
*/
|
||||
struct CMD_Queue {
|
||||
union {
|
||||
char name[5]; // queue key
|
||||
key_t code;
|
||||
} key;
|
||||
int32_t mode; // access mode (rwxrwxrwx)
|
||||
int32_t side; // connection type (Sender/Receiver - server/client)
|
||||
int32_t id; // connection identificator
|
||||
uint32_t acckey; // access key (for transmission from client to server)
|
||||
};
|
||||
|
||||
extern struct CMD_Queue mcmd;
|
||||
extern struct CMD_Queue ocmd;
|
||||
extern struct CMD_Queue ucmd;
|
||||
|
||||
void send_cmd_noarg(int);
|
||||
void send_cmd_str(int, char *);
|
||||
void send_cmd_i1(int, int32_t);
|
||||
void send_cmd_i2(int, int32_t, int32_t);
|
||||
void send_cmd_i3(int, int32_t, int32_t, int32_t);
|
||||
void send_cmd_i4(int, int32_t, int32_t, int32_t, int32_t);
|
||||
void send_cmd_d1(int, double);
|
||||
void send_cmd_d2(int, double, double);
|
||||
void send_cmd_i1d1(int, int32_t, double);
|
||||
void send_cmd_i2d1(int, int32_t, int32_t, double);
|
||||
void send_cmd_i3d1(int, int32_t, int32_t, int32_t, double);
|
||||
|
||||
/*******************************************************************************
|
||||
* Command list *
|
||||
*******************************************************************************/
|
||||
/* name code args type */
|
||||
// Stop telescope
|
||||
#define StopTel 1
|
||||
#define StopTeleskope() send_cmd_noarg( 1 )
|
||||
// High/low speed
|
||||
#define StartHS 2
|
||||
#define StartHighSpeed() send_cmd_noarg( 2 )
|
||||
#define StartLS 3
|
||||
#define StartLowSpeed() send_cmd_noarg( 3 )
|
||||
// Timer setup (Ch7_15 or SysTimer)
|
||||
#define SetTmr 4
|
||||
#define SetTimerMode(T) send_cmd_i1 ( 4, (int)(T))
|
||||
// Simulation (modeling) mode
|
||||
#define SetModMod 5
|
||||
#define SetModelMode(M) send_cmd_i1 ( 5, (int)(M))
|
||||
// Azimuth speed code
|
||||
#define SetCodA 6
|
||||
#define SetPKN_A(iA,sA) send_cmd_i2 ( 6, (int)(iA),(int)(sA))
|
||||
// Zenith speed code
|
||||
#define SetCodZ 7
|
||||
#define SetPKN_Z(iZ) send_cmd_i1 ( 7, (int)(iZ))
|
||||
// Parangle speed code
|
||||
#define SetCodP 8
|
||||
#define SetPKN_P(iP) send_cmd_i1 ( 8, (int)(iP))
|
||||
// Set Az velocity
|
||||
#define SetVA 9
|
||||
#define SetSpeedA(vA) send_cmd_d1 ( 9, (double)(vA))
|
||||
// Set Z velocity
|
||||
#define SetVZ 10
|
||||
#define SetSpeedZ(vZ) send_cmd_d1 (10, (double)(vZ))
|
||||
// Set P velocity
|
||||
#define SetVP 11
|
||||
#define SetSpeedP(vP) send_cmd_d1 (11, (double)(vP))
|
||||
// Set new polar coordinates
|
||||
#define SetAD 12
|
||||
#define SetRADec(Alp,Del) send_cmd_d2 (12, (double)(Alp),(double)(Del))
|
||||
// Set new azimutal coordinates
|
||||
#define SetAZ 13
|
||||
#define SetAzimZ(A,Z) send_cmd_d2 (13, (double)(A),(double)(Z))
|
||||
// Goto new object by polar coords
|
||||
#define GoToAD 14
|
||||
#define GoToObject() send_cmd_noarg(14 )
|
||||
// Start steering to object by polar coords
|
||||
#define MoveToAD 15
|
||||
#define MoveToObject() send_cmd_noarg(15 )
|
||||
// Go to object by azimutal coords
|
||||
#define GoToAZ 16
|
||||
#define GoToAzimZ() send_cmd_noarg(16 )
|
||||
// Set A&Z for simulation
|
||||
#define WriteAZ 17
|
||||
#define WriteModelAZ() send_cmd_noarg(17 )
|
||||
// Set P2 mode
|
||||
#define SetModP 18
|
||||
#define SetPMode(pmod) send_cmd_i1 (18, (int)(pmod))
|
||||
// Move(+-1)/Stop(0) P2
|
||||
#define P2Move 19
|
||||
#define MoveP2(dir) send_cmd_i1 (19, (int)(dir))
|
||||
// Move(+-2,+-1)/Stop(0) focus
|
||||
#define FocMove 20
|
||||
#define MoveFocus(speed,time) send_cmd_i1d1(20,(int)(speed),(double)(time))
|
||||
// Use/don't use pointing correction system
|
||||
#define UsePCorr 21
|
||||
#define SwitchPosCorr(pc_flag) send_cmd_i1 (21, (int)(pc_flag))
|
||||
// Tracking flags
|
||||
#define SetTrkFlags 22
|
||||
#define SetTrkOkMode(trk_flags) send_cmd_i1 (22, (int)(trk_flags))
|
||||
// Set focus (0 - primary, 1 - N1, 2 - N2)
|
||||
#define SetTFoc 23
|
||||
#define SetTelFocus(N) send_cmd_i1 ( 23, (int)(N))
|
||||
// Set intrinsic move parameters by RA/Decl
|
||||
#define SetVAD 24
|
||||
#define SetVelAD(VAlp,VDel) send_cmd_d2 (24, (double)(VAlp),(double)(VDel))
|
||||
// Reverse Azimuth direction when pointing
|
||||
#define SetRevA 25
|
||||
#define SetAzRevers(amod) send_cmd_i1 (25, (int)(amod))
|
||||
// Set P2 velocity
|
||||
#define SetVP2 26
|
||||
#define SetVelP2(vP2) send_cmd_d1 (26, (double)(vP2))
|
||||
// Set pointing target
|
||||
#define SetTarg 27
|
||||
#define SetSysTarg(Targ) send_cmd_i1 (27, (int)(Targ))
|
||||
// Send message to all clients (+write into protocol)
|
||||
#define SendMsg 28
|
||||
#define SendMessage(Mesg) send_cmd_str (28, (char *)(Mesg))
|
||||
// RA/Decl user correction
|
||||
#define CorrAD 29
|
||||
#define DoADcorr(dAlp,dDel) send_cmd_d2 (29, (double)(dAlp),(double)(dDel))
|
||||
// A/Z user correction
|
||||
#define CorrAZ 30
|
||||
#define DoAZcorr(dA,dZ) send_cmd_d2 (30, (double)(dA),(double)(dZ))
|
||||
// sec A/Z user correction speed
|
||||
#define SetVCAZ 31
|
||||
#define SetVCorr(vA,vZ) send_cmd_d2 (31, (double)(vA),(double)(vZ))
|
||||
// move P2 with given velocity for a given time
|
||||
#define P2MoveTo 32
|
||||
#define MoveP2To(vP2,time) send_cmd_d2 (32, (double)(vP2),(double)(time))
|
||||
// Go to t/Decl position
|
||||
#define GoToTD 33
|
||||
#define GoToSat() send_cmd_noarg (33 )
|
||||
// Move to t/Decl
|
||||
#define MoveToTD 34
|
||||
#define MoveToSat() send_cmd_noarg (34 )
|
||||
// Empty command for synchronisation
|
||||
#define NullCom 35
|
||||
#define SyncCom() send_cmd_noarg (35 )
|
||||
// Button "Start"
|
||||
#define StartTel 36
|
||||
#define StartTeleskope() send_cmd_noarg(36 )
|
||||
// Set telescope mode
|
||||
#define SetTMod 37
|
||||
#define SetTelMode(M) send_cmd_i1 ( 37, (int)(M))
|
||||
// Turn telescope on (oil etc)
|
||||
#define TelOn 38
|
||||
#define TeleskopeOn() send_cmd_noarg(38 )
|
||||
// Dome mode
|
||||
#define SetModD 39
|
||||
#define SetDomeMode(dmod) send_cmd_i1 (39, (int)(dmod))
|
||||
// Move(+-3,+-2,+-1)/Stop(0) dome
|
||||
#define DomeMove 40
|
||||
#define MoveDome(speed,time) send_cmd_i1d1(40,(int)(speed),(double)(time))
|
||||
// Set account password
|
||||
#define SetPass 41
|
||||
#define SetPasswd(LPass) send_cmd_str (41, (char *)(LPass))
|
||||
// Set code of access level
|
||||
#define SetLevC 42
|
||||
#define SetLevCode(Nlev,Cod) send_cmd_i2(42, (int)(Nlev),(int)(Cod))
|
||||
// Set key for access level
|
||||
#define SetLevK 43
|
||||
#define SetLevKey(Nlev,Key) send_cmd_i2(43, (int)(Nlev),(int)(Key))
|
||||
// Setup network
|
||||
#define SetNet 44
|
||||
#define SetNetAcc(Mask,Addr) send_cmd_i2(44, (int)(Mask),(int)(Addr))
|
||||
// Input meteo data
|
||||
#define SetMet 45
|
||||
#define SetMeteo(m_id,m_val) send_cmd_i1d1(45,(int)(m_id),(double)(m_val))
|
||||
// Cancel meteo data
|
||||
#define TurnMetOff 46
|
||||
#define TurnMeteoOff(m_id) send_cmd_i1 (46, (int)(m_id))
|
||||
// Set time correction (IERS DUT1=UT1-UTC)
|
||||
#define SetDUT1 47
|
||||
#define SetDtime(dT) send_cmd_d1 (47, (double)(dT))
|
||||
// Set polar motion (IERS polar motion)
|
||||
#define SetPM 48
|
||||
#define SetPolMot(Xp,Yp) send_cmd_d2 (48, (double)(Xp),(double)(Yp))
|
||||
// Get SEW parameter
|
||||
#define GetSEW 49
|
||||
#define GetSEWparam(Ndrv,Indx,Cnt) send_cmd_i3(49,(int)(Ndrv),(int)(Indx),(int)(Cnt))
|
||||
// Set SEW parameter
|
||||
#define PutSEW 50
|
||||
#define PutSEWparam(Ndrv,Indx,Key,Val) send_cmd_i4(50,(int)(Ndrv),(int)(Indx),(int)(Key),(int)(Val))
|
||||
// Set lock flags
|
||||
#define SetLocks 51
|
||||
#define SetLockFlags(f) send_cmd_i1 (SetLocks, (int)(f))
|
||||
// Clear lock flags
|
||||
#define ClearLocks 52
|
||||
#define ClearLockFlags(f) send_cmd_i1 (ClearLocks, (int)(f))
|
||||
// Set PEP-RK bits
|
||||
#define SetRKbits 53
|
||||
#define AddRKbits(f) send_cmd_i1 (SetRKbits, (int)(f))
|
||||
// Clear PEP-RK bits
|
||||
#define ClrRKbits 54
|
||||
#define ClearRKbits(f) send_cmd_i1 (ClrRKbits, (int)(f))
|
||||
// Set SEW dome motor number (for indication)
|
||||
#define SetSEWnd 55
|
||||
#define SetDomeDrive(ND) send_cmd_i1 (SetSEWnd, (int)(ND))
|
||||
// Turn SEW controllers of dome on/off
|
||||
#define SEWsDome 56
|
||||
#define DomeSEW(OnOff) send_cmd_i1 (SEWsDome, (int)(OnOff))
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* BTA data structure definitions *
|
||||
*******************************************************************************/
|
||||
|
||||
#define ServPID (sdt->pid) // PID of main program
|
||||
// model
|
||||
#define UseModel (sdt->model) // model variants
|
||||
enum{
|
||||
NoModel = 0 // OFF
|
||||
,CheckModel // control motors by model
|
||||
,DriveModel // "blind" management without real sensors
|
||||
,FullModel // full model without telescope
|
||||
};
|
||||
// timer
|
||||
#define ClockType (sdt->timer) // which timer to use
|
||||
enum{
|
||||
Ch7_15 = 0 // Inner timer with synchronisation by CH7_15
|
||||
,SysTimer // System timer (synchronisation unknown)
|
||||
,ExtSynchro // External synchronisation (bta_time or xntpd)
|
||||
};
|
||||
// system
|
||||
#define Sys_Mode (sdt->system) // main system mode
|
||||
enum{
|
||||
SysStop = 0 // Stop
|
||||
,SysWait // Wait for start (pointing)
|
||||
,SysPointAZ // Pointing by A/Z
|
||||
,SysPointAD // Pointing by RA/Decl
|
||||
,SysTrkStop // Tracking stop
|
||||
,SysTrkStart // Start tracking (acceleration to nominal velocity)
|
||||
,SysTrkMove // Tracking move to object
|
||||
,SysTrkSeek // Tracking in seeking mode
|
||||
,SysTrkOk // Tracking OK
|
||||
,SysTrkCorr // Correction of tracking position
|
||||
,SysTest // Test
|
||||
};
|
||||
// sys_target
|
||||
#define Sys_Target (sdt->sys_target) // system pointing target
|
||||
enum{
|
||||
TagPosition = 0 // point by A/Z
|
||||
,TagObject // point by RA/Decl
|
||||
,TagNest // point to "nest"
|
||||
,TagZenith // point to zenith
|
||||
,TagHorizon // point to horizon
|
||||
,TagStatObj // point to statinary object (t/Decl)
|
||||
};
|
||||
// tel_focus
|
||||
#define Tel_Focus (sdt->tel_focus) // telescope focus type
|
||||
enum{
|
||||
Prime = 0
|
||||
,Nasmyth1
|
||||
,Nasmyth2
|
||||
};
|
||||
// PCS
|
||||
#define PosCor_Coeff (sdt->pc_coeff) // pointing correction system coefficients
|
||||
// tel_state
|
||||
#define Tel_State (sdt->tel_state) // telescope state
|
||||
#define Req_State (sdt->req_state) // required state
|
||||
enum{
|
||||
Stopping = 0
|
||||
,Pointing
|
||||
,Tracking
|
||||
};
|
||||
// tel_hard_state
|
||||
#define Tel_Hardware (sdt->tel_hard_state) // Power state
|
||||
enum{
|
||||
Hard_Off = 0
|
||||
,Hard_On
|
||||
};
|
||||
// tel_mode
|
||||
#define Tel_Mode (sdt->tel_mode) // telescope mode
|
||||
enum{
|
||||
Automatic = 0 // Automatic (normal) mode
|
||||
,Manual = 1 // manual mode
|
||||
,ZenHor = 2 // work when Z<5 || Z>80
|
||||
,A_Move = 4 // hand move by A
|
||||
,Z_Move = 8 // hand move by Z
|
||||
,Balance =0x10// balancing
|
||||
};
|
||||
// az_mode
|
||||
#define Az_Mode (sdt->az_mode) // azimuth reverce
|
||||
enum{
|
||||
Rev_Off = 0 // move by nearest way
|
||||
,Rev_On // move by longest way
|
||||
};
|
||||
// p2_state
|
||||
#define P2_State (sdt->p2_state) // P2 motor state
|
||||
#define P2_Mode (sdt->p2_req_mode)
|
||||
enum{
|
||||
P2_Off = 0 // Stop
|
||||
,P2_On // Guiding
|
||||
,P2_Plus // Move to +
|
||||
,P2_Minus = -2 // Move to -
|
||||
};
|
||||
// focus_state
|
||||
#define Foc_State (sdt->focus_state) // focus motor state
|
||||
enum{
|
||||
Foc_Hminus = -2// fast "-" move
|
||||
,Foc_Lminus // slow "-" move
|
||||
,Foc_Off // Off
|
||||
,Foc_Lplus // slow "+" move
|
||||
,Foc_Hplus // fast "+" move
|
||||
};
|
||||
// dome_state
|
||||
#define Dome_State (sdt->dome_state) // dome motors state
|
||||
enum{
|
||||
D_Hminus = -3 // speeds: low, medium, high
|
||||
,D_Mminus
|
||||
,D_Lminus
|
||||
,D_Off // off
|
||||
,D_Lplus
|
||||
,D_Mplus
|
||||
,D_Hplus
|
||||
,D_On = 7 // auto
|
||||
};
|
||||
// pcor_mode
|
||||
#define Pos_Corr (sdt->pcor_mode) // pointing correction mode
|
||||
enum{
|
||||
PC_Off = 0
|
||||
,PC_On
|
||||
};
|
||||
// trkok_mode
|
||||
#define TrkOk_Mode (sdt->trkok_mode) // tracking mode
|
||||
enum{
|
||||
UseDiffVel = 1 // Isodrome (correction by real motors speed)
|
||||
,UseDiffAZ = 2 // Tracking by coordinate difference
|
||||
,UseDFlt = 4 // Turn on digital filter
|
||||
};
|
||||
// input RA/Decl values
|
||||
#define InpAlpha (sdt->i_alpha)
|
||||
#define InpDelta (sdt->i_delta)
|
||||
// current source RA/Decl values
|
||||
#define SrcAlpha (sdt->s_alpha)
|
||||
#define SrcDelta (sdt->s_delta)
|
||||
// intrinsic object velocity
|
||||
#define VelAlpha (sdt->v_alpha)
|
||||
#define VelDelta (sdt->v_delta)
|
||||
// input A/Z values
|
||||
#define InpAzim (sdt->i_azim)
|
||||
#define InpZdist (sdt->i_zdist)
|
||||
// calculated values
|
||||
#define CurAlpha (sdt->c_alpha)
|
||||
#define CurDelta (sdt->c_delta)
|
||||
// current values (from sensors)
|
||||
#define tag_A (sdt->tag_a)
|
||||
#define tag_Z (sdt->tag_z)
|
||||
#define tag_P (sdt->tag_p)
|
||||
// calculated corrections
|
||||
#define pos_cor_A (sdt->pcor_a)
|
||||
#define pos_cor_Z (sdt->pcor_z)
|
||||
#define refract_Z (sdt->refr_z)
|
||||
// reverse calculation corr.
|
||||
#define tel_cor_A (sdt->tcor_a)
|
||||
#define tel_cor_Z (sdt->tcor_z)
|
||||
#define tel_ref_Z (sdt->tref_z)
|
||||
// coords difference
|
||||
#define Diff_A (sdt->diff_a)
|
||||
#define Diff_Z (sdt->diff_z)
|
||||
#define Diff_P (sdt->diff_p)
|
||||
// base object velocity
|
||||
#define vel_objA (sdt->vbasea)
|
||||
#define vel_objZ (sdt->vbasez)
|
||||
#define vel_objP (sdt->vbasep)
|
||||
// correction by real speed
|
||||
#define diff_vA (sdt->diffva)
|
||||
#define diff_vZ (sdt->diffvz)
|
||||
#define diff_vP (sdt->diffvp)
|
||||
// motor speed
|
||||
#define speedA (sdt->speeda)
|
||||
#define speedZ (sdt->speedz)
|
||||
#define speedP (sdt->speedp)
|
||||
// last precipitation time
|
||||
#define Precip_time (sdt->m_time_precip)
|
||||
// reserved
|
||||
#define Reserve (sdt->reserve)
|
||||
// real motor speed (''/sec)
|
||||
#define req_speedA (sdt->rspeeda)
|
||||
#define req_speedZ (sdt->rspeedz)
|
||||
#define req_speedP (sdt->rspeedp)
|
||||
// model speed
|
||||
#define mod_vel_A (sdt->simvela)
|
||||
#define mod_vel_Z (sdt->simvelz)
|
||||
#define mod_vel_P (sdt->simvelp)
|
||||
#define mod_vel_F (sdt->simvelf)
|
||||
#define mod_vel_D (sdt->simvelf)
|
||||
// telescope & hand correction state
|
||||
/*
|
||||
* 0x8000 - ÁÚÉÍÕÔ ÐÏÌÏÖÉÔÅÌØÎÙÊ
|
||||
* 0x4000 - ÏÔÒÁÂÏÔËÁ ×ËÌ.
|
||||
* 0x2000 - ÒÅÖÉÍ ×ÅÄÅÎÉÑ
|
||||
* 0x1000 - ÏÔÒÁÂÏÔËÁ P2 ×ËÌ.
|
||||
* 0x01F0 - ÓË.ËÏÒÒ. 0.2 0.4 1.0 2.0 5.0("/ÓÅË)
|
||||
* 0x000F - ÎÁÐÒ.ËÏÒÒ. +Z -Z +A -A
|
||||
*/
|
||||
#define code_KOST (sdt->kost)
|
||||
// different time (UTC, stellar, local)
|
||||
#define M_time (sdt->m_time)
|
||||
#define S_time (sdt->s_time)
|
||||
#define L_time (sdt->l_time)
|
||||
// PPNDD sensor (rough) code
|
||||
#define ppndd_A (sdt->ppndd_a)
|
||||
#define ppndd_Z (sdt->ppndd_z)
|
||||
#define ppndd_P (sdt->ppndd_p)
|
||||
#define ppndd_B (sdt->ppndd_b) // atm. pressure
|
||||
// DUP sensor (precise) code (Gray code)
|
||||
#define dup_A (sdt->dup_a)
|
||||
#define dup_Z (sdt->dup_z)
|
||||
#define dup_P (sdt->dup_p)
|
||||
#define dup_F (sdt->dup_f)
|
||||
#define dup_D (sdt->dup_d)
|
||||
// binary 14-digit precise code
|
||||
#define low_A (sdt->low_a)
|
||||
#define low_Z (sdt->low_z)
|
||||
#define low_P (sdt->low_p)
|
||||
#define low_F (sdt->low_f)
|
||||
#define low_D (sdt->low_d)
|
||||
// binary 23-digit rough code
|
||||
#define code_A (sdt->code_a)
|
||||
#define code_Z (sdt->code_z)
|
||||
#define code_P (sdt->code_p)
|
||||
#define code_B (sdt->code_b)
|
||||
#define code_F (sdt->code_f)
|
||||
#define code_D (sdt->code_d)
|
||||
// ADC PCL818 (8-channel) codes
|
||||
#define ADC(N) (sdt->adc[(N)])
|
||||
#define code_T1 ADC(0) // External temperature code
|
||||
#define code_T2 ADC(1) // In-dome temperature code
|
||||
#define code_T3 ADC(2) // Mirror temperature code
|
||||
#define code_Wnd ADC(3) // Wind speed code
|
||||
// calculated values
|
||||
#define val_A (sdt->val_a) // A, ''
|
||||
#define val_Z (sdt->val_z) // Z, ''
|
||||
#define val_P (sdt->val_p) // P, ''
|
||||
#define val_B (sdt->val_b) // atm. pressure, mm.hg.
|
||||
#define val_F (sdt->val_f) // focus, mm
|
||||
#define val_D (sdt->val_d) // Dome Az, ''
|
||||
#define val_T1 (sdt->val_t1) // ext. T, degrC
|
||||
#define val_T2 (sdt->val_t2) // in-dome T, degrC
|
||||
#define val_T3 (sdt->val_t3) // mirror T, degrC
|
||||
#define val_Wnd (sdt->val_wnd) // wind speed, m/s
|
||||
// RA/Decl calculated by A/Z
|
||||
#define val_Alp (sdt->val_alp)
|
||||
#define val_Del (sdt->val_del)
|
||||
// measured speed
|
||||
#define vel_A (sdt->vel_a)
|
||||
#define vel_Z (sdt->vel_z)
|
||||
#define vel_P (sdt->vel_p)
|
||||
#define vel_F (sdt->vel_f)
|
||||
#define vel_D (sdt->vel_d)
|
||||
// system messages queue
|
||||
#define MesgNum 3
|
||||
#define MesgLen 39
|
||||
// message type
|
||||
enum{
|
||||
MesgEmpty = 0
|
||||
,MesgInfor
|
||||
,MesgWarn
|
||||
,MesgFault
|
||||
,MesgLog
|
||||
};
|
||||
#define Sys_Mesg(N) (sdt->sys_msg_buf[N])
|
||||
// access levels
|
||||
#define code_Lev1 (sdt->code_lev[0]) // remote observer - only information
|
||||
#define code_Lev2 (sdt->code_lev[1]) // local observer - input coordinates
|
||||
#define code_Lev3 (sdt->code_lev[2]) // main observer - correction by A/Z, P2/F management
|
||||
#define code_Lev4 (sdt->code_lev[3]) // operator - start/stop telescope, testing
|
||||
#define code_Lev5 (sdt->code_lev[4]) // main operator - full access
|
||||
#define code_Lev(x) (sdt->code_lev[(x-1)])
|
||||
// network settings
|
||||
#define NetMask (sdt->netmask) // subnet mask (usually 255.255.255.0)
|
||||
#define NetWork (sdt->netaddr) // subnet address (for ex.: 192.168.3.0)
|
||||
#define ACSMask (sdt->acsmask) // ACS network mask (for ex.: 255.255.255.0)
|
||||
#define ACSNet (sdt->acsaddr) // ACS subnet address (for ex.: 192.168.13.0)
|
||||
// meteo data
|
||||
#define MeteoMode (sdt->meteo_stat)
|
||||
enum{
|
||||
INPUT_B = 1 // pressure
|
||||
,INPUT_T1 = 2 // external T
|
||||
,INPUT_T2 = 4 // in-dome T
|
||||
,INPUT_T3 = 8 // mirror T
|
||||
,INPUT_WND = 0x10 // wind speed
|
||||
,INPUT_HMD = 0x20 // humidity
|
||||
};
|
||||
#define SENSOR_B (INPUT_B <<8) // external data flags
|
||||
#define SENSOR_T1 (INPUT_T1 <<8)
|
||||
#define SENSOR_T2 (INPUT_T2 <<8)
|
||||
#define SENSOR_T3 (INPUT_T3 <<8)
|
||||
#define SENSOR_WND (INPUT_WND<<8)
|
||||
#define SENSOR_HMD (INPUT_HMD<<8)
|
||||
#define ADC_B (INPUT_B <<16) // reading from ADC flags
|
||||
#define ADC_T1 (INPUT_T1 <<16)
|
||||
#define ADC_T2 (INPUT_T2 <<16)
|
||||
#define ADC_T3 (INPUT_T3 <<16)
|
||||
#define ADC_WND (INPUT_WND<<16)
|
||||
#define ADC_HMD (INPUT_HMD<<16)
|
||||
#define NET_B (INPUT_B <<24) // got by network flags
|
||||
#define NET_T1 (INPUT_T1 <<24)
|
||||
#define NET_WND (INPUT_WND<<24)
|
||||
#define NET_HMD (INPUT_HMD<<24)
|
||||
// input meteo values
|
||||
#define inp_B (sdt->inp_b) // atm.pressure (mm.hg)
|
||||
#define inp_T1 (sdt->inp_t1) // ext T
|
||||
#define inp_T2 (sdt->inp_t2) // in-dome T
|
||||
#define inp_T3 (sdt->inp_t3) // mirror T
|
||||
#define inp_Wnd (sdt->inp_wnd) // wind
|
||||
// values used for refraction calculation
|
||||
#define Temper (sdt->temper)
|
||||
#define Pressure (sdt->press)
|
||||
// last wind gust time
|
||||
#define Wnd10_time (sdt->m_time10)
|
||||
#define Wnd15_time (sdt->m_time15)
|
||||
// IERS DUT1
|
||||
#define DUT1 (sdt->dut1)
|
||||
// sensors reading time
|
||||
#define A_time (sdt->a_time)
|
||||
#define Z_time (sdt->z_time)
|
||||
#define P_time (sdt->p_time)
|
||||
// input speeds
|
||||
#define speedAin (sdt->speedain)
|
||||
#define speedZin (sdt->speedzin)
|
||||
#define speedPin (sdt->speedpin)
|
||||
// acceleration (''/sec^2)
|
||||
#define acc_A (sdt->acc_a)
|
||||
#define acc_Z (sdt->acc_z)
|
||||
#define acc_P (sdt->acc_p)
|
||||
#define acc_F (sdt->acc_f)
|
||||
#define acc_D (sdt->acc_d)
|
||||
// SEW code
|
||||
#define code_SEW (sdt->code_sew)
|
||||
// sew data
|
||||
#define statusSEW(Drv) (sdt->sewdrv[(Drv)-1].status)
|
||||
#define statusSEW1 (sdt->sewdrv[0].status)
|
||||
#define statusSEW2 (sdt->sewdrv[1].status)
|
||||
#define statusSEW3 (sdt->sewdrv[2].status)
|
||||
#define speedSEW(Drv) (sdt->sewdrv[(Drv)-1].set_speed)
|
||||
#define speedSEW1 (sdt->sewdrv[0].set_speed)
|
||||
#define speedSEW2 (sdt->sewdrv[1].set_speed)
|
||||
#define speedSEW3 (sdt->sewdrv[2].set_speed)
|
||||
#define vel_SEW(Drv) (sdt->sewdrv[(Drv)-1].mes_speed)
|
||||
#define vel_SEW1 (sdt->sewdrv[0].mes_speed)
|
||||
#define vel_SEW2 (sdt->sewdrv[1].mes_speed)
|
||||
#define vel_SEW3 (sdt->sewdrv[2].mes_speed)
|
||||
#define currentSEW(Drv) (sdt->sewdrv[(Drv)-1].current)
|
||||
#define currentSEW1 (sdt->sewdrv[0].current)
|
||||
#define currentSEW2 (sdt->sewdrv[1].current)
|
||||
#define currentSEW3 (sdt->sewdrv[2].current)
|
||||
#define indexSEW(Drv) (sdt->sewdrv[(Drv)-1].index)
|
||||
#define indexSEW1 (sdt->sewdrv[0].index)
|
||||
#define indexSEW2 (sdt->sewdrv[1].index)
|
||||
#define indexSEW3 (sdt->sewdrv[2].index)
|
||||
#define valueSEW(Drv) (sdt->sewdrv[(Drv)-1].value.l)
|
||||
#define valueSEW1 (sdt->sewdrv[0].value.l)
|
||||
#define valueSEW2 (sdt->sewdrv[1].value.l)
|
||||
#define valueSEW3 (sdt->sewdrv[2].value.l)
|
||||
#define bvalSEW(Drv,Nb) (sdt->sewdrv[(Drv)-1].value.b[Nb])
|
||||
// 23-digit PEP-controllers code
|
||||
#define PEP_code_A (sdt->pep_code_a)
|
||||
#define PEP_code_Z (sdt->pep_code_z)
|
||||
#define PEP_code_P (sdt->pep_code_p)
|
||||
// PEP end-switches code
|
||||
#define switch_A (sdt->pep_sw_a)
|
||||
enum{
|
||||
Sw_minus_A = 1 // negative A value
|
||||
,Sw_plus240_A = 2 // end switch +240degr
|
||||
,Sw_minus240_A = 4 // end switch -240degr
|
||||
,Sw_minus45_A = 8 // "horizon" end switch
|
||||
};
|
||||
#define switch_Z (sdt->pep_sw_z)
|
||||
enum{
|
||||
Sw_0_Z = 1
|
||||
,Sw_5_Z = 2
|
||||
,Sw_20_Z = 4
|
||||
,Sw_60_Z = 8
|
||||
,Sw_80_Z = 0x10
|
||||
,Sw_90_Z = 0x20
|
||||
};
|
||||
#define switch_P (sdt->pep_sw_p)
|
||||
enum{
|
||||
Sw_No_P = 0 // no switches
|
||||
,Sw_22_P = 1 // 22degr
|
||||
,Sw_89_P = 2 // 89degr
|
||||
,Sw_Sm_P = 0x80 // Primary focus smoke sensor
|
||||
};
|
||||
// PEP codes
|
||||
#define PEP_code_F (sdt->pep_code_f)
|
||||
#define PEP_code_D (sdt->pep_code_d)
|
||||
#define PEP_code_Rin (sdt->pep_code_ri)
|
||||
#define PEP_code_Rout (sdt->pep_code_ro)
|
||||
// PEP flags
|
||||
#define PEP_A_On (sdt->pep_on[0])
|
||||
#define PEP_A_Off (PEP_A_On==0)
|
||||
#define PEP_Z_On (sdt->pep_on[1])
|
||||
#define PEP_Z_Off (PEP_Z_On==0)
|
||||
#define PEP_P_On (sdt->pep_on[2])
|
||||
#define PEP_P_Off (PEP_P_On==0)
|
||||
#define PEP_F_On (sdt->pep_on[3])
|
||||
#define PEP_F_Off (PEP_F_On==0)
|
||||
#define PEP_D_On (sdt->pep_on[4])
|
||||
#define PEP_D_Off (PEP_D_On==0)
|
||||
#define PEP_R_On (sdt->pep_on[5])
|
||||
#define PEP_R_Off ((PEP_R_On&1)==0)
|
||||
#define PEP_R_Inp ((PEP_R_On&2)!=0)
|
||||
#define PEP_K_On (sdt->pep_on[6])
|
||||
#define PEP_K_Off ((PEP_K_On&1)==0)
|
||||
#define PEP_K_Inp ((PEP_K_On&2)!=0)
|
||||
// IERS polar motion
|
||||
#define polarX (sdt->xpol)
|
||||
#define polarY (sdt->ypol)
|
||||
// current Julian date, sidereal time correction by "Equation of the Equinoxes"
|
||||
#define JDate (sdt->jdate)
|
||||
#define EE_time (sdt->eetime)
|
||||
// humidity value (%%) & hand input
|
||||
#define val_Hmd (sdt->val_hmd)
|
||||
#define inp_Hmd (sdt->val_hmd)
|
||||
// worm position, mkm
|
||||
#define worm_A (sdt->worm_a)
|
||||
#define worm_Z (sdt->worm_z)
|
||||
// locking flags
|
||||
#define LockFlags (sdt->lock_flags)
|
||||
enum{
|
||||
Lock_A = 1
|
||||
,Lock_Z = 2
|
||||
,Lock_P = 4
|
||||
,Lock_F = 8
|
||||
,Lock_D = 0x10
|
||||
};
|
||||
#define A_Locked (LockFlags&Lock_A)
|
||||
#define Z_Locked (LockFlags&Lock_Z)
|
||||
#define P_Locked (LockFlags&Lock_P)
|
||||
#define F_Locked (LockFlags&Lock_F)
|
||||
#define D_Locked (LockFlags&Lock_D)
|
||||
// SEW dome divers speed
|
||||
#define Dome_Speed (sdt->sew_dome_speed)
|
||||
// SEW dome drive number (for indication)
|
||||
#define DomeSEW_N (sdt->sew_dome_num)
|
||||
// SEW dome driver parameters
|
||||
#define statusSEWD (sdt->sewdomedrv.status) // controller status
|
||||
#define speedSEWD (sdt->sewdomedrv.set_speed) // speed, rpm
|
||||
#define vel_SEWD (sdt->sewdomedrv.mes_speed) /*ÉÚÍÅÒÅÎÎÁÑ ÓËÏÒÏÓÔØ ÏÂ/ÍÉÎ (rpm)*/
|
||||
#define currentSEWD (sdt->sewdomedrv.current) // current, A
|
||||
#define indexSEWD (sdt->sewdomedrv.index) // parameter index
|
||||
#define valueSEWD (sdt->sewdomedrv.value.l) // parameter value
|
||||
// dome PEP codes
|
||||
#define PEP_code_Din (sdt->pep_code_di) // data in
|
||||
#define PEP_Dome_SEW_Ok 0x200
|
||||
#define PEP_Dome_Cable_Ok 0x100
|
||||
#define PEP_code_Dout (sdt->pep_code_do) // data out
|
||||
#define PEP_Dome_SEW_On 0x10
|
||||
#define PEP_Dome_SEW_Off 0x20
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* BTA data structure *
|
||||
*******************************************************************************/
|
||||
|
||||
#define BTA_Data_Ver 2
|
||||
struct BTA_Data {
|
||||
int32_t magic; // magic value
|
||||
int32_t version; // BTA_Data_Ver
|
||||
int32_t size; // sizeof(struct BTA_Data)
|
||||
int32_t pid; // main process PID
|
||||
int32_t model; // model modes
|
||||
int32_t timer; // timer selected
|
||||
int32_t system; // main system mode
|
||||
int32_t sys_target; // system pointing target
|
||||
int32_t tel_focus; // telescope focus type
|
||||
double pc_coeff[8]; // pointing correction system coefficients
|
||||
int32_t tel_state; // telescope state
|
||||
int32_t req_state; // new (required) state
|
||||
int32_t tel_hard_state; // Power state
|
||||
int32_t tel_mode; // telescope mode
|
||||
int32_t az_mode; // azimuth reverce
|
||||
int32_t p2_state; // P2 motor state
|
||||
int32_t p2_req_mode; // P2 required state
|
||||
int32_t focus_state; // focus motor state
|
||||
int32_t dome_state; // dome motors state
|
||||
int32_t pcor_mode; // pointing correction mode
|
||||
int32_t trkok_mode; // tracking mode
|
||||
double i_alpha, i_delta; // input values
|
||||
double s_alpha, s_delta; // source
|
||||
double v_alpha, v_delta; // intrinsic vel.
|
||||
double i_azim, i_zdist; // input A/Z
|
||||
double c_alpha, c_delta; // calculated values
|
||||
double tag_a, tag_z, tag_p; // current values (from sensors)
|
||||
double pcor_a, pcor_z, refr_z; // calculated corrections
|
||||
double tcor_a, tcor_z, tref_z; // reverse calculation corr.
|
||||
double diff_a, diff_z, diff_p; // coords difference
|
||||
double vbasea,vbasez,vbasep; // base object velocity
|
||||
double diffva,diffvz,diffvp; // correction by real speed
|
||||
double speeda,speedz,speedp; // motor speed
|
||||
double m_time_precip; // last precipitation time
|
||||
uint8_t reserve[16]; // reserved
|
||||
double rspeeda, rspeedz, rspeedp; // real motor speed (''/sec)
|
||||
double simvela, simvelz, simvelp, simvelf, simveld; // model speed
|
||||
uint32_t kost; // telescope & hand correction state
|
||||
double m_time, s_time, l_time; // different time (UTC, stellar, local)
|
||||
uint32_t ppndd_a, ppndd_z, ppndd_p, ppndd_b; // PPNDD sensor (rough) code
|
||||
uint32_t dup_a, dup_z, dup_p, dup_f, dup_d; // DUP sensor (precise) code (Gray code)
|
||||
uint32_t low_a, low_z, low_p, low_f, low_d; // binary 14-digit precise code
|
||||
uint32_t code_a, code_z, code_p, code_b, code_f, code_d; // binary 23-digit rough code
|
||||
uint32_t adc[8]; // ADC PCL818 (8-channel) codes
|
||||
double val_a, val_z, val_p, val_b, val_f, val_d;
|
||||
double val_t1, val_t2, val_t3, val_wnd; // calculated values
|
||||
double val_alp, val_del; // RA/Decl calculated by A/Z
|
||||
double vel_a, vel_z, vel_p, vel_f, vel_d; // measured speed
|
||||
// system messages queue
|
||||
struct SysMesg {
|
||||
int32_t seq_num;
|
||||
char type; // message type
|
||||
char text[MesgLen]; // message itself
|
||||
} sys_msg_buf[MesgNum];
|
||||
// access levels
|
||||
uint32_t code_lev[5];
|
||||
// network settings
|
||||
uint32_t netmask, netaddr, acsmask, acsaddr;
|
||||
int32_t meteo_stat; // meteo data
|
||||
double inp_b, inp_t1, inp_t2, inp_t3, inp_wnd; // input meteo values
|
||||
double temper, press; // values used for refraction calculation
|
||||
double m_time10, m_time15; // last wind gust time
|
||||
double dut1; // IERS DUT1 (src: ftp://maia.usno.navy.mil/ser7/ser7.dat), DUT1 = UT1-UTC
|
||||
double a_time, z_time, p_time; // sensors reading time
|
||||
double speedain, speedzin, speedpin; // input speeds
|
||||
double acc_a, acc_z, acc_p, acc_f, acc_d; // acceleration (''/sec^2)
|
||||
uint32_t code_sew; // SEW code
|
||||
struct SEWdata { // sew data
|
||||
int32_t status;
|
||||
double set_speed; // target speed, rpm
|
||||
double mes_speed; // measured speed, rpm
|
||||
double current; // measured current, A
|
||||
int32_t index; // parameter number
|
||||
union{ // parameter code
|
||||
uint8_t b[4];
|
||||
uint32_t l;
|
||||
} value;
|
||||
} sewdrv[3];
|
||||
uint32_t pep_code_a, pep_code_z, pep_code_p; // 23-digit PEP-controllers code
|
||||
uint32_t pep_sw_a, pep_sw_z, pep_sw_p; // PEP end-switches code
|
||||
uint32_t pep_code_f, pep_code_d, pep_code_ri, pep_code_ro; // PEP codes
|
||||
uint8_t pep_on[10]; // PEP flags
|
||||
double xpol, ypol; // IERS polar motion (src: ftp://maia.usno.navy.mil/ser7/ser7.dat)
|
||||
double jdate, eetime; // current Julian date, sidereal time correction by "Equation of the Equinoxes"
|
||||
double val_hmd, inp_hmd; // humidity value (%%) & hand input
|
||||
double worm_a, worm_z; // worm position, mkm
|
||||
/* ÆÌÁÇÉ ÂÌÏËÉÒÏ×ËÉ ÕÐÒÁ×ÌÅÎÉÑ ÕÚÌÁÍÉ */
|
||||
uint32_t lock_flags; // locking flags
|
||||
int32_t sew_dome_speed; // SEW dome divers speed: D_Lplus, D_Hminus etc
|
||||
int32_t sew_dome_num; // SEW dome drive number (for indication)
|
||||
struct SEWdata sewdomedrv; // SEW dome driver parameters
|
||||
uint32_t pep_code_di, pep_code_do; // dome PEP codes
|
||||
};
|
||||
|
||||
extern volatile struct BTA_Data *sdt;
|
||||
|
||||
/*******************************************************************************
|
||||
* Local data structure *
|
||||
*******************************************************************************/
|
||||
// Oil pressure, MPa
|
||||
#define PressOilA (sdtl->pr_oil_a)
|
||||
#define PressOilZ (sdtl->pr_oil_z)
|
||||
#define PressOilTank (sdtl->pr_oil_t)
|
||||
// Oil themperature, degrC
|
||||
#define OilTemper1 (sdtl->t_oil_1) // oil
|
||||
#define OilTemper2 (sdtl->t_oil_2) // water
|
||||
|
||||
// Local data structure
|
||||
struct BTA_Local {
|
||||
uint8_t reserve[120]; // reserved data
|
||||
double pr_oil_a,pr_oil_z,pr_oil_t; // Oil pressure
|
||||
double t_oil_1,t_oil_2; // Oil themperature
|
||||
};
|
||||
|
||||
/**
|
||||
* Message buffer structure
|
||||
*/
|
||||
struct my_msgbuf {
|
||||
int32_t mtype; // message type
|
||||
uint32_t acckey; // client access key
|
||||
uint32_t src_pid; // source PID
|
||||
uint32_t src_ip; // IP of command source or 0 for local
|
||||
char mtext[100]; // message itself
|
||||
};
|
||||
|
||||
extern volatile struct BTA_Local *sdtl;
|
||||
extern int snd_id;
|
||||
extern int cmd_src_pid;
|
||||
extern uint32_t cmd_src_ip;
|
||||
|
||||
#define ClientSide 0
|
||||
#define ServerSide 1
|
||||
|
||||
#ifndef BTA_MODULE
|
||||
void bta_data_init();
|
||||
int bta_data_check();
|
||||
void bta_data_close();
|
||||
int get_shm_block(volatile struct SHM_Block *sb, int server);
|
||||
int close_shm_block(volatile struct SHM_Block *sb);
|
||||
void get_cmd_queue(struct CMD_Queue *cq, int server);
|
||||
#endif
|
||||
|
||||
int check_shm_block(volatile struct SHM_Block *sb);
|
||||
|
||||
void encode_lev_passwd(char *passwd, int nlev, uint32_t *keylev, uint32_t *codlev);
|
||||
int find_lev_passwd(char *passwd, uint32_t *keylev, uint32_t *codlev);
|
||||
int check_lev_passwd(char *passwd);
|
||||
void set_acckey(uint32_t newkey);
|
||||
|
||||
// restore packing
|
||||
#pragma pack(pop)
|
||||
//#pragma GCC diagnostic pop
|
||||
|
||||
#endif // __BTA_SHDATA_H__
|
||||
Reference in New Issue
Block a user