|
@@ -19,6 +19,7 @@
|
19
|
19
|
#include "cmApBuf.h"
|
20
|
20
|
#include "cmMidi.h"
|
21
|
21
|
#include "cmMidiPort.h"
|
|
22
|
+#include "cmSerialPort.h"
|
22
|
23
|
#include "dsp/cmDspValue.h"
|
23
|
24
|
#include "cmMsgProtocol.h"
|
24
|
25
|
#include "cmThread.h"
|
|
@@ -91,6 +92,12 @@ typedef struct
|
91
|
92
|
unsigned msgsPerClientPoll;
|
92
|
93
|
const cmChar_t* dfltProgramLabel;
|
93
|
94
|
|
|
95
|
+ char* serialDeviceStr;
|
|
96
|
+ unsigned serialBaud;
|
|
97
|
+ unsigned serialCfgFlags;
|
|
98
|
+ unsigned serialPollPeriodMs;
|
|
99
|
+ cmSeH_t serialPortH;
|
|
100
|
+
|
94
|
101
|
cmAdAggDev_t* aggDevArray;
|
95
|
102
|
unsigned aggDevCnt;
|
96
|
103
|
|
|
@@ -169,6 +176,7 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
|
169
|
176
|
cmJsonNode_t* nrtDevArrNodePtr = NULL;
|
170
|
177
|
cmJsonNode_t* afpDevArrNodePtr = NULL;
|
171
|
178
|
cmJsonNode_t* audDspNodePtr = NULL;
|
|
179
|
+ cmJsonNode_t* serialNodePtr = NULL;
|
172
|
180
|
const cmChar_t* errLabelPtr = NULL;
|
173
|
181
|
unsigned i;
|
174
|
182
|
cmJsRC_t jsRC = kOkJsRC;
|
|
@@ -190,12 +198,28 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
|
190
|
198
|
"aggDevArray", kArrayTId | kOptArgJsFl, &aggDevArrNodePtr,
|
191
|
199
|
"nrtDevArray", kArrayTId | kOptArgJsFl, &nrtDevArrNodePtr,
|
192
|
200
|
"afpDevArray", kArrayTId | kOptArgJsFl, &afpDevArrNodePtr,
|
|
201
|
+ "serial", kObjectTId | kOptArgJsFl, &serialNodePtr,
|
193
|
202
|
NULL )) != kOkJsRC )
|
194
|
203
|
{
|
195
|
204
|
rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" );
|
196
|
205
|
goto errLabel;
|
197
|
206
|
}
|
198
|
207
|
|
|
208
|
+ // parse the serial port cfg
|
|
209
|
+ if( serialNodePtr != NULL )
|
|
210
|
+ {
|
|
211
|
+ if(( jsRC = cmJsonMemberValues( serialNodePtr, &errLabelPtr,
|
|
212
|
+ "device", kStringTId, &p->serialDeviceStr,
|
|
213
|
+ "baud", kIntTId, &p->serialBaud,
|
|
214
|
+ "flags", kIntTId, &p->serialCfgFlags,
|
|
215
|
+ "pollPeriodMs", kIntTId, &p->serialPollPeriodMs,
|
|
216
|
+ NULL )) != kOkJsRC )
|
|
217
|
+ {
|
|
218
|
+ rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "serial" );
|
|
219
|
+ goto errLabel;
|
|
220
|
+ }
|
|
221
|
+ }
|
|
222
|
+
|
199
|
223
|
// parse the aggregate device specifications into p->aggDevArray[].
|
200
|
224
|
if( aggDevArrNodePtr != NULL && (p->aggDevCnt = cmJsonChildCount(aggDevArrNodePtr)) > 0)
|
201
|
225
|
{
|
|
@@ -382,6 +406,22 @@ cmAdRC_t _cmAdSetup( cmAd_t* p )
|
382
|
406
|
return rc;
|
383
|
407
|
}
|
384
|
408
|
|
|
409
|
+cmAdRC_t _cmAdCreateSerialPort( cmAd_t* p )
|
|
410
|
+{
|
|
411
|
+ cmAdRC_t rc = kOkAdRC;
|
|
412
|
+
|
|
413
|
+ if( p->serialDeviceStr != NULL )
|
|
414
|
+ {
|
|
415
|
+ p->serialPortH = cmSeCreate( &p->ctx, &p->serialPortH, p->serialDeviceStr, p->serialBaud, p->serialCfgFlags, NULL, NULL, p->serialPollPeriodMs );
|
|
416
|
+
|
|
417
|
+ if( !cmSeIsOpen(p->serialPortH) )
|
|
418
|
+ {
|
|
419
|
+ rc = cmErrMsg(&p->err,kSerialDevCreateFailAdRC,"The serial device '%s' creation failed.",cmStringNullGuard(p->serialDeviceStr));
|
|
420
|
+ }
|
|
421
|
+ }
|
|
422
|
+ return rc;
|
|
423
|
+}
|
|
424
|
+
|
385
|
425
|
cmAdRC_t _cmAdCreateAggDevices( cmAd_t* p )
|
386
|
426
|
{
|
387
|
427
|
cmAdRC_t rc = kOkAdRC;
|
|
@@ -570,6 +610,15 @@ cmAdRC_t _cmAudDspFree( cmAd_t* p )
|
570
|
610
|
goto errLabel;
|
571
|
611
|
}
|
572
|
612
|
|
|
613
|
+ if( cmSeIsOpen(p->serialPortH) )
|
|
614
|
+ {
|
|
615
|
+ if( cmSeDestroy(&p->serialPortH) != kOkSeRC )
|
|
616
|
+ {
|
|
617
|
+ rc = cmErrMsg(&p->err,kSerialPortFailAdRC,"Serial port finalize failed.");
|
|
618
|
+ goto errLabel;
|
|
619
|
+ }
|
|
620
|
+ }
|
|
621
|
+
|
573
|
622
|
if( cmMpIsInitialized() )
|
574
|
623
|
if( cmMpFinalize() != kOkMpRC )
|
575
|
624
|
{
|
|
@@ -695,6 +744,13 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
|
695
|
744
|
goto errLabel;
|
696
|
745
|
}
|
697
|
746
|
|
|
747
|
+ // create the serial port
|
|
748
|
+ if( _cmAdCreateSerialPort(p) != kOkAdRC )
|
|
749
|
+ {
|
|
750
|
+ rc = cmErrMsg(&p->err,kSerialPortFailAdRC,"The MIDI system initialization failed.");
|
|
751
|
+ goto errLabel;
|
|
752
|
+ }
|
|
753
|
+
|
698
|
754
|
// initialize the MIDI system
|
699
|
755
|
if( cmMpInitialize(ctx,NULL,NULL,p->midiPortBufByteCnt,"app") != kOkMpRC )
|
700
|
756
|
{
|
|
@@ -713,7 +769,7 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
|
713
|
769
|
goto errLabel;
|
714
|
770
|
|
715
|
771
|
// initialize the DSP system
|
716
|
|
- if( cmDspSysInitialize(ctx,&p->dsH,p->netH) )
|
|
772
|
+ if( cmDspSysInitialize(ctx,&p->dsH,p->netH,p->serialPortH) )
|
717
|
773
|
{
|
718
|
774
|
rc = cmErrMsg(&p->err,kDspSysFailAdRC,"The DSP system initialization failed.");
|
719
|
775
|
goto errLabel;
|
|
@@ -1143,7 +1199,7 @@ cmAdRC_t _cmAudDspLoadAudioSys( cmAd_t* p, unsigned asCfgIdx )
|
1143
|
1199
|
{
|
1144
|
1200
|
// ... and allocate additional DSP systems when more than one sub-sys is
|
1145
|
1201
|
// defined in the audio system configuration
|
1146
|
|
- if( cmDspSysInitialize(&p->ctx,&dsH,p->netH) != kOkDspRC )
|
|
1202
|
+ if( cmDspSysInitialize(&p->ctx,&dsH,p->netH,p->serialPortH) != kOkDspRC )
|
1147
|
1203
|
{
|
1148
|
1204
|
rc = cmErrMsg(&p->err,kDspSysFailAdRC,"Unable to initialize an additional DSP system.");
|
1149
|
1205
|
goto errLabel;
|