Offline
Full Member
Karma: 0
Posts: 207
|
 |
« on: January 21, 2013, 10:32:32 am » |
Hey friend, I am very confuse and lack of knowledge in using the virtualwire library. Can anyone guide me ? I dont understand this : vw_send((uint8_t *)msg, strlen(msg)); What is that ? I want to ask, how if I want to just send a number to be received by the receiver ? For example I want to send a number '2'. So in the receiver code, I can write like if the message received is '2' then blink LED ? Thanks 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19003
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: January 21, 2013, 10:40:26 am » |
I dont understand this : vw_send((uint8_t *)msg, strlen(msg)); "msg" is a null-terminated C string, probably in a "char" buffer. So, "strlen" tell you how many characters are in the string (not including the terminator). "(uint8_t *)" says to the compiler "look, I know I'm not giving you the exact type of pointer (msg) you expect, but it'll be OK. Trust me". And vw_send sends the buffer. If you want to send just '2' in this way, vw_send((uint8_t *)"2", 1);
|
|
|
|
« Last Edit: January 22, 2013, 02:59:38 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #2 on: January 21, 2013, 10:45:27 am » |
Still not very clear..is that all about string , data type?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19003
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: January 21, 2013, 10:57:07 am » |
There is no string datatype in C - strings are just "char" arrays, with the last position filled with a zero (A true zero, not an ASCII zero). So, the string "Hello" occupies six consecutive locations in array, 'H', 'e', 'l', 'l', 'o' with '\0', where the backslash signifies to the compiler that is really is zero, not ASCII zero.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #4 on: January 21, 2013, 11:02:10 am » |
So if I use this function vw_send(message, length), the messagee must be an arrary of 8 bits ? And I must include write it like this : vw_send((uint8_t *)msg, strlen(msg)); ???
What are the alternatives ?
Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #5 on: January 21, 2013, 11:06:41 am » |
the messagee must be an arrary of 8 bits ? This doesn't make sense. The array can be any number of elements. The size of an element, in bytes, is dependent on the type of the array. All bytes are 8 bits.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #6 on: January 21, 2013, 11:10:43 am » |
If I want to just send number '2',
so can I just write vw_send(2, 1) ?
1 refer to the length of message .
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #7 on: January 21, 2013, 11:13:42 am » |
so can I just write vw_send(2, 1) ? No. For 2 reasons. First '2' is not equal to 2. Second, 2 is an int, not an array, and vw_send only sends arrays.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #8 on: January 21, 2013, 11:15:31 am » |
what do you mean 2 is not equal to 2 ? LOL
So everytime I write vw_send(I must include 'uint8_t', length) ?
Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #9 on: January 21, 2013, 11:31:13 am » |
what do you mean 2 is not equal to 2 ? LOL The number 2 and the letter '2' are not equal.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #10 on: January 21, 2013, 11:33:40 am » |
You mean '2' and 'two' ?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #11 on: January 21, 2013, 11:36:11 am » |
You mean '2' and 'two' ? No, I mean 2 as in 1+1 and the letter '2', between the letter '1' and the letter '3'. The letter '2' has an ASCII code of 50. So, if you send '2', the value 50 gets sent. If you send 2, the value 2 gets sent.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #12 on: January 21, 2013, 11:39:45 am » |
Ok, I get you. It all about the usage of the ' ' .
So, everytime I sent a message using vw_send, I have to type it like this : vw_send((uint8_t*)msg, length ) ?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #13 on: January 21, 2013, 11:40:38 am » |
So, everytime I sent a message using vw_send, I have to type it like this : vw_send((uint8_t*)msg, length ) ?
Yes.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #14 on: January 21, 2013, 11:41:39 am » |
And I have to define what is msg ?
For example msg = '2' ?
|
|
|
|
|
Logged
|
|
|
|
|
|