欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

LMD文件格式解析

发布时间:2024/3/24 编程问答 50 豆豆
生活随笔 收集整理的这篇文章主要介绍了 LMD文件格式解析 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

LMD格式是二进制保存方式,所以解析文件必须要分析文件内容的结构体,先看文件中定义的这些宏,然后我们再用二进制软件打开文件,数里面的码的位置是不是和描述的一致。

//-------------- 基本类型定义 ---------------

#define LMD_BLOCK_END 0

#define LMD_BYTE      1 // + unsigned 8-bit value

#define LMD_SHORT    2 // + signed 16bit integer

#define LMD_INT       3 // + signed 32 bit integer

#define LMD_LONG      4 // + signed 64bit Integer

#define LMD_FLOAT     5 // + 32bit real

#define LMD_DOUBLE    6 // + 64bit real

#define LMD_SSTRING   7 // + 0-terminated single-byte string

#define LMD_DSTRING   8 // + 0-terminated double-byte string

(unicode)

#define LMD_BINARY1   9 // + 1byte(=n) + (n/8)bytes;  (n==no.of

bits,round up)

#define LMD_BINARY4   10 // + 4bytes(=n) + (n/8)bytes;

(n==no.of bits,round up)

//-------------- 扩展类型定义 ---------------

#define LMD_TYPE_DEF 11 // + byte(=new-type) + int (=parameter_

size)

//-------------- 扩展类型 -------------------------

//- All commands from 12 to 127 are reserved for extended types

//- All extended types have a fixed length (command + param

eter_size)

//-------------- 预定义扩展类型 ---------------

#define LMD_MOVE        12  // + float(=x) + float(=y)

#define LMD_DRAW        13  // + float(=x) + float(=y)

#define LMD_CIRCLE      14  // + float(=x) + float(=y) + float

(=r; r>0 CCW)

future

#define LMD_DRILL       15  // + float(=x) + float(=y)

#define LMD_TOOL_SELECT 16  // + int(=iTool)

#define LMD_ARC         17  // + float(cx)+float(cy)+float(ex)

+float(ey)+float(r)

// draw arc 0..+-355 degree.

// If start and end points are the same,

// draw a 360 degree circle

// ********* 扩展型扫描头 *********

// scanner head has its window (box), defined by points

// (-xmax,-ymax) and (xmax,ymax).

// Origin of the head is at (0,0)

// Position of the head is the point at which the origin (0,0)

is placed

#define LMD_HEAD_BOX    18  // + float(=xmax) + float(=ymax)

#define LMD_HEAD_POS    19  // + float(=x) + float(=y)

#define LMD_HEAD_NONE   20  // head position undefined, do not

use head

//   -------------- 预定义块类型 -------------------

#define LMD_TOOL     128

//   + LMD_INT iTool for use in LMD_TOOL_SELECT

//   + LMD_BYTE for mode: 0:draw, 1=flash 2=flash+draw

//   + LMD_FLOAT: width

//   + LMD_SSTRING: tool-name

#define LMD_PHASE_HEADER   129

//   + LMD_SSTRING: phase-name

//   + LMD_SSTRING: layer-name

#define LMD_PHASE    130

//   + LMD_PHASE_HEADER()

//   + LMD_TOOL  { LMD_TOOL }

//   + { LMD_TOOL_SELECT() { LMD_DRILL() | path }

//   path ::= LMD_MOVE() { [LMD_CIRCLE()] LMD_DRAW() };

//Please note that this structure may change in future ver

sions.

2,查看了这些定义之后,我们大致可以分析出来,这个结构体的雏形。

LMD_begin

        Phase_Begin

                Layer_Begin

                        TOOL_Select

                        HEAD_Box

                        HEAD_POS

                        LMD_MOVE

                        LMD_DRAW

                        LMD_ARC

                        。。。

        Layer_End

        Phase_End        

        ....

LMD_End

3,我们需要用二进制查看软件,打开LMD格式的文件,这样方便我们验证

 

1,首先,我们找到了 82 ,81 ,对应的是LMD_PHASELMD_PHASE_HEADER,然后后面接的一串字符串,

#define LMD_PHASE_HEADER   129

//   + LMD_SSTRING: phase-name

//   + LMD_SSTRING: layer-name

明文中已经解析出来为MillingTop,TopLayer

2,后面我们找到80,对应LMD_TOOL,

#define LMD_TOOL     128

//   + LMD_INT iTool for use in LMD_TOOL_SELECT

//   + LMD_BYTE for mode: 0:draw, 1=flash 2=flash+draw

//   + LMD_FLOAT: width

//   + LMD_SSTRING: tool-name

Tool后面会跟一些参数。我们可以解析出来,但是最后LMD_SSTRING,这个是不固定的,所以必须解析到下一个特征,才能判断这个参数是多长。

  • 我们找到Tool_select -->10(16进制,后面我们都会用16进制),后面跟着4个字节,然后转成int类型(01 00 00 00)
  • 然后找到12,对应的是LMD_HEAD_BOX,后面跟着两个float,我们数8个字节
  • (C1,72,04,3c,34,12,21,3c),分别转成float,对应XY坐标值

  • 然后找到13,对应LMD_HEAD_POS,也是一样,读取8个字节,
  • 然后找到0c,对应LMC_MOVE,这里就是数据的开始了,表示跳转到某个位置。读出XY坐标
  • 然后到0d,对应LMD_DRAW,画一条直线。
  • 接下来继续找到0c,11(LMD_ARC),ARC对应的参数是20个字节
  • 然后找到11,又数20字节,到了00(LMD_BLOCK_END)。

     

  • 然后又到了 82,81,又和之前步骤1的解析类似了,中间又到了数据层,然后提取数据。
  • 最后结尾是00。
  • 到此,我们基本能提取出LMD格式里的数据了。
  • 分析LMD文件需要请留邮箱地址。

     

    总结

    以上是生活随笔为你收集整理的LMD文件格式解析的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。