Pages: [1]   Go Down
Author Topic: Working with uint8_t encoded data (virtualwire)  (Read 1873 times)
0 Members and 1 Guest are viewing this topic.
Los Angeles
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As usual I have managed to solve some problems while failing to solve others. Currently I am stuck on the translation of data. I am building a cheap tranceiver using radio transmitters and receivers I have got from Sparkfun. I am able to send an address and receive the addresses of others transmitting theirs.

The trick I am trying to pull off in the larger view is that I want to also send which tranceivers each individual tranceiver can see. I am able to send the data from variables as follows- 0:1,2 where 0 is the tranceiver that can see 1 and 2. However, currently the 1 and 2 is only hard coded not a variable like the address.

I am having trouble parsing the uint8_t data that I receive. I have worked out a script to translate a string to integers with , delineation. However I cannot get the uint8_t data to convert to a char so that i can strcat it into a string for parsing into int's.

here is the script where it needs to go.
Code:
char msg[30]="";

///////////////////////////////////////////Receive Data
void rx(){

 //   vw_rx_start();
 // Serial.println("Receive");//Debug Only
  uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    vw_wait_rx();
    if (vw_get_message(buf, &buflen)) // check to see if anything has been received
    {
      for (int i=0;i<buflen;i++) msg[i]=0;
    int i;

     // Message with a good checksum received.
      Serial.print("Got: ");
       for (int i = 0; i < buflen; i++)
        {
          Serial.print(buf[i], BYTE);
          msg[i]=buf[i];
        }
     Serial.println();
   }
}

I have tried many things (removed because they failed). Typically the error is either cannot convert uint8_t to const *char or cannot convert char to *char.

What is the proper method for parsing uint8_t to char. So far I can print the msg var but cannot do anything useful with it.

Thanks
« Last Edit: February 14, 2010, 10:21:54 pm by abocanegra » Logged

Los Angeles
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks anyways, sometimes you just need to write the problem out to figure it out.  It clicked not long after I posted this.  Here is the answer allowing you to receive data from the transmitter and then convert it to integers after creating a single string from the data.

Code:
///////////////////////////////////////////Receive Data
void rx(){

  //   vw_rx_start();
  // Serial.println("Receive");//Debug Only
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  vw_wait_rx();
  if (vw_get_message(buf, &buflen)) // check to see if anything has been received
  {
    for (int i=0;i<buflen;i++) msg[i]=0;
    {
      int i;
      char vBuff[30]="";
      // Message with a good checksum received.
      // Serial.print("Got: ");
      for (int i = 0; i < buflen; i++)
      {
        // Serial.print(buf[i], BYTE);
        msg[i]=buf[i];
      }
      Serial.println();
      //Create String from received data
      strcat(vBuff, msg);
      //Convert to individual integers from char
      char *rxString = vBuff;
      char *str[30];
      int convert[30];
      int j=0;
      while((str[j] = strtok_r(rxString, ":,", &rxString)) !=NULL){ // delimiter : and ,
        convert[j]=atoi(str[j]);
        if(j==0){
          Serial.print("Sensor= ");
          Serial.println(convert[j]);
        }else{
          Serial.print("near= ");
          Serial.println(convert[j]);
        }
        j++;
      }
    }
  }
}
Logged

Pages: [1]   Go Up
Jump to: