LMD文件格式解析
LMD格式是二進(jìn)制保存方式,所以解析文件必須要分析文件內(nèi)容的結(jié)構(gòu)體,先看文件中定義的這些宏,然后我們?cè)儆枚M(jìn)制軟件打開(kāi)文件,數(shù)里面的碼的位置是不是和描述的一致。
//-------------- 基本類型定義?---------------
#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)
//-------------- 擴(kuò)展類型定義?---------------
#define LMD_TYPE_DEF 11 // + byte(=new-type) + int (=parameter_
size)
//-------------- 擴(kuò)展類型?-------------------------
//- All commands from 12 to 127 are reserved for extended types
//- All extended types have a fixed length (command + param
eter_size)
//-------------- 預(yù)定義擴(kuò)展類型 ---------------
#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
// ********* 擴(kuò)展型掃描頭 *********
// 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
// ??-------------- 預(yù)定義塊類型?-------------------
#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,查看了這些定義之后,我們大致可以分析出來(lái),這個(gè)結(jié)構(gòu)體的雛形。
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,我們需要用二進(jìn)制查看軟件,打開(kāi)LMD格式的文件,這樣方便我們驗(yàn)證
?
1,首先,我們找到了 82 ,81 ,對(duì)應(yīng)的是LMD_PHASE,LMD_PHASE_HEADER,然后后面接的一串字符串,
#define LMD_PHASE_HEADER ??129
// ??+ LMD_SSTRING: phase-name
// ??+ LMD_SSTRING: layer-name
明文中已經(jīng)解析出來(lái)為MillingTop,TopLayer
2,后面我們找到80,對(duì)應(yīng)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后面會(huì)跟一些參數(shù)。我們可以解析出來(lái),但是最后LMD_SSTRING,這個(gè)是不固定的,所以必須解析到下一個(gè)特征,才能判斷這個(gè)參數(shù)是多長(zhǎng)。
(C1,72,04,3c,34,12,21,3c),分別轉(zhuǎn)成float,對(duì)應(yīng)XY坐標(biāo)值
然后找到11,又?jǐn)?shù)20字節(jié),到了00(LMD_BLOCK_END)。
?
分析LMD文件需要請(qǐng)留郵箱地址。
?
總結(jié)
- 上一篇: 基于stm32电子时钟设计
- 下一篇: 华硕(ASUS)TUF GAMING B