📄 dst.c
字号:
#include "file.h"
#include "dst.h"
#include <stdio.h>
//#include "data.h" //use by test
extern void number_to_char(uint8 data,char *tmp );
extern char UART_data[5];
//extern int UART0_SendStr(char * str);
extern uchar file_dst[];
uchar *file=file_dst;
//#define uint8 unsigned char
//得到一个字节某一位的值
uint8 getbit(unsigned char b, uint8 pos)
{
uint8 bit;
bit = (b>>pos)%2;
return (bit);
}
//解析文件,得到一针dx的值
uint8 decode_record_dx (unsigned char b0, unsigned char b1, unsigned char b2) {
uint8 x=0;
x+= getbit(b2,2)*(+81);
x+= getbit(b2,3)*(-81);
x+= getbit(b1,2)*(+27);
x+= getbit(b1,3)*(-27);
x+= getbit(b0,2)*(+9);
x+= getbit(b0,3)*(-9);
x+= getbit(b1,0)*(+3);
x+= getbit(b1,1)*(-3);
x+= getbit(b0,0)*(+1);
x+= getbit(b0,1)*(-1);
if(x>127)
{
x = 384-x;
}
return(x);
}
//解析文件,得到一针dy的值
uint8 decode_record_dy (unsigned char b0, unsigned char b1, unsigned char b2) {
uint8 y=0;
y+= getbit(b2,5)*(+81);
y+= getbit(b2,4)*(-81);
y+= getbit(b1,5)*(+27);
y+= getbit(b1,4)*(-27);
y+= getbit(b0,5)*(+9);
y+= getbit(b0,4)*(-9);
y+= getbit(b1,7)*(+3);
y+= getbit(b1,6)*(-3);
y+= getbit(b0,7)*(+1);
y+= getbit(b0,6)*(-1);
if(y>127)
{
y = 384-y;
}
return(y);
}
//解析每一针的功能属性
uint8 decode_record_flags (unsigned char b2)
{
uint8 cmd;
if (b2==243) return END; //结束
cmd = (b2&195);
switch (cmd) {
case 3:
return NORMAL; //正常刺绣
case 131:
return JUMP; //跳针
case 195:
return STOP; // 停止
default:
return UNKNOWN; //默认
}
}
extern UINT32 curr_pin;
//计算一个":"到下一个"."之间表示文件信息的内容
UINT32 get_header_info(UINT32 current_pin, uchar *file_mayb)
{
UINT32 i;
UINT32 info = 0;
//UART0_SendStr(" in get_header_info start \n");
for(i = current_pin;i<512;i++)
{
if(file[i] == 13 || file[i] == 0x2E )
{
if((file[i-1]>47)&&(file[i-1]<58))
{
info+= file[i-1]-48;
// UART0_SendStr("47<file[i-1]<58\n");
}
else
{
// UART0_SendStr("file[i-1]>58 && <47 \n");
break;
}
if((file[i-2]>47)&&(file[i-2]<58))
{
info+= (file[i-2]-48)*10;
// UART0_SendStr("47<file[i-2]<58\n");
}
else
{
// UART0_SendStr("file[i-2]>58 && <47 \n");
break;
}
if((file[i-3]>47)&&(file[i-3]<58))
{
info+= (file[i-3]-48)*100;
// UART0_SendStr("47<file[i-3]<58\n");
}
else
{
// UART0_SendStr("file[i-3]>58 && <47 \n");
break;
}
if((file[i-4]>47)&&(file[i-4]<58))
{
info+= (file[i-4]-48)*1000;
// UART0_SendStr("47<file[i-4]<58\n");
}
else
{
// UART0_SendStr("file[i-4]>58 && <47 \n");
break;
}
if((file[i-5]>47)&&(file[i-5]<58))
{
info+= (file[i-5]-48)*10000;
// UART0_SendStr("47<file[i-5]<58\n");
}
else
{
// UART0_SendStr("file[i-5]>58 && <47 \n");
break;
}
if((file[i-6]>47)&&(file[i-6]<58))
{
info+= (file[i-6]-48)*100000;
// UART0_SendStr("47<file[i-6]<58\n");
}
else
{
// UART0_SendStr("file[i-6]>58 && <47 \n");
break;
}
}
//number_to_char(file[i],&UART_data[0]);
//UART0_SendStr(UART_data);
//UART0_SendStr(" ");
//number_to_char(i,&UART_data[0]);
//UART0_SendStr(UART_data);
//UART0_SendStr(" ");
}
return info;
}
int guwj_x=0;
int guwj_y=0;
uint8 Decode_DST_Header( struct dst_inf *p ,uchar *file_mayb )
{
//头信息存储变量
unsigned char la; //LA:文件名称
int st=0; //ST:针数
int co=0; //CO:颜色数
int x_right=0; //+X:
int x_left=0; //-X:
int y_up=0; //+Y
int y_down=0; //-Y
int ax; //AX: the relative coordinates of the
int ay; //AY: last point from the start point in 0.1 mm
char var[3]; // temporary storage variable name
// char val[512];
int valpos = 10;
// unsigned char tmp;
int i;
//uint8 tmp;
// fill variables from header fields
for (i = valpos;i<522;i++)
{
if (file[i]==':')
{
var[0]=file[i-2];
var[1]=file[i-1];
var[2]='\0';
if((var[0]=='L')&&(var[1]=='A'))
{
la = 76;
valpos = i+1;
UART0_SendStr("\n1111\n");
//continue;
}
else if((var[0]=='S')&&(var[1]=='T'))
{
UART0_SendStr("\n2222\n");
st = get_header_info(i,file);
valpos = i+1;
//continue;
}
else if((var[0]=='C')&&(var[1]=='O'))
{
co = get_header_info(i,file);
valpos = i+1;
UART0_SendStr("\n3333\n");
//continue;
}
else if((var[0]=='+')&&(var[1]=='X'))
{
x_right = get_header_info(i,file);
valpos = i+1;
UART0_SendStr("\n4444\n");
//continue;
}
else if((var[0]=='-')&&(var[1]=='X'))
{
x_left = get_header_info(i,file);
valpos = i+1;
UART0_SendStr("\n5555\n");
//continue;
}
else if((var[0]=='+')&&(var[1]=='Y'))
{
y_up = get_header_info(i,file);
valpos = i+1;
UART0_SendStr("\n6666\n");
//continue;
}
else if((var[0]=='-')&&(var[1]=='Y'))
{
y_down = get_header_info(i,file);
valpos = i+1;
UART0_SendStr("\n7777\n");
//continue;
}
else if((var[0]=='A')&&(var[1]=='X'))
{
ax = get_header_info(i,file);
valpos = i+1;
UART0_SendStr("\n8888\n");
//continue;
}
else if((var[0]=='A')&&(var[1]=='Y'))
{
ay = get_header_info(i,file);
valpos = i+1;
UART0_SendStr("\n9999\n");
//continue;
}
else
{
continue;
}
}
// tmp = i;
// if(tmp>255)
// tmp = 0;
// number_to_char(tmp,&UART_data[0]);
// UART0_SendStr(UART_data);
// UART0_SendStr("?? end if ??");
}
guwj_x = x_left;
guwj_y = y_down;
p->width = x_left + x_right;
Uart_Printf(" x_left=%d,x_right=%d,p->width=%d \n",x_left,x_right,p->width);
p->hight = y_up + y_down;
Uart_Printf(" y_up=%d,y_down=%d,p->hight=%d \n",y_up,y_down,p->hight);
p->star_x = (p->width)/2 - x_right;
if((p->star_x)<0)
{
p->star_x = 32768 - p->star_x;
}
// tmp = p->star_x/0xff;
//number_to_char(tmp,&UART_data[0]);
//UART0_SendStr(UART_data);
//UART0_SendStr(" *256+");
//number_to_char(p->star_x,&UART_data[0]);
//UART0_SendStr(UART_data);
//UART0_SendStr(" ");
p->star_y = (p->hight)/2 - y_up;
if((p->star_y)<0)
{
p->star_y = 32768 - p->star_y;
}
// tmp = p->star_y/0xff;
//number_to_char(tmp,&UART_data[0]);
//UART0_SendStr(UART_data);
//UART0_SendStr(" *256+");
//number_to_char(p->star_y,&UART_data[0]);
//UART0_SendStr(UART_data);
//UART0_SendStr(" ");
p->whole_pin_num = st;
//number_to_char(st,&UART_data[0]);
//UART0_SendStr(UART_data);
//UART0_SendStr(" ");
//p->color_num = co;//改从头部信息获取花样色数,为从花样信息中获取色数信息
//number_to_char(co,&UART_data[0]);
//UART0_SendStr(UART_data);
//UART0_SendStr("\n ############\n");
return 0;
}
extern struct dst_inf *ppp;//added by guwj
uint8 Decode_DST_Body( struct dst_inf *p ,uchar *file_mayb )
{
int i;
//int j;
int co=1;//花样色数
/* for(j=0;j<12;j++)
{
number_to_char(file[j+522],&UART_data[0]);
UART0_SendStr(UART_data);
UART0_SendStr(" ");
}*/
// UART0_SendStr(" compared with move \n ");
for(i=522;i<522+p->whole_pin_num*3;i+=3)
{
file[i-10] = decode_record_flags(file[i+2]);
if(file[i-10] == 0xB2)
{
co++;
}
file[i-9] = decode_record_dx(file[i],file[i+1],file[i+2]);
file[i-8] = decode_record_dy(file[i],file[i+1],file[i+2]);
}
p->color_num = co;
p->data_stitch = file+512;
ppp=p;//added by guwj
// p->data = xydata[0];
/*
for(j=0;j<p->whole_pin_num*3;j++)
{
number_to_char(file[j+512],&UART_data[0]);
UART0_SendStr(UART_data);
UART0_SendStr(" ");
}
*/
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -