Commit 1ca7a060 authored by Benoit Rat's avatar Benoit Rat

epics: Add parsing of epicsdb_* fields to generate custom EPICS db fields

This commit lets the user define the fields in the .wb that are going to
forwarded to the EPICS database.

if we have in the *.wb

~~~~~~~~~~~~{.wb}
      field {
         name = "Amplitude";
         ...
         epicsdb_egu  = "V";
         epicsdb_hopr = "1.5";
      };
~~~~~~~~~~~~

We will obtain in the *.db

~~~~~~~~~~~~{.wb}
record(ao, "$(user):AdcAmpSet")
{
	...
	field(DESC ,"Amplitude")
	field(EGU  ,"V")
	field(HOPR ,"1.5")
}
~~~~~~~~~~~~
parent e0f0978a
......@@ -10,6 +10,17 @@
-- generates records for each field in the wishbone
--
function cgen_db_epics_fields(field)
if (field.epicsdb_desc == nil) then
emit(string.format("\tfield(%-5s,\"%s\")", "DESC", field.name));
end
for k,v in pairs(field) do
if(type(k)=="string" and string.match(k,"epicsdb_(.*)")) then
emit(string.format("\tfield(%-5s,\"%s\")",string.upper(string.sub(k,9)),v));
end
end
end
function cgen_db_field_records(field, reg, index)
local prefix;
-- anonymous field?
......@@ -24,6 +35,11 @@ function cgen_db_field_records(field, reg, index)
prefix_records= prefix_c:gsub("_(%a)", string.upper):gsub("^%l", string.upper);
end
field.precision=0
if(field.nbfp ~= nil and field.nbfp > 0) then
precision=math.ceil(math.log10(math.pow(2,field.nbfp)));
end
emit("##---------------- '"..field.name.."' in '"..reg.name.."'");
if(field.access_bus == WRITE_ONLY or field.access_bus == READ_WRITE) then
emit("");
......@@ -37,16 +53,16 @@ function cgen_db_field_records(field, reg, index)
emit("{");
if(field.nbfp ~= nil and field.nbfp > 0) then
emit(string.format("\tfield(%-5s,\"%s\")", "DTYP", "asynFloat64"));
precision=math.ceil(math.log10(math.pow(2,field.nbfp)));
emit(string.format("\tfield(%-5s,\"%d\")", "PREC", precision));
if (field.epicsdb_prec == nil) then
emit(string.format("\tfield(%-5s,\"%d\")", "PREC", precision));
end
else
emit(string.format("\tfield(%-5s,\"%s\")", "DTYP", "asynInt32"));
end
emit(string.format("\tfield(%-5s,\"%s%s\")", "OUT", "@asyn($(PORT),$(ADDR),$(TIMEOUT))",prefix_c));
end
emit(string.format("\tfield(%-5s,\"%s\")", "DESC", field.name));
cgen_db_epics_fields(field);
emit("}");
end
if(field.access_bus == READ_ONLY or field.access_bus == READ_WRITE) then
emit("");
......@@ -61,17 +77,19 @@ function cgen_db_field_records(field, reg, index)
emit("{");
if(field.nbfp ~= nil and field.nbfp > 0) then
emit(string.format("\tfield(%-5s,\"%s\")", "DTYP", "asynFloat64"));
precision=math.ceil(math.log10(math.pow(2,field.nbfp)));
emit(string.format("\tfield(%-5s,\"%d\")", "PREC", precision));
if (field.epicsdb_prec == nil) then
emit(string.format("\tfield(%-5s,\"%d\")", "PREC", precision));
end
else
emit(string.format("\tfield(%-5s,\"%s\")", "DTYP", "asynInt32"));
end
emit(string.format("\tfield(%-5s,\"%s%s\")", "INP", "@asyn($(PORT),$(ADDR),$(TIMEOUT))",prefix_c));
emit(string.format("\tfield(%-5s,\"%s\")", "SCAN", "I/O Intr"));
end
emit(string.format("\tfield(%-5s,\"%s\")", "DESC", field.name));
cgen_db_epics_fields(field);
emit("}");
end
emit("");
end
......@@ -103,7 +121,7 @@ function cgen_db_fileheader()
emit("# ");
emit("# * File : "..options.output_epics_db_file);
emit("# * Author : auto-generated by wbgen2 from "..input_wb_file);
emit("# * Generated : "..os.date());
emit("# * Generated : "..os.date());
emit("# ");
emit("# THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE "..input_wb_file);
emit("# ");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment