Rename asub and cleanup

This commit is contained in:
Anders Sandstrom
2021-03-18 10:01:35 +01:00
parent 5b518a0661
commit 46679dfc3e
5 changed files with 156 additions and 177 deletions

View File

@@ -57,7 +57,7 @@ SOURCES += $(APPSRC)/ecmcCANOpenSDO.cpp
SOURCES += $(APPSRC)/ecmcCANOpenPDO.cpp
SOURCES += $(APPSRC)/ecmcCANOpenDevice.cpp
SOURCES += $(APPSRC)/ecmcCANOpenMaster.cpp
SOURCES += $(APPSRC)/ecmcWriteArrayUint8Elements.cpp
SOURCES += $(APPSRC)/ecmcByteToArrayAsub.cpp
DBDS += $(APPSRC)/ecmcSocketCAN.dbd

View File

@@ -0,0 +1,152 @@
// aSub, EPICS related headers
#include <aSubRecord.h>
#include <registryFunction.h>
#include <epicsExport.h>
// std::cout
#include <iostream>
// split double into fractional and integer
#include <math.h>
#include <string.h>
// declare init function
static long ecmcByteToArrayInit(struct aSubRecord *rec);
epicsRegisterFunction(ecmcByteToArrayInit);
// declare worker function
static long ecmcByteToArray(struct aSubRecord *rec);
epicsRegisterFunction(ecmcByteToArray);
// init (INAM)
static long ecmcByteToArrayInit(struct aSubRecord *rec){
std::cout << "ecmcByteToArrayInit aSubRecord: "<< rec->name << std::endl;
printf("ecmcByteToArray aSubRecord: %d\n",rec->noa);
return 0;
}
static long ecmcByteToArray(struct aSubRecord *rec){
printf("EXECUTING!!!!!\n");
// input A must be size of output array
epicsUInt8 byteCount=(epicsUInt8)rec->nova;
// Max 18 byte in a row
if(byteCount <=0 || byteCount>18){
printf("WARNING: Only 18 first bytes will be transferred to output.\n");
}
epicsUInt8 *vala;
vala = (epicsUInt8 *)rec->vala;
if(byteCount >= 1 && rec->noa ==1) {
vala[0]=*(epicsUInt8 *)rec->a;
}
if(byteCount >= 2 && rec->nob ==1) {
vala[1]=*(epicsUInt8 *)rec->b;
}
if(byteCount >= 3 && rec->noc ==1) {
vala[2]=*(epicsUInt8 *)rec->c;
}
if(byteCount >= 4 && rec->nod ==1) {
vala[3]=*(epicsUInt8 *)rec->d;
}
if(byteCount >= 5 && rec->noe ==1) {
vala[4]=*(epicsUInt8 *)rec->e;
}
if(byteCount >= 6 && rec->nof ==1) {
vala[5]=*(epicsUInt8 *)rec->f;
}
if(byteCount >= 7 && rec->nog ==1) {
vala[6]=*(epicsUInt8 *)rec->g;
}
if(byteCount >= 8 && rec->noh ==1) {
vala[7]=*(epicsUInt8 *)rec->h;
}
if(byteCount >= 9 && rec->noi ==1) {
vala[8]=*(epicsUInt8 *)rec->i;
}
if(byteCount >= 10 && rec->noj ==1) {
vala[9]=*(epicsUInt8 *)rec->j;
}
if(byteCount >= 11 && rec->nok ==1) {
vala[10]=*(epicsUInt8 *)rec->k;
}
if(byteCount >= 12 && rec->nol ==1) {
vala[11]=*(epicsUInt8 *)rec->l;
}
if(byteCount >= 13 && rec->nom ==1) {
vala[12]=*(epicsUInt8 *)rec->m;
}
if(byteCount >= 13 && rec->non ==1) {
vala[13]=*(epicsUInt8 *)rec->n;
}
if(byteCount >= 14 && rec->noo ==1) {
vala[14]=*(epicsUInt8 *)rec->o;
}
if(byteCount >= 15 && rec->nop ==1) {
vala[15]=*(epicsUInt8 *)rec->p;
}
if(byteCount >= 16 && rec->noq ==1) {
vala[16]=*(epicsUInt8 *)rec->q;
}
if(byteCount >= 17 && rec->nor ==1) {
vala[17]=*(epicsUInt8 *)rec->r;
}
if(byteCount >= 18 && rec->nos ==1) {
vala[18]=*(epicsUInt8 *)rec->s;
}
return 0;
}
/*
--------------------------------------------------------------------------------
EPICS database example
record(aSub, "$(P)CAN${CH_ID}-BasicConfigPackArray_") {
field(INAM, "ecmcByteToArrayInit")
field(SNAM, "ecmcByteToArray")
field(FTA, "UCHAR")
field(NOA, "1")
field(INPA, "$(P)CAN${CH_ID}-BasicConfigB0_.VAL") # Byte 0
field(FTB, "UCHAR")
field(NOB, "1")
field(INPB, "$(P)CAN${CH_ID}-VrefPwrCmdCalcB1_.VAL") # Byte 1
field(FTC, "UCHAR")
field(NOC, "1")
field(INPC, "$(P)CAN${CH_ID}-VrefPwrCmdCalcB2_.VAL") # Byte 2
field(FTD, "UCHAR")
field(NOD, "1")
field(INPD, "$(P)CAN${CH_ID}-VdcCtrlCmdCalcB3_.VAL") # Byte 3
field(FTE, "UCHAR")
field(NOE, "1")
field(INPE, "$(P)CAN${CH_ID}-VdcCtrlCmdCalcB4_.VAL") # Byte 4
field(FTF, "UCHAR")
field(NOF, "1")
field(INPF, "0") # Byte 5
field(FTG, "UCHAR")
field(NOG, "1")
field(INPG, "0") # Byte 6
field(FTVA, "UCHAR")
field(OUTA, "$(P)CAN${CH_ID}-SDO02-BasicConfig")
field(NOVA, "7") # 7 bytes (0..6 corresponds to input A..G)
field(FLNK, "$(P)CAN${CH_ID}-SDO02-BasicConfig.PROC") # Send the data
}
--------------------------------------------------------------------------------
*/

View File

@@ -1,4 +1,3 @@
registrar("ecmcCANPluginDriverRegister")
function(ecmcWriteArrayUint8ElementsInit)
function(ecmcWriteArrayUint8Elements)
function(ecmcByteToArrayInit)
function(ecmcByteToArray)

View File

@@ -1,172 +0,0 @@
// aSub, EPICS related headers
#include <aSubRecord.h>
#include <registryFunction.h>
#include <epicsExport.h>
// std::cout
#include <iostream>
// split double into fractional and integer
#include <math.h>
#include <string.h>
// declare init function
static long ecmcWriteArrayUint8ElementsInit(struct aSubRecord *rec);
epicsRegisterFunction(ecmcWriteArrayUint8ElementsInit);
// declare worker function
static long ecmcWriteArrayUint8Elements(struct aSubRecord *rec);
epicsRegisterFunction(ecmcWriteArrayUint8Elements);
// init (INAM)
static long ecmcWriteArrayUint8ElementsInit(struct aSubRecord *rec){
std::cout << "ecmcWriteArrayUint8ElementsInit aSubRecord: "<< rec->name << std::endl;
printf("ecmcWriteArrayUint8ElementsInit aSubRecord: %d\n",rec->noa);
return 0;
}
////noa elements in A
////Note that the subroutine code must always handle the value fields (A-U, VALA-VALU) as arrays, even if they contain only a single element.
// /*memcpy(pwfData, (double *)precord->a, precord->noa *
//sizeof(double));
////data processing on pwfData: std, max, min, fft,...
// ...
//
// /* put the calculated results into ai records*/
// *(double *)precord->vala = ave;*/
//
//// work (SNAM)
// NEVA output filed size
static long ecmcWriteArrayUint8Elements(struct aSubRecord *rec){
printf("EXECUTING!!!!!\n");
// input A must be size of output array
if(rec->noa !=1){
printf("Input A not scalar\n");
return 0;
}
epicsUInt8 sizeOfBuffer=*(epicsUInt8*)rec->a;
// Max 20 byte in a row
if(sizeOfBuffer <=0 || sizeOfBuffer>18){
printf("Input A out of range\n");
return 0;
}
if(sizeOfBuffer != rec->nova){
printf("Size missmatch\n");
return 0;
}
printf("EXECUTING!!!!!\n");
epicsUInt8 *buffer;
buffer=new epicsUInt8[rec->noa];
memset(buffer,0,sizeOfBuffer);
if(sizeOfBuffer >= 1 && rec->nob ==1) {
buffer[1]=*(epicsUInt8 *)rec->b;
}
if(sizeOfBuffer >= 2 && rec->noc ==1) {
buffer[2]=*(epicsUInt8 *)rec->c;
}
if(sizeOfBuffer >= 3 && rec->nod ==1) {
buffer[3]=*(epicsUInt8 *)rec->d;
}
if(sizeOfBuffer >= 4 && rec->noe ==1) {
buffer[4]=*(epicsUInt8 *)rec->e;
}
if(sizeOfBuffer >= 5 && rec->nof ==1) {
buffer[5]=*(epicsUInt8 *)rec->f;
}
if(sizeOfBuffer >= 6 && rec->nog ==1) {
buffer[6]=*(epicsUInt8 *)rec->g;
}
if(sizeOfBuffer >= 7 && rec->noh ==1) {
buffer[7]=*(epicsUInt8 *)rec->h;
}
if(sizeOfBuffer >= 8 && rec->noi ==1) {
buffer[8]=*(epicsUInt8 *)rec->i;
}
if(sizeOfBuffer >= 9 && rec->noj ==1) {
buffer[9]=*(epicsUInt8 *)rec->j;
}
if(sizeOfBuffer >= 10 && rec->nok ==1) {
buffer[10]=*(epicsUInt8 *)rec->k;
}
if(sizeOfBuffer >= 11 && rec->nol ==1) {
buffer[11]=*(epicsUInt8 *)rec->l;
}
if(sizeOfBuffer >= 12 && rec->nom ==1) {
buffer[12]=*(epicsUInt8 *)rec->m;
}
if(sizeOfBuffer >= 13 && rec->non ==1) {
buffer[13]=*(epicsUInt8 *)rec->n;
}
if(sizeOfBuffer >= 14 && rec->noo ==1) {
buffer[14]=*(epicsUInt8 *)rec->o;
}
if(sizeOfBuffer >= 15 && rec->nop ==1) {
buffer[15]=*(epicsUInt8 *)rec->p;
}
if(sizeOfBuffer >= 16 && rec->noq ==1) {
buffer[16]=*(epicsUInt8 *)rec->q;
}
if(sizeOfBuffer >= 17 && rec->nor ==1) {
buffer[17]=*(epicsUInt8 *)rec->r;
}
if(sizeOfBuffer >= 18 && rec->nos ==1) {
buffer[18]=*(epicsUInt8 *)rec->s;
}
// if(sizeOfBuffer >= 19 && rec->not ==1) {
// buffer[19]=*(epicsUInt8 *)rec->t;
// }
//
// if(sizeOfBuffer >= 20 && rec->nou ==1) {
// buffer[20]=*(epicsUInt8 *)rec->u;
// }
// better to use vala direct instead of buffer... hmm
epicsUInt8 *vala;
vala = (epicsUInt8 *)rec->vala;
for(int i = 0; i<sizeOfBuffer; i++) {
vala[i] = buffer[i];
}
printf("EXECUTED!!!!!\n");
return 0;
}
/*
--------------------------------------------------------------------------------
EPICS database example
record(aSub, "${SYS}:ECATtimestamp") {
field(DESC, "ECAT timestamp")
field(INAM, "ECATtimestampInit")
field(SNAM, "ECATtimestamp")
field(FTA, "DOUBLE")
field(NOA, 1)
field(TSE, -2)
}
--------------------------------------------------------------------------------
*/