#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

int main()
{
char *path = "./js.jpg";
FILE *fd = fopen(path, "rb");

char buf[10] = {0};
if (fd == NULL)
{
printf("不能打开文件。");
}

int irDataOffset;//红外数据的起始偏移地址
int ret = 0;
if (0 == fseek(fd, -20, SEEK_END)) //向前偏移
{
ret = fread(buf, 4, 1, fd);
printf("ret = %d\n", ret);

memcpy(&irDataOffset, buf, sizeof(int));
printf("irDataOffset = %d\n", irDataOffset);
}

//文件开头到备注信息长度这段距离大小
int isumLenth = irDataOffset + 2 + 2 + 2 + 14 + 4 * 512 * 640 + 4 + 4 + 1 + 4 + 1 + 4 + 32 * 3 + 8 + 8 + 4;
printf("isumLenth = %d\n",isumLenth);

//获取宽度
short iwidth = 0;
fseek(fd, irDataOffset + 2, SEEK_SET);
memset(buf, 0, sizeof(buf));
fread(buf, 2, 1, fd);
memcpy(&iwidth, buf, 2);
printf("iwidth = %d\n", iwidth);

//获取高度
short iHeight = 0;
fseek(fd,irDataOffset+4,SEEK_SET);
memset(buf,0,sizeof(buf));
fread(buf,2,1,fd);
memcpy(&iHeight,buf,2);
printf("iHeight = %d\n",iHeight);

//设备型号
char type[32] = {0};
int offsetlen = irDataOffset + 2 + 2 + 2 + 14 + 4 * 512 * 640 + 4 + 4 + 1 + 4 + 1 + 4 + 32;
fseek(fd, offsetlen, SEEK_SET);
fread(type, 32, 1, fd);
printf("type = %s\n", type);


//相对湿度
char crelativeHumidity = 0;
int ioffsetLen = 0;
ioffsetLen = irDataOffset + 2 + 2 + 2 + 14 + 4 * 512 * 640 + 4 + 4 + 1 + 4 ;
fseek(fd,ioffsetLen,SEEK_SET);
bzero(buf,sizeof(buf));
fread(buf,1,1,fd);
memcpy(&crelativeHumidity,buf,1);
printf("crelativeHumidity = %d\n",crelativeHumidity);

//反射温度
float fReflectiveTemperature = 0.0;
fseek(fd,ioffsetLen+1,SEEK_SET);
bzero(buf,sizeof(buf));
fread(buf,4,1,fd);
memcpy(&fReflectiveTemperature,buf,4);
printf("fReflectiveTemperature = %f\n",fReflectiveTemperature);



//从文件开始偏移,计算描述信息长度
int idescriptionLen = 0;
if (0 == fseek(fd, isumLenth, SEEK_SET))
{
memset(buf, 0, sizeof(buf));
ret = 0;
ret = fread(buf, 4, 1, fd);
memcpy(&idescriptionLen, buf, 4);
printf("ret = %d,idescriptionLen = %d\n", ret, idescriptionLen);
}

char cjsonBuf[1024 * 10] = {0};
fseek(fd, 4, SEEK_CUR);
// fseek(fd,isumLenth+4,SEEK_SET);
fread(cjsonBuf, idescriptionLen, 1, fd);
printf("cjsonBuf = %s\n", cjsonBuf);

return 0;
}

结果如下:

ret = 1
irDataOffset = 51198
isumLenth = 1362072
iwidth = 640
iHeight = 512
type = IPT640M-V3
crelativeHumidity = 50
fReflectiveTemperature = 23.000000
ret = 1,idescriptionLen = 3864
cjsonBuf = “analyser_param”: [
{
“alarm_avg”: 0,
“alarm_maxt”: 0,
“alarm_min”: 0,
“alarm_type”: 0,
“analyser_type”: 2,
“avg_temp”: 372,
“distance”: 5,
“emiss”: 95,
“emiss_type”: 0,
“humidity”: 50,
“mark_type”: 0,
“max_temp”: 374,
“min_temp”: 370,
“name”: “R1”,
“point”: [
{
“x”: 115,
“y”: 117
},
{
“x”: 215,
“y”: 201
}
],
“reflect_temp”: 230,
“show_type”: 0
},
{
“alarm_avg”: 0,
“alarm_maxt”: 0,
“alarm_min”: 0,
“alarm_type”: 0,
“analyser_type”: 2,
“avg_temp”: 374,
“distance”: 5,
“emiss”: 95,
“emiss_type”: 0,
“humidity”: 50,
“mark_type”: 0,
“max_temp”: 378,
“min_temp”: 371,
“name”: “R2”,
“point”: [
{
“x”: 436,
“y”: 111
},
{
“x”: 561,
“y”: 204
}
],
“reflect_temp”: 230,
“show_type”: 0
},
{
“alarm_avg”: 0,
“alarm_maxt”: 0,
“alarm_min”: 0,
“alarm_type”: 0,
“analyser_type”: 2,
“avg_temp”: 374,
“distance”: 5,
“emiss”: 95,
“emiss_type”: 0,
“humidity”: 50,
“mark_type”: 0,
“max_temp”: 377,
“min_temp”: 372,
“name”: “R3”,
“point”: [
{
“x”: 277,
“y”: 240
},
{
“x”: 433,
“y”: 384
}
],
“reflect_temp”: 230,
“show_type”: 0
},
{
“alarm_avg”: 0,
“alarm_maxt”: 0,
“alarm_min”: 0,
“alarm_type”: 0,
“analyser_type”: 2,
“avg_temp”: 375,
“distance”: 5,
“emiss”: 95,
“emiss_type”: 0,
“humidity”: 50,
“mark_type”: 0,
“max_temp”: 379,
“min_temp”: 372,
“name”: “R4”,
“point”: [
{
“x”: 82,
“y”: 282
},
{
“x”: 212,
“y”: 401
}
],
“reflect_temp”: 230,
“show_type”: 0
}
],
“iso_param”: {
“iso_color”: -16777216,
“iso_hightemperature”: 400,
“iso_lowtemperature”: 100,
“iso_othercolor”: -16777216,
“iso_type”: 0
},
“mapping_param”: {
“manual_mapping”: false,
“tmax_mapping”: 377,
“tmin_mapping”: 372
},
“mark_param”: {
“audio_data”: “”,
“file_note”: “”,
“important_level”: 0
},
“measure_param”: {
“atmospheric_transmittance”: 100,
“b2”: 0,
“distance”: 5,
“distance_a0”: -131542,
“distance_a1”: -16300,
“distance_a2”: 183961,
“distance_a3”: 9687465,
“distance_a4”: -42455,
“distance_a5”: 94263,
“emiss_type”: 0,
“first_shutter_temp”: 0,
“fusion_type”: 0,
“gears”: 0,
“k3”: 0,
“optical_transmittance”: 100,
“temp_max”: 1500,
“temp_min”: -200,
“window_temp”: 23
},
“palette_param”: {
“palette_index”: 2
}
}