Skip to content

Commit 790243d

Browse files
committed
fix 3.15 incompatibilities
1 parent b555645 commit 790243d

5 files changed

Lines changed: 72 additions & 29 deletions

File tree

luaApp/src/luaEpics.h

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,33 @@ epicsShareFunc std::string luaMacrosFromTable(lua_State* state, int index);
6666
*
6767
* The native field_type values from dbFldTypes.h conflict with the
6868
* DBF_* macros from db_access.h (included by cadef.h) -- they use
69-
* different numeric values for the same names. These constants and
70-
* the dbf_to_lua_type mapping resolve this by using the known numeric
71-
* values from dbFldTypes.h directly.
69+
* different numeric values for the same names. These DB_DBR_*
70+
* constants use the dbFldTypes.h numbering for dbGetField/dbPutField.
71+
*
72+
* Base 7.0 inserted INT64/UINT64 at positions 7-8, shifting
73+
* FLOAT/DOUBLE/ENUM by 2 relative to 3.15.
74+
*
75+
* dbFldTypes.h enum (3.15):
76+
* 0=STRING, 1=CHAR, 2=UCHAR, 3=SHORT, 4=USHORT,
77+
* 5=LONG, 6=ULONG, 7=FLOAT, 8=DOUBLE, 9=ENUM,
78+
* 10=MENU, 11=DEVICE
79+
*
80+
* dbFldTypes.h enum (7.0+):
81+
* 0=STRING, 1=CHAR, 2=UCHAR, 3=SHORT, 4=USHORT,
82+
* 5=LONG, 6=ULONG, 7=INT64, 8=UINT64, 9=FLOAT,
83+
* 10=DOUBLE, 11=ENUM, 12=MENU, 13=DEVICE
7284
*/
7385

74-
/* Database-side DBR request type values from dbFldTypes.h */
86+
/* Database-side request type values from dbFldTypes.h */
7587
#define DB_DBR_STRING 0
7688
#define DB_DBR_CHAR 1
7789
#define DB_DBR_LONG 5
90+
91+
#if EPICS_VERSION_INT >= VERSION_INT(7, 0, 0, 0)
7892
#define DB_DBR_DOUBLE 10
93+
#else
94+
#define DB_DBR_DOUBLE 8
95+
#endif
7996

8097
enum db_lua_type {
8198
DB_LUA_STRING,
@@ -88,25 +105,27 @@ enum db_lua_type {
88105

89106
/*
90107
* Map the native database field_type (dbFldTypes.h enum values)
91-
* to a Lua type category.
92-
*
93-
* dbFldTypes.h enum:
94-
* 0=STRING, 1=CHAR, 2=UCHAR, 3=SHORT, 4=USHORT,
95-
* 5=LONG, 6=ULONG, 7=INT64, 8=UINT64, 9=FLOAT,
96-
* 10=DOUBLE, 11=ENUM, 12=MENU, 13=DEVICE
108+
* to a Lua type category. Version-guarded for the INT64/UINT64
109+
* shift between base 3.15 and 7.0.
97110
*/
98111
static inline enum db_lua_type dbf_to_lua_type(short field_type)
99112
{
100113
switch (field_type)
101114
{
102-
case 0: return DB_LUA_STRING;
103-
case 1: case 2: return DB_LUA_CHAR;
104-
case 3: case 4: return DB_LUA_INTEGER;
105-
case 5: case 6: return DB_LUA_INTEGER;
106-
case 7: case 8: return DB_LUA_DOUBLE;
107-
case 9: case 10: return DB_LUA_DOUBLE;
115+
case 0: return DB_LUA_STRING; /* STRING */
116+
case 1: case 2: return DB_LUA_CHAR; /* CHAR, UCHAR */
117+
case 3: case 4: return DB_LUA_INTEGER; /* SHORT, USHORT */
118+
case 5: case 6: return DB_LUA_INTEGER; /* LONG, ULONG */
119+
#if EPICS_VERSION_INT >= VERSION_INT(7, 0, 0, 0)
120+
case 7: case 8: return DB_LUA_DOUBLE; /* INT64, UINT64 */
121+
case 9: case 10: return DB_LUA_DOUBLE; /* FLOAT, DOUBLE */
108122
case 11: case 12:
109-
case 13: return DB_LUA_ENUM;
123+
case 13: return DB_LUA_ENUM; /* ENUM, MENU, DEVICE */
124+
#else
125+
case 7: case 8: return DB_LUA_DOUBLE; /* FLOAT, DOUBLE */
126+
case 9: case 10:
127+
case 11: return DB_LUA_ENUM; /* ENUM, MENU, DEVICE */
128+
#endif
110129
default: return DB_LUA_UNKNOWN;
111130
}
112131
}

luaApp/test/luaEpicsTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,18 @@ MAIN(luaEpicsTest)
360360
testIocInitOk();
361361
eltc(1);
362362

363+
/* Initialize waveform test data (replaces JSON INP syntax for 3.15 compat) */
364+
{
365+
DBADDR addr;
366+
double dvals[] = {1.0, 2.0, 3.0, 4.0, 5.0};
367+
dbNameToAddr("etest:test_dwf", &addr);
368+
dbPutField(&addr, DBF_DOUBLE, dvals, 5);
369+
370+
char cvals[] = {72, 101, 108, 108, 111}; /* "Hello" */
371+
dbNameToAddr("etest:test_cwf", &addr);
372+
dbPutField(&addr, DBF_CHAR, cvals, 5);
373+
}
374+
363375
/* Local PV fast path */
364376
testGetLocalDouble();
365377
testGetLocalString();

luaApp/test/luaEpicsTest.db

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ record(stringout, "$(P)test_so") {
2424
record(waveform, "$(P)test_dwf") {
2525
field(FTVL, "DOUBLE")
2626
field(NELM, "5")
27-
field(INP, "[1.0, 2.0, 3.0, 4.0, 5.0]")
28-
field(PINI, "YES")
2927
}
3028

3129
record(waveform, "$(P)test_cwf") {
3230
field(FTVL, "CHAR")
3331
field(NELM, "256")
34-
field(INP, "[72,101,108,108,111]")
35-
field(PINI, "YES")
3632
}

luaApp/test/luaScriptTest.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,30 @@ MAIN(luaScriptTest)
453453
testIocInitOk();
454454
eltc(1);
455455

456+
/* Initialize waveform test data (replaces JSON INP syntax for 3.15 compat) */
457+
{
458+
DBADDR addr;
459+
double dvals[] = {1.0, 2.0, 3.0, 4.0, 5.0};
460+
dbNameToAddr("test:double_wf", &addr);
461+
dbPutField(&addr, DBF_DOUBLE, dvals, 5);
462+
463+
epicsInt32 ivals[] = {10, 20, 30, 40, 50};
464+
dbNameToAddr("test:int_wf", &addr);
465+
dbPutField(&addr, DBF_LONG, ivals, 5);
466+
467+
char cvals[] = {72, 101, 108, 108, 111}; /* "Hello" */
468+
dbNameToAddr("test:char_wf", &addr);
469+
dbPutField(&addr, DBF_CHAR, cvals, 5);
470+
471+
char svals[3][MAX_STRING_SIZE];
472+
memset(svals, 0, sizeof(svals));
473+
strncpy(svals[0], "alpha", MAX_STRING_SIZE - 1);
474+
strncpy(svals[1], "beta", MAX_STRING_SIZE - 1);
475+
strncpy(svals[2], "gamma", MAX_STRING_SIZE - 1);
476+
dbNameToAddr("test:string_wf", &addr);
477+
dbPutField(&addr, DBF_STRING, svals, 3);
478+
}
479+
456480
testNumericReturn();
457481
testStringReturn();
458482
testTableReturn();

luaApp/test/luaScriptTest.db

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,21 @@ record(luascript, "$(P)udf") {
8686
record(waveform, "$(P)double_wf") {
8787
field(FTVL, "DOUBLE")
8888
field(NELM, "5")
89-
field(INP, "[1.0, 2.0, 3.0, 4.0, 5.0]")
90-
field(PINI, "YES")
9189
}
9290

9391
record(waveform, "$(P)int_wf") {
9492
field(FTVL, "LONG")
9593
field(NELM, "5")
96-
field(INP, "[10, 20, 30, 40, 50]")
97-
field(PINI, "YES")
9894
}
9995

10096
record(waveform, "$(P)char_wf") {
10197
field(FTVL, "CHAR")
10298
field(NELM, "256")
103-
field(INP, "[72, 101, 108, 108, 111]")
104-
field(PINI, "YES")
10599
}
106100

107101
record(waveform, "$(P)string_wf") {
108102
field(FTVL, "STRING")
109103
field(NELM, "3")
110-
field(INP, "[\"alpha\", \"beta\", \"gamma\"]")
111-
field(PINI, "YES")
112104
}
113105

114106
record(waveform, "$(P)output_wf") {

0 commit comments

Comments
 (0)