Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #15 on: January 21, 2013, 11:42:56 am » |
So, everytime I sent a message using vw_send, I have to type it like this : vw_send((uint8_t*)msg, length ) ?
Yes. Any alternatif ? And why got a * ?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #16 on: January 21, 2013, 12:04:49 pm » |
Because you're casting a pointer.
|
|
|
|
« Last Edit: January 22, 2013, 02:41:17 am 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 #17 on: January 21, 2013, 12:08:11 pm » |
Okay, I think I have to read more about pointer and array. Thanks !
vw_send(message, length) Transmit a message. "message" is an array of the bytes to send, and "length" is the number of bytes stored in the array. This function returns immediately and the message is sent slowly by an interrupt-based background process.
so the message is refering to ((uint8_t*)msg), where msg is any number of words ? It is not array anymore because we include the uint8_t already ?
Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #18 on: January 21, 2013, 12:12:59 pm » |
For example msg = '2' ? No. 2 != '2' != "2" It is not array anymore because we include the uint8_t already ? I don't understand what you're saying, but obviously it still is an array, because if it were not, then we wouldn't need to specify a buffer length to transmit.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #19 on: January 21, 2013, 12:17:24 pm » |
I mean I can also write like this vw_send(char msg[8],8) ? Instead of writing it like vw_send((uint8_t*)msg,8), char msg[8] = {'1','2','3','4','5','6','7','8'}
Hahaha.. well, so confuse ><
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #20 on: January 21, 2013, 12:20:51 pm » |
Yes, you can write it like that, but you need to declare the array before the call.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #21 on: January 21, 2013, 12:22:48 pm » |
So the purpose of adding (uint8_t*)msg is just to tell that the message is an array of 8 bits.
Am I correct ?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #22 on: January 21, 2013, 12:26:47 pm » |
The function expects to be given an array of type uint8_t. If you give it an array of that type, you don't need the cast.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #23 on: January 21, 2013, 12:32:32 pm » |
Okay. Got it.
Means if I give the function unsigned integer with 8 bits(An array), then I do not need to write the keyword uint8_t ?
Correct ? Heheh
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #24 on: January 21, 2013, 01:24:43 pm » |
Means if I give the function unsigned integer with 8 bits(An array), then I do not need to write the keyword uint8_t ?
Correct ? No. An unsigned integer is not an array and it isn't 8 bits.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #25 on: January 21, 2013, 01:37:04 pm » |
So, if I want to send a number 2, then how do I wrote it in array of 8 bits ??? Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #26 on: January 21, 2013, 01:40:23 pm » |
So, if I want to send a number 2, then how do I wrote it in array of 8 bits ??? Thanks uint8_t msg[1] = 2; vw_send(msg, 1);
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #27 on: January 21, 2013, 08:48:34 pm » |
So from this can I say uint8_t is like a data type ?
For example int variable, so uint8_t variable ?
Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 207
|
 |
« Reply #28 on: January 21, 2013, 09:13:25 pm » |
So, if I want to send a number 2, then how do I wrote it in array of 8 bits ??? Thanks uint8_t msg[1] = 2; vw_send(msg, 1); So how about the receiving part ? void loop() { uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN;
[b] if (vw_get_message(buf, &buflen)) // Non-blocking[/b] { int i;
digitalWrite(13, true); // Flash a light to show received good message // Message with a good checksum received, dump it. Serial.print("Got: "); for (i = 0; i < buflen; i++) { Serial.print((char)buf[i]); Serial.print(" "); } Serial.println(""); digitalWrite(13, false); } } What does it means ?
|
|
|
|
« Last Edit: January 22, 2013, 02:55:25 am by Vincent19 »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #29 on: January 22, 2013, 02:43:28 am » |
What does it means ? As you posted it, it means nothing, which is why you should post your code between code tags [code] [/code]
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|