Browse Source

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

master
kevin.larke 4 years ago
parent
commit
e686cc2c9c
7 changed files with 108 additions and 7 deletions
  1. 58
    2
      cmAudDsp.c
  2. 2
    0
      cmAudDsp.h
  3. 30
    0
      cmAudioSys.c
  4. 2
    0
      cmAudioSys.h
  5. 1
    0
      dsp/cmDspNet.h
  6. 13
    4
      dsp/cmDspSys.c
  7. 2
    1
      dsp/cmDspSys.h

+ 58
- 2
cmAudDsp.c View File

19
 #include "cmApBuf.h"
19
 #include "cmApBuf.h"
20
 #include "cmMidi.h"
20
 #include "cmMidi.h"
21
 #include "cmMidiPort.h"
21
 #include "cmMidiPort.h"
22
+#include "cmSerialPort.h"
22
 #include "dsp/cmDspValue.h"
23
 #include "dsp/cmDspValue.h"
23
 #include "cmMsgProtocol.h"
24
 #include "cmMsgProtocol.h"
24
 #include "cmThread.h"
25
 #include "cmThread.h"
91
   unsigned           msgsPerClientPoll;
92
   unsigned           msgsPerClientPoll;
92
   const cmChar_t*    dfltProgramLabel;
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
   cmAdAggDev_t*      aggDevArray;
101
   cmAdAggDev_t*      aggDevArray;
95
   unsigned           aggDevCnt;
102
   unsigned           aggDevCnt;
96
 
103
 
169
   cmJsonNode_t*   nrtDevArrNodePtr = NULL;
176
   cmJsonNode_t*   nrtDevArrNodePtr = NULL;
170
   cmJsonNode_t*   afpDevArrNodePtr = NULL;
177
   cmJsonNode_t*   afpDevArrNodePtr = NULL;
171
   cmJsonNode_t*   audDspNodePtr    = NULL;
178
   cmJsonNode_t*   audDspNodePtr    = NULL;
179
+  cmJsonNode_t*   serialNodePtr    = NULL;
172
   const cmChar_t* errLabelPtr      = NULL;
180
   const cmChar_t* errLabelPtr      = NULL;
173
   unsigned        i;
181
   unsigned        i;
174
   cmJsRC_t      jsRC = kOkJsRC;
182
   cmJsRC_t      jsRC = kOkJsRC;
190
         "aggDevArray",        kArrayTId  | kOptArgJsFl, &aggDevArrNodePtr,
198
         "aggDevArray",        kArrayTId  | kOptArgJsFl, &aggDevArrNodePtr,
191
         "nrtDevArray",        kArrayTId  | kOptArgJsFl, &nrtDevArrNodePtr,
199
         "nrtDevArray",        kArrayTId  | kOptArgJsFl, &nrtDevArrNodePtr,
192
         "afpDevArray",        kArrayTId  | kOptArgJsFl, &afpDevArrNodePtr,
200
         "afpDevArray",        kArrayTId  | kOptArgJsFl, &afpDevArrNodePtr,
201
+        "serial",             kObjectTId | kOptArgJsFl, &serialNodePtr,
193
         NULL )) != kOkJsRC )
202
         NULL )) != kOkJsRC )
194
   {
203
   {
195
     rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" );
204
     rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" );
196
     goto errLabel;
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
   // parse the aggregate device specifications into p->aggDevArray[].
223
   // parse the aggregate device specifications into p->aggDevArray[].
200
   if( aggDevArrNodePtr != NULL && (p->aggDevCnt = cmJsonChildCount(aggDevArrNodePtr)) > 0)
224
   if( aggDevArrNodePtr != NULL && (p->aggDevCnt = cmJsonChildCount(aggDevArrNodePtr)) > 0)
201
   {
225
   {
382
   return rc;
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
 cmAdRC_t _cmAdCreateAggDevices( cmAd_t* p )
425
 cmAdRC_t _cmAdCreateAggDevices( cmAd_t* p )
386
 {
426
 {
387
   cmAdRC_t rc = kOkAdRC;
427
   cmAdRC_t rc = kOkAdRC;
570
     goto errLabel;
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
   if( cmMpIsInitialized() )
622
   if( cmMpIsInitialized() )
574
     if( cmMpFinalize() != kOkMpRC )
623
     if( cmMpFinalize() != kOkMpRC )
575
     {
624
     {
695
     goto errLabel;
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
   // initialize the MIDI system
754
   // initialize the MIDI system
699
   if( cmMpInitialize(ctx,NULL,NULL,p->midiPortBufByteCnt,"app") != kOkMpRC )
755
   if( cmMpInitialize(ctx,NULL,NULL,p->midiPortBufByteCnt,"app") != kOkMpRC )
700
   {
756
   {
713
     goto errLabel;
769
     goto errLabel;
714
 
770
 
715
   // initialize the DSP system
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
     rc = cmErrMsg(&p->err,kDspSysFailAdRC,"The DSP system initialization failed.");
774
     rc = cmErrMsg(&p->err,kDspSysFailAdRC,"The DSP system initialization failed.");
719
     goto errLabel;
775
     goto errLabel;
1143
       {
1199
       {
1144
         // ... and allocate additional DSP systems when more than one sub-sys is 
1200
         // ... and allocate additional DSP systems when more than one sub-sys is 
1145
         // defined in the audio system configuration
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
           rc = cmErrMsg(&p->err,kDspSysFailAdRC,"Unable to initialize an additional DSP system.");
1204
           rc = cmErrMsg(&p->err,kDspSysFailAdRC,"Unable to initialize an additional DSP system.");
1149
           goto errLabel;
1205
           goto errLabel;

+ 2
- 0
cmAudDsp.h View File

13
     kAudioPortFailAdRC,
13
     kAudioPortFailAdRC,
14
     kAudioSysFailAdRC,
14
     kAudioSysFailAdRC,
15
     kMidiSysFailAdRC,
15
     kMidiSysFailAdRC,
16
+    kSerialPortFailAdRC,
16
     kDspSysFailAdRC,
17
     kDspSysFailAdRC,
17
     kFileSysFailAdRC,
18
     kFileSysFailAdRC,
18
     kJsonFailAdRC,
19
     kJsonFailAdRC,
21
     kNoPgmLoadedAdRC,
22
     kNoPgmLoadedAdRC,
22
     kInvalidSubSysIdxAdRC,
23
     kInvalidSubSysIdxAdRC,
23
     kUnknownMsgTypeAdRC,
24
     kUnknownMsgTypeAdRC,
25
+    kSerialDevCreateFailAdRC,
24
     kAggDevSysFailAdRC,
26
     kAggDevSysFailAdRC,
25
     kAggDevCreateFailAdRC,
27
     kAggDevCreateFailAdRC,
26
     kNrtDevSysFailAdRC,
28
     kNrtDevSysFailAdRC,

+ 30
- 0
cmAudioSys.c View File

15
 #include "cmThread.h"
15
 #include "cmThread.h"
16
 #include "cmUdpPort.h"
16
 #include "cmUdpPort.h"
17
 #include "cmUdpNet.h"
17
 #include "cmUdpNet.h"
18
+#include "cmSerialPort.h"
18
 #include "cmAudioSysMsg.h"
19
 #include "cmAudioSysMsg.h"
19
 #include "cmAudioSys.h"
20
 #include "cmAudioSys.h"
20
 #include "cmMidi.h"
21
 #include "cmMidi.h"
37
   cmTsMp1cH_t        htdQueueH; // host-to-dsp thread safe msg queue
38
   cmTsMp1cH_t        htdQueueH; // host-to-dsp thread safe msg queue
38
   cmThreadMutexH_t   engMutexH; // thread mutex and condition variable
39
   cmThreadMutexH_t   engMutexH; // thread mutex and condition variable
39
   cmUdpNetH_t        netH;
40
   cmUdpNetH_t        netH;
41
+  cmSeH_t            serialPortH; 
40
   bool               enableFl;  // application controlled pause flag
42
   bool               enableFl;  // application controlled pause flag
41
   bool               runFl;     // false during finalization otherwise true
43
   bool               runFl;     // false during finalization otherwise true
42
   bool               statusFl;  // true if regular status notifications should be sent
44
   bool               statusFl;  // true if regular status notifications should be sent
507
 
509
 
508
 }
510
 }
509
 
511
 
512
+void _cmAudioSysSerialPortCallback( void* cbArg, const void* byteA, unsigned byteN )
513
+{
514
+  //_cmAsCfg_t* p (_cmAsCfg_t*)cbArg;
515
+  
516
+  // TODO: handle serial receive
517
+}
518
+
510
 cmAsRC_t cmAudioSysAllocate( cmAudioSysH_t* hp, cmRpt_t* rpt, const cmAudioSysCfg_t* cfg )
519
 cmAsRC_t cmAudioSysAllocate( cmAudioSysH_t* hp, cmRpt_t* rpt, const cmAudioSysCfg_t* cfg )
511
 {
520
 {
512
   cmAsRC_t rc;
521
   cmAsRC_t rc;
832
     cp->iMeterArray      = cmMemAllocZ( double, cp->status.iMeterCnt );
841
     cp->iMeterArray      = cmMemAllocZ( double, cp->status.iMeterCnt );
833
     cp->oMeterArray      = cmMemAllocZ( double, cp->status.oMeterCnt );
842
     cp->oMeterArray      = cmMemAllocZ( double, cp->status.oMeterCnt );
834
     cp->netH             = cfg->netH;
843
     cp->netH             = cfg->netH;
844
+    cp->serialPortH      = cfg->serialPortH;
835
 
845
 
836
     // create the audio System thread
846
     // create the audio System thread
837
     if((rc = cmThreadCreate( &cp->threadH, _cmAsThreadCallback, cp, ss->args.rpt )) != kOkThRC )
847
     if((rc = cmThreadCreate( &cp->threadH, _cmAsThreadCallback, cp, ss->args.rpt )) != kOkThRC )
874
         goto errLabel;
884
         goto errLabel;
875
       }
885
       }
876
 
886
 
887
+    // install the serial port 
888
+    if( cmSeIsOpen(cp->serialPortH) )
889
+    {
890
+      if( cmSeSetCallback(cp->serialPortH, _cmAudioSysSerialPortCallback, cp ) != kOkSeRC )
891
+      {
892
+        rc = _cmAsError(p,kSerialPortFailAsRC,"Serial port callback installation failed.");
893
+        goto errLabel;        
894
+      }
895
+    }
896
+
877
     // setup the sub-system status notification 
897
     // setup the sub-system status notification 
878
     cp->statusUpdateSmpCnt = floor(cmApBufMeterMs() * cp->ss.args.srate / 1000.0 );
898
     cp->statusUpdateSmpCnt = floor(cmApBufMeterMs() * cp->ss.args.srate / 1000.0 );
879
     cp->statusUpdateSmpIdx = 0;
899
     cp->statusUpdateSmpIdx = 0;
886
       rc = _cmAsError(p,kThreadErrAsRC,"Thread start failed.");
906
       rc = _cmAsError(p,kThreadErrAsRC,"Thread start failed.");
887
       goto errLabel;
907
       goto errLabel;
888
     }
908
     }
909
+
910
+    if( cmSeIsOpen(cp->serialPortH) )
911
+    {
912
+      if( cmSeStart( cp->serialPortH ) != kOkSeRC )
913
+      {
914
+        rc = _cmAsError(p,kSerialPortFailAsRC,"Serial port start failed.");
915
+        goto errLabel;        
916
+      }
917
+      
918
+    }
889
   }
919
   }
890
 
920
 
891
 
921
 

+ 2
- 0
cmAudioSys.h View File

73
     kBufTooSmallAsRC,
73
     kBufTooSmallAsRC,
74
     kNoMsgWaitingAsRC,
74
     kNoMsgWaitingAsRC,
75
     kMidiSysFailAsRC,
75
     kMidiSysFailAsRC,
76
+    kSerialPortFailAsRC,
76
     kMsgSerializeFailAsRC,
77
     kMsgSerializeFailAsRC,
77
     kStateBufFailAsRC,
78
     kStateBufFailAsRC,
78
     kInvalidArgAsRC,
79
     kInvalidArgAsRC,
197
     cmTsQueueCb_t         clientCbFunc; // Called by  cmAudioSysReceiveMsg() to deliver internally generated msg's to the host. 
198
     cmTsQueueCb_t         clientCbFunc; // Called by  cmAudioSysReceiveMsg() to deliver internally generated msg's to the host. 
198
                                         //  Set to NULL if msg's will be directly returned by buffers passed to cmAudioSysReceiveMsg().
199
                                         //  Set to NULL if msg's will be directly returned by buffers passed to cmAudioSysReceiveMsg().
199
     cmUdpNetH_t           netH;
200
     cmUdpNetH_t           netH;
201
+    cmSeH_t               serialPortH;
200
   } cmAudioSysCfg_t;
202
   } cmAudioSysCfg_t;
201
 
203
 
202
   extern cmAudioSysH_t cmAudioSysNullHandle;
204
   extern cmAudioSysH_t cmAudioSysNullHandle;

+ 1
- 0
dsp/cmDspNet.h View File

72
     cmDspPresetMgr_t    pm;
72
     cmDspPresetMgr_t    pm;
73
     unsigned            nextInstId;
73
     unsigned            nextInstId;
74
     unsigned            pgmIdx;
74
     unsigned            pgmIdx;
75
+    cmSeH_t             serialPortH;
75
 
76
 
76
 
77
 
77
     cmUdpNetH_t           netH;          //
78
     cmUdpNetH_t           netH;          //

+ 13
- 4
dsp/cmDspSys.c View File

19
 #include "cmThread.h"
19
 #include "cmThread.h"
20
 #include "cmUdpPort.h"
20
 #include "cmUdpPort.h"
21
 #include "cmUdpNet.h"
21
 #include "cmUdpNet.h"
22
+#include "cmSerialPort.h"
22
 #include "cmAudioSys.h"
23
 #include "cmAudioSys.h"
23
 #include "cmProcObj.h"
24
 #include "cmProcObj.h"
24
 #include "cmDspCtx.h"
25
 #include "cmDspCtx.h"
165
   return rc;
166
   return rc;
166
 }
167
 }
167
 
168
 
168
-cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH )
169
+cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH, cmSeH_t serialPortH )
169
 {
170
 {
170
   unsigned        i;
171
   unsigned        i;
171
   cmDspRC_t       rc     = kOkDspRC;
172
   cmDspRC_t       rc     = kOkDspRC;
178
 
179
 
179
   cmErrSetup(&p->err,&ctx->rpt,"DSP System");
180
   cmErrSetup(&p->err,&ctx->rpt,"DSP System");
180
   //p->ctx.ctx   = asCtx;
181
   //p->ctx.ctx   = asCtx;
181
-  p->cmCtx     = *ctx;
182
-  p->netH      = netH;
183
-  p->pgmIdx    = cmInvalidIdx;
182
+  p->cmCtx       = *ctx;
183
+  p->netH        = netH;
184
+  p->serialPortH = serialPortH;
185
+  p->pgmIdx      = cmInvalidIdx;
184
 
186
 
185
   // create the DSP class  linked heap
187
   // create the DSP class  linked heap
186
   if(cmLHeapIsValid( p->lhH = cmLHeapCreate(1024,ctx)) == false)
188
   if(cmLHeapIsValid( p->lhH = cmLHeapCreate(1024,ctx)) == false)
1560
   return p->ctx.stH;  
1562
   return p->ctx.stH;  
1561
 }
1563
 }
1562
 
1564
 
1565
+cmSeH_t      cmDspSysSerialPort( cmDspSysH_t h )
1566
+{
1567
+  cmDsp_t* p = _cmDspHandleToPtr(h);
1568
+  return p->serialPortH;
1569
+}
1570
+
1571
+
1563
 unsigned     cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel )
1572
 unsigned     cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel )
1564
 { return cmSymTblRegisterStaticSymbol( cmDspSysSymbolTable(h), symLabel ); }
1573
 { return cmSymTblRegisterStaticSymbol( cmDspSysSymbolTable(h), symLabel ); }
1565
 
1574
 

+ 2
- 1
dsp/cmDspSys.h View File

23
   //  Control Functions
23
   //  Control Functions
24
   //
24
   //
25
 
25
 
26
-  cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH );
26
+  cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH, cmSeH_t serialPortH );
27
   cmDspRC_t cmDspSysFinalize(  cmDspSysH_t* hp );
27
   cmDspRC_t cmDspSysFinalize(  cmDspSysH_t* hp );
28
   
28
   
29
   bool      cmDspSysIsValid(   cmDspSysH_t h );
29
   bool      cmDspSysIsValid(   cmDspSysH_t h );
156
   double          cmDspSysSampleRate( cmDspSysH_t h );
156
   double          cmDspSysSampleRate( cmDspSysH_t h );
157
   cmJsonH_t       cmDspSysPgmRsrcHandle( cmDspSysH_t h );
157
   cmJsonH_t       cmDspSysPgmRsrcHandle( cmDspSysH_t h );
158
   cmSymTblH_t     cmDspSysSymbolTable( cmDspSysH_t h );
158
   cmSymTblH_t     cmDspSysSymbolTable( cmDspSysH_t h );
159
+  cmSeH_t         cmDspSysSerialPort( cmDspSysH_t h );
159
 
160
 
160
   unsigned        cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel );
161
   unsigned        cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel );
161
   unsigned        cmDspSysRegisterSymbol( cmDspSysH_t h, const cmChar_t* symLabel );
162
   unsigned        cmDspSysRegisterSymbol( cmDspSysH_t h, const cmChar_t* symLabel );

Loading…
Cancel
Save