Skip to content

Commit ccfe803

Browse files
committed
Copy syncwrite changes to asyncwrite
1 parent 044e9d4 commit ccfe803

1 file changed

Lines changed: 119 additions & 1 deletion

File tree

luaApp/src/rec/luaSoft.c

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <callback.h>
66
#include <dbCa.h>
7+
#include <errlog.h>
78

89
#include "alarm.h"
910
#include "dbDefs.h"
@@ -47,10 +48,127 @@ static long asyncWrite(luascriptRecord* record, double* val, char* sval, struct
4748
short field_type = 0;
4849

4950
field_type = dbCaGetLinkDBFtype(out);
51+
dbCaGetNelements(out, &n_elements);
5052

5153
if (devLuaSoftDebug)
5254
{ printf("write_Script: field_type=%d\n", field_type); }
5355

56+
int bytes_per_elem = 1;
57+
58+
if (record->atyp == luascriptAVALType_Integer) { bytes_per_elem = sizeof(int); }
59+
if (record->atyp == luascriptAVALType_Double) { bytes_per_elem = sizeof(double); }
60+
if (record->atyp == luascriptAVALType_Char) { bytes_per_elem = sizeof(char); }
61+
62+
63+
int array_len = (int) record->asiz / bytes_per_elem;
64+
65+
66+
if (n_elements > 1)
67+
{
68+
int index;
69+
70+
if (array_len > n_elements)
71+
{
72+
errlogPrintf("%s: Array too large to write to output\n", record->name);
73+
return 0;
74+
}
75+
76+
switch (field_type)
77+
{
78+
case DBF_CHAR:
79+
case DBF_UCHAR:
80+
{
81+
if (record->atyp == luascriptAVALType_Char)
82+
{
83+
return dbCaPutLinkCallback(out, DBF_CHAR, record->aval, array_len, (dbCaCallback) dbCaCallbackProcess, out);
84+
85+
}
86+
else if (record->atyp == luascriptAVALType_Integer)
87+
{
88+
#if defined(_MSC_VER)
89+
char buffer[1024];
90+
#else
91+
char buffer[array_len];
92+
#endif
93+
94+
for (index = 0; index < n_elements && index < array_len; index += 1)
95+
{
96+
buffer[index] = (char) ((int*) record->aval)[index];
97+
}
98+
99+
return dbCaPutLinkCallback(out, DBF_CHAR, buffer, array_len, (dbCaCallback) dbCaCallbackProcess, out);
100+
}
101+
102+
return 0;
103+
}
104+
105+
case DBF_DOUBLE:
106+
{
107+
if (record->atyp == luascriptAVALType_Double)
108+
{
109+
return dbCaPutLinkCallback(out, DBF_DOUBLE, record->aval, array_len, (dbCaCallback) dbCaCallbackProcess, out);
110+
}
111+
else if (record->atyp == luascriptAVALType_Integer)
112+
{
113+
#if defined(_MSC_VER)
114+
double buffer[1024];
115+
#else
116+
double buffer[array_len];
117+
#endif
118+
119+
for (index = 0; index < n_elements && index < array_len; index += 1)
120+
{
121+
buffer[index] = ((int*) record->aval)[index];
122+
}
123+
124+
return dbCaPutLinkCallback(out, DBF_DOUBLE, buffer, array_len, (dbCaCallback) dbCaCallbackProcess, out);
125+
}
126+
127+
return 0;
128+
}
129+
130+
case DBF_FLOAT:
131+
{
132+
#if defined(_MSC_VER)
133+
float buffer[1024];
134+
#else
135+
float buffer[array_len];
136+
#endif
137+
138+
if (record->atyp == luascriptAVALType_Double)
139+
{
140+
for(index = 0; index < n_elements && index < array_len; index += 1)
141+
{
142+
buffer[index] = (float) ((double*) record->aval)[index];
143+
}
144+
145+
return dbCaPutLinkCallback(out, DBF_FLOAT, buffer, array_len, (dbCaCallback) dbCaCallbackProcess, out);
146+
}
147+
else if(record->atyp == luascriptAVALType_Integer)
148+
{
149+
for(index = 0; index < n_elements && index < array_len; index += 1)
150+
{
151+
buffer[index] = (float) ((int*) record->aval)[index];
152+
}
153+
154+
return dbCaPutLinkCallback(out, DBF_FLOAT, buffer, array_len, (dbCaCallback) dbCaCallbackProcess, out);
155+
}
156+
157+
return 0;
158+
}
159+
160+
default:
161+
{
162+
if (record->atyp == luascriptAVALType_Integer)
163+
{
164+
dbCaPutLinkCallback(out, DBF_LONG, record->aval, array_len, (dbCaCallback) dbCaCallbackProcess, out);
165+
}
166+
167+
return 0;
168+
}
169+
}
170+
}
171+
54172
switch (field_type)
55173
{
56174
case DBF_STRING:
@@ -118,7 +236,7 @@ static long syncWrite(luascriptRecord* record, double* val, char* sval, struct l
118236
}
119237
else if (out->type == DB_LINK)
120238
{
121-
if (!dbNameToAddr(out->value.pv_link.pvname, pAddr))
239+
if (!dbNameToAddr(out->value.pv_link.pvname, pAddr))
122240
{
123241
field_type = pAddr->field_type;
124242
n_elements = pAddr->no_elements;

0 commit comments

Comments
 (0)