2Pascal-新时代的Pascal

 找回密码
 立即注册
搜索
热搜: fastreport
查看: 1245|回复: 1
打印 上一主题 下一主题

c语言的union里面成员是结构体,在delphi里面怎么定义这个union

[复制链接]

1

主题

1

帖子

7

积分

新手上路

Rank: 1

积分
7
跳转到指定楼层
楼主
发表于 2015-5-27 15:12:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
京东数码购物支持本站
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;
回复

使用道具 举报

90

主题

293

帖子

8万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
81883
推荐
发表于 2015-5-27 15:38:48 | 只看该作者
京东数码购物支持本站
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;
(C)(P)Flying Wang
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|新时代Pascal论坛

GMT+8, 2024-4-29 13:40 , Processed in 0.064278 second(s), 24 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表