|
@@ -5587,6 +5587,7 @@ cmDspInst_t* _cmDspPortToSym_Alloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, uns
|
5587
|
5587
|
// register the symbol
|
5588
|
5588
|
symIdArray[i] = cmSymTblRegisterSymbol(ctx->stH,symLabel);
|
5589
|
5589
|
|
|
5590
|
+ // input port - any msg in this port will generate an output from 'out' as well as the associated output port
|
5590
|
5591
|
cmDspArgSetup(ctx, args+kBaseInPtsId+i, symLabel, cmInvalidId, kBaseInPtsId+i, 0, 0, kInDsvFl | kTypeDsvMask, cmTsPrintfH(ctx->lhH,"%s Input.",symLabel) );
|
5591
|
5592
|
|
5592
|
5593
|
cmDspArgSetup(ctx, args+baseOutPtsId+i, symLabel, cmInvalidId, baseOutPtsId+i, 0, 0, kOutDsvFl | kSymDsvFl, cmTsPrintfH(ctx->lhH,"%s Output.",symLabel) );
|
|
@@ -5631,7 +5632,7 @@ cmDspRC_t _cmDspPortToSym_Recv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEv
|
5631
|
5632
|
unsigned idx = evt->dstVarId - kBaseInPtsId;
|
5632
|
5633
|
assert( idx < p->symIdCnt );
|
5633
|
5634
|
cmDspSetSymbol(ctx,inst,p->baseOutPtsId + idx, p->symIdArray[idx]);
|
5634
|
|
- return cmDspSetSymbol(ctx,inst,kOutPtsId,p->symIdArray[ evt->dstVarId - kBaseInPtsId ]);
|
|
5635
|
+ return cmDspSetSymbol(ctx,inst,kOutPtsId, p->symIdArray[idx]);
|
5635
|
5636
|
}
|
5636
|
5637
|
|
5637
|
5638
|
return rc;
|
|
@@ -5654,6 +5655,180 @@ cmDspClass_t* cmPortToSymClassCons( cmDspCtx_t* ctx )
|
5654
|
5655
|
|
5655
|
5656
|
//------------------------------------------------------------------------------------------------------------
|
5656
|
5657
|
//)
|
|
5658
|
+//( { label:cmDspIntToSym file_desc:"Send a pre-defined symbol every time a message arrives a given input port." kw:[sunit] }
|
|
5659
|
+enum
|
|
5660
|
+{
|
|
5661
|
+ kInItsId,
|
|
5662
|
+ kOutItsId,
|
|
5663
|
+ kBaseInItsId
|
|
5664
|
+};
|
|
5665
|
+
|
|
5666
|
+cmDspClass_t _cmIntToSym_DC;
|
|
5667
|
+
|
|
5668
|
+typedef struct
|
|
5669
|
+{
|
|
5670
|
+ cmDspInst_t inst;
|
|
5671
|
+ int* intArray;
|
|
5672
|
+ unsigned* symIdArray;
|
|
5673
|
+ unsigned symIdCnt;
|
|
5674
|
+ unsigned baseIntItsId;
|
|
5675
|
+ unsigned baseOutItsId;
|
|
5676
|
+
|
|
5677
|
+} cmDspIntToSym_t;
|
|
5678
|
+
|
|
5679
|
+cmDspInst_t* _cmDspIntToSym_Alloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
5680
|
+{
|
|
5681
|
+ va_list vl1;
|
|
5682
|
+ va_copy(vl1,vl);
|
|
5683
|
+
|
|
5684
|
+ if( va_cnt < 2 || va_cnt % 2 !=0 )
|
|
5685
|
+ {
|
|
5686
|
+ va_end(vl1);
|
|
5687
|
+ cmDspClassErr(ctx,classPtr,kVarArgParseFailDspRC,"The 'IntToSym' constructor argument list must contain at least one int/symbol pair and all pairs must be complete.");
|
|
5688
|
+ return NULL;
|
|
5689
|
+ }
|
|
5690
|
+
|
|
5691
|
+ unsigned symCnt = va_cnt/2;
|
|
5692
|
+ unsigned argCnt = 2 + 3*symCnt;
|
|
5693
|
+ cmDspVarArg_t args[argCnt+1];
|
|
5694
|
+
|
|
5695
|
+ unsigned* symIdArray = cmMemAllocZ(unsigned,symCnt);
|
|
5696
|
+ int* intArray = cmMemAllocZ(int,symCnt);
|
|
5697
|
+ unsigned baseIntItsId = kBaseInItsId + symCnt;
|
|
5698
|
+ unsigned baseOutItsId = baseIntItsId + symCnt;
|
|
5699
|
+
|
|
5700
|
+ // setup the integer input and symbol output port arg recd
|
|
5701
|
+ cmDspArgSetup(ctx,args, "in", cmInvalidId, kInItsId, 0, 0, kInDsvFl | kIntDsvFl, "Integer input" );
|
|
5702
|
+ cmDspArgSetup(ctx,args+1,"out", cmInvalidId, kOutItsId, 0, 0, kOutDsvFl | kSymDsvFl, "Output" );
|
|
5703
|
+
|
|
5704
|
+ unsigned i;
|
|
5705
|
+
|
|
5706
|
+ for(i=0; i<symCnt; ++i)
|
|
5707
|
+ {
|
|
5708
|
+ // get the integer value
|
|
5709
|
+ intArray[i] = va_arg(vl,int);
|
|
5710
|
+
|
|
5711
|
+ // get the symbol label
|
|
5712
|
+ const cmChar_t* symLabel = va_arg(vl,const char*);
|
|
5713
|
+ assert( symLabel != NULL );
|
|
5714
|
+
|
|
5715
|
+ unsigned intLabelN = (symLabel==NULL ? 0 : strlen(symLabel)) + 5;
|
|
5716
|
+ cmChar_t intLabel[ intLabelN ];
|
|
5717
|
+ snprintf(intLabel,intLabelN,"%s%s", symLabel==NULL ? "" : symLabel, "-int" );
|
|
5718
|
+
|
|
5719
|
+ // register the symbol
|
|
5720
|
+ symIdArray[i] = cmSymTblRegisterSymbol(ctx->stH,symLabel);
|
|
5721
|
+
|
|
5722
|
+ // trigger port associated with this symbol (any msg on this port will trigger an output)
|
|
5723
|
+ cmDspArgSetup(ctx, args+kBaseInItsId+i, symLabel, cmInvalidId, kBaseInItsId+i, 0, 0, kInDsvFl | kTypeDsvMask, cmTsPrintfH(ctx->lhH,"%s Input.",symLabel) );
|
|
5724
|
+
|
|
5725
|
+ // this port is used to set the integer value associated with this symbol
|
|
5726
|
+ cmDspArgSetup(ctx, args+baseIntItsId+i, intLabel, cmInvalidId, baseIntItsId+i, 0, 0, kInDsvFl | kIntDsvFl, cmTsPrintfH(ctx->lhH,"Set the integer value associated with %s.",symLabel) );
|
|
5727
|
+
|
|
5728
|
+ // symbol output port - when ever this symbol is sent out it will go out this port as well as the 'out' port
|
|
5729
|
+ cmDspArgSetup(ctx, args+baseOutItsId+i, symLabel, cmInvalidId, baseOutItsId+i, 0, 0, kOutDsvFl | kSymDsvFl, cmTsPrintfH(ctx->lhH,"%s Output.",symLabel) );
|
|
5730
|
+
|
|
5731
|
+
|
|
5732
|
+ }
|
|
5733
|
+
|
|
5734
|
+ cmDspArgSetupNull(args + argCnt);
|
|
5735
|
+
|
|
5736
|
+ cmDspIntToSym_t* p = cmDspInstAlloc(cmDspIntToSym_t,ctx,classPtr,args,instSymId,id,storeSymId,0,vl1);
|
|
5737
|
+
|
|
5738
|
+ p->symIdCnt = symCnt;
|
|
5739
|
+ p->intArray = intArray;
|
|
5740
|
+ p->symIdArray = symIdArray;
|
|
5741
|
+ p->baseOutItsId = baseOutItsId;
|
|
5742
|
+ p->baseIntItsId = baseIntItsId;
|
|
5743
|
+
|
|
5744
|
+ cmDspSetDefaultSymbol(ctx,&p->inst,kOutItsId,cmInvalidId);
|
|
5745
|
+
|
|
5746
|
+ va_end(vl1);
|
|
5747
|
+
|
|
5748
|
+ return &p->inst;
|
|
5749
|
+}
|
|
5750
|
+cmDspRC_t _cmDspIntToSym_Free(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
5751
|
+{
|
|
5752
|
+ cmDspIntToSym_t* p = (cmDspIntToSym_t*)inst;
|
|
5753
|
+ cmMemFree(p->symIdArray);
|
|
5754
|
+ return kOkDspRC;
|
|
5755
|
+}
|
|
5756
|
+
|
|
5757
|
+cmDspRC_t _cmDspIntToSym_Reset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
5758
|
+{
|
|
5759
|
+ return cmDspApplyAllDefaults(ctx,inst);
|
|
5760
|
+}
|
|
5761
|
+
|
|
5762
|
+cmDspRC_t _cmDspIntToSymSendOut( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned idx )
|
|
5763
|
+{
|
|
5764
|
+ cmDspIntToSym_t* p = (cmDspIntToSym_t*)inst;
|
|
5765
|
+ assert( idx < p->symIdCnt );
|
|
5766
|
+ cmDspSetSymbol(ctx,inst,p->baseOutItsId + idx, p->symIdArray[idx]);
|
|
5767
|
+ return cmDspSetSymbol(ctx, inst, kOutItsId, p->symIdArray[ idx ]);
|
|
5768
|
+}
|
|
5769
|
+
|
|
5770
|
+
|
|
5771
|
+cmDspRC_t _cmDspIntToSym_Recv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
5772
|
+{
|
|
5773
|
+ cmDspRC_t rc = kOkDspRC;
|
|
5774
|
+ cmDspIntToSym_t* p = (cmDspIntToSym_t*)inst;
|
|
5775
|
+ unsigned idx = cmInvalidIdx;
|
|
5776
|
+
|
|
5777
|
+ // if an integer arrived at 'in'
|
|
5778
|
+ if( evt->dstVarId == kInItsId )
|
|
5779
|
+ {
|
|
5780
|
+ unsigned i;
|
|
5781
|
+ int intVal = cmDspInt(inst,kInItsId);
|
|
5782
|
+
|
|
5783
|
+ for(i=0; i<p->symIdCnt; ++i)
|
|
5784
|
+ if( intVal == p->intArray[i] )
|
|
5785
|
+ {
|
|
5786
|
+ rc = _cmDspIntToSymSendOut( ctx, inst, idx );
|
|
5787
|
+ idx = i;
|
|
5788
|
+ break;
|
|
5789
|
+ }
|
|
5790
|
+ }
|
|
5791
|
+ else
|
|
5792
|
+ {
|
|
5793
|
+ // if a msg of any type is recieved on an input port - send out the associated symbol
|
|
5794
|
+ if( kBaseInItsId <= evt->dstVarId && evt->dstVarId < kBaseInItsId + p->symIdCnt )
|
|
5795
|
+ {
|
|
5796
|
+ _cmDspIntToSymSendOut( ctx, inst, evt->dstVarId - kBaseInItsId );
|
|
5797
|
+ }
|
|
5798
|
+ else
|
|
5799
|
+
|
|
5800
|
+ // if this is a new interger value for this symbol
|
|
5801
|
+ if( p->baseIntItsId <= evt->dstVarId && evt->dstVarId < p->baseIntItsId + p->symIdCnt )
|
|
5802
|
+ {
|
|
5803
|
+ cmDspSetEvent(ctx,inst,evt);
|
|
5804
|
+
|
|
5805
|
+ int x = cmDspInt( inst, evt->dstVarId );
|
|
5806
|
+ printf("%i %i\n", x, p->symIdArray[evt->dstVarId - p->baseIntItsId] );
|
|
5807
|
+ p->intArray[ evt->dstVarId - p->baseIntItsId ] = x;
|
|
5808
|
+ }
|
|
5809
|
+ }
|
|
5810
|
+
|
|
5811
|
+
|
|
5812
|
+ return rc;
|
|
5813
|
+}
|
|
5814
|
+
|
|
5815
|
+cmDspClass_t* cmIntToSymClassCons( cmDspCtx_t* ctx )
|
|
5816
|
+{
|
|
5817
|
+ cmDspClassSetup(&_cmIntToSym_DC,ctx,"IntToSym",
|
|
5818
|
+ NULL,
|
|
5819
|
+ _cmDspIntToSym_Alloc,
|
|
5820
|
+ _cmDspIntToSym_Free,
|
|
5821
|
+ _cmDspIntToSym_Reset,
|
|
5822
|
+ NULL,
|
|
5823
|
+ _cmDspIntToSym_Recv,
|
|
5824
|
+ NULL,NULL,
|
|
5825
|
+ "If a message of any kind is received on a port then send the symbol associated with the port.");
|
|
5826
|
+
|
|
5827
|
+ return &_cmIntToSym_DC;
|
|
5828
|
+}
|
|
5829
|
+
|
|
5830
|
+//------------------------------------------------------------------------------------------------------------
|
|
5831
|
+//)
|
5657
|
5832
|
//( { label:cmDspRouter file_desc:"Route the input value to one of multiple output ports." kw:[sunit] }
|
5658
|
5833
|
|
5659
|
5834
|
enum
|