Problems with message queue

As per the WMF sample in one of the application notes,
I want to create a message queue as the cornerstone of the framework I'm working on.

And to be honest I'm getting bogged down in the head/tail (next/first/last message) parameters.
I've attached some code and not sure if the bits where I de-queue the message is correct or not.

I'm okay with queueing the new message into the message queue,
but de-queueing it, I'm just getting confused, maybe it is because the variables I'm using are not right,
like instead of nxt/first/last/qty maybe I should just use head/tail? or readptr/writeptr/qtymsgs

Once I am sure it's right, then I will move the data/variables for whole thing from VAR into DAT
As I read in the forums that its shared between all instances of the object.


Oh before I forget,
Another question is...
Is there anyway to know if a procedure exists or not?

Say if I want to check if a (third party) subroutine/procedure called "LoadFromSRam" exists within a program
is there anyway to do this from code and simply return true/false?

Thanks.

PS.
Please be gentle, :D
My aspirations are bigger than my knowledge of spin lol

Comments

  • Well I think I have solved it :)

    I re-did the enqueue/dequeue routines.
    '
    '-> [Start] StartManager
    '
    PUB StartManager | tmpId
    '
    '-> Start Message Manager
    _bQueueStatus := _oDeclarations#QUEUE_OFFLINE
    _bQtyMessages := 0
    _bReadMsgId := 0
    _bWriteMsgId := 0
    Repeat tmpId From 0 To MAX_RECORDS_IN_QUEUE
    _oMsgQueue[tmpId].InitialiseMessage(tmpId)
    'End Repeat
    _bQueueStatus := _oDeclarations#QUEUE_READY
    RETURN TRUE
    '
    'End Pub
    '
    '-> [Function] EnqueueMessage
    '
    PUB EnqueueMessage(pbIsFor, pwSrcObjId, pwDstObjId, pwEventTypeId, pwParam1, pwParam2, pwParam3, pbParam4) : RtnResult
    '
    '-> Init return
    RtnResult := FALSE
    '
    '-> Queue Ready?
    If (_bQueueStatus == _oDeclarations#QUEUE_READY )
    _bQueueStatus := _oDeclarations#QUEUE_ENQUEUEINGMESSAGE
    '
    '-> If space is available
    If (_bQtyMessages < MAX_RECORDS_IN_QUEUE)
    '
    '-> Enqueue New Message
    _oMsgQueue[_bWriteMsgId].QueueMessage(pbIsFor, pwSrcObjId, pwDstObjId, pwEventTypeId, pwParam1, pwParam2, pwParam3, pbParam4)

    '-> Increase QtyMessages count
    _bQtyMessages := _bQtyMessages + 1
    '
    '-> Increase WriteMsgId ptr
    _bWriteMsgId := _bWriteMsgId + 1
    If (_bWriteMsgId >= MAX_RECORDS_IN_QUEUE)
    _bWriteMsgId := 0
    'End If
    '
    '-> Set Return Result Value
    RtnResult := TRUE
    '
    Else
    'queue is full
    _bQueueStatus := _oDeclarations#QUEUE_IS_FULL
    'End If
    '
    Else
    'Queue Manager is busy, full or in error state!
    'End If
    '
    '-> Return Process result
    RETURN RtnResult
    '
    'End Pub
    '
    '-> [Function] DequeueMessage
    '
    PUB DequeueMessage : RtnResult
    '
    '-> Init return
    RtnResult := FALSE
    '
    '-> Queue Ready?
    If (_bQueueStatus == _oDeclarations#QUEUE_READY )
    _bQueueStatus := _oDeclarations#QUEUE_DEQUEUEINGMESSAGE
    '
    '-> If space is available
    If (_bQtyMessages > 0 AND _bQtyMessages =< MAX_RECORDS_IN_QUEUE)
    '
    '-> Extract message data for user
    LoadDataBuffer(_bReadMsgId)
    _oMsgQueue[_bReadMsgId].ClearMessage
    '
    '-> Decrease QtyMessages count
    _bQtyMessages := _bQtyMessages - 1
    '
    '-> Increase ReadMsgId ptr
    _bReadMsgId := _bReadMsgId + 1
    If (_bReadMsgId >= MAX_RECORDS_IN_QUEUE)
    _bReadMsgId := 0
    'End If
    '
    '-> Set Return Result Value
    RtnResult := TRUE
    '
    Else
    'queue is full
    _bQueueStatus := _oDeclarations#QUEUE_IS_FULL
    'End If
    '
    Else
    'Queue Manager is busy, full or in error state!
    'End If
    '
    '-> Return Process result
    RETURN RtnResult
    '
    'End Pub
    '
    '-> [Function] LoadDataBuffer
    '
    PRI LoadDataBuffer(pbIndex)
    '
    BYTEMOVE(@_aDataBuf[0], _oMsgQueue[pbIndex].DataStartAddress, 15)
    '
    'END PRI
    '
    '
Sign In or Register to comment.