2Pascal-新时代的Pascal

标题: c语言的union里面成员是结构体,在delphi里面怎么定义这个union [打印本页]

作者: samyin    时间: 2015-5-27 15:12
标题: c语言的union里面成员是结构体,在delphi里面怎么定义这个union
c语言的union里面成员是结构体,在delphi里面怎么定义这个union:
c的定义如下:
struct s_xl_lin_msg {
  unsigned char id;
  unsigned char dlc;
  unsigned short flags;
  unsigned char data[8];
  unsigned char crc;
};
struct s_xl_lin_sleep {
  unsigned char flag;
};

struct s_xl_lin_no_ans {
  unsigned char id;
};

struct s_xl_lin_wake_up {
  unsigned char flag;
};

struct s_xl_lin_crc_info {
  unsigned char id;
  unsigned char flags;
};

//------------------------------------------------------------------------------
// LIN messages structure
union  s_xl_lin_msg_api {
       struct s_xl_lin_msg          linMsg;
       struct s_xl_lin_no_ans       linNoAns;
       struct s_xl_lin_wake_up      linWakeUp;
       struct s_xl_lin_sleep        linSleep;
       struct s_xl_lin_crc_info     linCRCinfo;
};

//------------------------------------------------------------------------------
// BASIC bus message structure
union s_xl_tag_data {
        struct s_xl_can_msg              msg;
        struct s_xl_chip_state           chipState;
        union  s_xl_lin_msg_api          linMsgApi;   
        struct s_xl_sync_pulse           syncPulse;
        struct s_xl_daio_data            daioData;
        struct s_xl_transceiver          transceiver;
      };

typedef unsigned char  XLeventTag;
作者: wang_80919    时间: 2015-5-27 15:38
type
  s_xl_lin_msg = record   //可能是 pack record 。
    id: Byte;
    dlc: Byte;
    flags: USHORT;
    data: Array [0..7] of Byte;
  end;

  s_xl_lin_sleep = record
    flag: Byte;
  end;

  s_xl_lin_no_ans = record
    id: Byte;
  end;


  s_xl_lin_wake_up = record
    flag: Byte;
  end;

  s_xl_lin_crc_info = record
    id: Byte;
    flags: Byte;
  end;

//------------------------------------------------------------------------------
// LIN messages structure
  s_xl_lin_msg_api = packed record //别人都是这样写的。也许不需要 packed 。
    case Integer of
       1: (linMsg: s_xl_lin_msg);
       2: (linNoAns: s_xl_lin_no_ans);
       3: (linWakeUp: s_xl_lin_wake_up);
       4: (linSleep: s_xl_lin_sleep);
       5: (linCRCinfo: s_xl_lin_crc_info);
  end;

//------------------------------------------------------------------------------
// BASIC bus message structure
  s_xl_tag_data = packed record
    case Integer of
       1: (msg: s_xl_can_msg);
       2: (chipState: s_xl_chip_state);
       3: (linMsgApi: s_xl_lin_msg_api);
       4: (syncPulse: s_xl_sync_pulse);
       5: (daioData: s_xl_daio_data);
       6: (transceiver: s_xl_transceiver);
  end;

XLeventTag = Byte;




欢迎光临 2Pascal-新时代的Pascal (http://2pascal.com/) Powered by Discuz! X3