lib/clib/vxwcom.c
Go to the documentation of this file.
1 /****************************************************************/
2 /* vxwcom.c
3 /* rpc communication with VxWorks
4 /* (c) 1991, Toshihiro Matsui, Electrotechnical Laboratory
5 /* Copying and modification is free as long as the copied and modified
6 /* products are also copy/modify-free.
7 /****************************************************************
8 
9 #include "eus.h"
10 #include "vxw_proto.h"
11 
12 static void putlong(s,i)
13 pointer s;
14 long i;
15 { unsigned char *ip= (unsigned char *)&i;
16  writech(s,*ip++); writech(s,*ip++); writech(s,*ip++); writech(s,*ip++);}
17 
18 static unsigned long getlong(con)
19 pointer con;
20 { register unsigned int ival=0;
21  ival=readch(con);
22  ival=(ival<<8)+readch(con);
23  ival=(ival<<8)+readch(con);
24  ival=(ival<<8)+readch(con);
25 /* printf("result=%d\n",ival); */
26  return(ival);}
27 
28 
29 static putlength(s,len)
30 pointer s;
31 unsigned int len;
32 { if (len<128) writech(s,len);
33  else if (len<16384) {
34  writech(s, 0x80 | (len >> 8));
35  writech(s, len & 0xff);}
36  else error(E_USER, (pointer)"argument to large");}
37 
38 static int putarg(s,p)
39 pointer s,p;
40 { numunion nu;
41  register int i,len, elmt;
42  register unsigned char *bp;
43 
44  if (isint(p)) {
45  writech(s, A_LONG); putlong(s,intval(p));}
46  else if (isflt(p)) {
47  writech(s, A_FLOAT); nu.fval=fltval(p); putlong(s, nu.ival);}
48  else {
49  if (isarray(p)) p=p->c.ary.entity;
50  if (isvector(p)) {
51  len=vecsize(p); elmt=elmtypeof(p);
52  writech(s, A_VECTOR);
53  bp= p->c.str.chars;
54  switch(elmt) {
55  case ELM_BIT: len=(len+7)/8; break;
56  case ELM_FOREIGN: bp=(unsigned char *)p->c.ivec.iv[0]; break;
57  case ELM_CHAR: case ELM_BYTE: break;
58  case ELM_POINTER: error(E_USER, (pointer)"binary vector expected"); break;
59  case ELM_FLOAT: case ELM_INT: len<<=2; break;}
60  putlength(s,len);
61  writestr(s,bp,len); }
62  else error(E_USER, (pointer)"invalid argument for VXW"); } }
63 
64 pointer CALL_VXW(context *ctx, int n, pointer argv[])
65 { int i=0, j, argc=3, len, stat;
66  pointer con=argv[0], entry=argv[1], result=argv[2];
67  pointer in,out;
68  pointer p,result_vec;
69  numunion rv, nu;
70 
71  if (!isiostream(con)) error(E_STREAM);
72  in=con->c.iostream.in; out=con->c.iostream.out;
73 
74  if (issymbol(entry)) entry= (pointer)getstring(entry);
75  if (isstring(entry)) {
76  writech(out, A_SYMBOL);
77  writech(out, vecsize(entry));
78  writestr(out, entry->c.str.chars, vecsize(entry));}
79  else if (isint(entry)) {
80  writech(out, A_LONG);
81  putlong(out, intval(entry));}
82 
83  while (argc<n) {
84  if (debug) { prinx(ctx, argv[argc],STDOUT); terpri(STDOUT);}
85  putarg(out, argv[argc++]);}
86 
87  writech(out, A_END);
88 
89  if (result==K_INTEGER) writech(out, A_LONG);
90  else if (result==K_FLOAT) writech(out, A_FLOAT);
91  else {
92  if (isarray(result)) result=result->c.ary.entity;
93  if (isvector(result)) {
94  writech(out, A_VECTOR);
95  len=vecsize(result);
96  if ((elmtypeof(result) == ELM_INT) || (elmtypeof(result) == ELM_FLOAT))
97  len=len*sizeof(long);
98  putlength(out,len);}
99  else error(E_NOVECTOR);}
100  flushstream(out);
101 
102  /*read protocol status*/
103  stat=readch(in);
104  if (stat != (int)NULL) return(cons(ctx, makeint(stat), NIL));
105 
106  /*read result*/
107  if (result==K_INTEGER)
108  return(makeint(getlong(in)));
109  else if (result==K_FLOAT) {
110  rv.ival=getlong(in);
111  return(makeflt(rv.fval));}
112  else if (result==K_STRING) { }
113  else { /*vector*/
114  for (i=0; i<len; i++) result->c.str.chars[i]=readch(in);
115  return(argv[2]);}
116  }
117 
118 pointer vxwcom(context *ctx, int n, pointer argv[], pointer env)
119 { pointer mod = argv[0];
120  defun(ctx, "VXW",mod,CALL_VXW,NULL);
121  return(T);
122  }
123 
124 
125 
writestr
int writestr(pointer, byte *, int)
Definition: eusstream.c:218
numunion
Definition: eus.h:428
NIL
pointer NIL
Definition: eus.c:110
putlength
static putlength(pointer s, unsigned int len)
Definition: lib/clib/vxwcom.c:29
A_FLOAT
@ A_FLOAT
Definition: contrib/vxworks/vxw_proto.h:2
defun
defun("ADR_TO_STRING", mod, ADR_TO_STRING)
makeint
#define makeint(v)
Definition: sfttest.c:2
context
Definition: eus.h:524
putarg
static int putarg(pointer s, pointer p)
Definition: lib/clib/vxwcom.c:38
s
short s
Definition: structsize.c:2
readch
int readch(pointer)
Definition: eusstream.c:114
numunion::ival
eusinteger_t ival
Definition: eus.h:431
A_LONG
@ A_LONG
Definition: contrib/vxworks/vxw_proto.h:2
intval
#define intval(p)
Definition: sfttest.c:1
T
pointer T
Definition: eus.c:110
numunion::fval
eusfloat_t fval
Definition: eus.h:430
pointer
struct cell * pointer
Definition: eus.h:165
A_END
@ A_END
Definition: contrib/vxworks/vxw_proto.h:3
A_SYMBOL
@ A_SYMBOL
Definition: contrib/vxworks/vxw_proto.h:3
iostream::out
pointer out
Definition: eus.h:291
string::chars
byte chars[1]
Definition: eus.h:212
cell::c
union cell::cellunion c
K_STRING
pointer K_STRING
Definition: eus.c:131
putlong
static void putlong(pointer s, long i)
Definition: contrib/vxworks/vxwcom.c:4
flushstream
int flushstream(pointer)
Definition: eusstream.c:159
STDOUT
pointer STDOUT
Definition: eus.c:119
NULL
#define NULL
Definition: transargv.c:8
fltval
float fltval()
K_INTEGER
pointer K_INTEGER
Definition: eus.c:132
E_STREAM
@ E_STREAM
Definition: eus.h:954
prinx
pointer prinx(context *, pointer, pointer)
Definition: printer.c:611
cons
pointer cons(context *, pointer, pointer)
Definition: makes.c:97
bp
static int bp
Definition: helpsub.c:22
E_NOVECTOR
@ E_NOVECTOR
Definition: eus.h:963
getlong
static unsigned long getlong(pointer con)
Definition: contrib/vxworks/vxwcom.c:10
makeflt
pointer makeflt()
error
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
Definition: eus.c:297
argc
static int argc
Definition: transargv.c:56
cell
Definition: eus.h:381
vxwcom
pointer vxwcom(context *ctx, int n, pointer argv[], pointer env)
Definition: lib/clib/vxwcom.c:118
iostream::in
pointer in
Definition: eus.h:291
writech
int writech(pointer, int)
cell::cellunion::iostream
struct iostream iostream
Definition: eus.h:407
terpri
void terpri(pointer)
Definition: printer.c:637
E_USER
@ E_USER
Definition: eus.h:1006
CALL_VXW
pointer CALL_VXW(context *ctx, int n, pointer argv[])
Definition: lib/clib/vxwcom.c:64
n
GLfloat n[6][3]
Definition: cube.c:15
K_FLOAT
pointer K_FLOAT
Definition: eus.c:133
A_VECTOR
@ A_VECTOR
Definition: contrib/vxworks/vxw_proto.h:3
cell::cellunion::str
struct string str
Definition: eus.h:402


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 15 2023 02:06:43