医用设备心跳心率检测mp3文件输出(心电图)(一)

时间:2022-07-15 19:04:09


本系统是通过一套国外先进的医用设备将用户心跳心率存储到 mp3文件中, 该软件系统由于日本以非常高的价格出售, 公司决定由我破译硬件数据,开发一套替换日本软件产品。  该项目共花费2个月时间完成。    如有需要可电邮448520782@qq.com邮箱获取整套系统代码。


//--------SC.h--------------------------------------------------

typedef struct st_pcm
{
int id;
float ftime;
int pcmlen;
int fliyeLen;
int samplerate;
short* pcm;
int* fliye;
int status;
struct st_pcm* pnext;
}ST_PCM;




void Screen(char filename[], char* ID, int dataID, int datalen);


//-------SC.cpp ----------------------------------------------------------------------

#include "stdafx.h"

#include "SC.h"
#include <afxwin.h>
extern int *g_pData;
extern ST_PCM* g_pCurrent_st;


void DrowModel(int n, CDC &dc)
{


for(int k=0; k<4; k++)
{


for(int i=0; i<9;i++)
{
dc.MoveTo(44, 740+ i*59.05 + k*(473+59));
dc.LineTo(2406, 740+ i*59.05 + k*(473+59));
}


for(int i=0; i<(888/22+1 );i++)
{
dc.MoveTo(44+i*59.125, 740 + k*(473+59.125));
dc.LineTo(44+i*59.125, 740+ 8*59.125 + k*(473+59.125));
}
}


dc.MoveTo(44, 2865);
dc.LineTo(1449, 2865);
dc.MoveTo(44, 2865);
dc.LineTo(44, 3368);


dc.MoveTo(1449, 2865);
dc.LineTo(1449, 3368);
dc.MoveTo(44, 3368);
dc.LineTo(1449, 3368);
//------------------------------------
dc.MoveTo(1473, 2865);
dc.LineTo(2406, 2865);
dc.MoveTo(1473, 2865);
dc.LineTo(1473, 3368);


dc.MoveTo(2406, 2865);
dc.LineTo(2406, 3368);
dc.MoveTo(1473, 3368);
dc.LineTo(2406, 3368);
//------------------------------------
dc.MoveTo(45, 3396);
dc.LineTo(2406, 3396);
dc.MoveTo(45, 3397);
dc.LineTo(2406, 3397);
dc.MoveTo(45, 3398);
dc.LineTo(2406, 3398);
dc.MoveTo(45, 3399);
dc.LineTo(2406, 3399);

}


void DrowLine(int n, CDC &dc, int *Px, int *Py)
{
//int *Px = new int(n+2);
//int *Py = new int(n+2);


int i,j;
int k = 3;
float a,b,c,d, t, t1, t2, t3;
int tx, ty;
t = 0.5;


Px[0] = Px[1]; 
Py[0] = Py[1]; 


Px[n+1] = Px[n];
Py[n+1] = Py[n];


dc.MoveTo(Px[0], Py[0]);
for(i=0; i<n-1; i++)
{
for(j = 1; j<k; j++)
{
t1 = j*t;
t2 = t1 * t1;
t3 = t2 * t1;
a = 4.0*t2 - t1-4.0*t3;
b = 1.0 - 10.0*t2 + 12.0*t3;
c = t1 + 8.0*t2 -12.0*t3;
d = 4.0*t3 - 2.0 * t2;
tx = a* Px[i] + b* Px[i+1] + c* Px[i+2] + d* Px[i+3];
ty = a* Py[i] + b* Py[i+1] + c*Py[i+2] + d*Py[i+3];
dc.LineTo(tx, ty);
}
dc.LineTo(Px[i+2] , Py[i+2]);
}


for(i=0; i<n+2; i++)
{
dc.Ellipse(Px[i]-2, Py[i]-2, Px[i]+2, Py[i]+2 );//绘制数据圆点



}
ST_PCM* GetNextData(int x)
{
ST_PCM* pcm =g_pCurrent_st;
g_pCurrent_st = g_pCurrent_st->pnext;

return pcm;
}


int lasty;
void Screen(char filename[], char* ID, int dataID, int datalen)
{
    CDC *pDC;//屏幕DC
    pDC = CDC::FromHandle(GetDC(NULL));//获取当前整个屏幕DC
    int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);//获得颜色模式
    int Width = 2479;//pDC->GetDeviceCaps(HORZRES);
    int Height = 3508;//pDC->GetDeviceCaps(VERTRES);


    printf("当前屏幕色彩模式为%d位色彩n", BitPerPixel);
    printf("屏幕宽度:%dn", Width);
    printf("屏幕高度:%dn", Height);
    
    CDC memDC;//内存DC
    memDC.CreateCompatibleDC(pDC);//创建一个设备环境。
    //dcGrid.CreateCompatibleDC(&dc) ;//创建一个设备环境。
    CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
    memBitmap.CreateCompatibleBitmap(pDC, Width, Height);


    oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
//---复制 屏幕图像
    //memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY);//复制屏幕图像到内存DC
//------------
CPen *oldPen ;
CPen solidPen(PS_SOLID, 1, RGB(0,0,0)) ;
CPen solidbluePen(PS_SOLID, 1, RGB(0,0,0)) ;
CFont axisFont, yUnitFont, *oldFont ; 
CString strTemp ;
memDC.SetBkMode(TRANSPARENT);
//-----
CBrush m_brushBack(RGB(255, 255, 255));
CRect rect;
rect.left =0;
rect.top =0;
rect.bottom = Height;
rect.right =Width;
memDC.FillRect(&rect, &m_brushBack) ;//设置客户区填充色
oldPen = memDC.SelectObject (&solidbluePen) ;
//memDC.SetBackgroundColor(RGB(200, 200, 200)) ; //背景颜色
//-----画线
int posx=0; 
int posy=0;
int lastposx=0; 
int lastposy=0;
int xx=0;


lasty = 0;
int drowX=0;
CString txt = "仪器编号 :" ;
txt += ID;
CRect rc(20, 40, 180, 80);
//memDC.SetT
memDC.DrawTextA(txt, &rc, 0);


DrowModel(0, memDC);
oldPen = memDC.SelectObject (&solidPen) ;
for(int i=0; i<=23; i++)
{
//g_pData[datalen-23 + dataID+400 + i] = g_pData[datalen-63 + dataID+400+i];
}


for(int i=datalen+dataID+400; i> datalen-888*2-44; i--)
{
//g_pData[i] = g_pData[i-8];
}
// for(int i=0; i<=8; i++)
// {
// g_pData[3552-888*2-44+ 832+ i] = g_pData[3552-888*2-36 + 832+i];
// }
int beg=888;
dataID = 3000/2+150;
int head = dataID+400/2;
 
lastposx = 0;
lastposy = 1040-(g_pData[head]);


for(int xj=0; xj < 5; xj++)
{
lastposx = 44;
lastposy =(980-(g_pData[head+2406*xj/2])+ xj*533);


//for(int x=0; x<2406/2 && x*2+2406/2*xj < 9552; x++)
int px=16;
float fft= 2.67;
//if(xj>0 && xj != 3) fft =2.69;

for(int x=0; x<111 && xj*111+x <444 ; x++)
{
ST_PCM* pcm = GetNextData(x);
for(int xx=0; xx<pcm->fliyeLen; xx++)
{
int data = pcm->fliye[xx];
memDC.MoveTo(lastposx, lastposy);
float ff = fft*(px);
posx =  fft*(px++);
if(ff*10 - posx*10 >5 ) posx++;


if (posx > 2409 ) continue;
//posy = 300-g_pData[x+1200*xj]/10;
//if(x+1200*xj <820)
// posy = 200-(g_pData[x+1300*xj]-1200 > 0 ? g_pData[x+1300*xj]-1200 : 0)/20;
//else
//posy = 980-(g_pData[x+head+2406*xj/2]);
//if(g_pData[x+head+2406*xj/2] > 400 || g_pData[x+head+2406*xj/2] < -400 ) posy = lastposy - xj*533;


posy = 1040-(data);
if(data > 400 || data < -400 ) posy = lastposy - xj*533;


posy = posy;

//if(x+1300*xj > 5850)
// posy = 150;


posy += xj*533;
//posx = drowX;
//if(posy != lastposy && x+1300*xj >= 836 && x+1300*xj < 5850)

memDC.LineTo(posx, posy);
lastposx = posx;
lastposy = posy;
drowX+=4;
}

}
}
//-----画点


    //以下代码保存memDC中的位图到文件
    BITMAP bmp;
    memBitmap.GetBitmap(&bmp);//获得位图信息
    
    FILE *fp = fopen(filename, "w+b");
printf("openFile: %s \n", filename);
    BITMAPINFOHEADER bih = {0};//位图信息头
    bih.biBitCount = bmp.bmBitsPixel;//每个像素字节大小
    bih.biCompression = BI_RGB;
    bih.biHeight = bmp.bmHeight;//高度
    bih.biPlanes = 1;
    bih.biSize = sizeof(BITMAPINFOHEADER);
    bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;//图像数据大小
    bih.biWidth = bmp.bmWidth;//宽度
    
    BITMAPFILEHEADER bfh = {0};//位图文件头
    bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//到位图数据的偏移量
    bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;//文件总的大小
    bfh.bfType = (WORD)0x4d42;
    
    fwrite(&bfh, 1, sizeof(BITMAPFILEHEADER), fp);//写入位图文件头
    
    fwrite(&bih, 1, sizeof(BITMAPINFOHEADER), fp);//写入位图信息头
    
    byte * p = new byte[bmp.bmWidthBytes * bmp.bmHeight];//申请内存保存位图数据


    GetDIBits(memDC.m_hDC, (HBITMAP) memBitmap.m_hObject, 0, Height, p, 
        (LPBITMAPINFO) &bih, DIB_RGB_COLORS);//获取位图数据


    fwrite(p, 1, bmp.bmWidthBytes * bmp.bmHeight, fp);//写入位图数据


    delete [] p;


    fclose(fp);


    memDC.SelectObject(oldmemBitmap); 医用设备心跳心率检测mp3文件输出(心电图)(一)
}