Pumpkin, Inc.

Pumpkin User Forums

Passing Strings

If you can't make Salvo do what you want it to do, post it here.

Passing Strings

Postby kiddster » Sat Sep 22, 2001 3:43 am

I want to pass a string between two tasks and I am using the OSSignalMsg and OS_WaitMsg commands. My string that I want to pass is an unsigned char array of 15 bytes. How do I set up the correct signalling and receiving of the pointers?
kiddster
 
Posts: 5
Joined: Fri Sep 21, 2001 11:00 pm

Re: Passing Strings

Postby luben » Sat Sep 22, 2001 8:50 am

Hello,

Let me explain, before the SALVO stuff will bring you the detailed information.

1. if you want to pass the address of the first byte of the string array you have to set OSBIG_MESSAGES_POINTERS to TRUE in your salvocfg.h file of the project with

code:

#define OSBIG_MESSAGES_POINTERS TRUE

This will allow the SALVO to transmit the address (that's 16 bit) between tasks like a message.

2. Define your array in the memory like:

code:

const byte MESSAGE[] ="Your message";

defining this way will place automatically zero at the end of the string, that's indicator for your program of the end of the string. Well, you can define different bytes with HEX values too - it's up to you, but text strings is desirable to be defined that way. For CR, LF there are some way to be defined with "/n" and other simbols.

3. You have to define in the program the message and after that to create the message (look the examples in the manual for OSSignalMsg(), OS_WaitMsg() and OSCreateMsg())

4. Signall the message like this

code:

OSSignalMsg(MSQ_your, (OStypeMsgP)&MESSAGE[0]);

5. To receive the message you have to declare first pointer like:

code:

OStypeMsgP pointer;

6. Wait for the message with:

code:

OS_WaitMsg(MSG_your, &pointer,time_out, LABEL);


the timeout is optional.
After the kernel returns the control and you don't have timeout in the pointer will reside the address of the MESSAGE[0] - the first element of the string. Now it's up to you to fetch byte by byte the whole information of the string.

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: Passing Strings

Postby aek » Sat Sep 22, 2001 10:36 am

The only thing I would add to Luben's excellent overview is that this technique requires a source code build using the Salvo source code your application requires -- the libraries are compiled with OSBIG_MESSAGE_POINTERS set to FALSE.

Thanks, Luben!

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Passing Strings

Postby luben » Sun Sep 23, 2001 1:56 am

Hello,

Like old user of DEMO version I can propose that - you make one array of addresses to the messages in the ROM. So you pass like message the number in this array and then you fetch the real address of the message.
Because you can not pass zero message, the first cell of this array is empty. The indexes are 1, 2, 3, 4....

code:

code byte MESS1 = "hello1";
code byte MESS2 = "hello2";
code byte MESS3 = "hello3";
code byte MESS4 = "hello4";

code word ADDRESS[5] = 0,(word)&MESS1[0], (word)&MESS2[0],(word)&MESS3[0],(word)&MESS4[0];

// in ADDRESS array now you have the addresses of the messages


Now you can exchange not the real address, but the index to array, that hold the begin addresses of the messages. This is a little bit more complicated, but could be used in the DEMO version to imitate big messages. You know - who don't have money, have to use his brain. For sure the DEMO version of SALVO is very powerful and even for small projects you don't need the full one. I suspect that people from SALVO brought more then is required for one demo version - it should be renamed to "LITE fully working version". By the way, even message queues could be imitate in DEMO if the user has semaphores and messages - but this will take long time and need experience.

Regards
Luben

[This message has been edited by luben (edited September 23, 2001).]

[This message has been edited by luben (edited September 23, 2001).]

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: Passing Strings

Postby kiddster » Sun Sep 23, 2001 7:29 am

Luben,

Thank you for the helpful reply. Maybe you or Andrew can help me with some of details associated with assigning the pointer appropriately once the message has been received.

I have a unsigned char array that I load ascii values into appropriate indexes.

For example:

code:
static unsigned char pTime[16];

I pass the message to another task using the OSSignalMsg command:

code:
OSSignalMsg(MSG_PRINT_TIME, (OStypeMsgP) &pTime);

The other task is waiting for the signal:

code:
static OStypeMsgP msgP;

code:
OS_WaitMsg(MSG_PRINT_TIME, &msgP, TaskBM_Debug1);

Now, I want to assign the message pointer to a variable that I can use to print out the indexes of my char array from above. Do I need to define this variable with the same type as pTime[16]? How do I assign the pointer correctly?

Thank you,

-Brian

[This message has been edited by aek (edited September 24, 2001).]

kiddster
 
Posts: 5
Joined: Fri Sep 21, 2001 11:00 pm

Re: Passing Strings

Postby aek » Mon Sep 24, 2001 10:00 am

Brian, have you been reviewing the App Notes ... In particular, AN-3? :-)

If I understand you correctly, you're having problems dereferencing the message pointer.

First off, keep in mind that this sort of pointer thing is always confusing to the unitiated. And it's not very easy to debug in the MPLAB environment. So you may want to write a simple command-line C program on a PC to test the way you're passing pointers, etc ... rather than try to debug on your intended target.

Anyway, I think what you want is something like:

code:

unsigned char * pTimeLocal;

...
pTimeLocal = (unsigned char *) &msgP;



this will result in the pointer pTimeLocal pointing to the string that you passed in the message.

Alternately, if you did this:

code:

unsigned char TimeLocal;

...
TimeLocal = * (unsigned char *) &msgP;


you'd end up with TimeLocal containing the first character in the string that was passed as a message, which I don't think you want ...

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron