修复连续采集时没有时间间隔导致通讯失败从而导致无有法正常连续采集的问题 修改如下
This commit is contained in:
@ -1,11 +1,30 @@
|
||||
#include "IS3Comon.h"
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <Communication_Protocol.h>
|
||||
#elif
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <time.h>
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 199309L
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
unsigned long long get_system_uptime_ms() {
|
||||
#ifdef _WIN32
|
||||
return GetTickCount64();
|
||||
#elif
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (unsigned long long)(ts.tv_sec) * 1000 + ts.tv_nsec / 1000000;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void delay(int ms){
|
||||
Sleep(ms);
|
||||
@ -18,12 +37,12 @@ u_char BufferFortempWrite[1000];
|
||||
// MySerialWrite=nullptr;
|
||||
SERIALWRITE MySerialWrite = nullptr;
|
||||
SERIALREAD MySerialRead = nullptr;
|
||||
bool isis3_init = false;
|
||||
bool isIS3Init = false;
|
||||
uint16_t crc16(const uint8_t *data, size_t len, uint16_t polynomial)
|
||||
{
|
||||
uint16_t i, j, tmp, CRC16;
|
||||
|
||||
CRC16 = 0xFFFF; // CRC寄存器初始值
|
||||
CRC16 = 0xFFFF; // CRC<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼֵ
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
CRC16 ^= data[i];
|
||||
@ -33,157 +52,209 @@ uint16_t crc16(const uint8_t *data, size_t len, uint16_t polynomial)
|
||||
CRC16 >>= 1;
|
||||
if (tmp == 1)
|
||||
{
|
||||
CRC16 ^= polynomial; // 异或多项式
|
||||
CRC16 ^= polynomial; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
||||
}
|
||||
}
|
||||
}
|
||||
return CRC16;
|
||||
}
|
||||
|
||||
size_t SendSettingCommand(u_char *Command, size_t CommandLenth, u_char *Value, size_t ValueLenth)
|
||||
size_t SendSettingCommand(u_char Command, size_t CommandLenth, u_char *Value, size_t ValueLenth)
|
||||
{
|
||||
memcpy(BufferFortempWrite, Command, CommandLenth);
|
||||
memcpy(BufferFortempWrite + CommandLenth, Value, ValueLenth);
|
||||
uint16_t crc = crc16(BufferFortempWrite, CommandLenth + ValueLenth);
|
||||
memcpy(BufferFortempWrite + CommandLenth + ValueLenth, &crc, 2);
|
||||
SerialWrite(BufferFortempWrite, CommandLenth + ValueLenth + 2);
|
||||
// Serial.write(BufferFortempWrite, CommandLenth+ValueLenth + 2);
|
||||
return GetSetBackFromSensor();
|
||||
|
||||
int lenthforwrite = IRIS_Protocol_Pack(Command, (uint16_t)ValueLenth, Value, (uint8_t *)BufferFortempWrite);
|
||||
SerialWrite(BufferFortempWrite, lenthforwrite);
|
||||
// for 5 <20><>
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
size_t retunnumber = GetInfoBackFromSensorinTime(Command,1000);
|
||||
if (retunnumber!=OVERTIME ) {
|
||||
return retunnumber;
|
||||
}
|
||||
if (i%2==0) {
|
||||
printf("send command again\n");
|
||||
SerialWrite(BufferFortempWrite, lenthforwrite);
|
||||
|
||||
}
|
||||
|
||||
// <20><>I<EFBFBD>γ<EFBFBD><CEB3><EFBFBD> <20><><EFBFBD>ݻظ<DDBB><D8B8>쳣 <20><><EFBFBD><EFBFBD>ȷʵ <20><>Ӣ<EFBFBD>Ĵ<EFBFBD>ӡ
|
||||
printf("warning try %d times: date not enough,try again!!\n",i);
|
||||
|
||||
|
||||
}
|
||||
|
||||
printf("ERROR date not enough,retunr !!\n");
|
||||
return OVERTIME;
|
||||
|
||||
|
||||
}
|
||||
|
||||
size_t SendGetData(int shutter)
|
||||
{
|
||||
int lenth = sizeof(GET_ALL_DN);
|
||||
uint16_t crc = crc16(GET_ALL_DN, lenth);
|
||||
memcpy(BufferFortempWrite, GET_ALL_DN, lenth);
|
||||
memcpy(BufferFortempWrite + lenth, &crc, 2);
|
||||
SerialWrite(BufferFortempWrite, lenth + 2);
|
||||
// Serial.write(BufferFortempWrite, lenth + 2);
|
||||
// Serial.println(shutter);
|
||||
uint8_t dataforsend=NONE_DATA;
|
||||
int lenthforwrite=IRIS_Protocol_Pack(GET_DATA_FROM_SENSOR, (uint16_t)01, &dataforsend, (uint8_t *)BufferFortempWrite );
|
||||
SerialWrite(BufferFortempWrite, lenthforwrite);
|
||||
for (int i=0;i<10;i++)
|
||||
{
|
||||
size_t retunnumber = GetInfoBackFromSensorinTime(GET_DATA_FROM_SENSOR,shutter+2000);
|
||||
if (retunnumber!=OVERTIME ) {
|
||||
return retunnumber;
|
||||
}
|
||||
if (i%2==0) {
|
||||
printf("send command again\n");
|
||||
SerialWrite(BufferFortempWrite, lenthforwrite);
|
||||
|
||||
}
|
||||
// <20><>I<EFBFBD>γ<EFBFBD><CEB3><EFBFBD> <20><><EFBFBD>ݻظ<DDBB><D8B8>쳣 <20><><EFBFBD><EFBFBD>ȷʵ <20><>Ӣ<EFBFBD>Ĵ<EFBFBD>ӡ
|
||||
printf("warning try %d times: date not enough,try again!!\n",i);
|
||||
}
|
||||
|
||||
// size_t retunnumber = GetInfoBackFromSensor(GET_DATA_FROM_SENSOR);
|
||||
|
||||
|
||||
delay(shutter);
|
||||
return GetInfoBackFromSensor(true);
|
||||
return OVERTIME;
|
||||
}
|
||||
|
||||
size_t SendGetSensorInfo(u_char *Command, size_t lenth)
|
||||
size_t SendGetSensorInfo(u_char Command, size_t lenth)
|
||||
{
|
||||
uint8_t dataforsend=NONE_DATA;
|
||||
|
||||
int lenthforwrite= IRIS_Protocol_Pack(Command,(uint16_t)01,&dataforsend,(uint8_t *)BufferFortempWrite);
|
||||
|
||||
|
||||
uint16_t crc = crc16(Command, lenth);
|
||||
memcpy(BufferFortempWrite, Command, lenth);
|
||||
memcpy(BufferFortempWrite + lenth, &crc, 2);
|
||||
// Serial.println((int)MySerialWrite);
|
||||
// Serial.write(BufferFortempWrite,lenth+2);
|
||||
//delay(200);
|
||||
SerialWrite(BufferFortempWrite, lenth + 2);
|
||||
SerialWrite(BufferFortempWrite, lenthforwrite);
|
||||
|
||||
size_t retunnumber = GetInfoBackFromSensor();
|
||||
size_t retunnumber = GetInfoBackFromSensor(Command);
|
||||
|
||||
return retunnumber;
|
||||
}
|
||||
|
||||
size_t GetSetBackFromSensor()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t GetInfoBackFromSensor(uint8_t Command) // big <20><>ָ<EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD>ֽڱ<D6BD>ʾ<EFBFBD><CABE><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> <20><>ʱֻ<CAB1><D6BB><EFBFBD>ֲɼ<D6B2><C9BC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
{
|
||||
delay(1);
|
||||
TotalIndexNow = 0;
|
||||
TotalIndexNow += (int)SerailRead(BufferForRead + TotalIndexNow, 1);
|
||||
BufferForRead[0] = 0x00;
|
||||
memset(BufferForRead, 0, 200);
|
||||
|
||||
while (TotalIndexNow < 8)
|
||||
{
|
||||
// Serial.println(TotalIndexNow);
|
||||
// Serial.write(BufferForRead,1);
|
||||
TotalIndexNow += (int)SerailRead(BufferForRead + TotalIndexNow, 1);
|
||||
|
||||
size_t retrunlenth=SerailRead(BufferForRead + TotalIndexNow, 2);
|
||||
|
||||
|
||||
TotalIndexNow += retrunlenth;
|
||||
// TotalIndexNow=IRIS_Cut_Befor_Header(BufferForRead,TotalIndexNow);
|
||||
while (TotalIndexNow<5) {
|
||||
size_t retrunlenth=SerailRead(BufferForRead + TotalIndexNow, 5-TotalIndexNow);
|
||||
TotalIndexNow += retrunlenth;
|
||||
// if (retrunlenth!=0) {
|
||||
// //<2F><><EFBFBD><EFBFBD>bufferforread
|
||||
// for (int i = 0; i < TotalIndexNow; i++) {
|
||||
// printf("%02x ", BufferForRead[i]);
|
||||
// }
|
||||
// printf("here3 %d\n",retrunlenth);
|
||||
// fflush(stdout);
|
||||
// }
|
||||
TotalIndexNow=IRIS_Cut_Befor_Header(BufferForRead,TotalIndexNow);
|
||||
|
||||
// if (retrunlenth!=10) {
|
||||
// delay(1000);
|
||||
// }
|
||||
}
|
||||
int lenth = BufferForRead[3] * 256 + BufferForRead[4];
|
||||
while (TotalIndexNow < lenth + 7)
|
||||
{
|
||||
int sizeread=SerailRead(BufferForRead + TotalIndexNow, 10);
|
||||
//printf("Data from sensor: %d\n",sizeread);
|
||||
TotalIndexNow +=sizeread;
|
||||
if (sizeread!=10) {
|
||||
//delay(10);
|
||||
}
|
||||
//delay(10);
|
||||
//delay(10);
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>bufferforread
|
||||
printf("Data from sensor: ");
|
||||
int maxoutput= TotalIndexNow>50 ? 50 : TotalIndexNow;
|
||||
for (int i = 0; i <maxoutput; i++) {
|
||||
printf("%02x ", BufferForRead[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
TotalIndexNow= IRIS_Protocol_Unpack(BufferForRead,TotalIndexNow,Command,BufferForRead);
|
||||
return TotalIndexNow;
|
||||
|
||||
}
|
||||
|
||||
bool panduanHeader()
|
||||
#include <chrono>
|
||||
|
||||
size_t GetInfoBackFromSensorinTime(uint8_t Command,uint32_t waittime) // big <20><>ָ<EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD>ֽڱ<D6BD>ʾ<EFBFBD><CABE><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> <20><>ʱֻ<CAB1><D6BB><EFBFBD>ֲɼ<D6B2><C9BC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
{
|
||||
if (TotalIndexNow < 2)
|
||||
{
|
||||
return false;
|
||||
/* code */
|
||||
}
|
||||
int temp = 0;
|
||||
while (BufferForRead[temp] != 0x01 &&
|
||||
!(BufferForRead[temp + 1] == 0x03 || BufferForRead[temp + 1] == 0x06 || BufferForRead[temp + 1] == 0x10))
|
||||
{
|
||||
if (temp >= TotalIndexNow - 2)
|
||||
{
|
||||
break;
|
||||
/* code */
|
||||
}
|
||||
temp++;
|
||||
delay(1);
|
||||
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
size_t begintime= get_system_uptime_ms();
|
||||
|
||||
/* code */
|
||||
TotalIndexNow = 0;
|
||||
BufferForRead[0] = 0x00;
|
||||
memset(BufferForRead, 0, 200);
|
||||
|
||||
|
||||
size_t retrunlenth=SerailRead(BufferForRead + TotalIndexNow, 2);
|
||||
|
||||
|
||||
TotalIndexNow += retrunlenth;
|
||||
// TotalIndexNow=IRIS_Cut_Befor_Header(BufferForRead,TotalIndexNow);
|
||||
while (TotalIndexNow<5) {
|
||||
size_t retrunlenth=SerailRead(BufferForRead + TotalIndexNow, 5-TotalIndexNow);
|
||||
TotalIndexNow += retrunlenth;
|
||||
// if (retrunlenth!=0) {
|
||||
// //<2F><><EFBFBD><EFBFBD>bufferforread
|
||||
// for (int i = 0; i < TotalIndexNow; i++) {
|
||||
// printf("%02x ", BufferForRead[i]);
|
||||
// }
|
||||
// printf("here3 %d\n",retrunlenth);
|
||||
// fflush(stdout);
|
||||
// }
|
||||
TotalIndexNow=IRIS_Cut_Befor_Header(BufferForRead,TotalIndexNow);
|
||||
if (get_system_uptime_ms()-begintime>waittime) return OVERTIME;
|
||||
// if (retrunlenth!=10) {
|
||||
// delay(1000);
|
||||
// }
|
||||
}
|
||||
memcpy(BufferForRead, BufferForRead + temp, TotalIndexNow - temp);
|
||||
TotalIndexNow = TotalIndexNow - temp;
|
||||
temp = 0;
|
||||
if (BufferForRead[temp] != 0x01 &&
|
||||
!(BufferForRead[temp + 1] == 0x03 || BufferForRead[temp + 1] == 0x06 || BufferForRead[temp + 1] == 0x10))
|
||||
int lenth = BufferForRead[3] * 256 + BufferForRead[4];
|
||||
while (TotalIndexNow < lenth + 7)
|
||||
{
|
||||
return false;
|
||||
int sizeread=SerailRead(BufferForRead + TotalIndexNow, 10);
|
||||
//printf("Data from sensor: %d\n",sizeread);
|
||||
TotalIndexNow +=sizeread;
|
||||
if (sizeread!=10) {
|
||||
//delay(10);
|
||||
}
|
||||
if (get_system_uptime_ms()-begintime>waittime) return OVERTIME;
|
||||
//delay(10);
|
||||
//delay(10);
|
||||
}
|
||||
return true;
|
||||
// <20><><EFBFBD><EFBFBD>bufferforread
|
||||
printf("Data from sensor: ");
|
||||
int maxoutput= TotalIndexNow>50 ? 50 : TotalIndexNow;
|
||||
for (int i = 0; i <maxoutput; i++) {
|
||||
printf("%02x ", BufferForRead[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
TotalIndexNow= IRIS_Protocol_Unpack(BufferForRead,TotalIndexNow,Command,BufferForRead);
|
||||
return TotalIndexNow;
|
||||
|
||||
}
|
||||
|
||||
size_t GetInfoBackFromSensor(bool isbig) // big 是指用几个字节表示数据长度 暂时只发现采集数据时用两个字节
|
||||
{
|
||||
|
||||
if (isbig)
|
||||
{
|
||||
// 长度用两个字节表示
|
||||
// Serial.println(shutter);
|
||||
// Serial.println("i am here12312312312312312");
|
||||
TotalIndexNow = 0;
|
||||
BufferForRead[0] = 0x00;
|
||||
TotalIndexNow +=(int) SerailRead(BufferForRead + TotalIndexNow, 2);
|
||||
|
||||
// while(BufferForRead)
|
||||
|
||||
while (!panduanHeader())
|
||||
{
|
||||
TotalIndexNow +=(int) SerailRead(BufferForRead + TotalIndexNow, 1);
|
||||
}
|
||||
while (TotalIndexNow < 4)
|
||||
{
|
||||
// Serial.write(BufferForRead,TotalIndexNow);
|
||||
//delay(20);
|
||||
// Serial.println("i am here12312312312312312");
|
||||
TotalIndexNow += (int)SerailRead(BufferForRead + TotalIndexNow, 1);
|
||||
}
|
||||
|
||||
int lenth = BufferForRead[2] * 256 + BufferForRead[3];
|
||||
while (TotalIndexNow < lenth + 4)
|
||||
{
|
||||
// delay(20);
|
||||
// Serial.write(BufferForRead,TotalIndexNow);
|
||||
// Serial.println(lenth);
|
||||
// Serial.println(TotalIndexNow);
|
||||
// Serial.println("i am here12312312312312312");
|
||||
TotalIndexNow +=(int) SerailRead(BufferForRead + TotalIndexNow, 1024);
|
||||
}
|
||||
return TotalIndexNow;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 长度用一个字节表示
|
||||
TotalIndexNow = 0;
|
||||
TotalIndexNow += (int)SerailRead(BufferForRead + TotalIndexNow, 1);
|
||||
|
||||
while (TotalIndexNow < 3)
|
||||
{
|
||||
TotalIndexNow += (int)SerailRead(BufferForRead + TotalIndexNow, 1);
|
||||
}
|
||||
int lenth = BufferForRead[2];
|
||||
while (TotalIndexNow < lenth + 5)
|
||||
{
|
||||
TotalIndexNow += (int)SerailRead(BufferForRead + TotalIndexNow, 1);
|
||||
}
|
||||
// Serial.write(BufferForRead,TotalIndexNow);
|
||||
return TotalIndexNow;
|
||||
}
|
||||
}
|
||||
|
||||
size_t SerialWrite(u_char *data, size_t lenth)
|
||||
{
|
||||
@ -211,7 +282,7 @@ void InitFunction(SERIALWRITE a, SERIALWRITE readfunc)
|
||||
MySerialRead = readfunc;
|
||||
//std::string temp = "01";
|
||||
//a((u_char *)temp.c_str(), 2);
|
||||
isis3_init = true;
|
||||
isIS3Init = true;
|
||||
}
|
||||
|
||||
u_char *GetDataBufferPTR()
|
||||
@ -220,7 +291,7 @@ u_char *GetDataBufferPTR()
|
||||
}
|
||||
bool isSensorInit()
|
||||
{
|
||||
return isis3_init;
|
||||
return isIS3Init;
|
||||
}
|
||||
|
||||
void CoverLittleAndBig(char *data, int lenth)
|
||||
@ -235,4 +306,15 @@ void CoverLittleAndBig(char *data, int lenth)
|
||||
/* code */
|
||||
}
|
||||
delete[] tempdata;
|
||||
}
|
||||
|
||||
void CoverLittleandBigbyNumber(void *data, int lenth)
|
||||
{
|
||||
char *tempdata = new char[lenth];
|
||||
memcpy(tempdata, data, lenth);
|
||||
for (size_t i = 0; i < lenth ; i++) {
|
||||
((char *)data)[i] = tempdata[lenth-1-i];
|
||||
}
|
||||
delete[] tempdata;
|
||||
|
||||
}
|
@ -1,23 +1,24 @@
|
||||
|
||||
/**
|
||||
* @brief is11相关底层函数
|
||||
* @brief is11<EFBFBD><EFBFBD><EFBFBD>صײ㺯<EFBFBD><EFBFBD>
|
||||
*
|
||||
*/
|
||||
#ifndef __IS3COMON_H__
|
||||
#define __IS3COMON_H__
|
||||
#ifndef __IS11COMON_H__
|
||||
#define __IS11COMON_H__
|
||||
|
||||
#ifndef IS3COMMON_H
|
||||
#define IS3COMMON_H
|
||||
#ifndef IS11COMMON_H
|
||||
#define IS11COMMON_H
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
#define COMMAND_GET 0x03
|
||||
#define COMMAND_SET 0x06
|
||||
#define COMMAND_MULTSET 0x10
|
||||
#define POLYNOMIAL 0xa001 //modbus crc
|
||||
#define OVERTIME 1000000000
|
||||
#include "comon.h"
|
||||
|
||||
|
||||
@ -28,7 +29,7 @@ const u_char GET_AVERAGE_NUMBER[]={0x01,0x03,0x00,0x07,0x00,0x01};
|
||||
const u_char GET_WAVELENTH_AT_BAND[]={0x01, 0x03, 0x00,0x10, 0x00,0x02};
|
||||
const u_char GET_VALUE_AT_BAND[]={0x01, 0x03, 0x00,0x30, 0x00,0x02};
|
||||
const u_char GET_SETTING_OF_LAMP[]={0x01, 0x03, 0x00,0x04, 0x00,0x01};
|
||||
const u_char GET_WAVELENTH_COEFF[]={0x01, 0x03, 0x00,0x20, 0x00,0x08};
|
||||
// const u_char GET_WAVELENTH_COEFF[]={0x01, 0x03, 0x00,0x20, 0x00,0x08};
|
||||
const u_char GET_ALL_DN[]={0x01, 0x03, 0x01,0x00, 0x10,0x00};
|
||||
const u_char GET_SERIAL_NUMBER[]={0x01, 0x03, 0x00,0x40, 0x00,0x00};
|
||||
const u_char GET_PRODUCT_NAME[]={0x01, 0x03, 0x00,0x50, 0x00,0x00};
|
||||
@ -41,96 +42,103 @@ const u_char SET_WORK_MODE[]={0x01,0x06, 0x00,0x01};
|
||||
const u_char SET_WAVELENTH_COEFF[]={0x01,0x10,0x00,0x20,0x00,0x08,0x16};
|
||||
|
||||
/**
|
||||
* @brief 判断传感器是否初始化完成
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
* @brief <EFBFBD>жϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool isSensorInit();
|
||||
/**
|
||||
* @brief 初始化传感器
|
||||
*
|
||||
* @param writefunc 写函数
|
||||
* @param readfunc 读函数
|
||||
* @brief <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @param writefunc д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param readfunc <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void InitFunction(SERIALWRITE writefunc,SERIALWRITE readfunc);
|
||||
|
||||
/**
|
||||
* @brief 获取 BufferForRead 的指针 用于读取返回的数据
|
||||
*
|
||||
* @brief <EFBFBD><EFBFBD>ȡ BufferForRead <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD> <20><><EFBFBD>ڶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
*/
|
||||
u_char * GetDataBufferPTR();
|
||||
|
||||
/**
|
||||
* @brief 发送获取设备信息的指令 适用于Get指令
|
||||
*
|
||||
* @param Command 指令 预定的数组
|
||||
* @param lenth 指令长度 可以用sizeof来求算
|
||||
* @return size_t 返回数据的长度 输出存放于 BufferForRead;
|
||||
* @brief <EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD>ȡ<EFBFBD>豸<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Getָ<74><D6B8>
|
||||
*
|
||||
* @param Command ָ<EFBFBD><EFBFBD> Ԥ<><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param lenth ָ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sizeof<6F><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @return size_t <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> BufferForRead;
|
||||
*/
|
||||
size_t SendGetSensorInfo(u_char * Command,size_t lenth);//此过程不适合获取数据
|
||||
size_t SendGetSensorInfo(u_char Command,size_t lenth);//<EFBFBD>˹<EFBFBD><EFBFBD>̲<EFBFBD><EFBFBD>ʺϻ<EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param shutter
|
||||
* @return size_t
|
||||
* @brief
|
||||
*
|
||||
* @param shutter
|
||||
* @return size_t
|
||||
*/
|
||||
size_t SendGetData(int shutter);
|
||||
/**
|
||||
* @brief 发送设置指令
|
||||
*
|
||||
* @param Command 指令内容
|
||||
* @param CommandLenth 指令长度
|
||||
* @param Value 设置值
|
||||
* @param ValueLenth 值长度 默认是两个字节
|
||||
* @return size_t 返回值长度
|
||||
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
||||
*
|
||||
* @param Command ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param CommandLenth ָ<EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param Value <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
* @param ValueLenth ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
* @return size_t <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
size_t SendSettingCommand(u_char * Command,size_t CommandLenth,u_char *Value,size_t ValueLenth=2);
|
||||
size_t SendSettingCommand(u_char Command,size_t CommandLenth,u_char *Value,size_t ValueLenth=2);
|
||||
|
||||
//big
|
||||
//big
|
||||
/**
|
||||
* @brief 用来获取信息的返回的数据
|
||||
*
|
||||
* @param isbig 是指用几个字节表示数据长度 暂时只发现采集数据时用两个字节
|
||||
* @return size_t 接收到的数据大小
|
||||
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ķ<EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @param isbig <EFBFBD><EFBFBD>ָ<EFBFBD>ü<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڱ<EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD> <20><>ʱֻ<CAB1><D6BB><EFBFBD>ֲɼ<D6B2><C9BC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
* @return size_t <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С
|
||||
*/
|
||||
size_t GetInfoBackFromSensor(bool isbig=false);
|
||||
size_t GetInfoBackFromSensor(uint8_t Command);
|
||||
/**
|
||||
* @brief 获取设置后返回数据
|
||||
*
|
||||
* @return size_t 返回数据长度;
|
||||
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @return size_t <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>;
|
||||
*/
|
||||
size_t GetSetBackFromSensor();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param data
|
||||
* @param lenth
|
||||
* @return size_t
|
||||
* @brief
|
||||
*
|
||||
* @param data
|
||||
* @param lenth
|
||||
* @return size_t
|
||||
*/
|
||||
|
||||
size_t SerialWrite(u_char* data,size_t lenth);
|
||||
size_t SerailRead(u_char* data,size_t lenth=0);
|
||||
/**
|
||||
* @brief 计算crc16
|
||||
*
|
||||
* @param data 数据
|
||||
* @param len 数据长度
|
||||
* @param polynomial crc16多项式 默认是A001H
|
||||
* @return uint16_t crc16的值
|
||||
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>crc16
|
||||
*
|
||||
* @param data <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param len <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param polynomial crc16<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ Ĭ<><C4AC><EFBFBD><EFBFBD>A001H
|
||||
* @return uint16_t crc16<EFBFBD><EFBFBD>ֵ
|
||||
*/
|
||||
uint16_t crc16(const uint8_t *data, size_t len, uint16_t polynomial=POLYNOMIAL) ;
|
||||
|
||||
bool panduanHeader();
|
||||
/**
|
||||
*
|
||||
* @param Command
|
||||
* @param waittime <20><><EFBFBD><EFBFBD>
|
||||
* @return
|
||||
*/
|
||||
size_t GetInfoBackFromSensorinTime(uint8_t Command,uint32_t waittime=5000);
|
||||
|
||||
|
||||
void CoverLittleAndBig(char *data,int lenth);
|
||||
void CoverLittleandBigbyNumber(void *data, int lenth);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif // __IS11COMON_H__
|
@ -25,12 +25,12 @@ int IS3SensorInit()
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Set_Serial_FUN(SERIALWRITE writefunc,SERIALWRITE readfunc)
|
||||
void IS3Set_Serial_FUN(SERIALWRITE writefunc,SERIALWRITE readfunc)
|
||||
{
|
||||
InitFunction(writefunc,readfunc);
|
||||
}
|
||||
|
||||
STRsensorinfo_C Get_SensorInfo() {
|
||||
STRsensorinfo_C IS3Get_SensorInfo() {
|
||||
STRSensorInfo sensorinfo= thissensorIS3->SensorInfo;
|
||||
STRsensorinfo_C sensorinfo_c;
|
||||
//把sensorname 拷贝到sensorinfo_c
|
||||
@ -55,6 +55,20 @@ int IS3OptSnenser(int percent) {
|
||||
int IS3GetData(uint16_t *outdata, int shuttertime) {
|
||||
thissensorIS3->GetOneDate(shuttertime);
|
||||
memcpy(outdata,thissensorIS3->DATABUFF, sizeof(int16_t)*thissensorIS3->SensorInfo.BandNum);
|
||||
float averageofdrift=(thissensorIS3->DATABUFF[thissensorIS3->SensorInfo.BandNum-1]+thissensorIS3->DATABUFF[thissensorIS3->SensorInfo.BandNum-0]+thissensorIS3->DATABUFF[thissensorIS3->SensorInfo.BandNum+1])/3;
|
||||
// for(int i=0;i<thissensorIS3->SensorInfo.BandNum;i++)
|
||||
// {
|
||||
// outdata[i]-=averageofdrift;
|
||||
// if (outdata[i]<0)
|
||||
// outdata[i]=0;
|
||||
// }
|
||||
return thissensorIS3->SensorInfo.BandNum;
|
||||
|
||||
}
|
||||
int IS3SetWeaveLenthCoeff(double *a,int lenth) {
|
||||
// printf("IS3SetWeaveLenthCoeff\n");
|
||||
// printf("lenth=%d\n",lenth);
|
||||
// printf("a[0]=%f\n",a[0]);
|
||||
thissensorIS3->SetWeaveLenthCoeff(a,lenth);
|
||||
return 1;
|
||||
}
|
@ -21,10 +21,11 @@ extern "C" {
|
||||
|
||||
|
||||
__declspec(dllexport) int IS3SensorInit();
|
||||
__declspec(dllexport) void Set_Serial_FUN(SERIALWRITE writefunc,SERIALWRITE readfunc);
|
||||
__declspec(dllexport) STRsensorinfo_C Get_SensorInfo();
|
||||
__declspec(dllexport) void IS3Set_Serial_FUN(SERIALWRITE writefunc,SERIALWRITE readfunc);
|
||||
__declspec(dllexport) STRsensorinfo_C IS3Get_SensorInfo();
|
||||
__declspec(dllexport) int IS3OptSnenser(int percent);
|
||||
__declspec(dllexport) int IS3GetData(uint16_t *outdata,int shuttertime);
|
||||
__declspec(dllexport) int IS3SetWeaveLenthCoeff(double *a,int lenth);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,5 +1,23 @@
|
||||
#include"SensorIS3.h"
|
||||
|
||||
#include <Communication_Protocol.h>
|
||||
|
||||
#include "iostream"
|
||||
#include "IRIS_Method.h"
|
||||
|
||||
static void split(const std::string& s, std::vector<std::string>& sv, char flag)
|
||||
{
|
||||
sv.clear();
|
||||
std::istringstream iss(s);
|
||||
std::string temp;
|
||||
|
||||
while (getline(iss, temp, flag)) {
|
||||
sv.push_back(temp);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool SensorIS3::initSensor(int id)
|
||||
{
|
||||
|
||||
@ -23,36 +41,50 @@ STRSensorInfo SensorIS3::GetSensorInfo()
|
||||
}
|
||||
|
||||
|
||||
int retlenth= SendGetSensorInfo((u_char *)GET_SERIAL_NUMBER,sizeof(GET_SERIAL_NUMBER));
|
||||
int retlenth= SendGetSensorInfo(GET_BASIC_INFO,sizeof(GET_BASIC_INFO));
|
||||
|
||||
char * result=new char[5];
|
||||
memcpy(result,DataRetrun+3,4);
|
||||
result[4]='\0';
|
||||
char * result=new char[100];
|
||||
memcpy(result,DataRetrun,retlenth);
|
||||
result[retlenth]='\0';
|
||||
std::cout<<result<<std::endl;
|
||||
std::string str11(result);
|
||||
setem.serialnumber=str11;
|
||||
std::vector<std::string> strvec;
|
||||
split(str11,strvec,'-');
|
||||
setem.SensorName=strvec[0];
|
||||
|
||||
if (strvec.size()>=2) {
|
||||
setem.serialnumber=strvec[1];
|
||||
}
|
||||
delete[] result;
|
||||
//Serial.println(setem.serialnumber);
|
||||
|
||||
retlenth= SendGetSensorInfo((u_char *)GET_PRODUCT_NAME,sizeof(GET_PRODUCT_NAME));
|
||||
result=new char[5];
|
||||
memcpy(result,DataRetrun+3,4);
|
||||
// delay(500);
|
||||
|
||||
result[4]='\0';
|
||||
std::string str1(result);
|
||||
setem.SensorName=str1;
|
||||
delete result;
|
||||
setem.BandNum=2048;
|
||||
retlenth= SendGetSensorInfo(GET_BANDNUMBER,sizeof(GET_BASIC_INFO));
|
||||
int bandnumber=0;
|
||||
memcpy(&bandnumber,DataRetrun,retlenth);
|
||||
CoverLittleandBigbyNumber(&bandnumber,4);
|
||||
setem.BandNum=bandnumber;
|
||||
|
||||
setem.maxValue=65535;
|
||||
|
||||
setem.wavelenthlist=new float[setem.BandNum]();
|
||||
retlenth= SendGetSensorInfo((u_char *)GET_WAVELENTH_COEFF,sizeof(GET_WAVELENTH_COEFF));
|
||||
float a[4];
|
||||
memcpy(a,DataRetrun+3,16);
|
||||
retlenth= SendGetSensorInfo(GET_WEAVE_COEFF,sizeof(GET_WEAVE_COEFF));
|
||||
double a[4];
|
||||
char tempaa[100];
|
||||
memcpy(tempaa,DataRetrun,100);
|
||||
int lenthtemp=sizeof(double);
|
||||
memcpy(a,DataRetrun,4*sizeof(double));
|
||||
|
||||
CoverLittleAndBig((char *)a,4*sizeof(float));
|
||||
CoverLittleandBigbyNumber(a,sizeof(double));
|
||||
CoverLittleandBigbyNumber(a+1,sizeof(double));
|
||||
CoverLittleandBigbyNumber(a+2,sizeof(double));
|
||||
CoverLittleandBigbyNumber(a+3,sizeof(double));
|
||||
// a[0]=0;
|
||||
// a[1]=0;
|
||||
// a[2]=1;
|
||||
// a[3]=350;
|
||||
|
||||
|
||||
|
||||
// CoverLittleAndBig((char *)a,4*sizeof(float));
|
||||
int bandsss= setem.BandNum;
|
||||
#ifdef ARDUINO
|
||||
|
||||
@ -81,7 +113,7 @@ STRSensorInfo SensorIS3::GetSensorInfo()
|
||||
// Serial.write(dataretrun,retlenth);
|
||||
// memcpy(a,dataretrun+)
|
||||
u_char temp[2]={0x00,0x01};
|
||||
retlenth=SendSettingCommand((u_char*)SET_AVERAGE_NUMBER,sizeof(SET_AVERAGE_NUMBER),temp,sizeof(temp));
|
||||
// retlenth=SendSettingCommand((u_char*)SET_AVERAGE_NUMBER,sizeof(SET_AVERAGE_NUMBER),temp,sizeof(temp));
|
||||
// Serial.println("init ok");
|
||||
|
||||
return setem;
|
||||
@ -116,21 +148,48 @@ void SensorIS3::SetShutter(int id)
|
||||
#endif
|
||||
}
|
||||
|
||||
void SensorIS3::SetWeaveLenthCoeff(double *a, int lenth) {
|
||||
u_char *datetosend=new u_char[lenth*sizeof(double)];
|
||||
printf("c++:a0:%f a1:%f a2:%f a3:%f\n",a[0],a[1],a[2],a[3]);
|
||||
CoverLittleandBigbyNumber(a,sizeof(double));
|
||||
CoverLittleandBigbyNumber(a+1,sizeof(double));
|
||||
CoverLittleandBigbyNumber(a+2,sizeof(double));
|
||||
CoverLittleandBigbyNumber(a+3,sizeof(double));
|
||||
|
||||
memcpy(datetosend,a,lenth*sizeof(double));
|
||||
SendSettingCommand(SET_WEAVE_COEFF,1,datetosend,lenth*sizeof(double));
|
||||
delete[] datetosend;
|
||||
// GetSensorInfo();
|
||||
}
|
||||
|
||||
void SensorIS3::GetOneDate(int msc)
|
||||
{
|
||||
|
||||
if (msc!=shutternow)
|
||||
{
|
||||
u_char shutter[2];
|
||||
shutter[0]=msc/256;
|
||||
shutter[1]=msc%256;
|
||||
SendSettingCommand((u_char *) SET_INTEGRAL_TIME,sizeof(SET_INTEGRAL_TIME),shutter,sizeof(shutter));
|
||||
|
||||
u_char shutter[4];
|
||||
memcpy(shutter,&msc,4);
|
||||
//交换下shutter 前后
|
||||
u_char shutterlitte[4];
|
||||
shutterlitte[0]=shutter[3];
|
||||
shutterlitte[1]=shutter[2];
|
||||
shutterlitte[2]=shutter[1];
|
||||
shutterlitte[3]=shutter[0];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int ret= SendSettingCommand(SET_INTEGRAL_TIME,1,shutterlitte,sizeof(shutterlitte));
|
||||
|
||||
|
||||
}
|
||||
shutternow=msc;
|
||||
size_t retsize= SendGetData(shutternow);
|
||||
memcpy(DATABUFF,DataRetrun+4,4096);
|
||||
shortLittletoBiG(DATABUFF, SensorInfo.BandNum*2);
|
||||
memcpy(DATABUFF,DataRetrun,515*2);
|
||||
//shortLittletoBiG(DATABUFF, SensorInfo.BandNum*2);
|
||||
|
||||
|
||||
|
||||
@ -139,10 +198,11 @@ void SensorIS3::GetOneDate(int msc)
|
||||
|
||||
int SensorIS3::OptSnenser(int persent)
|
||||
{
|
||||
long maxtime = 20000;
|
||||
|
||||
long maxtime = 10000;
|
||||
int maxvalue=SensorInfo.maxValue*1.0*persent / 100;
|
||||
int maxvaluenow = 0;
|
||||
float shutternow = 10;
|
||||
float shutternow = 20;
|
||||
GetOneDate(shutternow);
|
||||
maxvaluenow= Getmaxvalue(DATABUFF, SensorInfo.BandNum);
|
||||
|
||||
@ -152,6 +212,10 @@ int SensorIS3::OptSnenser(int persent)
|
||||
{
|
||||
shutternow = shutternow *0.7;
|
||||
}
|
||||
else if (maxvaluenow==0)
|
||||
{
|
||||
shutternow =shutternow*10;
|
||||
}
|
||||
else
|
||||
{
|
||||
shutternow = maxvalue * 0.98 / (maxvaluenow * 1.0)*shutternow + 1;
|
||||
@ -183,7 +247,7 @@ int SensorIS3::OptSnenser(int persent)
|
||||
|
||||
return maxtime;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef ARDUINO
|
||||
Serial.print("zi dong value:");
|
||||
Serial.println(shutternow);
|
||||
@ -193,7 +257,7 @@ int SensorIS3::OptSnenser(int persent)
|
||||
shutternow=maxtime;
|
||||
/* code */
|
||||
}
|
||||
|
||||
|
||||
return shutternow;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ public:
|
||||
bool initSensor(int id = 2);
|
||||
STRSensorInfo GetSensorInfo();
|
||||
void SetShutter(int id);// 0 dark 1 green 2 blue
|
||||
void SetWeaveLenthCoeff(double *a,int lenth);
|
||||
void GetOneDate(int msc);
|
||||
int OptSnenser(int percent);
|
||||
unsigned short DATABUFF[2048];
|
||||
|
@ -1,7 +1,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
typedef unsigned char u_char;
|
||||
/**
|
||||
* @brief 串口写函数类型
|
||||
|
@ -18,7 +18,7 @@ u_char BufferFortempWrite[1000];
|
||||
// MySerialWrite=nullptr;
|
||||
SERIALWRITE MySerialWrite = nullptr;
|
||||
SERIALREAD MySerialRead = nullptr;
|
||||
bool ISIS11Init = false;
|
||||
bool isIS3Init = false;
|
||||
uint16_t crc16(const uint8_t *data, size_t len, uint16_t polynomial)
|
||||
{
|
||||
uint16_t i, j, tmp, CRC16;
|
||||
@ -211,7 +211,7 @@ void InitFunction(SERIALWRITE a, SERIALWRITE readfunc)
|
||||
MySerialRead = readfunc;
|
||||
//std::string temp = "01";
|
||||
//a((u_char *)temp.c_str(), 2);
|
||||
ISIS11Init = true;
|
||||
isIS3Init = true;
|
||||
}
|
||||
|
||||
u_char *GetDataBufferPTR()
|
||||
@ -220,7 +220,7 @@ u_char *GetDataBufferPTR()
|
||||
}
|
||||
bool isSensorInit()
|
||||
{
|
||||
return ISIS11Init;
|
||||
return isIS3Init;
|
||||
}
|
||||
|
||||
void CoverLittleAndBig(char *data, int lenth)
|
||||
|
Reference in New Issue
Block a user