سلام دوست عزیز
آره برنامه به زبان c هست.
کاملا حرفه ای هست از این بابت خیالت جمع.چون این یک سخت افزاره که از طریق پورت سریال دیتا میفرسته و این برنامه توی کاتالوگش نوشته شده.
اصولا دریافت از پورت سریال یا به صورت کد اسکی هست یا هگزادسیمال.یعنی مقادیری مابین ۰ تا ۲۵۵ !
حالا این برنامه ۵ بایت اطلاعات میفرسته که نمیدونم چه جوری کد گشایی کنم.
من با C++ برنامه مینویسم تحت فریمورک کیوتی.
حالا میشه یه کمکی بکنین تا از این گرفتاری راحت شم.
ممنون.
بعد هم میشه یکم بیشتر در مورد این کد توضیح بدین.
/* operate checksum */
checksum += *(pack+i+1);
*(pack+i) = (*(pack+i+1)&0x7f) | ( (head&0x1)<<7 );
head >>= 1;
}
}
if ( (checksum & 0x7f) != ((*(pack+len-1)) &0x7f) )
return -2;
return 0;}
این هم کد کامل برنامه در زیر:
[code]
/*--------------------------------------------------------
Data field module -> host
---------------------------------------------------------*/
#define ID_RESET
0x01
#define ID_COM_STS
0x02
#define ID_SELFTEST
0x03
#define
ID_CMD_ACK
0x04
#define ID_TEMP
0x15
#define ID_SPO2_WAVE
0x16
#define ID_SPO2_PR
0x17
#define ID_NIBP_CUFPRE 0x20
#define ID_NIBP_END
0x21
#define ID_NIBP_RESULT1 0x22
#define ID_NIBP_RESULT2 0x23
#define ID_NIBP_STS
0x24
/*--------------------------------------------------------
Data field host -> module
---------------------------------------------------------*/#define CMD_GET_POST_RESULT 0x40
#define CMD_PAT_TYPE
0x42
#define CMD_TEMP_TYPE
0x53
#define CMD_SPO2
0x54
#define CMD_NIBP_START
0x55
#define CMD_NIBP_END
0x56
#define CMD_NIBP_PERIOD
0x57
#define CMD_NIBP_CAL
0x58
#define CMD_NIBP_RESET
0x59
#define CMD_NIBP_PNEUMATIC
0x5A
#define CMD_NIBP_POLL_STATE
0x5B
#define CMD_NIBP_PRE_PRESSURE 0x5C
#define CMD_NIBP_CONTINUE
0x5D
#define CMD_NIBP_GET_RESULT 0x5E
5.3.2 Example for Debagging C language program
CHAR gPackLength[128] =
{
0, // 00: Retention
2, // 01: System replacement information
5, // 02: System mode
9, // 03: System self-check
5, // 04: Order reply
8, // 15:TEMP data
5, // 16: SPO2 waveform data
7, // 17: SPO2 data
7, // 20: NIBP real-time measurement data
4, // 21: NIBP survey conclusion packet
9, // 22: NIBP measurement result 1
5, // 23: NIBP measurement result 2
8, // 24: NIBP measure condition
0, // 25: Retention
0, // 26: Retention
0, // 27: Retention
0, // 28: Retention
0, // 29: Retention
0, // 2A: Retention
0, // 2b: Retention
0, // 2c: Retention
0, // 2d: Retention
0, // 2E: Retention
0, // 2f: Retention
0, // 30: Retention
0, // 31: Retention
0, // 32: Retention
0, // 33: Retention
0, // 34: Retention0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
2,
4,
4,
0,
0,
4,
4,
2,
2,
4,
2,
2,
2,
2,
5,
2,
2,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
35: Retention
36: Retention
37: Retention
38: Retention
39: Retention
3A: Retention
3b: Retention
3c: Retention
3d: Retention
3E: Retention
3f: Retention
40: Reading the self-checking result
41: Receive data access
42: Patient information establishment
43: Retention
44: Retention
53: The TEMP probe type establishment
54: SPO2 establishment
55: NIBP starts a manually /Automatic measure
56: NIBP end measuring
57: NIBP measure cycle establishment
58: NIBP starts to calibrate
59: NIBP replacement
5A: NIBP leaking gas inspection
5b: NIBP inquiry condition
5c: NIBP establishes the primary inflation pressure
5d: NIBP starts the STAT measure
5E: NIBP inquiry result
66: Retention
67: Retention
68: Retention
69: Retention
6a: Retention
6b: Retention
6c: Retention
6d: Retention
6e: Retention
6f: Retention
70: Retention
71: Retention
72: Retention
73: Retention
74: Retention
75: Retention
76: Retention
77: Retention
78: Retention
79: Retention0, // 7a: Retention
0, // 7b: Retention
0, // 7c: Retention
0, // 7d: Retention
0, // 7e: Retention
0, // 7f: Retention
};
/******************************************************************
Functional description: Restored the data from the buffer area,
debagging data is still placed in the original buffer area, the data
head is deleted after debagging.
*Parameters:
* pack
The buffer indicator, this indicator must aim at the data
buffer where a packet type starts;
* len
the wanted debagging data packet length (including a
packet type and checksum);
* Returned value:
* 0: Debagging OK
* -1: The packet length is wrong
* -2: Checksum mistake
*******************************************************************/
int UnPackData(unsigned char * pack, int len)
{
unsigned char head;
int i;
unsigned char checksum;
if ( len < 2 )
return -1;
/* starts to operate checksum */
checksum = *(pack);
if ( 2 > len ){
head = *(pack+1);
/* checksum plus data head */
checksum += head;
for (i = 1; i < len - 2; i ++) {
/* operate checksum */
checksum += *(pack+i+1);
*(pack+i) = (*(pack+i+1)&0x7f) | ( (head&0x1)<<7 );
head >>= 1;
}
}
if ( (checksum & 0x7f) != ((*(pack+len-1)) &0x7f) )
return -2;
return 0;}
/********************************************************************
* Functional description:Debagging from the buffering area of the
receiving serial port.
*Parameters:
* data
indicator of serial port buffer area;
* len
the wanted debagging data length of serial port buffer
area;
* Returned value:
* 0: Debagging OK
* -1: The packet length is wrong
* -2: Checksum mistake
*******************************************************************/
void UnBind (unsigned char *data, int length)
{
static unsigned char sCurrPacket[10];
static int
sPacketIdFound = 0;/* mark of receiving packet type
ID,1 stands for received*/
static int
sCurrPacketLen;/*the currently received packet
length*/
unsigned char current_data;
int
result = 0;
/* red the data of buffering area */
while (length > 0)
{
current_data = * data;
/* received packet type bytes */
if ( sPacketIdFound ){
/* the current data is data byte,the sufficient data byte must
be bigger than or equal with 0x80 */
if (current_data >= 0x80 ){
// preserve data
sCurrPacket [sCurrPacketLen++] = current_data;
/* received the entire packet data, start to debagging */
if (sCurrPacketLen == gPackLength [sCurrPacket [0]]) {
result = UnBind (sCurrPacket, sCurrPacketLen );
if ( 0 == result ){
/* TODO:the user can deal with the debagging
data */
}
sPacketIdFound = 0;
}
}else{
/*if the current data is smaller than 0x80, it is wrong*/
sPacketIdFound = 0;
result = -1;}
}else{
/* Inspect whether the current data byte is correct packet type
ID */
if (gPackLength [current_data] > 0 )
{
sCurrPacketLen = 1;
sCurrPacket[0] = current_data;
sPacketIdFound
= 1;
}else {
/* the current data is of wrong packet type */
result = -1;
}
}
/* aim at the next serial port data */
data ++;
/* the data length reduces 1 */
length --;
}
return (result);
}
5.3.3 Example for forming packet of the C language program
/********************************************************************
Function description: send order to the lower position machine.
Parameters:
Pack---- indicator of the wanted send order buffer, the content is the
unorganized order: ID+DATA.
Returned value: non.
********************************************************************/
void SendCommand (unsigned char* pack)
{
unsigned char head;
int i;
unsigned char checksum;
len = gPackLength [*pack]
/* if the packet length is smaller than 2,return directly*/
if (len < 2 )
return;
/* start to operate checksum */
checksum = *(pack);
if (len > 2 ){
head = 0;for (i = len-2; i > 1; i --) {
head <<= 1;
/* the highest position1 */
*(pack+i) = *(pack+i-1) | 0x80;
/*operate the checksum */
checksum += *(pack+i);
/*operate the data head */
head |= (*(pack+i-1)&0x80) >> 7;
}
/* the highest position 1 of data head 1 */
*(pack+1) = head | 0x80;
/* checksum plus data head */
checksum += *(pack+1);
}
/* preserve the checksum */
*(pack+len-1) = checksum | 0x80;
/* TODO: the user can send order to the serial port of the lower
position machine */
/* uart.write(pack, len); */
}