ccs.c 44.3 KB
Newer Older
kollo's avatar
kollo committed
1 2 3 4 5 6 7 8
/* CCS.C (c) Markus Hoffmann  */

/* This file is part of X11BASIC, the basic interpreter for Unix/X
 * ============================================================
 * X11BASIC is free software and comes with NO WARRANTY - read the file
 * COPYING for details
 */

kollo's avatar
kollo committed
9 10 11
/*  bug mit notify-handler behoben      18.01.2005    (c) Markus Hoffmann*/
/*  ccs_err fuer tine verbessert        18.01.2005    (c) Markus Hoffmann*/

kollo's avatar
kollo committed
12 13
#include <stdio.h>
#include <stdlib.h>
kollo's avatar
kollo committed
14
#include <string.h>
kollo's avatar
kollo committed
15

kollo's avatar
kollo committed
16
#include "defs.h"
kollo's avatar
kollo committed
17 18
#include "x11basic.h"
#include "variablen.h"
kollo's avatar
kollo committed
19
#include "svariablen.h"
kollo's avatar
kollo committed
20 21
#include "xbasic.h"

kollo's avatar
kollo committed
22

kollo's avatar
kollo committed
23 24 25 26
#if defined CONTROL || defined TINE
static int ccs_err;
int v_ccserr() {return(ccs_err);}
#endif
kollo's avatar
kollo committed
27 28 29

/* Falls mit Kontrollsystem  */

kollo's avatar
kollo committed
30
#define MAXPIDS 250
kollo's avatar
kollo committed
31
#if defined CONTROL || defined TINE
kollo's avatar
kollo committed
32 33 34 35 36
int notify_handler(int , int , int );
int pids[MAXPIDS];
int isubs[MAXPIDS];
int pidanz=0;
#endif
kollo's avatar
kollo committed
37

kollo's avatar
kollo committed
38 39 40 41 42 43 44 45 46 47
#ifdef CONTROL

#include "ccsdef.h"
#include "piddef.h"
#include "kernel.h"
#include "supman.h"
#include "errdef.h"
#include "attrdef.h"
#include "resourcebaseman.h"

kollo's avatar
kollo committed
48

kollo's avatar
kollo committed
49
int v_ccsaplid() {return(aplid);}
kollo's avatar
kollo committed
50

kollo's avatar
kollo committed
51 52 53 54 55 56 57
/* Kontrollsystemstuff */

void cs_init() {
  ccs_attach_control( xbasic_name, &aplid );
  if (CCSERR) printf("ERROR in ccs_attach_control\n");
  else {
    /* attach to notification system */
kollo's avatar
kollo committed
58

kollo's avatar
kollo committed
59 60 61 62 63 64 65 66 67 68 69 70 71
    ccs_attach_notification( xbasic_name, CCS_NOTIFY_ASYNC, notify_handler, MAXPIDS, 1);
    if ( CCSERR ) printf ( "CCS: Keine Verbindung zum Benachrichtigungs-System: %s\n", ccs_get_error_message() );
#ifdef DEBUG
    else printf("Erfolgreich an Kontrollsystem angemeldet. aplid=%d\n",aplid);
#endif
  }
  ccs_err=CCSERR;
}

void cs_exit() {
  ccs_detach_notification();
  ccs_detach_control();
}
kollo's avatar
kollo committed
72
#endif
kollo's avatar
kollo committed
73

kollo's avatar
kollo committed
74
#if defined CONTROL || defined TINE
kollo's avatar
kollo committed
75 76
int notify_handler(int pid, int overflow, int entries) {
  int i,pc2,flag=0;
kollo's avatar
kollo committed
77
  printf("ent=%d\n",entries);
kollo's avatar
kollo committed
78 79 80 81 82
  for(i=0;i<pidanz;i++) {
    if(pids[i]==pid) {
      int oldbatch,osp=sp;
      pc2=procs[isubs[i]].zeile;
      if(sp<STACKSIZE) {stack[sp++]=pc;pc=pc2+1;}
kollo's avatar
kollo committed
83
      else xberror(75,""); /* Stack Overflow! */
kollo's avatar
kollo committed
84 85 86 87 88 89 90 91 92 93 94 95
      oldbatch=batch;batch=1;
      programmlauf();
      batch=min(oldbatch,batch);
      if(osp!=sp) {
	pc=stack[--sp]; /* wenn error innerhalb der func. */
        printf("Fehler innerhalb Interrupt-FUNCTION. \n");
      }
      flag=1;
    }
  }
  if(flag==0) printf("Uninitialisierter Interrupt: pid=%d, over=%d, ent=%d \n",pid,overflow,entries);
}
kollo's avatar
kollo committed
96 97
#endif
#ifdef CONTROL
kollo's avatar
kollo committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
int cssize(char *n) {
  int pid;
  ROUTE route;
  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) {
	printf("ERROR in ccs_convert_parametername_id\n");
	
  } else {
    /* get size of Vector */
    ccs_convert_pid_netroute( pid, &route );
    if (CCSERR) printf("ERROR in ccs_convert_pid_netroute\n");
    else return(route.size);
  }
  ccs_err=CCSERR;
  return(0);
}

int cstyp(char *n) {
kollo's avatar
kollo committed
116
  int typ=0;
kollo's avatar
kollo committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130
  int pid;
  ROUTE route;
  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) {
	printf("ERROR in ccs_convert_parametername_id\n");
	
  } else {
    if ( IS_PID_ANALOG(pid) ) typ=typ|FLOATTYP;
    else if ( IS_PID_DIGITAL(pid) ) typ=typ|INTTYP;
    else if ( IS_PID_STRING(pid) ) typ=typ|STRINGTYP;
    /* get size of Vector */
    ccs_convert_pid_netroute( pid, &route );
    if (CCSERR) printf("ERROR in ccs_convert_pid_netroute\n");
    else {
kollo's avatar
kollo committed
131
      if(route.size>1) typ=typ|ARRAYTYP;
kollo's avatar
kollo committed
132 133 134
    }
  }
  ccs_err=CCSERR;
kollo's avatar
kollo committed
135

kollo's avatar
kollo committed
136 137 138 139 140 141 142 143 144 145 146
  return(typ);
}

int cspid(char *n) {
  int pid;
  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) printf("ERROR in ccs_convert_parametername_id\n");
  ccs_err=CCSERR;
  return(pid);
}

kollo's avatar
kollo committed
147

kollo's avatar
kollo committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
char *cspname(int pid) {
  char *pname=malloc(80);
  ccs_convert_id_parametername( pid, pname );
  if (CCSERR) printf("ERROR in ccs_convert_id_parametername (%s) !\n", ccs_get_error_message());
  ccs_err=CCSERR;
  return(pname);
}

char *csunit(char *n) {
  char *unit=malloc(32);
  int pid;
  union {int i;float f;double d;} min, max;
  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) printf("ERROR in ccs_convert_parametername_id\n");
  else {
    ccs_resource_read_parameter_minmax( pid, &min, &max, unit );
    if (CCSERR) printf("ERROR in ccs_resource_read_parameter_minmax (%s) !\n", ccs_get_error_message());
  }
  ccs_err=CCSERR;
  return(unit);
}


double csget(char *n) {
kollo's avatar
kollo committed
172

kollo's avatar
kollo committed
173 174 175
  int pid,j;
  float data;
  int i;
kollo's avatar
kollo committed
176

kollo's avatar
kollo committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) printf("ERROR in ccs_convert_parametername_id\n");
  else {

/* switch appropriate to type */

    if ( IS_PID_ANALOG(pid) ) {
      ccs_get_value( pid, &data, &j, 1, NULL );
      if (CCSERR) printf("ERROR in ccs_get_value: %s\n", ccs_get_error_message());
      else return((double)data);
    } else if ( IS_PID_DIGITAL(pid) ) {
      ccs_get_value( pid, &i, &j, 1, NULL );
      if (CCSERR) printf("ERROR in ccs_get_value: %s\n", ccs_get_error_message());
      else return((double)i);
    } else 	printf("Csget: Parameter hat falschen Typ %s\n",n);
  }
  return(0.0);
}

double csmin(char *n) {
kollo's avatar
kollo committed
197

kollo's avatar
kollo committed
198 199 200
  int pid;
  char unit[32];
  union {int i;float f;double d; char *s;} min,max;
kollo's avatar
kollo committed
201

kollo's avatar
kollo committed
202 203 204 205 206 207 208 209 210 211 212
  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) printf("ERROR in ccs_convert_parametername_id\n");
  else {
    ccs_resource_read_parameter_minmax( pid, &min, &max, unit );
    if (CCSERR) printf(" ERROR in ccs_resource_read_parameter_minmax: %s\n", ccs_get_error_message());
/* switch appropriate to type */

    if ( IS_PID_ANALOG(pid) ) return((double)min.f);
    else if ( IS_PID_DIGITAL(pid) ) return((double)min.i);
    else 	printf("Csget: Parameter hat falschen Typ %s\n",n);
  }
kollo's avatar
kollo committed
213

kollo's avatar
kollo committed
214 215 216
  return(0.0);
}
double csmax(char *n) {
kollo's avatar
kollo committed
217

kollo's avatar
kollo committed
218 219 220
  int pid;
  char unit[32];
  union {int i;float f;double d; char *s;} min,max;
kollo's avatar
kollo committed
221

kollo's avatar
kollo committed
222 223 224 225 226 227 228 229 230 231 232
  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) printf("ERROR in ccs_convert_parametername_id\n");
  else {
    ccs_resource_read_parameter_minmax( pid, &min, &max, unit );
    if (CCSERR) printf(" ERROR in ccs_resource_read_parameter_minmax: %s\n", ccs_get_error_message());
/* switch appropriate to type */

    if ( IS_PID_ANALOG(pid) ) return((double)max.f);
    else if ( IS_PID_DIGITAL(pid) ) return((double)max.i);
    else 	printf("Csget: Parameter hat falschen Typ %s\n",n);
  }
kollo's avatar
kollo committed
233

kollo's avatar
kollo committed
234 235 236
  return(0.0);
}
double csres(char *n) {
kollo's avatar
kollo committed
237

kollo's avatar
kollo committed
238 239
  int pid;
  union {int i;float f;double d; char *s;} res;
kollo's avatar
kollo committed
240

kollo's avatar
kollo committed
241 242 243
  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) printf("ERROR in ccs_convert_parametername_id\n");
  else {
kollo's avatar
kollo committed
244

kollo's avatar
kollo committed
245
    ccs_resource_read_parameter_resolution( pid, &res, NULL );
kollo's avatar
kollo committed
246

kollo's avatar
kollo committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260

    if (CCSERR) printf(" ERROR in ccs_resource_read_parameter_resolution: %s\n", ccs_get_error_message());
    if ( IS_PID_ANALOG(pid) ) return((double)res.f);
    else if ( IS_PID_DIGITAL(pid) ) return((double)res.i);
    else 	printf("Csget: Parameter hat falschen Typ %s\n",n);
  }
  return(0.0);
}


ARRAY *csvget(char *n,int nn, int o) {
  int pid,j;
  ROUTE route;
  ARRAY *ergebnis=malloc(sizeof(ARRAY));
kollo's avatar
kollo committed
261

kollo's avatar
kollo committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
  ergebnis->dimension=1;
  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) {
	printf("ERROR in ccs_convert_parametername_id\n");
	ergebnis->pointer=malloc(40);
	((int *)ergebnis->pointer)[0]=1;
        return(ergebnis);
  } else {
    if(nn==0) {
      /* get size of Vector */
      ccs_convert_pid_netroute( pid, &route );
      if (CCSERR) {
	printf("ERROR in ccs_convert_pid_netroute\n");
	nn=1;
      } else nn=route.size;
    }
    /* switch appropriate to type */

    if ( IS_PID_ANALOG(pid) ) {
        double *varptr;
	float *fpt;
        ergebnis->typ=FLOATARRAYTYP;
	ergebnis->pointer=malloc(1*INTSIZE+nn*sizeof(double));
	((int *)ergebnis->pointer)[0]=nn;
	varptr=ergebnis->pointer+INTSIZE;
kollo's avatar
kollo committed
287
	fpt=malloc(nn*sizeof(float));
kollo's avatar
kollo committed
288 289 290 291 292 293 294 295 296 297
	ccs_get_subvector( pid,fpt, &j, o, nn, NULL );
	for(j=0;j<nn;j++) varptr[j]=(double)fpt[j];
	free(fpt);
	if (CCSERR) printf("ERROR in ccs_get_subvector: %s\n", ccs_get_error_message());
	return(ergebnis);
    } else if ( IS_PID_DIGITAL(pid) ) {
        int *varptr;
        ergebnis->typ=INTARRAYTYP;
	ergebnis->pointer=malloc(1*INTSIZE+nn*sizeof(int));
	((int *)ergebnis->pointer)[0]=nn;
kollo's avatar
kollo committed
298
	varptr=ergebnis->pointer+INTSIZE;
kollo's avatar
kollo committed
299 300 301 302
	ccs_get_subvector( pid, varptr, &j,o,nn, NULL );
	if (CCSERR) printf("ERROR in ccs_get_subvector: %s\n", ccs_get_error_message());
	return(ergebnis);
    } else {
kollo's avatar
kollo committed
303
	xberror(46,n); /* Parameter hat falschen Typ */
kollo's avatar
kollo committed
304 305 306 307 308 309
	return(ergebnis);
    }
  }
}

char *csgets(char *n) {
kollo's avatar
kollo committed
310

kollo's avatar
kollo committed
311
  int pid;
kollo's avatar
kollo committed
312 313 314 315 316

  ccs_convert_parametername_id(n, &pid );
  if (CCSERR) {
    printf("ERROR in ccs_convert_parametername_id\n");
    ccs_err=CCSERR;
kollo's avatar
kollo committed
317
    return(strdup("<ERROR>"));
kollo's avatar
kollo committed
318 319 320 321 322 323
  } else {

/* switch appropriate to type */

    if ( IS_PID_STRING(pid) ) {
      int bytes;
kollo's avatar
kollo committed
324
      char s[256];
kollo's avatar
kollo committed
325 326 327 328
      ccs_get_value( pid, s, &bytes, sizeof(s), NULL );
      if (CCSERR) {
        printf("ERROR in ccs_get_value: %s\n", ccs_get_error_message());
	ccs_err=CCSERR;
kollo's avatar
kollo committed
329
        return(strdup("<ERROR>"));
kollo's avatar
kollo committed
330
      }
kollo's avatar
kollo committed
331
      ccs_err=CCSERR;
kollo's avatar
kollo committed
332
      return(strdup(s));
kollo's avatar
kollo committed
333
    } else {
kollo's avatar
kollo committed
334
      xberror(47,n); /* Parameter hat falschen Typ */
kollo's avatar
kollo committed
335
      ccs_err=CCSERR;
kollo's avatar
kollo committed
336
      return(strdup("<ERROR>"));
kollo's avatar
kollo committed
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
    }
  }
}
void c_cssetcallback(char *n) {
  int i,flag,newpid,pc2;
  char w1[strlen(n)+1],w2[strlen(n)+1];
  char *test;
  int e=wort_sep(n,',',TRUE,w1,w2);
  if(e<2) {
    printf("Syntax-Error bei CSSETCALLBACK. <%s>\n",n);
    return;
  }
  test=s_parser(w1);
  ccs_convert_parametername_id(test, &newpid );
  if (CCSERR) {
	printf("ERROR in ccs_convert_parametername_id <%s>\n",test);
        free(test);
        ccs_err=CCSERR;
        return;
kollo's avatar
kollo committed
356
  }
kollo's avatar
kollo committed
357 358
  free(test);
  pc2=procnr(w2,1);
kollo's avatar
kollo committed
359
  if(pc2==-1)   xberror(19,w2); /* Procedure nicht gefunden */
kollo's avatar
kollo committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
  else {
    if(pidanz<MAXPIDS) {
    ccs_disable_ccs_interrupts();
    ccs_release_interest(pids, pidanz, NULL);
    flag=-1;
    for(i=0;i<pidanz;i++) {
      if(pids[i]==newpid) flag=i;
    }
    if(flag==-1) {
      pids[pidanz]=newpid;
      isubs[pidanz++]=pc2;
    } else isubs[flag]=pc2;
    ccs_declare_interest(pids, pidanz  );
    ccs_enable_ccs_interrupts();
    } else printf("Zu viele Callbacks. max. <%d>\n",MAXPIDS);
  }
}

void c_csclearcallbacks(char *n) {
  ccs_release_interest(pids, pidanz, NULL);
  ccs_disable_ccs_interrupts();
}

void c_csvput(char *w) {
  char n[strlen(w)+1],t[strlen(w)+1];
  char *test,*r;
  int pid,j,e,i,nn,typ,vnr,o=0;
  float f;
  ROUTE route;
  e=wort_sep(w,',',TRUE,n,t);
  if(e<2) {
    printf("Syntax-Error bei CSPUT. <%s>\n",w);
    return;
  }
  test=s_parser(n);
  ccs_convert_parametername_id(test, &pid );
  if (CCSERR) {
	printf("ERROR in ccs_convert_parametername_id <%s>\n",test);
        free(test);
        ccs_err=CCSERR;
        return;
kollo's avatar
kollo committed
401
  }
kollo's avatar
kollo committed
402 403
  free(test);
  e=wort_sep(t,',',TRUE,n,t);
kollo's avatar
kollo committed
404

kollo's avatar
kollo committed
405 406 407 408 409 410 411
      /* get size of Vector */
  ccs_convert_pid_netroute( pid, &route );
  if (CCSERR) {
    printf("ERROR in ccs_convert_pid_netroute\n");
    nn=1;
  } else nn=route.size;
  if(e==2) nn=min(nn,(int)parser(t));
kollo's avatar
kollo committed
412

kollo's avatar
kollo committed
413
     /* Typ bestimmem. Ist es Array ? */
kollo's avatar
kollo committed
414

kollo's avatar
kollo committed
415
    typ=type(n)&(~CONSTTYP);
kollo's avatar
kollo committed
416 417 418 419
    if(typ & ARRAYTYP) {
      r=varrumpf(n);
      vnr=variable_exist(r,typ);
      free(r);
kollo's avatar
kollo committed
420
      if(vnr==-1) xberror(15,n); /* Feld nicht dimensioniert */
kollo's avatar
kollo committed
421 422
      else {
        int anz=min(do_dimension(vnr),nn);
kollo's avatar
kollo committed
423
        if((typ&TYPMASK)!=FLOATTYP && (typ&TYPMASK)!=INTTYP) {printf("CSVPUT: Muss Float-ARRAY sein. \n");return;}
kollo's avatar
kollo committed
424 425 426 427 428 429


	/*  printf("CSVPUT: pid=%d, vnr=%d, nn=%d, anz=%d \n",pid,vnr,nn,anz); */

	if ( IS_PID_ANALOG(pid) ) {
          float *buffer=calloc(anz,sizeof(float));
kollo's avatar
kollo committed
430
	
kollo's avatar
kollo committed
431
	  if((typ&TYPMASK)==FLOATTYP) {
kollo's avatar
kollo committed
432 433
	    double *varptr=(double  *)(variablen[vnr].pointer+variablen[vnr].opcode*INTSIZE);
	    for(i=0;i<anz;i++) buffer[i]=(float)varptr[i];
kollo's avatar
kollo committed
434
          } else if((typ&TYPMASK)==INTTYP) {
kollo's avatar
kollo committed
435 436
	    int *varptr=(int  *)(variablen[vnr].pointer+variablen[vnr].opcode*INTSIZE);
	    for(i=0;i<anz;i++) buffer[i]=(float)varptr[i];
kollo's avatar
kollo committed
437 438
	  }
	
kollo's avatar
kollo committed
439 440 441 442 443 444
	  /* Schreiben !!! */
	  if(o) {
            ccs_put_subvector( pid,o,anz, buffer, &j);
	    if (CCSERR) printf("ERROR in ccs_put_subvector: %s\n", ccs_get_error_message());
	  } else {
	    ccs_put_value_secure( pid, anz, buffer, &j );
kollo's avatar
kollo committed
445
	    if (CCSERR)   printf("ERROR in ccs_set_value: %s\n", ccs_get_error_message());
kollo's avatar
kollo committed
446
	  }
kollo's avatar
kollo committed
447
	
kollo's avatar
kollo committed
448 449 450
          free(buffer);
	} else if ( IS_PID_DIGITAL(pid) ) {
	  int *buffer=calloc(anz,sizeof(int));
kollo's avatar
kollo committed
451
	  if((typ&TYPMASK)==FLOATTYP) {
kollo's avatar
kollo committed
452 453
	    double *varptr=(double  *)(variablen[vnr].pointer+variablen[vnr].opcode*INTSIZE);
	    for(i=0;i<anz;i++) buffer[i]=(int)varptr[i];
kollo's avatar
kollo committed
454
          } else if((typ&TYPMASK)==INTTYP) {
kollo's avatar
kollo committed
455 456
	    int *varptr=(int  *)(variablen[vnr].pointer+variablen[vnr].opcode*INTSIZE);
	    for(i=0;i<anz;i++) buffer[i]=(int)varptr[i];
kollo's avatar
kollo committed
457 458
	  }
	
kollo's avatar
kollo committed
459 460 461 462 463 464
	  /* Schreiben !!! */
	  if(o) {
	    ccs_put_subvector( pid,o,anz, buffer, &j);
	    if (CCSERR) printf("ERROR in ccs_put_subvector: %s\n", ccs_get_error_message());
	  } else {
	    ccs_put_value_secure( pid, anz, buffer, &j );
kollo's avatar
kollo committed
465
	    if (CCSERR)   printf("ERROR in ccs_set_value: %s\n", ccs_get_error_message());
kollo's avatar
kollo committed
466 467 468 469
	  }
	  free(buffer);
        } else printf("Csvput: Parameter hat falschen Typ %s\n",n);
      }
kollo's avatar
kollo committed
470 471
      ccs_err=CCSERR;
    } else printf("CSVPUT: Kein ARRAY. \n");
kollo's avatar
kollo committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
}



void c_csput(char *w) {


 char n[strlen(w)+1],t[strlen(w)+1];
 char *test;
 int pid,j,e,i;
 float f;
  e=wort_sep(w,',',TRUE,n,t);
  if(e<2) {
    printf("Syntax-Error bei CSPUT. <%s>\n",w);
    return;
  }
  test=s_parser(n);
  ccs_convert_parametername_id(test, &pid );
  if (CCSERR) {
	printf("ERROR in ccs_convert_parametername_id <%s>\n",test);
        free(test);
        ccs_err=CCSERR;
        return;
kollo's avatar
kollo committed
495
  }
kollo's avatar
kollo committed
496 497 498
  free(test);
/* switch appropriate to type */

kollo's avatar
kollo committed
499
    if ( IS_PID_ANALOG(pid) &&  ((type(t)&TYPMASK)==FLOATTYP ||(type(t)&TYPMASK)==INTTYP)) {
kollo's avatar
kollo committed
500 501
        f=(float)parser(t);
        ccs_put_value_secure( pid, 1, &f, &j );
kollo's avatar
kollo committed
502
	if (CCSERR)   printf("ERROR in ccs_set_value: %s\n", ccs_get_error_message());
kollo's avatar
kollo committed
503
    } else if ( IS_PID_DIGITAL(pid) && ((type(t)&TYPMASK)==FLOATTYP ||(type(t)&TYPMASK)==INTTYP)) {
kollo's avatar
kollo committed
504 505
	i=(int)parser(t);
	ccs_put_value_secure( pid, 1, &i, &j );
kollo's avatar
kollo committed
506
	if (CCSERR)   printf("ERROR in ccs_set_value: %s\n", ccs_get_error_message());
kollo's avatar
kollo committed
507
    } else if ( IS_PID_STRING(pid) && ((type(t)&TYPMASK)==STRINGTYP) ) {
kollo's avatar
kollo committed
508 509 510
        test=s_parser(t);
        ccs_put_value_secure( pid, strlen(test), test, &j );
	free(test);
kollo's avatar
kollo committed
511
	if (CCSERR)   printf("ERROR in ccs_set_value: %s\n", ccs_get_error_message());
kollo's avatar
kollo committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
    } else printf("Csput: Parameter hat falschen Typ %s\n",w);
  ccs_err=CCSERR;
}

void c_cssweep(char *w) {

/* CSSWEEP a$,endwert,stepweite,delay   */

 char n[strlen(w)+1],t[strlen(w)+1];
 char *test;
 int pid,j,e;
  e=wort_sep(w,',',TRUE,n,t);
  if(e<2) {
    printf("Syntax-Error bei CSSWEEP. <%s>\n",w);
    return;
  }
  test=s_parser(n);
  ccs_convert_parametername_id(test, &pid );
  if (CCSERR) {
	printf("ERROR in ccs_convert_parametername_id <%s>\n",test);
        free(test);
        return;
kollo's avatar
kollo committed
534
  }
kollo's avatar
kollo committed
535 536 537
  free(test);
/* switch appropriate to type */

kollo's avatar
kollo committed
538
    if ( IS_PID_ANALOG(pid) && (type(t)&TYPMASK)==FLOATTYP) {
kollo's avatar
kollo committed
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
        float end,deltatime;
	int nsteps;
	e=wort_sep(t,',',TRUE,n,t);
        end=(float)parser(n);
	e=wort_sep(t,',',TRUE,n,t);
        nsteps=(int)parser(n);
	e=wort_sep(t,',',TRUE,n,t);
        deltatime=(float)parser(n);
	if(e==0) printf("CSSWEEP: Zu wenig Parameter.\n");
        else {
	  float startvalue,minval,maxval,data;
	  ccs_get_value(pid, &startvalue, &j, 1, NULL );
          if (CCSERR) {
                 printf("CSSWEEP: %s\n", ccs_get_error_message());
		 return;
          }
	  /* get lower and upper boundary values */
          ccs_resource_read_parameter_minmax( pid, &minval, &maxval, NULL );
          if (CCSERR) {
                 printf("CSSWEEP: %s\n", ccs_get_error_message());
                 return;
          }
	  data=startvalue;
	  sweep_value( pid,startvalue, end, deltatime, nsteps );
	  ccs_put_value( pid, 1, &end, &j );  /* force last value to be exact */
	  if (CCSERR) {
		printf("CSSWEEP: %s\n", ccs_get_error_message());
		return;
	  }
        }
    } else printf("Cssweep: Parameter hat falschen Typ, muss analog sein. %s\n",w);
}

/* sweep for last value to new value 'v' within time dt, and use 'steps' steps */

void sweep_value( int pid, float lastvalue, float v, float dt, int steps ) {
  float ddt,dv,tv;
  int i, ret, wrt;

  dv=(v-lastvalue)/steps;  /* compute delta value */
  ddt=dt/steps;            /* compute intermediate delay */

	/* sweep value now */

	for (tv = lastvalue, i=0; i<steps; i++, tv += dv) {
		ccs_put_value( pid, 1, &tv, &wrt );
		if (CCSERR) {
			printf("CSSWEEP: %s\n", ccs_get_error_message());
			/* ignore intermediate errors */
		}
		ccs_wait(ddt); /* and wait intermediate delay */
kollo's avatar
kollo committed
590
	}
kollo's avatar
kollo committed
591 592 593
}

#endif
kollo's avatar
kollo committed
594 595 596



kollo's avatar
kollo committed
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611















kollo's avatar
kollo committed
612
/* Mit DESY-Kontrollsystem */
kollo's avatar
kollo committed
613

kollo's avatar
kollo committed
614
#ifdef TINE
kollo's avatar
kollo committed
615
#ifdef WINDOWS
kollo's avatar
kollo committed
616 617 618 619 620 621 622
  #include "rpctypes.h"
  #define RPCERR_SIZE 32
  extern char RPCLastErrorString[RPCERR_SIZE];
  extern unsigned short MaxPollingRate;
  extern int defaultClientTimeout;
  #define defaultClientTimeoutMsec defaultClientTimeout
  #include "servdef.h"
kollo's avatar
kollo committed
623
#else
kollo's avatar
kollo committed
624 625 626 627 628
  #include "tine/prolog.h"
  #include "tine/errors.h"
  #include "tine/rpctypes.h"
  #include "tine/toolkit.h"
  #include "tine/servdef.h"
kollo's avatar
kollo committed
629
#endif
kollo's avatar
kollo committed
630 631 632 633

extern int nofeclog;
extern int ListenForGlobals;
extern int ListenForMCasts;
kollo's avatar
kollo committed
634
extern int NGdebug;
kollo's avatar
kollo committed
635 636


kollo's avatar
kollo committed
637
/* Verhindert, dass Logfile angelegt wird und bestimmt die Geschwindigkeit der
kollo's avatar
kollo committed
638 639 640
   Abfragen */

void fix_tine_start() {
kollo's avatar
kollo committed
641 642
   /*    MaxNumConnections = 3;  */
  /*  ListenForGlobals = ListenForMCasts = FALSE; */
kollo's avatar
kollo committed
643 644
    /* MaxPollingRate = MinPollingRate = 200; */
    MaxPollingRate = MinPollingRate = 50;
kollo's avatar
kollo committed
645
   /* nofeclog = TRUE; */
kollo's avatar
kollo committed
646
    defaultClientTimeout=100;
kollo's avatar
kollo committed
647
    NGdebug=2;   /* hier wollen wir spaeter mal eine 0 haben */
kollo's avatar
kollo committed
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
}
extern void closeClients(void);

void tine_init() {
  static int flag=0;
  if(flag) return;
  fix_tine_start();
 
  initClient();
  atexit(closeClients);
  flag=1;
}



void tmonitorCallback(int id,int cc) {
  if (cc) printf("Callback id=%d : TRC error %d : %s\n",id,cc,GetRPCLastError(cc));
  else notify_handler(id,0,GetCompletionDataSizeFromCallbackId(id));
kollo's avatar
kollo committed
666
}
kollo's avatar
kollo committed
667

kollo's avatar
kollo committed
668
int my_ExecLinkEx(char *dev, char *prop, DTYPE *dout, DTYPE *din,short access,int buflen) {
kollo's avatar
kollo committed
669
  int rc,retry=0;
kollo's avatar
kollo committed
670 671
  fix_tine_start();
  rc=ExecLinkEx(dev,prop,dout,din,access,buflen);
kollo's avatar
kollo committed
672
  if(rc==98) {retry=4; defaultClientTimeout=1000;MaxPollingRate = MinPollingRate = 200;}
kollo's avatar
kollo committed
673 674 675 676 677 678 679 680 681 682
  while(retry-- && rc!=0) {
    if(rc) printf("retry(%d) with %d\n",retry,rc);
    rc=ExecLinkEx(dev,prop,dout,din,access,buflen);
  }
  return(rc);
}

int GetPropertyInformation(char *srv,char *prp,PropertyQueryStruct *srvProps){
  DTYPE dout,din;
  int cc = 0;
kollo's avatar
kollo committed
683

kollo's avatar
kollo committed
684 685 686 687 688 689
  din.dFormat = CF_NAME32;
  din.dArrayLength = 1;
  din.data.vptr = prp;
  dout.dFormat = CF_STRUCT;
  dout.dArrayLength = PROPERTYQUERYSTRUCT_SIZE;
  dout.data.vptr = srvProps;
kollo's avatar
kollo committed
690
  if((cc=my_ExecLinkEx(srv,"PROPS",&dout,&din,CA_READ|CA_RETRY,500))!=0) return cc;
kollo's avatar
kollo committed
691
  srvProps->prpSize=ISWAP(srvProps->prpSize);
kollo's avatar
kollo committed
692 693 694 695 696 697 698 699
  return 0;
}
#if 0
int tservers(char *cnt) {
  int i,cc,n = 256;
  NAME16 srvs[256];
  if ((cc=GetDeviceServersEx(cnt,srvs,&n)) != 0) return cc;
  printf("%d servers found :\n",n);
kollo's avatar
kollo committed
700
  for (i=0; i<n; i++)
kollo's avatar
kollo committed
701 702 703 704 705 706 707 708 709 710 711
  {
    printf("%16s ",srvs[i].name);
    if ((i+1)%4 == 0) printf("\n");
  }
  return 0;
}
int tprops(char *dev) {
  int i,cc,n = 256;
  NAME32 prps[256];
  if ((cc=GetDeviceProperties(dev,prps,&n)) != 0) return cc;
  printf("%d properties found :\n",n);
kollo's avatar
kollo committed
712
  for (i=0; i<n; i++)
kollo's avatar
kollo committed
713 714 715 716 717 718 719 720 721 722 723 724
  {
    printf("%32s ",prps[i].name);
    if ((i+1)%4 == 0) printf("\n");
  }
  return 0;
}
int tdevs(char *dev) {
  int i,cc,n = 256;
  NAME16 devs[256];
  char devname[32];
  if ((cc=GetDeviceNames(dev,devs,&n)) != 0) return cc;
  printf("%d devices found :\n",n);
kollo's avatar
kollo committed
725
  for (i=0; i<n; i++)
kollo's avatar
kollo committed
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
  {
    strncpy(devname,devs[i].name,16);
    if (devname[15] == '&')
    {
      i++; devname[15] = 0;
      strncat(devname,devs[i].name,16);
    }
    printf("%32s ",devname);
    if ((i+1)%4 == 0) printf("\n");
  }
  return 0;
}
#endif

/* DEVICE[PROPERTY]     */

int convert_name_convention(char *input,char *device, char *property){
kollo's avatar
kollo committed
743
  int flag=0;
kollo's avatar
kollo committed
744 745 746 747
  while(*input!='[' && *input!=0) {*device=*input;device++;input++;}
  *device=0;
  if(*input!='[') return(-1);
   input++;
kollo's avatar
kollo committed
748 749 750 751 752
  while((*input!=']' || flag) && *input!=0) {
    if(*input==']' && flag) flag--;
    else if(*input=='[') flag++;
    *property=*input; property++;input++;
  }
kollo's avatar
kollo committed
753
   if(*input!=']') return(-2);
kollo's avatar
kollo committed
754
  *property=0;
kollo's avatar
kollo committed
755 756 757 758
  return(0);
}
int tinesize(char *n) {
  char dev[strlen(n)+1],prop[strlen(n)+1];
kollo's avatar
kollo committed
759
  if(convert_name_convention(n,dev,prop)) printf("Syntax-Error in Parameter-Name %s\n",n);
kollo's avatar
kollo committed
760 761 762
  else {
    PropertyQueryStruct prpinfo;
    /* get size of Vector */
kollo's avatar
kollo committed
763
    if(ccs_err=GetPropertyInformation(dev,prop,&prpinfo))
kollo's avatar
kollo committed
764
      printf("Tine-Error: %d  %s\n",ccs_err,erlst[ccs_err]);
kollo's avatar
kollo committed
765 766 767 768 769 770
    else return(prpinfo.prpSize);
  }
  return(0);
}
int tinetyp(char *n) {
  char w1[strlen(n)+1],w2[strlen(n)+1];
kollo's avatar
kollo committed
771
  if(ccs_err=convert_name_convention(n,w1,w2))
kollo's avatar
kollo committed
772
	printf("Syntax-Error %d in Parameter-Name %s\n",ccs_err,n);
kollo's avatar
kollo committed
773 774
  else {
    PropertyQueryStruct prpinfo;
kollo's avatar
kollo committed
775

kollo's avatar
kollo committed
776
    /* get size of Vector */
kollo's avatar
kollo committed
777 778
    ccs_err=GetPropertyInformation(w1,w2,&prpinfo);
    if(ccs_err) printf("Tine-Error: %d  %s\n",ccs_err,erlst[ccs_err]);
kollo's avatar
kollo committed
779 780 781 782 783 784 785 786 787 788 789
    else {
      int typ=0,f=LFMT(prpinfo.prpFormat);
      if(f==CF_BYTE) typ=typ|STRINGTYP;
      else if(f==CF_SHORT) typ=typ|INTTYP;
      else if(f==CF_LONG) typ=typ|INTTYP;
      else if(f==CF_FLOAT) typ=typ|FLOATTYP;
      else if(f==CF_DOUBLE) typ=typ|FLOATTYP;
      else if(f==CF_TEXT) typ=typ|STRINGTYP;
      else if(f==CF_NAME16) typ=typ|STRINGTYP;
      else if(f==CF_NAME32) typ=typ|STRINGTYP;
      else printf("Unbekannter Paramertertyp: %d\n",prpinfo.prpFormat);
kollo's avatar
kollo committed
790
      if(prpinfo.prpSize>1) typ=typ|ARRAYTYP;
kollo's avatar
kollo committed
791 792 793 794 795 796 797 798
      return(typ);
    }
  }
  return(0);
}
char *tineunit(char *n) {
  char *unit=malloc(80);
  char w1[strlen(n)+1],w2[strlen(n)+1];
kollo's avatar
kollo committed
799 800 801
  ccs_err=convert_name_convention(n,w1,w2);
  if(ccs_err) printf("Syntax-Error %d in Parameter-Name %s\n",ccs_err,n);
  else {
kollo's avatar
kollo committed
802
    float mmax,mmin;
kollo's avatar
kollo committed
803
    fix_tine_start();
kollo's avatar
kollo committed
804 805
    ccs_err=GetDevicePropertyEGU(w1,w2,&mmax,&mmin,unit);
    if(ccs_err) printf("Tine-Error: %d  %s\n",ccs_err,erlst[ccs_err]);
kollo's avatar
kollo committed
806 807 808 809 810 811 812
  }
  return(unit);
}
char *tineinfo(char *n) {
  char *des=malloc(80);
  char w1[strlen(n)+1],w2[strlen(n)+1];
  int rc=convert_name_convention(n,w1,w2);
kollo's avatar
kollo committed
813
  ccs_err=rc;
kollo's avatar
kollo committed
814
  if(rc)
kollo's avatar
kollo committed
815
	printf("Syntax-Error %d in Parameter-Name %s\n",rc,n);
kollo's avatar
kollo committed
816
  else {
kollo's avatar
kollo committed
817 818 819 820 821 822 823 824 825 826 827
    PropertyQueryStruct prpinfo;
    rc=GetPropertyInformation(w1,w2,&prpinfo);
    strncpy(des,prpinfo.prpDescription,80);
    if(rc) printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
  }
  return(des);
}
double tinemin(char *n) {
  char unit[80];float mmax,mmin;
  char w1[strlen(n)+1],w2[strlen(n)+1];
  int rc=convert_name_convention(n,w1,w2);
kollo's avatar
kollo committed
828 829
  ccs_err=rc;
  if(rc)
kollo's avatar
kollo committed
830 831 832
	printf("Syntax-Error %d in Parameter-Name %s\n",rc,n);
   else {
    float mmax,mmin;
kollo's avatar
kollo committed
833
    fix_tine_start();
kollo's avatar
kollo committed
834 835 836 837 838 839 840 841 842
    rc=GetDevicePropertyEGU(w1,w2,&mmax,&mmin,unit);
     if(rc) printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
  }
  return((double)mmin);
}
double tinemax(char *n) {
  char unit[80];float mmax,mmin;
  char w1[strlen(n)+1],w2[strlen(n)+1];
  int rc=convert_name_convention(n,w1,w2);
kollo's avatar
kollo committed
843
  ccs_err=rc;
kollo's avatar
kollo committed
844 845
  if(rc)  printf("Syntax-Error %d in Parameter-Name %s\n",rc,n);
  else {
kollo's avatar
kollo committed
846
    fix_tine_start();
kollo's avatar
kollo committed
847
    rc=GetDevicePropertyEGU(w1,w2,&mmax,&mmin,unit);
kollo's avatar
kollo committed
848
    ccs_err=rc;
kollo's avatar
kollo committed
849
    if(rc) printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
kollo's avatar
kollo committed
850 851 852 853 854 855 856 857 858
  }
  return((double)mmax);
}
double tineget(char *n) {
  char w1[strlen(n)+1],w2[strlen(n)+1];
  int rc=convert_name_convention(n,w1,w2);
  char *buf;
  int buflen;
  double ergeb;
kollo's avatar
kollo committed
859
  if(rc)
kollo's avatar
kollo committed
860 861
	printf("Syntax-Error %d in Parameter-Name %s\n",rc,n);
  else {
kollo's avatar
kollo committed
862
    PropertyQueryStruct prpinfo;
kollo's avatar
kollo committed
863
    DTYPE dout;
kollo's avatar
kollo committed
864

kollo's avatar
kollo committed
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896
    /* get size of Vector */
    rc=GetPropertyInformation(w1,w2,&prpinfo);
    if(rc) {
      printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
      return(0);
    }
    buflen=prpinfo.prpSize*getFormatSize(LFMT(prpinfo.prpFormat));
    buf=malloc(buflen);
    dout.dFormat = LFMT(prpinfo.prpFormat);
    dout.dArrayLength = prpinfo.prpSize;
    dout.dTag[0] = 0;
    dout.data.vptr = buf;
    rc=my_ExecLinkEx(w1,w2,&dout,NULL,CA_READ,buflen);
    if(rc) {
      printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
    } else {
      switch (LFMT(prpinfo.prpFormat)) {
    case CF_BYTE:
      ergeb=(double)(*(char *)buf); break;
    case CF_SHORT:
      ergeb=(double)(*(short *)buf);break;
    case CF_LONG:
      ergeb=(double)(*(long *)buf);break;
    case CF_FLOAT:
      ergeb=(double)(*(float *)buf);break;
    case CF_DOUBLE:
      ergeb=(double)(*(double *)buf);break;
    default: printf("output format type %d is not a number !\n",LFMT(prpinfo.prpFormat));
      }
    }
    free(buf);
  }
kollo's avatar
kollo committed
897
  ccs_err=rc;
kollo's avatar
kollo committed
898 899 900 901 902 903 904 905 906 907 908 909
  return(ergeb);
}

STRING tinegets(char *n) {
  char w1[strlen(n)+1],w2[strlen(n)+1];
  int rc=convert_name_convention(n,w1,w2);
  char *buf;
  int buflen;
  STRING ergebnis;

  if(rc) {
	printf("Syntax-Error %d in Parameter-Name %s\n",rc,n);
kollo's avatar
kollo committed
910
        ergebnis=vs_error();
kollo's avatar
kollo committed
911
  } else {
kollo's avatar
kollo committed
912
    PropertyQueryStruct prpinfo;
kollo's avatar
kollo committed
913
    DTYPE dout;
kollo's avatar
kollo committed
914

kollo's avatar
kollo committed
915 916 917 918
    /* get size of Vector */
    rc=GetPropertyInformation(w1,w2,&prpinfo);
    if(rc) {
      printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
kollo's avatar
kollo committed
919
        ergebnis=vs_error();
kollo's avatar
kollo committed
920 921 922 923 924 925 926 927 928 929 930
    } else {
      buflen=prpinfo.prpSize*getFormatSize(LFMT(prpinfo.prpFormat));
      buf=malloc(buflen);
      dout.dFormat = LFMT(prpinfo.prpFormat);
      dout.dArrayLength = prpinfo.prpSize;
      dout.dTag[0] = 0;
      dout.data.vptr = buf;
      rc=my_ExecLinkEx(w1,w2,&dout,NULL,CA_READ,buflen);
      if(rc) {
        printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
	free(buf);
kollo's avatar
kollo committed
931
	ergebnis=vs_error();
kollo's avatar
kollo committed
932
      } else {
kollo's avatar
kollo committed
933
#if 0
kollo's avatar
kollo committed
934
        switch (LFMT(prpinfo.prpFormat)) {
kollo's avatar
kollo committed
935 936 937 938
          case CF_BYTE:
          case CF_TEXT:
          case CF_NAME16:
          case CF_NAME32:  break;
kollo's avatar
kollo committed
939 940
          default: printf("output format type %d is not a string !\n",LFMT(prpinfo.prpFormat));
        }
kollo's avatar
kollo committed
941
#endif
kollo's avatar
kollo committed
942 943 944 945
	ergebnis.pointer=buf;
	ergebnis.len=buflen;
      }
    }
kollo's avatar
kollo committed
946

kollo's avatar
kollo committed
947
  }
kollo's avatar
kollo committed
948
  ccs_err=rc;
kollo's avatar
kollo committed
949 950
  return(ergebnis);
}
kollo's avatar
kollo committed
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966

/* Holt einen Wert, wobei ein bestimmter Timestamp vorgegeben werden kann */
/* Rueckgabe ist immer ein STring, auch wenn es sich um Arrays oder floats etc
   handelt.    Allgemeinste Form des Tine-Zugriffs.    */

STRING tinequery(char *n,int start) {
  char w1[strlen(n)+1],w2[strlen(n)+1];
  int rc=convert_name_convention(n,w1,w2);
  char *buf;
  int buflen;
  STRING ergebnis;

  if(rc) {
	printf("Syntax-Error %d in Parameter-Name %s\n",rc,n);
        ergebnis=vs_error();
  } else {
kollo's avatar
kollo committed
967
    PropertyQueryStruct prpinfo;
kollo's avatar
kollo committed
968
    DTYPE dout,din;
kollo's avatar
kollo committed
969

kollo's avatar
kollo committed
970 971 972 973 974 975 976 977 978 979 980 981 982 983
    /* get size of Vector */
    rc=GetPropertyInformation(w1,w2,&prpinfo);
    if(rc) {
      printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
        ergebnis=vs_error();
    } else {
      buflen=prpinfo.prpSize*getFormatSize(LFMT(prpinfo.prpFormat));
      buf=malloc(buflen);
      dout.dFormat = LFMT(prpinfo.prpFormat);
      dout.dArrayLength = prpinfo.prpSize;
      dout.dTag[0] = 0;
      dout.data.vptr = buf;
      din.dArrayLength = 1;
      din.dFormat = CF_LONG;
kollo's avatar
kollo committed
984
      din.data.lptr = (UINT32 *)&start;
kollo's avatar
kollo committed
985 986 987 988 989 990 991 992 993 994
      rc=my_ExecLinkEx(w1,w2,&dout,&din,CA_READ,buflen);
      if(rc) {
        printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
	free(buf);
	ergebnis=vs_error();
      } else {
	ergebnis.pointer=buf;
	ergebnis.len=buflen;
      }
    }
kollo's avatar
kollo committed
995

kollo's avatar
kollo committed
996 997 998 999
  }
  ccs_err=rc;
  return(ergebnis);
}
kollo's avatar
kollo committed
1000
ARRAY tinevget(char *n,int nn, int o) {
kollo's avatar
kollo committed
1001 1002 1003 1004 1005
  char w1[strlen(n)+1],w2[strlen(n)+1];
  int rc=convert_name_convention(n,w1,w2);
  char *buf;
  int buflen;
  int f,j;
kollo's avatar
kollo committed
1006
  ARRAY ergebnis;
kollo's avatar
kollo committed
1007

kollo's avatar
kollo committed
1008
  ergebnis.dimension=1;
kollo's avatar
kollo committed
1009 1010
  if(rc) {
    printf("Syntax-Error %d in Parameter-Name %s\n",rc,n);
kollo's avatar
kollo committed
1011 1012
    ergebnis.pointer=malloc(40);
    ((int *)ergebnis.pointer)[0]=1;
kollo's avatar
kollo committed
1013 1014 1015
  } else {
      /* get size of Vector */

kollo's avatar
kollo committed
1016
    PropertyQueryStruct prpinfo;
kollo's avatar
kollo committed
1017
    DTYPE dout;
kollo's avatar
kollo committed
1018

kollo's avatar
kollo committed
1019 1020 1021
    rc=GetPropertyInformation(w1,w2,&prpinfo);
    if(rc) {
      printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
kollo's avatar
kollo committed
1022 1023
      ergebnis.pointer=malloc(40);
      ((int *)ergebnis.pointer)[0]=1;
kollo's avatar
kollo committed
1024
      return(ergebnis);
kollo's avatar
kollo committed
1025
    }
kollo's avatar
kollo committed
1026 1027 1028 1029 1030 1031 1032 1033 1034
    if(nn==0) nn=prpinfo.prpSize;
    nn=min(nn,prpinfo.prpSize-o);
    buflen=prpinfo.prpSize*getFormatSize(LFMT(prpinfo.prpFormat));
    buf=malloc(buflen);
    dout.dFormat = LFMT(prpinfo.prpFormat);
    dout.dArrayLength = prpinfo.prpSize;
    dout.dTag[0] = 0;
    dout.data.vptr = buf;
    rc=my_ExecLinkEx(w1,w2,&dout,NULL,CA_READ,buflen);
kollo's avatar
kollo committed
1035
    ccs_err=rc;
kollo's avatar
kollo committed
1036 1037 1038
    if(rc) {
      printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
      free(buf);
kollo's avatar
kollo committed
1039 1040
      ergebnis.pointer=malloc(40);
      ((int *)ergebnis.pointer)[0]=1;
kollo's avatar
kollo committed
1041 1042
      return(ergebnis);
    }
kollo's avatar
kollo committed
1043

kollo's avatar
kollo committed
1044 1045 1046 1047 1048
    /* switch appropriate to type */

    f=LFMT(prpinfo.prpFormat);
    if(f==CF_FLOAT) {
      double *varptr;
kollo's avatar
kollo committed
1049 1050 1051 1052
      ergebnis.typ=FLOATARRAYTYP;
      ergebnis.pointer=malloc(1*INTSIZE+nn*sizeof(double));
      ((int *)ergebnis.pointer)[0]=nn;
      varptr=ergebnis.pointer+INTSIZE;
kollo's avatar
kollo committed
1053 1054 1055 1056
      for(j=0;j<nn;j++) varptr[j]=(double)(((float *)buf)[j+o]);
      free(buf);
    } else if(f==CF_DOUBLE) {
      double *varptr;
kollo's avatar
kollo committed
1057 1058 1059 1060
      ergebnis.typ=FLOATARRAYTYP;
      ergebnis.pointer=malloc(1*INTSIZE+nn*sizeof(double));
      ((int *)ergebnis.pointer)[0]=nn;
      varptr=ergebnis.pointer+INTSIZE;
kollo's avatar
kollo committed
1061 1062 1063 1064
      for(j=0;j<nn;j++) varptr[j]=(double)(((double *)buf)[j+o]);
      free(buf);
    } else if(f==CF_BYTE) {
      double *varptr;
kollo's avatar
kollo committed
1065 1066 1067 1068
      ergebnis.typ=FLOATARRAYTYP;
      ergebnis.pointer=malloc(1*INTSIZE+nn*sizeof(double));
      ((int *)ergebnis.pointer)[0]=nn;
      varptr=ergebnis.pointer+INTSIZE;
kollo's avatar
kollo committed
1069 1070 1071 1072
      for(j=0;j<nn;j++) varptr[j]=(double)(((char *)buf)[j+o]);
      free(buf);
    } else if(f==CF_SHORT) {
      double *varptr;
kollo's avatar
kollo committed
1073 1074 1075 1076
      ergebnis.typ=FLOATARRAYTYP;
      ergebnis.pointer=malloc(1*INTSIZE+nn*sizeof(double));
      ((int *)ergebnis.pointer)[0]=nn;
      varptr=ergebnis.pointer+INTSIZE;
kollo's avatar
kollo committed
1077 1078 1079 1080
      for(j=0;j<nn;j++) varptr[j]=(double)(((short *)buf)[j+o]);
      free(buf);
    } else if(f==CF_LONG) {
      double *varptr;
kollo's avatar
kollo committed
1081 1082 1083 1084
      ergebnis.typ=FLOATARRAYTYP;
      ergebnis.pointer=malloc(1*INTSIZE+nn*sizeof(double));
      ((int *)ergebnis.pointer)[0]=nn;
      varptr=ergebnis.pointer+INTSIZE;
kollo's avatar
kollo committed
1085 1086 1087 1088
      for(j=0;j<nn;j++) varptr[j]=(double)(((long *)buf)[j+o]);
      free(buf);
    } else {
      printf("output format type %d is not implemented !\n",LFMT(prpinfo.prpFormat));
kollo's avatar
kollo committed
1089
      xberror(46,n); /* Parameter hat falschen Typ */
kollo's avatar
kollo committed
1090
      free(buf);
kollo's avatar
kollo committed
1091 1092
      ergebnis.pointer=malloc(40);
      ((int *)ergebnis.pointer)[0]=1;
kollo's avatar
kollo committed
1093 1094 1095 1096
    }
  }
 return(ergebnis);
}
kollo's avatar
kollo committed
1097
ARRAY tinehistory(char *n,int start, int stop) {
kollo's avatar
kollo committed
1098 1099 1100 1101 1102
  char w1[strlen(n)+1],w2[strlen(n)+1];
  int rc=convert_name_convention(n,w1,w2);
  char *buf;
  int buflen,nn;
  int f,j;
kollo's avatar
kollo committed
1103
  ARRAY ergebnis;
kollo's avatar
kollo committed
1104 1105 1106
  UINT32 startstopArray[3];
  DTYPE dout,din;
  double *varptr;
kollo's avatar
kollo committed
1107

kollo's avatar
kollo committed
1108
  ergebnis.dimension=2;
kollo's avatar
kollo committed
1109

kollo's avatar
kollo committed
1110 1111
  if(rc) {
    printf("Syntax-Error %d in Parameter-Name %s\n",rc,n);
kollo's avatar
kollo committed
1112 1113 1114 1115
    ergebnis.pointer=malloc((4+2)*sizeof(int));
    ergebnis.typ=INTTYP;
    ((int *)ergebnis.pointer)[0]=1;
    ((int *)ergebnis.pointer)[1]=1;
kollo's avatar
kollo committed
1116 1117
  } else {
      /* get size of History */
kollo's avatar
kollo committed
1118

kollo's avatar
kollo committed
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
    buflen=65532;
    buf=malloc(buflen);

    startstopArray[0] = start;
    startstopArray[1] = stop;

    dout.dFormat = CF_FLTINT;
    dout.dArrayLength = (int)buflen/8;
    dout.dTag[0] = 0;
    dout.data.vptr = buf;
    din.dArrayLength = 2;
    din.dFormat = CF_LONG;
    din.data.lptr = startstopArray;
    rc=my_ExecLinkEx(w1,w2,&dout,&din,CA_READ,buflen);
kollo's avatar
kollo committed
1133
    ccs_err=rc;
kollo's avatar
kollo committed
1134 1135 1136
    if(rc) {
      printf("Tine-Error: %d  %s\n",rc,erlst[rc]);
      free(buf);
kollo's avatar
kollo committed
1137 1138 1139 1140
      ergebnis.pointer=malloc((4+2)*sizeof(int));
      ergebnis.typ=INTTYP;
      ((int *)ergebnis.pointer)[0]=1;
      ((int *)ergebnis.pointer)[1]=1;
kollo's avatar
kollo committed
1141 1142
      return(ergebnis);
    }
kollo's avatar
kollo committed
1143 1144 1145
  /*    nn=((int *)buf)[1];  */
  /*  nn=dout.dArrayLength;  */
    nn=GetCompletionDataSize(-1);
kollo's avatar
kollo committed
1146 1147 1148 1149 1150
    ergebnis.typ=FLOATARRAYTYP;
    ergebnis.pointer=malloc(2*INTSIZE+2*nn*sizeof(double));
    ((int *)ergebnis.pointer)[0]=nn;
    ((int *)ergebnis.pointer)[1]=2;
    varptr=ergebnis.pointer+2*INTSIZE;
kollo's avatar
kollo committed
1151
      for(j=0;j<nn;j++) {
kollo's avatar
kollo committed
1152 1153
        varptr[2*j]=(double)(((float *)buf)[2*j]);  /*+2 entfernt*/
        varptr[2*j+1]=(double)(((int *)buf)[2*j+1]);/*+2 entfernt*/
kollo's avatar
kollo committed
1154
      }
kollo's avatar
kollo committed
1155 1156 1157 1158 1159
      free(buf);
  }
  return(ergebnis);
}

kollo's avatar
kollo committed
1160 1161 1162
/* tinemonitor "sender[PROP]",callback,interval */

void c_tinemonitor(PARAMETER *plist, int e) {
kollo's avatar
kollo committed
1163
  static PropertyQueryStruct prpinfo;
kollo's avatar
kollo committed
1164 1165 1166 1167 1168 1169 1170 1171
  char dev[plist[0].integer+1],prop[plist[0].integer+1];
  int rc=convert_name_convention(plist[0].pointer,dev,prop);
  if(rc) printf("Syntax-Error in Parameter-Name %s\n",plist[0].pointer);
  else {
    tine_init();
    printf("dev=<%s>, prop=<%s>\n",dev,prop);
    ccs_err=GetPropertyInformation(dev,prop,&prpinfo);
    if(ccs_err) printf("Tine-Error: %d  %s\n",ccs_err,erlst[ccs_err]);
kollo's avatar
kollo committed
1172
    else {
kollo's avatar
kollo committed
1173
      DTYPE dout;
kollo's avatar
kollo committed
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
      int newpid,buflen=prpinfo.prpSize*getFormatSize(LFMT(prpinfo.prpFormat));
      char *buf=malloc(buflen);
      dout.dFormat = LFMT(prpinfo.prpFormat);
      dout.dArrayLength = prpinfo.prpSize;
      dout.dTag[0] = 0;
      dout.data.vptr = buf; /* wird nirgendwo freigegeben */
      newpid=AttachLink(dev,prop,&dout,NULL,CA_READ,100,tmonitorCallback,CM_REFRESH|CM_NETWORK);
      if(newpid<0) {
        ccs_err=-newpid;
	printf("Tine-Error AttachLink: %d  %s\n",ccs_err,erlst[ccs_err]);
	free(buf);
      } else {
	if(pidanz<MAXPIDS) {
          int i,flag;
kollo's avatar
kollo committed
1188 1189 1190 1191 1192 1193
            flag=-1;
            for(i=0;i<pidanz;i++) {
              if(pids[i]==newpid) flag=i;
            }
            if(flag==-1) {
              pids[pidanz]=newpid;
kollo's avatar
kollo committed
1194 1195 1196
              isubs[pidanz++]=plist[1].integer;
            } else isubs[flag]=plist[1].integer;
        } else printf("Zu viele Callbacks. max. <%d>\n",MAXPIDS);
kollo's avatar
kollo committed
1197
      }
kollo's avatar
kollo committed
1198
    }
kollo's avatar
kollo committed
1199 1200
  }
}
kollo's avatar
kollo committed
1201 1202 1203

void c_tineput(char *w) {
  char n[strlen(w)+1],t[strlen(w)+1];
kollo's avatar
kollo committed
1204
  int pid,j,e,i;
kollo's avatar
kollo committed
1205 1206 1207 1208 1209 1210 1211 1212
  float f;
  e=wort_sep(w,',',TRUE,n,t);
  if(e<2) {
    printf("Syntax-Error bei TINEPUT. <%s>\n",w);
    return;
  } else {
    char *test=s_parser(n);
    char w1[strlen(test)+1],w2[strlen(test)+1];
kollo's avatar
kollo committed
1213
    ccs_err=convert_name_convention(test,w1,w2);
kollo's avatar
kollo committed
1214
    free(test);
kollo's avatar
kollo committed
1215 1216
    if(ccs_err) printf("Syntax-Error %d in Parameter-Name %s\n",ccs_err,test);
    else {
kollo's avatar
kollo committed
1217
      PropertyQueryStruct prpinfo;
kollo's avatar
kollo committed
1218 1219 1220 1221
      DTYPE dout;
      int buflen;
      char *buf;
    /* get size of Vector */
kollo's avatar
kollo committed
1222 1223 1224
      ccs_err=GetPropertyInformation(w1,w2,&prpinfo);
      if(ccs_err) {
        printf("Tine-Error: %d  %s\n",ccs_err,erlst[ccs_err]);
kollo's avatar
kollo committed
1225 1226 1227 1228 1229 1230 1231 1232
        return;
      }
      buflen=prpinfo.prpSize*getFormatSize(LFMT(prpinfo.prpFormat));
      buf=malloc(buflen);
      dout.dFormat = LFMT(prpinfo.prpFormat);
      dout.dArrayLength = prpinfo.prpSize;
      dout.dTag[0] = 0;
      dout.data.vptr = buf;
kollo's avatar
kollo committed
1233

kollo's avatar
kollo committed
1234
      if(type(t)&ARRAYTYP) {
kollo's avatar
kollo committed
1235
        ARRAY abuffer=array_parser(t);
kollo's avatar
kollo committed
1236
	int l=anz_eintraege(&abuffer);
kollo's avatar
kollo committed
1237 1238 1239
	int i;
	void *ptr=(char *)abuffer.pointer+abuffer.dimension*INTSIZE;
	l=min(l,dout.dArrayLength);
kollo's avatar
kollo committed
1240
        printf("Ist Vektor [%d]!!!\n",anz_eintraege(&abuffer));
kollo's avatar
kollo committed
1241
	if(abuffer.typ==FLOATTYP ||abuffer.typ==INTTYP)) {
kollo's avatar
kollo committed
1242 1243 1244
	  /* Tu was hier !!! */
	  switch (LFMT(prpinfo.prpFormat)) {
	  case CF_FLOAT:
kollo's avatar
kollo committed
1245
	    if(abuffer.typ==FLOATTYP) {
kollo's avatar
kollo committed
1246 1247 1248 1249 1250 1251
  	      for(i=0;i<l;i++) ((float *)buf)[i]=(float)((double *)ptr)[i];
	    } else {
  	      for(i=0;i<l;i++) ((float *)buf)[i]=(float)((int *)ptr)[i];
	    }
	    break;
	  case CF_DOUBLE:
kollo's avatar
kollo committed
1252
	    if(abuffer.typ==FLOATTYP) {
kollo's avatar
kollo committed
1253 1254 1255 1256 1257 1258
  	      for(i=0;i<l;i++) ((double *)buf)[i]=((double *)ptr)[i];
	    } else {
  	      for(i=0;i<l;i++) ((double *)buf)[i]=(double)((int *)ptr)[i];
	    }
	    break;
	  case CF_BYTE:
kollo's avatar
kollo committed
1259
	    if(abuffer.typ==FLOATTYP) {
kollo's avatar
kollo committed
1260 1261 1262 1263
  	      for(i=0;i<l;i++) ((char *)buf)[i]=(char)((double *)ptr)[i];
	    } else {
  	      for(i=0;i<l;i++) ((char *)buf)[i]=(char)((int *)ptr)[i];
	    }
kollo's avatar
kollo committed
1264
	    break;
kollo's avatar
kollo committed
1265
	  case CF_SHORT:
kollo's avatar
kollo committed
1266
	    if(abuffer.typ==FLOATTYP) {
kollo's avatar
kollo committed
1267 1268 1269 1270
  	      for(i=0;i<l;i++) ((short *)buf)[i]=(short)((double *)ptr)[i];
	    } else {
  	      for(i=0;i<l;i++) ((short *)buf)[i]=(short)((int *)ptr)[i];
	    }
kollo's avatar
kollo committed
1271
	    break;  	
kollo's avatar
kollo committed
1272
	  case CF_LONG:
kollo's avatar
kollo committed
1273
	    if(abuffer.typ==FLOATTYP) {
kollo's avatar
kollo committed
1274 1275 1276 1277
  	      for(i=0;i<l;i++) ((long *)buf)[i]=(long)((double *)ptr)[i];
	    } else {
  	      for(i=0;i<l;i++) ((long *)buf)[i]=(long)((int *)ptr)[i];
	    }
kollo's avatar
kollo committed
1278
	    break;  	
kollo's avatar
kollo committed
1279 1280
	  default:
            printf("output format type %d is not numeric !\n",LFMT(prpinfo.prpFormat));
kollo's avatar
kollo committed
1281
	    free_array(&abuffer);
kollo's avatar
kollo committed
1282 1283
            free(buf);return;
	  }
kollo's avatar
kollo committed
1284
	} else if((type(t)&TYPMASK)==STRINGTYP) {
kollo's avatar
kollo committed
1285 1286
          switch (LFMT(prpinfo.prpFormat)) {
          case CF_BYTE:
kollo's avatar
kollo committed
1287 1288 1289 1290
          case CF_TEXT:
          case CF_NAME8:
          case CF_NAME16:
          case CF_NAME16FI:
kollo's avatar
kollo committed
1291 1292 1293 1294 1295 1296
          case CF_NAME32:
          case CF_NAME48:
          case CF_STRUCT:
	  /* Tu was hier !!! */
	  printf("Art der Uebergabe noch nicht realisiert !\n");
          break;
kollo's avatar
kollo committed
1297
          default:
kollo's avatar
kollo committed
1298
            printf("output format type %d is not a Stringtype !\n",LFMT(prpinfo.prpFormat));
kollo's avatar
kollo committed
1299
            free(buf);free_array(&abuffer); return;
kollo's avatar
kollo committed
1300 1301 1302 1303
          }

	}
	
kollo's avatar
kollo committed
1304
	free_array(&abuffer);
kollo's avatar
kollo committed
1305 1306
      } else {
        /* switch appropriate to type */
kollo's avatar
kollo committed
1307
        if((type(t)&TYPMASK)==FLOATTYP ||(type(t)&TYPMASK)==INTTYP) {
kollo's avatar
kollo committed
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
          switch (LFMT(prpinfo.prpFormat)) {
          case CF_BYTE:
            *((char *)buf)=(char)parser(t); break;
          case CF_SHORT:
            *((short *)buf)=(short)parser(t);break;
          case CF_LONG:
            *((long *)buf)=(long)parser(t);break;
          case CF_FLOAT:
            *((float *)buf)=(float)parser(t);break;
          case CF_DOUBLE:
            *((double *)buf)=(double)parser(t);break;
kollo's avatar
kollo committed
1319
          default:
kollo's avatar
kollo committed
1320 1321 1322
            printf("output format type %d is not a number !\n",LFMT(prpinfo.prpFormat));
            free(buf);return;
          }
kollo's avatar
kollo committed
1323
        } else if((type(t)&TYPMASK)==STRINGTYP) {
kollo's avatar
kollo committed
1324 1325 1326 1327
          STRING sss=string_parser(t);
	  memcpy(buf,sss.pointer,min(sss.len,buflen));
	  free(sss.pointer);
	  buflen=min(sss.len,buflen);
kollo's avatar
kollo committed
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
#if 0
        printf("output format type %d  !\n",dout.dFormat);
	dout.dFormat=CF_NAME16FI;
#endif
        dout.dArrayLength = buflen/getFormatSize(LFMT(prpinfo.prpFormat));

#if 0
      /* Typen ueberpruefen */
      switch (LFMT(prpinfo.prpFormat)) {
      case CF_BYTE:
kollo's avatar
kollo committed
1338 1339 1340 1341
      case CF_TEXT:
      case CF_NAME8:
      case CF_NAME16:
      case CF_NAME16FI:
kollo's avatar
kollo committed
1342 1343 1344 1345
      case CF_NAME32:
      case CF_NAME48:
      case CF_STRUCT:
        break;
kollo's avatar
kollo committed
1346
      default:
kollo's avatar
kollo committed
1347 1348 1349
        printf("output format type %d is not a Stringtype !\n",LFMT(prpinfo.prpFormat));
        free(buf);return;
      }
kollo's avatar
kollo committed
1350
      printf("Gebe #%d Daten\n",buflen);
kollo's avatar
kollo committed
1351
#endif
kollo's avatar
kollo committed
1352
        }
kollo's avatar
kollo committed
1353
      }
kollo's avatar
kollo committed
1354 1355
      ccs_err=my_ExecLinkEx(w1,w2,NULL,&dout,CA_WRITE,buflen);
      if(ccs_err) printf("Tine-Error: %d  %s\n",ccs_err,erlst[ccs_err]);
kollo's avatar
kollo committed
1356 1357 1358 1359
      free(buf);
    }
  }
}
kollo's avatar
kollo committed
1360 1361 1362 1363

char tine_eqn[32]="X11BASIC";
int tineexportvars[100];
int anztineexportvars=0;
kollo's avatar
kollo committed
1364

kollo's avatar
kollo committed
1365 1366 1367 1368 1369 1370 1371 1372 1373
int tineserver_callback(char *devName,char *Property, DTYPE *dout, DTYPE *din, short access) {
  int devicenumber=0,vnr=-1,typ,etyp,len;
  char *r;
  if(devName[0] == '#') devicenumber=atoi(&devName[1]);
  else devicenumber=GetDeviceNumber(tine_eqn,devName);
  typ=vartype(Property);
  r=varrumpf(Property);
  vnr=variable_exist(r,typ);
  free(r);
kollo's avatar
kollo committed
1374 1375
  printf("Got request for %s ",Property);
  printf("VNR=%d ",vnr);
kollo's avatar
kollo committed
1376 1377 1378
  if(vnr==-1) return illegal_property;
  else {
    len=do_dimension(vnr);
kollo's avatar
kollo committed
1379 1380 1381 1382 1383
    switch(typ&TYPMASK) {
    case STRINGTYP: etyp=CF_TEXT; break;
    case INTTYP:    etyp=CF_LONG; break;
    case FLOATTYP:  etyp=CF_DOUBLE; break;
    }
kollo's avatar
kollo committed
1384

kollo's avatar
kollo committed
1385
    if(access&CA_WRITE) {
kollo's avatar
kollo committed
1386
      printf("write access: \n");
kollo's avatar
kollo committed
1387 1388
      if(din->dFormat!=etyp) return illegal_format;
      if(din->dArrayLength > len) return dimension_error;
kollo's avatar
kollo committed
1389
      if(typ & ARRAYTYP) ;
kollo's avatar
kollo committed
1390
      else if((typ&TYPMASK)==STRINGTYP) {
kollo's avatar
kollo committed
1391 1392 1393
        STRING a;
	a.pointer=din->data.vptr;
	a.len=din->dArrayLength;  /* wirklich ??? */
kollo's avatar
kollo committed
1394
	string_zuweis(&variablenn[vnr],a);
kollo's avatar
kollo committed
1395
      }
kollo's avatar
kollo committed
1396 1397
      else if((typ&TYPMASK)==INTTYP) variablen[vnr].opcode=din->data.lptr[0];
      else if((typ&TYPMASK)==FLOATTYP) variablen[vnr].zahl=din->data.dptr[0];
kollo's avatar
kollo committed
1398

kollo's avatar
kollo committed
1399
    } else if(access&CA_READ) {
kollo's avatar
kollo committed
1400 1401
        printf("read access: Format=%d ALEN=%d\n",dout->dFormat,dout->dArrayLength);
  
kollo's avatar
kollo committed
1402 1403
      if(dout->dFormat!=etyp) return illegal_format;
      if(dout->dArrayLength < len) return dimension_error;
kollo's avatar
kollo committed
1404
      if(typ & ARRAYTYP) ;
kollo's avatar
kollo committed
1405
      else if((typ&TYPMASK)==STRINGTYP) {
kollo's avatar
kollo committed
1406 1407
        dout->data.vptr=variablen[vnr].pointer;
	dout->dArrayLength=variablen[vnr].opcode;
kollo's avatar
kollo committed
1408 1409
      } else if((typ&TYPMASK)==INTTYP) dout->data.lptr[0]=variablen[vnr].opcode;
      else if((typ&TYPMASK)==FLOATTYP) dout->data.dptr[0]=variablen[vnr].zahl;
kollo's avatar
kollo committed
1410

kollo's avatar
kollo committed
1411 1412 1413 1414
    }
    return(0);
  }
}
kollo's avatar
kollo committed
1415
#define MY_TINE_TCP_PORT        41
kollo's avatar
kollo committed
1416
void c_tineserver(PARAMETER *plist, int e) {
kollo's avatar
kollo committed
1417
  int i,cc,port_offset=MY_TINE_TCP_PORT;
kollo's avatar
kollo committed
1418
  if(e>0) strncpy(tine_eqn,plist[0].pointer,31);
kollo's avatar
kollo committed
1419 1420 1421 1422 1423 1424 1425 1426
  if(e>1) port_offset=plist[0].integer;
  if((i=RegisterFecNameEx(tine_eqn,tine_eqn,
      "UNIX","Geb.24","X11Basic","M. Hoffmann",port_offset,"DEFAULT"))!=0)
      printf("Register FecName %s error: %d %s\n",tine_eqn,i,erlst[i]);
  else {
    /* init RPC server: */
    fix_tine_start();
    if((cc=SystemInit(FALSE))!=0) printf("SystemInit error: %s\n",erlst[cc]);
kollo's avatar
kollo committed
1427 1428 1429
    else RegisterEquipmentModule(tine_eqn,tine_eqn,1,tineserver_callback,NULL,NULL,1000,NULL);
  }
}
kollo's avatar
kollo committed
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447
void completion_callback(int id,int cc) {  
  #ifdef DEBUG
    printf("Completion Callback id=%d rc=%d!\n",id,cc);
  #endif
  if (cc) {
    printf("TRC error : %s\n",GetRPCLastError(cc));
    return;
  }
}
void c_tinebroadcast(char *n) {
  char v[strlen(n)+1],w[strlen(n)+1],*r;
  int p,typ,vnr,rc;
  double tolerance=0;
  int minPeriod=-1,maxPeriod=-1;
  DTYPE din;
  strcpy(v,n);
  p=wort_sep(v,',',TRUE,w,v);
  xtrim(w,TRUE,w);
kollo's avatar
kollo committed
1448
  typ=type(w);
kollo's avatar
kollo committed
1449
  if(typ & CONSTTYP) xberror(32,"TINEBROADCAST");  /* Syntax error */
kollo's avatar
kollo committed
1450 1451 1452 1453
  else {
    r=varrumpf(w);
    vnr=variable_exist(r,typ);
    if(typ & ARRAYTYP) { /* ganzes Array  */
kollo's avatar
kollo committed
1454
      if(vnr==-1) xberror(15,w); /* Feld nicht dimensioniert */   
kollo's avatar
kollo committed
1455 1456 1457 1458 1459 1460
      din.dFormat=CF_BYTE;
      din.dArrayLength=do_dimension(vnr);
      din.data.vptr=variablen[vnr].pointer;
    } else {
      /*Hier sollte man die Variable anlegen, falls nicht existent...*/
      if(vnr==-1) vnr=variable_exist_or_create(r,typ);
kollo's avatar
kollo committed
1461 1462
      switch(typ&TYPMASK) {
      case STRINGTYP:
kollo's avatar
kollo committed
1463 1464 1465
	  din.dFormat=CF_TEXT;
	  din.dArrayLength=variablen[vnr].opcode;
  	  din.data.vptr=variablen[vnr].pointer;
kollo's avatar
kollo committed
1466 1467
	  break;
      case INTTYP:
kollo's avatar
kollo committed
1468 1469 1470
          din.dFormat=CF_LONG;
	  din.dArrayLength=1;
          din.data.lptr=&variablen[vnr].opcode;
kollo's avatar
kollo committed
1471 1472
	  break;
      case FLOATTYP:
kollo's avatar
kollo committed
1473 1474
          din.dFormat=CF_DOUBLE;
	  din.dArrayLength=1;
kollo's avatar
kollo committed
1475 1476
          din.data.dptr=&variablen[vnr].zahl;
	  break; 
kollo's avatar
kollo committed
1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
      } 

      din.dTag[0] = 0;

      rc=sendNetGlobal(w,&din,completion_callback,minPeriod,maxPeriod,tolerance); 
      if(rc<0) {
        printf("Tine-Error recvNetGlobal: %d  %s\n",-rc,erlst[-rc]);
	ccs_err=-rc;
      } 
    }
    free(r);
  }
}
void c_tinelisten(char *n) {
  char v[strlen(n)+1],w[strlen(n)+1],*r;
  int i,flag,newpid,pc2=-1,p,typ,vnr,rc;
  DTYPE dout;
  strcpy(v,n);
  p=wort_sep(v,',',TRUE,w,v);
  xtrim(w,TRUE,w);
kollo's avatar
kollo committed