2

こんにちは、次のようなエラーがあります: コードを Arduino atmega にアップロードするたびに typedef-declaration に type-name がありません。

typedef union DrsData
{
unsigned char   ucData[MAX_PACKET_SIZE-MIN_PACKET_SIZE];

 DrsRWData      stRWData;
 DrsIJogData        stIJogData;
 DrsSJogData        stSJogData; <-the error is highlighted at this line
}DrsData;

このコードの何が問題なのか分かりますか? ありがとう!

これは、ヘッダーを含むソース コードです。

#include<Arduino.h>
#include<Wire.h>
#include<Math.h> 
#include <SoftwareSerial.h>//
#define rxPin 19   // Defines the "recieve" pin for software serial to motor `enter code here`controller
#define txPin 18    // Defines the "transmit" pin for software serial to motor controller

    //CPU
    #define F_CPU 16000000

//ATmega128? ???? ?? ???? ??
#include <avr/io.h>
//interrupt? ???? ? ??? ???? ???? ??
#include <avr/interrupt.h>
//_delay_ms ? ??? ??? ???? ??
#include <util/delay.h>

#include<inttypes.h> 

#define PROTOCOL_SIZE_IDX 2
#define PROTOCOL_ID_IDX   3
#define PROTOCOL_CMD_IDX  4
#define PROTOCOL_CS1_IDX  5
#define PROTOCOL_CS2_IDX  6
#define PROTOCOL_DATA_IDX  7

#define HEADER      0xFF

//SIZE
#define MIN_PACKET_SIZE     7
#define MIN_ACK_PACKET_SIZE     9
#define MAX_PACKET_SIZE         223
#define MAX_DATA_SIZE       (MAX_PACKET_SIZE-MIN_PACKET_SIZE)

//ID ??
#define MAX_ID                  0xFD    
#define BROADCAST_ID            0xFE  

//CMD - Request Packet
#define CMD_EEP_WRITE           0x01
#define CMD_EEP_READ            0x02
#define CMD_RAM_WRITE           0x03
#define CMD_RAM_READ            0x04    
    #define CMD_RW_DATA_ADDR_IDX    7
    #define CMD_RW_DATA_LEN_IDX     8
#define CMD_I_JOG               0x05
    #define CMD_I_JOG_STRUCT_SIZE   5
    #define CMD_I_JOG_MAX_DRS       (MAX_DATA_SIZE/CMD_I_JOG_STRUCT_SIZE)
#define CMD_S_JOG                   0x06
    #define CMD_S_JOG_STRUCT_SIZE   4
    #define CMD_S_JOG_MAX_DRS       (MAX_DATA_SIZE/CMD_S_JOG_STRUCT_SIZE)
#define CMD_STAT                    0x07    
#define CMD_ROLLBACK                0x08
#define CMD_REBOOT                  0x09

#define CMD_MIN                             (CMD_EEP_WRITE)
#define CMD_MAX                             (CMD_REBOOT)

//CMD - ACK Packet
#define CMD_ACK_MASK                        0x40

#define CMD_EEP_WRITE_ACK                   (CMD_EEP_WRITE|CMD_ACK_MASK)
#define CMD_EEP_READ_ACK                    (CMD_EEP_READ|CMD_ACK_MASK)
#define CMD_RAM_WRITE_ACK                   (CMD_RAM_WRITE|CMD_ACK_MASK)
#define CMD_RAM_READ_ACK                    (CMD_RAM_READ|CMD_ACK_MASK)
#define CMD_I_JOG_ACK                       (CMD_I_JOG|CMD_ACK_MASK)
#define CMD_S_JOG_ACK                       (CMD_S_JOG|CMD_ACK_MASK)
#define CMD_STAT_ACK                        (CMD_STAT|CMD_ACK_MASK)
#define CMD_ROLLBACK_ACK                    (CMD_ROLLBACK|CMD_ACK_MASK)
#define CMD_REBOOT_ACK                      (CMD_REBOOT|CMD_ACK_MASK

#define CMD_ACK_MIN                         (CMD_EEP_WRITE_ACK)
#define CMD_ACK_MAX                         (CMD_REBOOT_ACK)

#define DrsPacket
#define stPacket
#define pstPacket
#define DrsData
 typedef struct DrsSet
  {
    unsigned char   ucStopFlag : 1;
    unsigned char   ucMode : 1;
    unsigned char   ucLedGreen : 1;
    unsigned char   ucLedBlue : 1;
    unsigned char   ucLedRed : 1;
    unsigned char   ucJogInvalid : 1;
    unsigned char   reserved : 2;
  }DrsSet;

    typedef struct DrsJog
    {   
    unsigned int    uiValue : 15;
    unsigned int    reserved : 1;
    }DrsJog;

  typedef struct DrsSJog 
  {
    DrsJog          stJog;
    DrsSet          stSet;
    unsigned char   ucId;
  }DrsSJog;

  typedef struct DrsIJog 
  {
        DrsJog          stJog;
        DrsSet          stSet;
    unsigned char   ucId;
    unsigned char   ucPlayTime;
  }DrsIJog;

  typedef struct DrsIJogData
  {
     DrsIJog            stIJog[CMD_I_JOG_MAX_DRS];
  }DrsIJogData;

  typedef struct DrsSJogData
  {
    unsigned char   ucPlayTime;
     DrsSJog            stSJog[CMD_S_JOG_MAX_DRS];
  }DrsSJogData;

  typedef struct DrsRWData
  {  
    unsigned char   ucAddress;
    unsigned char   ucLen;        
    unsigned char   ucData[MAX_DATA_SIZE-2];
  }DrsRWData;

  typedef union DrsData
  {
    unsigned char   ucData[MAX_PACKET_SIZE-MIN_PACKET_SIZE];

     DrsRWData      stRWData;
     DrsIJogData        stIJogData;
     DrsSJogData        stSJogData;
  }DrsData;

typedef struct DrsPacket 
  {
    unsigned char           ucHeader[2];
    unsigned char           ucPacketSize;
    unsigned char           ucChipID;
    unsigned char           ucCmd;
    unsigned char           ucCheckSum1;
    unsigned char           ucCheckSum2;
    union DrsData               unData;
  }DrsPacket;


//CheckSum
#define CHKSUM_MASK                         0xFE


//////////////////////////////receiving state result value //////////////////////////////
  enum{
    DRS_RXWAITING,
    DRS_RXCOMPLETE,
    DRS_HEADERNOTFOUND,
    DRS_INVALIDSIZE,
    DRS_UNKNOWNCMD,
    DRS_INVALIDID,
    DRS_CHKSUMERROR,
    DRS_RXTIMEOUT
  }DrsRxStatus;

//?? ??? ??? ??
#define USART_BUF_SIZE 256

//?? ??, ?? ???, ?? ???, ??? ?? ??? ?? ??
//USART0_EXT volatile unsigned char gucRxBuffer[USART_BUF_SIZE];
//USART0_EXT volatile unsigned char gucRxBufferReadIdx;
//USART0_EXT volatile unsigned char gucRxBufferWriteIdx;
//USART0_EXT volatile unsigned char gucRxBufferCnt;

volatile unsigned char gucRxBuffer[USART_BUF_SIZE];
volatile unsigned char gucRxBufferReadIdx;
volatile unsigned char gucRxBufferWriteIdx;
volatile unsigned char gucRxBufferCnt;

//USART0? ??? ??
void USART0_Init(unsigned long ulBaudRate);
//USART0? ?? ??? ???? ??
void USART0_PutChar(unsigned char ucData);
//USART0? ?? ?? ?? ???? ??
void USART0_PutNChar(unsigned char *pucData, unsigned char ucCnt);
//USART0? ?? ???? ?? ?? ???? ???? ??
unsigned char USART0_ucGetNChar(unsigned char *pucTarget, unsigned char ucCnt);
//USART0? ?? ???? ?? ?? ???? ??? ??
unsigned char USART0_ucTrashNChar(unsigned char ucCnt);
//USART0? ?? ??? ????? ??
void USART0_ClearBuffer(void);

void hklx_Init(unsigned long ulBaudRate);

void hklx_SendPacket( DrsPacket stPacket);

unsigned char hklx_ucReceivePacket( DrsPacket *pstPacket);

void setup()
{
  //DRS-0101? Calibrated Position ??? ???? ?? ???
typedef struct DrsCaliPos
{
    int     iPosition : 13;
    unsigned int    uiGPIO1 : 1;
    unsigned int    uiGPIO2 : 1;
    unsigned int    reserved : 1;
}

DrsCaliPos;

//Calibrated Position ??? ?? ??? ?? ???
typedef union DrsUnionCaliPos
{
     DrsCaliPos stCaliPos;
    unsigned int    uiCaliPos;
}

DrsUnionCaliPos;

//HerkuleX? ???? ?? ???
    Serial.begin(9600);
    Serial.begin(115200);
    pinMode(rxPin, INPUT); //RX //connect to TX of motor 
    pinMode(txPin, OUTPUT); //TX //connect to RX of motor

}

  typedef struct DrsPacket 
  {
    unsigned char   ucHeader[2];
    unsigned char   ucPacketSize;
    unsigned char   ucChipID;
    unsigned char   ucCmd;
    unsigned char   ucCheckSum1;
    unsigned char   ucCheckSum2;
     DrsData        unData;
  }DrsPacket;

 // void hklx_SendPacket(DrsPacket stPacket){
void hklx_SendPacket(DrsPacket stPacket){
    unsigned char i;
        DrsPacket stPacket;

    // declare header 
    stPacket.ucHeader[0] = HEADER;
    stPacket.ucHeader[1] = HEADER;

    //CheckSum 
    stPacket.ucCheckSum1 = stPacket.ucPacketSize ^ stPacket.ucChipID ^ stPacket.ucCmd;
    for( i=0; i<(stPacket.ucPacketSize-MIN_PACKET_SIZE); i++ )    
        stPacket.ucCheckSum1 ^= stPacket.unData.ucData[i];

    stPacket.ucCheckSum2 = ~(stPacket.ucCheckSum1);
    stPacket.ucCheckSum1 &= CHKSUM_MASK;    
    stPacket.ucCheckSum2 &= CHKSUM_MASK;

    //PacketSize ?? USART0?? ??
    USART0_PutNChar(&stPacket.ucHeader[0], stPacket.ucPacketSize);

    return 0;
}

完全なエラー メッセージ:

line 136: error: missing type-name in typedef-declaration
line 147: error: missing type-name in typedef-declaration
line 250: error: ISO C++ forbids declaration of 'unData' with no type
line 251: error: missing type-name in typedef-declaration
line 259: error: expected primary-expression before '.' token
4

1 に答える 1

0

Arduino IDE には、初心者が簡単に作業できるように設計された独自のプリプロセッサがあります。残念ながら、ユーザー定義型は、私たちの残りの部分を実際に難しくしている領域です。

リンクされたページは、型宣言を別のヘッダー ファイルに配置することを提案しています。次のような手法でも成功しました。

typedef struct _xyz {
    int a;
    int b;
    int c;
} XYZ;

void myFunc(struct _xyz *xyzName) {
    ...
}

エラーを生成する行を に変更すると、エラーstruct _DrsSJogData stSJogData;が解決されるはずです (DrsSJogData私が提案するように の宣言も変更すると仮定します) が、Arduino の推奨事項を読んだばかりなので、それで行きます。

すべての型宣言をメイン スケッチとは別のヘッダー ファイルに配置すれば問題ありません。

于 2013-03-05T06:40:17.160 に答える