CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

struct errors, i need help!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fedetouz



Joined: 01 Aug 2007
Posts: 14

View user's profile Send private message

struct errors, i need help!
PostPosted: Wed Aug 22, 2007 10:52 pm     Reply with quote

i make this code for Xbee radios in API frame format

Code:


#include "alarma_gsm.h"
#include <stdio.h>
#include "string.h"

typedef unsigned char bool;
typedef unsigned char uchar;
typedef unsigned char uint8;
typedef unsigned int uint;






// states for receiving packets
#define XBEE_PACKET_RX_START 0
#define XBEE_PACKET_RX_LENGTH_1 1
#define XBEE_PACKET_RX_LENGTH_2 2
#define XBEE_PACKET_RX_PAYLOAD 3
#define XBEE_PACKET_RX_CRC 4

// general xbee constants
#define XBEE_PACKET_STARTBYTE 0x7E
#define XBEE_PACKET_ESCAPE 0x7D
#define XBEE_INPUTS 15 // counts analog and digital ins separately



#define BUFFER_SIZE 32
char buffer[BUFFER_SIZE+1];
int8 buf_index = 0;


/**Respuestas del XBEE**/
char ok[] = { "OK" };

#int_RDA
void  RDA_isr(void)
{
 
   // Don't exceed the size of the buffer
   if (buf_index < BUFFER_SIZE)
   {
     buffer[buf_index]=fgetc(Xbee232);
     //printf(lcd_putc,"\n%c",buffer[buf_index]);
     //delay_ms(300);
     buf_index++;
     // Terminate our string
     buffer[buf_index] = 0;
     
   }
}


void clear_buffer(void)
{
  disable_interrupts(INT_RDA);
  buf_index = 0;
  buffer[0] = 0;
  enable_interrupts(INT_RDA);
}

#inline
void delay_sec (void)
{
   delay_ms(1000);
}


char  *Xbee_response(
char    *s,         
int16  timeout)    /* wait ms */
{

  char  *p;

  while (TRUE)
  {
    p = STRSTR(buffer, s);
   
    if (p)
    {
       /*fprintf(GSM,"encontrado\r");*/
       return (P); //drop out of function
    }     
   
    if (timeout)
    {   
      timeout--;
      if (!timeout)
      {
        /*fprintf(GSM,"timeout\r");*/
        /*timeout Buffer  */
        return (NULL);
      }
    }
  }
}




/** \defgroup XBeePacketTypes XBee Packet Types
   The different types of packet that can be used with the \ref XBee subsystem.

  These structures are to be used when the module has already been set into packet (API) mode
  with a call to XBee_SetPacketApiMode( )

  \ingroup XBee
  @{
*/

/**
  The structure used for a standard AT Command packet.
  - \b frameID is the ID for this packet that subsequent response/status messages can refer to.
  - \b command is the 2-character AT command.
  - \b parameters is a buffer that holds the value of the AT command.
 */
typedef struct
{
  uint8 frameID;
  uint8 command[ 2 ];
  uint8 parameters[ 97 ];
} XBee_ATCommand;

/**
  The structure used for a response to a standard AT Command packet.
  - \b frameID is the ID that this response is referring to.
  - \b command is the 2-character AT command.
  - \b status is response value - 0 (OK) or 1 (ERROR).
  - \b value is a buffer that holds the value of the AT command response.
 */
typedef struct
{
  uint8 frameID;
  uint8 command[ 2 ];
  uint8 status;
  uint8 value[ 96 ];
}  XBee_ATCommandResponse;

/**
  The structure used to transmit an XBee packet with a 64-bit destination address.
  - \b frameID is the ID for this packet that subsequent response/status messages can refer to.
  - \b destination is the 64-bit (8-byte) address of the destination.
  - \b options - 0x01 (disable ACK) or 0x04 (Send with Broadcast PAN ID).
  - \b data is a buffer that holds the value of the outgoing packet.
 */
typedef struct
{
  uint8 frameID;
  uint8 destination[ 8 ];
  uint8 options;
  uint8 data[ 90 ];
}  XBee_TX64;

/**
  The structure used to transmit an XBee packet with a 16-bit destination address.
  - \b frameID is the ID for this packet that subsequent response/status messages can refer to.
  - \b destination is the 16-bit (2-byte) address of the destination.
  - \b options - 0x01 (disable ACK) or 0x04 (Send with Broadcast PAN ID).
  - \b data is a buffer that holds the value of the outgoing packet.
 */
typedef struct
{
  uint8 frameID;
  uint8 destination[ 2 ];
  uint8 options;
  uint8 data[ 96 ];
}  XBee_TX16;

/**
  When a transmit request is completed, the module sends a transmit status message.
  - \b frameID is the ID that this response is referring to.
  - \b status can have values of:
    - 0 - success
    - 1 - No ACK received
    - 2 - CCA failure
    - 3 - Purged
 */
typedef struct
{
  uint8 frameID;
  uint8 status;
}  XBee_TXStatus;

/**
  An incoming packet with a 64-bit address.
  - \b source is the 64-bit (8-byte) address of the sender.
  - \b rssi is the signal strength of the received message.
  - \b options - bit 1 is Address Broadcast, bit 2 is PAN broadcast.  Other bits reserved.
  - \b data is a buffer that holds the value of the incoming packet.
 */
typedef struct
{
  uint8 source[ 8 ];
  uint8 rssi;
  uint8 options;
  uint8 data[ 89 ];
}  XBee_RX64;

/**
  An incoming packet with a 16-bit address.
  - \b source is the 16-bit (2-byte) address of the sender.
  - \b rssi is the signal strength of the received message.
  - \b options - bit 1 is Address Broadcast, bit 2 is PAN broadcast.  Other bits reserved.
  - \b data is a buffer that holds the value of the incoming packet.
 */
typedef struct
{
  uint8 source[ 2 ];
  uint8 rssi;
  uint8 options;
  uint8 data[ 95 ];
}  XBee_RX16;

/**
  An incoming packet with IO data from a 64-bit address.
  - \b source is the 64-bit (8-byte) address of the sender.
  - \b rssi is the signal strength of the received message.
  - \b options - bit 1 is Address Broadcast, bit 2 is PAN broadcast.  Other bits reserved.
  - \b samples - the number of samples in this packet.
  - \b channelIndicators - bit mask indicating which channels have been sampled.
  - \b data is a buffer that holds the IO values as indicated by \b channelIndicators.
 */
typedef struct
{
  uint8 source[ 8 ];
  uint8 rssi;
  uint8 options;
  uint8 samples;
  uint8 channelIndicators[ 2 ];
  uint8 data[ 86 ];
}  XBee_IO64;

/**
  An incoming packet with IO data from a 16-bit address.
  - \b source is the 16-bit (2-byte) address of the sender.
  - \b rssi is the signal strength of the received message.
  - \b options - bit 1 is Address Broadcast, bit 2 is PAN broadcast.  Other bits reserved.
  - \b samples - the number of samples in this packet.
  - \b channelIndicators - bit mask indicating which channels have been sampled.
  - \b data is a buffer that holds the IO values as indicated by \b channelIndicators.
 */
typedef struct
{
  uint8 source[ 2 ];
  uint8 rssi;
  uint8 options;
  uint8 samples;
  uint8 channelIndicators[ 2 ];
  uint8 data[ 92 ];
}  XBee_IO16;

typedef enum
{
  XBEE_COMM_TX64 = 0x00,
  XBEE_COMM_TX16 = 0x01,
  XBEE_COMM_TXSTATUS = 0x89,
  XBEE_COMM_RX64 = 0x80,
  XBEE_COMM_RX16 = 0x81,
  XBEE_COMM_ATCOMMAND = 0x08,
  XBEE_COMM_ATCOMMANDQ = 0x09,
  XBEE_COMM_ATCOMMANDRESPONSE = 0x88,
  XBEE_COMM_IO64 = 0x82,
  XBEE_COMM_IO16 = 0x83
} XBeeApiId;

/** @}
*/


typedef struct
{
  enum { XB_IDLE, XB_SLEEP, XB_RECEIVE, XB_TRANSMIT, XB_COMMAND } mode;
} XBee_;

typedef struct
{
  uint8 apiId;
  union
  {
    uint8 payload[ 100 ];
    XBee_TX64 tx64;
    XBee_TX16 tx16;
    XBee_TXStatus txStatus;
    XBee_RX64 rx64;
    XBee_RX16 rx16;
    XBee_ATCommand atCommand;
    XBee_ATCommandResponse atResponse;
    XBee_IO64 io64;
    XBee_IO16 io16;
  };
 
  uint8 crc;
  uint8 *dataPtr;
  int rxState;
  int length;
  int index;
}XBeePacket;



void XBee_SendPacket( XBeePacket* packet, int size );

XBee_* XBee;

uint8 *p;
uint8 *packet;
/**   
  Send an XBee packet.

  Check the possible \ref XBeePacketTypes that can be sent, and populate the packet structures
  appropriately before sending them.
  @param packet The XBeePacket to send.
  @param datalength The length of the actual data being sent (not including headers, options, etc.)
   @return Zero on success.
  @see XBee_SetPacketApiMode( )

  \par Example
  \code
  XBeePacket myPacket;
  packet->apiId = XBEE_COMM_TX16; // we're going to send a packet with a 16-bit address
  packet->tx16.frameID = 0x00;
  packet->tx16.destination[0] = 0xFF; // 0xFFFF is the broadcast address
  packet->tx16.destination[1] = 0xFF;
  packet->tx16.options = 0x00; // no options
  packet->tx16.data[0] = 'A'; // now pack in the data
  packet->tx16.data[1] = 'B';
  packet->tx16.data[2] = 'C';
  // finally, send the packet indicating that we're sending 3 bytes of data - "ABC"
  XBee_SendPacket( &myPacket, 3 );
  \endcode
*/
void XBee_SendPacket( XBeePacket* packet, int size )
{
 
  fputc(XBEE_PACKET_STARTBYTE,Xbee232 );
  //int8 size=datalength;
  switch( packet->apiId )
  {
    case XBEE_COMM_RX64: //account for apiId, 8 bytes source address, signal strength, and options
    case XBEE_COMM_TX64: //account for apiId, frameId, 8 bytes destination, and options
      size += 11;
      break;
    case XBEE_COMM_RX16: //account for apiId, 2 bytes source address, signal strength, and options
    case XBEE_COMM_TX16: //account for apiId, frameId, 2 bytes destination, and options
    case XBEE_COMM_ATCOMMANDRESPONSE: // account for apiId, frameID, 2 bytes AT cmd, 1 byte status
      size += 5;
      break;
    case XBEE_COMM_TXSTATUS:
      size = 3; // explicitly set this, since there's no data afterwards
      break;
    case XBEE_COMM_ATCOMMAND: // account for apiId, frameID, 2 bytes AT command
    case XBEE_COMM_ATCOMMANDQ: // same
      size += 4;
      break;
    default:
      size = 0;
      break;
  }

  fputc( (size >> 8) & 0xFF ,Xbee232); // send the most significant bit
  fputc( size & 0xFF,Xbee232 ); // then the LSB
  packet->crc = 0; // just in case it hasn't been initialized.
  (uint8*)p = (uint8*)packet;
  while( size-- )
  {
    fputc( *p ,Xbee232);
    packet->crc += *p++;
  }
  fputc( 0xFF - packet->crc ,Xbee232);
 
}







void main()
{

  setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
 
  setup_adc_ports(NO_ANALOGS);
  setup_adc(ADC_OFF);
  setup_spi(FALSE);
 
  enable_interrupts(INT_RDA);
 
  enable_interrupts(GLOBAL);


  fprintf(Xbee232,"+++");
  Xbee_response(ok,20000);
  fprintf(Xbee232,"ATAP1\r");
  delay_sec();
  delay_sec();


 
  XBeePacket myPacket;
  packet->apiId = XBEE_COMM_TX16; // we're going to send a packet with a 16-bit address
  packet->tx16.frameID = 0x00;
  packet->tx16.destination[0] = 0x0; // 0xFFFF is the broadcast address
  packet->tx16.destination[1] = 0x2;
  packet->tx16.options = 0x00; // no options
  packet->tx16.data[0] = 'A'; // now pack in the data
  packet->tx16.data[1] = 'B';
  packet->tx16.data[2] = 'C';
  // finally, send the packet indicating that we're sending 3 bytes of data - "ABC"
  XBee_SendPacket( &mypacket, 3 ); */

}


i compile this and i have 11 errors, this is the respond of the compiler:
    *** Error 54 "E:\alarma GSM\mplab\xbee_API.c" Line 409(14,24): Expecting a variable
    *** Error 57 "E:\alarma GSM\mplab\xbee_API.c" Line 410(17,22): Expecting a structure/union
    *** Error 57 "E:\alarma GSM\mplab\xbee_API.c" Line 411(11,15): Expecting a structure/union
    *** Error 57 "E:\alarma GSM\mplab\xbee_API.c" Line 412(11,15): Expecting a structure/union
    *** Error 57 "E:\alarma GSM\mplab\xbee_API.c" Line 413(11,15): Expecting a structure/union
    *** Error 57 "E:\alarma GSM\mplab\xbee_API.c" Line 414(11,15): Expecting a structure/union
    *** Error 57 "E:\alarma GSM\mplab\xbee_API.c" Line 415(11,15): Expecting a structure/union
    *** Error 57 "E:\alarma GSM\mplab\xbee_API.c" Line 416(11,15): Expecting a structure/union
    *** Error 57 "E:\alarma GSM\mplab\xbee_API.c" Line 417(11,15): Expecting a structure/union
    *** Error 12 "E:\alarma GSM\mplab\xbee_API.c" Line 419(21,29): Undefined identifier myPacket
    *** Error 51 "E:\alarma GSM\mplab\xbee_API.c" Line 419(37,38): A numeric expression must appear here

i see error on this part of the code:
Code:

XBeePacket myPacket;
  packet->apiId = XBEE_COMM_TX16; // we're going to send a packet with a 16-bit address
  packet->tx16.frameID = 0x00;
  packet->tx16.destination[0] = 0x0; // 0xFFFF is the broadcast address
  packet->tx16.destination[1] = 0x2;
  packet->tx16.options = 0x00; // no options
  packet->tx16.data[0] = 'A'; // now pack in the data
  packet->tx16.data[1] = 'B';
  packet->tx16.data[2] = 'C';
  // finally, send the packet indicating that we're sending 3 bytes of data - "ABC"
  XBee_SendPacket( &mypacket, 3 ); */


i need help for fix this error, i try a lot of variants and no results!
Thanks, and sorry for my english!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 23, 2007 12:28 am     Reply with quote

Make the 5 changes shown in bold below:

void main()
{

// Move the structure declaration to the start of main(), and add
// a declaration of 'packet' as a pointer to the structure.
XBeePacket myPacket, *packet;

packet = &myPacket; // Initialize the structure pointer.

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);

enable_interrupts(INT_RDA);

enable_interrupts(GLOBAL);


fprintf(Xbee232,"+++");
Xbee_response(ok,20000);
fprintf(Xbee232,"ATAP1\r");
delay_sec();
delay_sec();

// Delete the following line. You need to put declarations at
// the start of main(), not within the code.
XBeePacket myPacket;

packet->apiId = XBEE_COMM_TX16; // we're going to send a packet with a 16-bit address
packet->tx16.frameID = 0x00;
packet->tx16.destination[0] = 0x0; // 0xFFFF is the broadcast address
packet->tx16.destination[1] = 0x2;
packet->tx16.options = 0x00; // no options
packet->tx16.data[0] = 'A'; // now pack in the data
packet->tx16.data[1] = 'B';
packet->tx16.data[2] = 'C';
// finally, send the packet indicating that we're sending 3 bytes of data - "ABC"
XBee_SendPacket( &mypacket, 3 ); */ <== Delete this comment.


// Add a continuous loop at the end of main(), so the code doesn't
// fall off the end and hit the hidden SLEEP instruction that CCS
// puts there. Do this in all your programs.
while(1);
}
fedetouz



Joined: 01 Aug 2007
Posts: 14

View user's profile Send private message

PostPosted: Thu Aug 23, 2007 8:31 am     Reply with quote

Thanks PCM, i have one error "Not enough RAM" on 16F877A , but i fix this with a 18F458, its works ok!!, thanks again PCM!!!!!!!!!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group