File: apl.c

package info (click to toggle)
clif 0.90.2-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 4,336 kB
  • ctags: 2,815
  • sloc: ansic: 29,914; yacc: 4,338; lex: 644; makefile: 373; sh: 48
file content (231 lines) | stat: -rw-r--r-- 3,841 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include <stdio.h>
#include <math.h>
#include <signal.h>
#include <sys/time.h>
#include <rpc/rpc.h>
#include "lin.h"

#ifndef O_RDONLY
#define O_RDONLY 00
#endif
#ifndef O_WRONLY
#define O_WRONLY 01
#endif

#define A_2 0.0000821
#define B 0.0017
#define EPS 1.e-3

static double tmp1,tmp2,tmp3,suma;


CLIENT *cl;
int *result;
static int i;
static remote_o_struct ros[] = {{"/dev/lc0",O_RDONLY,2},
				  {"/dev/lc1",O_RDONLY,2},
				  {"/dev/lc2",O_RDONLY,2},
				  {"/dev/lc3",O_RDONLY,2},
				  {"/dev/lc4",O_RDONLY,2},
				  {"/dev/lc5",O_RDONLY,2},
				  {"/dev/lc6",O_RDONLY,2},
				  {"/dev/lc7",O_RDONLY,2},
				  {"/dev/lc16",O_WRONLY,2}};
  
static remote_r_w_struct rrws[9],*res;
static char server[]="air.vm.stuba.sk";

void open_termo()
{
  
  if((cl = clnt_create(server,REMOTEDEVICE,REMOTEVERS,"tcp")) == NULL)
    {
      clnt_pcreateerror(server);
      exit(1);
    }
  for(i=0; i < 8; i++)
    {
      if((result=remote_open_1(&ros[i],cl)) == NULL)
	{
	  clnt_perror(cl,server);
	  exit(1);
	}
      if(*result == -1)
	{
	  printf("bad open\n");
	  exit(1);
	}
      rrws[i].fd = *result;
      rrws[i].bytes = 2;
    }
  if((result=remote_open_1(&ros[8],cl)) == NULL)
    {
      clnt_perror(cl,server);
      exit(1);
    }
  if(*result == -1)
    {
      printf("bad open\n");
      exit(1);
    }
      rrws[8].fd = *result;
      rrws[8].bytes = 2;
}


void read_termo(a)
     char **a;
{
  double *resu;

  resu = (double *)a[0];
  
  for(i=0; i < 8; i++)
    {
      if((res=remote_read_1(&rrws[i],cl)) == NULL)
	{
	  clnt_perror(cl,server);
	  exit(1);
	}
      if(res->bytes == -1)
	{
	  printf("bad read\n");
	  exit(1);
	}
      *(short *)rrws[i].buf = *(short *)res->buf;
      resu[i] = 5*((double)*(short *)rrws[i].buf-2048)/1024;
/*      printf("%g %d\n",resu[i],*(short *)rrws[i].buf);*/
    }
}


void write_termo(a)
     char **a;
{
  short pom;
  double dat;


  dat = *(double *)a[0];
  
  pom = (short)(2048 * dat/5);

  *(short *)rrws[8].buf = pom;
    
  if((result=remote_write_1(&rrws[8],cl)) == NULL)
    {
      clnt_perror(cl,server);
      exit(1);
    }
  if(*result == -1)
    {
      printf("bad write\n");
      exit(1);
    }
}


void close_termo()
{
  for(i=0; i < 9; i++)
    {
      if((result=remote_close_1(&rrws[i].fd,cl)) == NULL)
	{
	  clnt_perror(cl,server);
	  exit(1);
	}
    }
}


void mysig_handler()
{
}

void init_wait(a)
     char **a;
{
  struct itimerval cas_new, cas_old;
  long milisec;

  milisec = *(int *)a[0];
  
  cas_new.it_interval.tv_sec=milisec/1000;
  cas_new.it_interval.tv_usec=(milisec % 1000)*1000;
  cas_new.it_value.tv_sec=milisec/1000;
  cas_new.it_value.tv_usec=(milisec % 1000)*1000;

  setitimer(ITIMER_REAL,&cas_new,&cas_old);
  signal(SIGALRM,mysig_handler);
}


double green_func(a)
     char **a;
{
  int n=0;
  double periodic = 0;
  double lambda = 0.;
  double majorant = 0.;
  double x,t,l,tk;
  
  x = *(double *)a[0];
  t = *(double *)a[1];
  l = *(double *)a[2];
  tk = *(double *)a[3];
  
  suma = 0.;

  while(1)
    {
      periodic = (2*n + 1) * M_PI / (2 * l);
      tmp1 = sin(periodic * x);
      lambda = pow(periodic,(double)2) * A_2;
      tmp2 = exp(-lambda * (tk-t))/(2 * n + 1);
#ifdef DEBUG
      printf("tmp2 %g\n",tmp2);
#endif
      if(n == 0)
	{
	  if(tmp2 == 0.)
	    {
	      majorant = 1.;
	    }
	  else
	    {
	      majorant = fabs(tmp2);
	    }
	}
      if (fabs(tmp2) < majorant)
	{
	  if(suma == 0. && n > 5)
	    {
	      break;
	    }
	  if(fabs(suma/majorant) > 1/EPS)
	    {
	      break;
	    }
	  else
	    {
	      majorant = majorant / 10.;
	    }
	}
      tmp3 = tmp1 * tmp2 ;
      suma = suma + tmp3;
      n += 1;
    }
#ifdef DEBUG
  printf(" suma %g\n",suma);
#endif

  suma = 4. / M_PI * exp(-B * (tk-t)) * suma;
  return(suma);
}

void csigpause(a)
     char **a;
{
  sigpause(*(int *)a[0]);
}