cmAudDsp.h/c, cmAudioSys.h/c, cmDspSys.h/c, cmDspNet.h : Added support for serial port.

This commit is contained in:
kevin.larke 2020-02-21 15:41:24 -05:00
parent 5fc0fccb83
commit e686cc2c9c
7 changed files with 108 additions and 7 deletions

View File

@ -19,6 +19,7 @@
#include "cmApBuf.h" #include "cmApBuf.h"
#include "cmMidi.h" #include "cmMidi.h"
#include "cmMidiPort.h" #include "cmMidiPort.h"
#include "cmSerialPort.h"
#include "dsp/cmDspValue.h" #include "dsp/cmDspValue.h"
#include "cmMsgProtocol.h" #include "cmMsgProtocol.h"
#include "cmThread.h" #include "cmThread.h"
@ -91,6 +92,12 @@ typedef struct
unsigned msgsPerClientPoll; unsigned msgsPerClientPoll;
const cmChar_t* dfltProgramLabel; const cmChar_t* dfltProgramLabel;
char* serialDeviceStr;
unsigned serialBaud;
unsigned serialCfgFlags;
unsigned serialPollPeriodMs;
cmSeH_t serialPortH;
cmAdAggDev_t* aggDevArray; cmAdAggDev_t* aggDevArray;
unsigned aggDevCnt; unsigned aggDevCnt;
@ -169,6 +176,7 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
cmJsonNode_t* nrtDevArrNodePtr = NULL; cmJsonNode_t* nrtDevArrNodePtr = NULL;
cmJsonNode_t* afpDevArrNodePtr = NULL; cmJsonNode_t* afpDevArrNodePtr = NULL;
cmJsonNode_t* audDspNodePtr = NULL; cmJsonNode_t* audDspNodePtr = NULL;
cmJsonNode_t* serialNodePtr = NULL;
const cmChar_t* errLabelPtr = NULL; const cmChar_t* errLabelPtr = NULL;
unsigned i; unsigned i;
cmJsRC_t jsRC = kOkJsRC; cmJsRC_t jsRC = kOkJsRC;
@ -190,12 +198,28 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
"aggDevArray", kArrayTId | kOptArgJsFl, &aggDevArrNodePtr, "aggDevArray", kArrayTId | kOptArgJsFl, &aggDevArrNodePtr,
"nrtDevArray", kArrayTId | kOptArgJsFl, &nrtDevArrNodePtr, "nrtDevArray", kArrayTId | kOptArgJsFl, &nrtDevArrNodePtr,
"afpDevArray", kArrayTId | kOptArgJsFl, &afpDevArrNodePtr, "afpDevArray", kArrayTId | kOptArgJsFl, &afpDevArrNodePtr,
"serial", kObjectTId | kOptArgJsFl, &serialNodePtr,
NULL )) != kOkJsRC ) NULL )) != kOkJsRC )
{ {
rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" ); rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" );
goto errLabel; goto errLabel;
} }
// parse the serial port cfg
if( serialNodePtr != NULL )
{
if(( jsRC = cmJsonMemberValues( serialNodePtr, &errLabelPtr,
"device", kStringTId, &p->serialDeviceStr,
"baud", kIntTId, &p->serialBaud,
"flags", kIntTId, &p->serialCfgFlags,
"pollPeriodMs", kIntTId, &p->serialPollPeriodMs,
NULL )) != kOkJsRC )
{
rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "serial" );
goto errLabel;
}
}
// parse the aggregate device specifications into p->aggDevArray[]. // parse the aggregate device specifications into p->aggDevArray[].
if( aggDevArrNodePtr != NULL && (p->aggDevCnt = cmJsonChildCount(aggDevArrNodePtr)) > 0) if( aggDevArrNodePtr != NULL && (p->aggDevCnt = cmJsonChildCount(aggDevArrNodePtr)) > 0)
{ {
@ -382,6 +406,22 @@ cmAdRC_t _cmAdSetup( cmAd_t* p )
return rc; return rc;
} }
cmAdRC_t _cmAdCreateSerialPort( cmAd_t* p )
{
cmAdRC_t rc = kOkAdRC;
if( p->serialDeviceStr != NULL )
{
p->serialPortH = cmSeCreate( &p->ctx, &p->serialPortH, p->serialDeviceStr, p->serialBaud, p->serialCfgFlags, NULL, NULL, p->serialPollPeriodMs );
if( !cmSeIsOpen(p->serialPortH) )
{
rc = cmErrMsg(&p->err,kSerialDevCreateFailAdRC,"The serial device '%s' creation failed.",cmStringNullGuard(p->serialDeviceStr));
}
}
return rc;
}
cmAdRC_t _cmAdCreateAggDevices( cmAd_t* p ) cmAdRC_t _cmAdCreateAggDevices( cmAd_t* p )
{ {
cmAdRC_t rc = kOkAdRC; cmAdRC_t rc = kOkAdRC;
@ -570,6 +610,15 @@ cmAdRC_t _cmAudDspFree( cmAd_t* p )
goto errLabel; goto errLabel;
} }
if( cmSeIsOpen(p->serialPortH) )
{
if( cmSeDestroy(&p->serialPortH) != kOkSeRC )
{
rc = cmErrMsg(&p->err,kSerialPortFailAdRC,"Serial port finalize failed.");
goto errLabel;
}
}
if( cmMpIsInitialized() ) if( cmMpIsInitialized() )
if( cmMpFinalize() != kOkMpRC ) if( cmMpFinalize() != kOkMpRC )
{ {
@ -695,6 +744,13 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
goto errLabel; goto errLabel;
} }
// create the serial port
if( _cmAdCreateSerialPort(p) != kOkAdRC )
{
rc = cmErrMsg(&p->err,kSerialPortFailAdRC,"The MIDI system initialization failed.");
goto errLabel;
}
// initialize the MIDI system // initialize the MIDI system
if( cmMpInitialize(ctx,NULL,NULL,p->midiPortBufByteCnt,"app") != kOkMpRC ) if( cmMpInitialize(ctx,NULL,NULL,p->midiPortBufByteCnt,"app") != kOkMpRC )
{ {
@ -713,7 +769,7 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
goto errLabel; goto errLabel;
// initialize the DSP system // initialize the DSP system
if( cmDspSysInitialize(ctx,&p->dsH,p->netH) ) if( cmDspSysInitialize(ctx,&p->dsH,p->netH,p->serialPortH) )
{ {
rc = cmErrMsg(&p->err,kDspSysFailAdRC,"The DSP system initialization failed."); rc = cmErrMsg(&p->err,kDspSysFailAdRC,"The DSP system initialization failed.");
goto errLabel; goto errLabel;
@ -1143,7 +1199,7 @@ cmAdRC_t _cmAudDspLoadAudioSys( cmAd_t* p, unsigned asCfgIdx )
{ {
// ... and allocate additional DSP systems when more than one sub-sys is // ... and allocate additional DSP systems when more than one sub-sys is
// defined in the audio system configuration // defined in the audio system configuration
if( cmDspSysInitialize(&p->ctx,&dsH,p->netH) != kOkDspRC ) if( cmDspSysInitialize(&p->ctx,&dsH,p->netH,p->serialPortH) != kOkDspRC )
{ {
rc = cmErrMsg(&p->err,kDspSysFailAdRC,"Unable to initialize an additional DSP system."); rc = cmErrMsg(&p->err,kDspSysFailAdRC,"Unable to initialize an additional DSP system.");
goto errLabel; goto errLabel;

View File

@ -13,6 +13,7 @@ extern "C" {
kAudioPortFailAdRC, kAudioPortFailAdRC,
kAudioSysFailAdRC, kAudioSysFailAdRC,
kMidiSysFailAdRC, kMidiSysFailAdRC,
kSerialPortFailAdRC,
kDspSysFailAdRC, kDspSysFailAdRC,
kFileSysFailAdRC, kFileSysFailAdRC,
kJsonFailAdRC, kJsonFailAdRC,
@ -21,6 +22,7 @@ extern "C" {
kNoPgmLoadedAdRC, kNoPgmLoadedAdRC,
kInvalidSubSysIdxAdRC, kInvalidSubSysIdxAdRC,
kUnknownMsgTypeAdRC, kUnknownMsgTypeAdRC,
kSerialDevCreateFailAdRC,
kAggDevSysFailAdRC, kAggDevSysFailAdRC,
kAggDevCreateFailAdRC, kAggDevCreateFailAdRC,
kNrtDevSysFailAdRC, kNrtDevSysFailAdRC,

View File

@ -15,6 +15,7 @@
#include "cmThread.h" #include "cmThread.h"
#include "cmUdpPort.h" #include "cmUdpPort.h"
#include "cmUdpNet.h" #include "cmUdpNet.h"
#include "cmSerialPort.h"
#include "cmAudioSysMsg.h" #include "cmAudioSysMsg.h"
#include "cmAudioSys.h" #include "cmAudioSys.h"
#include "cmMidi.h" #include "cmMidi.h"
@ -37,6 +38,7 @@ typedef struct
cmTsMp1cH_t htdQueueH; // host-to-dsp thread safe msg queue cmTsMp1cH_t htdQueueH; // host-to-dsp thread safe msg queue
cmThreadMutexH_t engMutexH; // thread mutex and condition variable cmThreadMutexH_t engMutexH; // thread mutex and condition variable
cmUdpNetH_t netH; cmUdpNetH_t netH;
cmSeH_t serialPortH;
bool enableFl; // application controlled pause flag bool enableFl; // application controlled pause flag
bool runFl; // false during finalization otherwise true bool runFl; // false during finalization otherwise true
bool statusFl; // true if regular status notifications should be sent bool statusFl; // true if regular status notifications should be sent
@ -507,6 +509,13 @@ void _cmAudioSysMidiCallback( const cmMidiPacket_t* pktArray, unsigned pktCnt )
} }
void _cmAudioSysSerialPortCallback( void* cbArg, const void* byteA, unsigned byteN )
{
//_cmAsCfg_t* p (_cmAsCfg_t*)cbArg;
// TODO: handle serial receive
}
cmAsRC_t cmAudioSysAllocate( cmAudioSysH_t* hp, cmRpt_t* rpt, const cmAudioSysCfg_t* cfg ) cmAsRC_t cmAudioSysAllocate( cmAudioSysH_t* hp, cmRpt_t* rpt, const cmAudioSysCfg_t* cfg )
{ {
cmAsRC_t rc; cmAsRC_t rc;
@ -832,6 +841,7 @@ cmAsRC_t cmAudioSysInitialize( cmAudioSysH_t h, const cmAudioSysCfg_t* cfg )
cp->iMeterArray = cmMemAllocZ( double, cp->status.iMeterCnt ); cp->iMeterArray = cmMemAllocZ( double, cp->status.iMeterCnt );
cp->oMeterArray = cmMemAllocZ( double, cp->status.oMeterCnt ); cp->oMeterArray = cmMemAllocZ( double, cp->status.oMeterCnt );
cp->netH = cfg->netH; cp->netH = cfg->netH;
cp->serialPortH = cfg->serialPortH;
// create the audio System thread // create the audio System thread
if((rc = cmThreadCreate( &cp->threadH, _cmAsThreadCallback, cp, ss->args.rpt )) != kOkThRC ) if((rc = cmThreadCreate( &cp->threadH, _cmAsThreadCallback, cp, ss->args.rpt )) != kOkThRC )
@ -874,6 +884,16 @@ cmAsRC_t cmAudioSysInitialize( cmAudioSysH_t h, const cmAudioSysCfg_t* cfg )
goto errLabel; goto errLabel;
} }
// install the serial port
if( cmSeIsOpen(cp->serialPortH) )
{
if( cmSeSetCallback(cp->serialPortH, _cmAudioSysSerialPortCallback, cp ) != kOkSeRC )
{
rc = _cmAsError(p,kSerialPortFailAsRC,"Serial port callback installation failed.");
goto errLabel;
}
}
// setup the sub-system status notification // setup the sub-system status notification
cp->statusUpdateSmpCnt = floor(cmApBufMeterMs() * cp->ss.args.srate / 1000.0 ); cp->statusUpdateSmpCnt = floor(cmApBufMeterMs() * cp->ss.args.srate / 1000.0 );
cp->statusUpdateSmpIdx = 0; cp->statusUpdateSmpIdx = 0;
@ -886,6 +906,16 @@ cmAsRC_t cmAudioSysInitialize( cmAudioSysH_t h, const cmAudioSysCfg_t* cfg )
rc = _cmAsError(p,kThreadErrAsRC,"Thread start failed."); rc = _cmAsError(p,kThreadErrAsRC,"Thread start failed.");
goto errLabel; goto errLabel;
} }
if( cmSeIsOpen(cp->serialPortH) )
{
if( cmSeStart( cp->serialPortH ) != kOkSeRC )
{
rc = _cmAsError(p,kSerialPortFailAsRC,"Serial port start failed.");
goto errLabel;
}
}
} }

View File

@ -73,6 +73,7 @@ extern "C" {
kBufTooSmallAsRC, kBufTooSmallAsRC,
kNoMsgWaitingAsRC, kNoMsgWaitingAsRC,
kMidiSysFailAsRC, kMidiSysFailAsRC,
kSerialPortFailAsRC,
kMsgSerializeFailAsRC, kMsgSerializeFailAsRC,
kStateBufFailAsRC, kStateBufFailAsRC,
kInvalidArgAsRC, kInvalidArgAsRC,
@ -197,6 +198,7 @@ extern "C" {
cmTsQueueCb_t clientCbFunc; // Called by cmAudioSysReceiveMsg() to deliver internally generated msg's to the host. cmTsQueueCb_t clientCbFunc; // Called by cmAudioSysReceiveMsg() to deliver internally generated msg's to the host.
// Set to NULL if msg's will be directly returned by buffers passed to cmAudioSysReceiveMsg(). // Set to NULL if msg's will be directly returned by buffers passed to cmAudioSysReceiveMsg().
cmUdpNetH_t netH; cmUdpNetH_t netH;
cmSeH_t serialPortH;
} cmAudioSysCfg_t; } cmAudioSysCfg_t;
extern cmAudioSysH_t cmAudioSysNullHandle; extern cmAudioSysH_t cmAudioSysNullHandle;

View File

@ -72,6 +72,7 @@ extern "C" {
cmDspPresetMgr_t pm; cmDspPresetMgr_t pm;
unsigned nextInstId; unsigned nextInstId;
unsigned pgmIdx; unsigned pgmIdx;
cmSeH_t serialPortH;
cmUdpNetH_t netH; // cmUdpNetH_t netH; //

View File

@ -19,6 +19,7 @@
#include "cmThread.h" #include "cmThread.h"
#include "cmUdpPort.h" #include "cmUdpPort.h"
#include "cmUdpNet.h" #include "cmUdpNet.h"
#include "cmSerialPort.h"
#include "cmAudioSys.h" #include "cmAudioSys.h"
#include "cmProcObj.h" #include "cmProcObj.h"
#include "cmDspCtx.h" #include "cmDspCtx.h"
@ -165,7 +166,7 @@ cmDspRC_t _cmDspSysFinalize( cmDsp_t* p )
return rc; return rc;
} }
cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH ) cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH, cmSeH_t serialPortH )
{ {
unsigned i; unsigned i;
cmDspRC_t rc = kOkDspRC; cmDspRC_t rc = kOkDspRC;
@ -178,9 +179,10 @@ cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH )
cmErrSetup(&p->err,&ctx->rpt,"DSP System"); cmErrSetup(&p->err,&ctx->rpt,"DSP System");
//p->ctx.ctx = asCtx; //p->ctx.ctx = asCtx;
p->cmCtx = *ctx; p->cmCtx = *ctx;
p->netH = netH; p->netH = netH;
p->pgmIdx = cmInvalidIdx; p->serialPortH = serialPortH;
p->pgmIdx = cmInvalidIdx;
// create the DSP class linked heap // create the DSP class linked heap
if(cmLHeapIsValid( p->lhH = cmLHeapCreate(1024,ctx)) == false) if(cmLHeapIsValid( p->lhH = cmLHeapCreate(1024,ctx)) == false)
@ -1560,6 +1562,13 @@ cmSymTblH_t cmDspSysSymbolTable( cmDspSysH_t h )
return p->ctx.stH; return p->ctx.stH;
} }
cmSeH_t cmDspSysSerialPort( cmDspSysH_t h )
{
cmDsp_t* p = _cmDspHandleToPtr(h);
return p->serialPortH;
}
unsigned cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel ) unsigned cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel )
{ return cmSymTblRegisterStaticSymbol( cmDspSysSymbolTable(h), symLabel ); } { return cmSymTblRegisterStaticSymbol( cmDspSysSymbolTable(h), symLabel ); }

View File

@ -23,7 +23,7 @@ extern "C" {
// Control Functions // Control Functions
// //
cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH ); cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH, cmSeH_t serialPortH );
cmDspRC_t cmDspSysFinalize( cmDspSysH_t* hp ); cmDspRC_t cmDspSysFinalize( cmDspSysH_t* hp );
bool cmDspSysIsValid( cmDspSysH_t h ); bool cmDspSysIsValid( cmDspSysH_t h );
@ -156,6 +156,7 @@ extern "C" {
double cmDspSysSampleRate( cmDspSysH_t h ); double cmDspSysSampleRate( cmDspSysH_t h );
cmJsonH_t cmDspSysPgmRsrcHandle( cmDspSysH_t h ); cmJsonH_t cmDspSysPgmRsrcHandle( cmDspSysH_t h );
cmSymTblH_t cmDspSysSymbolTable( cmDspSysH_t h ); cmSymTblH_t cmDspSysSymbolTable( cmDspSysH_t h );
cmSeH_t cmDspSysSerialPort( cmDspSysH_t h );
unsigned cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel ); unsigned cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel );
unsigned cmDspSysRegisterSymbol( cmDspSysH_t h, const cmChar_t* symLabel ); unsigned cmDspSysRegisterSymbol( cmDspSysH_t h, const cmChar_t* symLabel );