Attempt to remove incorrect submodule myis11/src/third (path not found by rm)

This commit is contained in:
xin
2025-02-19 16:39:23 +08:00
parent e8d98f155d
commit 4c6b3fc4d7
9 changed files with 807 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "myis11/src/third"]
path = myis11/src/third
url = http://172.16.0.230:3000/xin/IRIS_Communication_Protocol.git

View File

@ -0,0 +1,238 @@
#include "IS3Comon.h"
#ifdef _WIN32
#include <windows.h>
#elif
#include <unistd.h>
#endif
void delay(int ms){
Sleep(ms);
}
u_char BufferForRead[10000];
int TotalIndexNow = 0;
u_char BufferFortempWrite[1000];
// MySerialWrite=nullptr;
SERIALWRITE MySerialWrite = nullptr;
SERIALREAD MySerialRead = nullptr;
bool isis3_init = false;
uint16_t crc16(const uint8_t *data, size_t len, uint16_t polynomial)
{
uint16_t i, j, tmp, CRC16;
CRC16 = 0xFFFF; // CRC寄存器初始值
for (i = 0; i < len; i++)
{
CRC16 ^= data[i];
for (j = 0; j < 8; j++)
{
tmp = (uint16_t)(CRC16 & 0x0001);
CRC16 >>= 1;
if (tmp == 1)
{
CRC16 ^= polynomial; // 异或多项式
}
}
}
return CRC16;
}
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();
}
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);
delay(shutter);
return GetInfoBackFromSensor(true);
}
size_t SendGetSensorInfo(u_char *Command, size_t lenth)
{
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);
size_t retunnumber = GetInfoBackFromSensor();
return retunnumber;
}
size_t GetSetBackFromSensor()
{
TotalIndexNow = 0;
TotalIndexNow += (int)SerailRead(BufferForRead + TotalIndexNow, 1);
while (TotalIndexNow < 8)
{
// Serial.println(TotalIndexNow);
// Serial.write(BufferForRead,1);
TotalIndexNow += (int)SerailRead(BufferForRead + TotalIndexNow, 1);
}
return TotalIndexNow;
}
bool panduanHeader()
{
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++;
/* code */
}
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))
{
return false;
}
return true;
}
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)
{
if (MySerialWrite != nullptr)
{
// Serial.println("init ok");
return MySerialWrite(data, lenth);
}
return 0;
}
size_t SerailRead(u_char *data, size_t lenth)
{
if (MySerialRead != nullptr)
{
return MySerialRead(data, lenth);
}
return 0;
}
void InitFunction(SERIALWRITE a, SERIALWRITE readfunc)
{
MySerialWrite = a;
MySerialRead = readfunc;
//std::string temp = "01";
//a((u_char *)temp.c_str(), 2);
isis3_init = true;
}
u_char *GetDataBufferPTR()
{
return BufferForRead;
}
bool isSensorInit()
{
return isis3_init;
}
void CoverLittleAndBig(char *data, int lenth)
{
char *tempdata = new char[lenth];
memcpy(tempdata, data, lenth);
for (size_t i = 0; i < lenth / 2; i++)
{
data[2 * i] = tempdata[2 * i + 1];
data[2 * i + 1] = tempdata[2 * i];
/* code */
}
delete[] tempdata;
}

View File

@ -0,0 +1,136 @@
/**
* @brief is11相关底层函数
*
*/
#ifndef __IS3COMON_H__
#define __IS3COMON_H__
#ifndef IS3COMMON_H
#define IS3COMMON_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
#include "comon.h"
const u_char GET_ADDRESS[]={0x01,0x03,0x00,0x01,0x00,0x01};
const u_char GET_BANDRATE[]={0x01,0x03,0x00,0x02,0x00,0x01};
const u_char GET_INTEGRAL_TIME[]={0x01,0x03,0x00,0x06,0x00,0x01};
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_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};
const u_char SET_ADDRESS[]={0x01,0x06, 0x00,0x01};
const u_char SET_BandRATE[]={0x01,0x06, 0x00,0x02};
const u_char SET_INTEGRAL_TIME[]={0x01,0x06, 0x00,0x06};
const u_char SET_AVERAGE_NUMBER[]={0x01,0x06, 0x00,0x07};
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
*/
bool isSensorInit();
/**
* @brief 初始化传感器
*
* @param writefunc 写函数
* @param readfunc 读函数
*/
void InitFunction(SERIALWRITE writefunc,SERIALWRITE readfunc);
/**
* @brief 获取 BufferForRead 的指针 用于读取返回的数据
*
*/
u_char * GetDataBufferPTR();
/**
* @brief 发送获取设备信息的指令 适用于Get指令
*
* @param Command 指令 预定的数组
* @param lenth 指令长度 可以用sizeof来求算
* @return size_t 返回数据的长度 输出存放于 BufferForRead;
*/
size_t SendGetSensorInfo(u_char * Command,size_t lenth);//此过程不适合获取数据
/**
* @brief
*
* @param shutter
* @return size_t
*/
size_t SendGetData(int shutter);
/**
* @brief 发送设置指令
*
* @param Command 指令内容
* @param CommandLenth 指令长度
* @param Value 设置值
* @param ValueLenth 值长度 默认是两个字节
* @return size_t 返回值长度
*/
size_t SendSettingCommand(u_char * Command,size_t CommandLenth,u_char *Value,size_t ValueLenth=2);
//big
/**
* @brief 用来获取信息的返回的数据
*
* @param isbig 是指用几个字节表示数据长度 暂时只发现采集数据时用两个字节
* @return size_t 接收到的数据大小
*/
size_t GetInfoBackFromSensor(bool isbig=false);
/**
* @brief 获取设置后返回数据
*
* @return size_t 返回数据长度;
*/
size_t GetSetBackFromSensor();
/**
* @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的值
*/
uint16_t crc16(const uint8_t *data, size_t len, uint16_t polynomial=POLYNOMIAL) ;
bool panduanHeader();
void CoverLittleAndBig(char *data,int lenth);
#ifdef __cplusplus
}
#endif
#endif
#endif // __IS11COMON_H__

View File

@ -0,0 +1,60 @@
/**
******************************************************************************
* @file : IS11_INST.cpp
* @author : xin
* @brief : None
* @attention : None
* @date : 2024/8/14
******************************************************************************
*/
//
// Created by xin on 2024/8/14.
//
#include "SensorIS3.h"
#include "IS3_INST.h"
#include "iostream"
#include "cstring"
SensorIS3 *thissensorIS3;
int IS3SensorInit()
{
std::cout<< "IS3SensorInit" << std::endl;
thissensorIS3 = new SensorIS3();
thissensorIS3->initSensor(1);
return 1;
}
void Set_Serial_FUN(SERIALWRITE writefunc,SERIALWRITE readfunc)
{
InitFunction(writefunc,readfunc);
}
STRsensorinfo_C Get_SensorInfo() {
STRSensorInfo sensorinfo= thissensorIS3->SensorInfo;
STRsensorinfo_C sensorinfo_c;
//把sensorname 拷贝到sensorinfo_c
strcpy_s(sensorinfo_c.SensorName,sensorinfo.SensorName.c_str());
sensorinfo_c.BandNum = sensorinfo.BandNum;
sensorinfo_c.maxValue = sensorinfo.maxValue;
strcpy_s(sensorinfo_c.serialnumber,sensorinfo.serialnumber.c_str());
sensorinfo_c.a1 = sensorinfo.a1;
sensorinfo_c.a2 = sensorinfo.a2;
sensorinfo_c.a3 = sensorinfo.a3;
sensorinfo_c.a4 = sensorinfo.a4;
sensorinfo_c.issensorinit= sensorinfo.isSensorInit;
return sensorinfo_c;
}
int IS3OptSnenser(int percent) {
return thissensorIS3->OptSnenser(percent);
}
int IS3GetData(uint16_t *outdata, int shuttertime) {
thissensorIS3->GetOneDate(shuttertime);
memcpy(outdata,thissensorIS3->DATABUFF, sizeof(int16_t)*thissensorIS3->SensorInfo.BandNum);
return thissensorIS3->SensorInfo.BandNum;
}

View File

@ -0,0 +1,34 @@
/**
******************************************************************************
* @file : IS3_INST.h
* @author : xin
* @brief : None
* @attention : None
* @date : 2024/8/14
******************************************************************************
*/
//
// Created by xin on 2024/8/14.
//
#ifndef IS3LIB_IS3_INST_H
#define IS3LIB_IS3_INST_H
#include "comon.h"
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) int IS3SensorInit();
__declspec(dllexport) void Set_Serial_FUN(SERIALWRITE writefunc,SERIALWRITE readfunc);
__declspec(dllexport) STRsensorinfo_C Get_SensorInfo();
__declspec(dllexport) int IS3OptSnenser(int percent);
__declspec(dllexport) int IS3GetData(uint16_t *outdata,int shuttertime);
#ifdef __cplusplus
}
#endif
#endif //IS3LIB_IS3_INST_H

View File

@ -0,0 +1,292 @@
#include"SensorIS3.h"
#include "iostream"
bool SensorIS3::initSensor(int id)
{
DataRetrun=GetDataBufferPTR();
// IS1Sensor.SetPortName(id);
SensorInfo=GetSensorInfo();
// pinMode(22,OUTPUT);
// pinMode(23,OUTPUT);
return true;
}
STRSensorInfo SensorIS3::GetSensorInfo()
{
STRSensorInfo setem;
if (!isSensorInit())
{
return setem;
}
int retlenth= SendGetSensorInfo((u_char *)GET_SERIAL_NUMBER,sizeof(GET_SERIAL_NUMBER));
char * result=new char[5];
memcpy(result,DataRetrun+3,4);
result[4]='\0';
std::cout<<result<<std::endl;
std::string str11(result);
setem.serialnumber=str11;
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;
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);
CoverLittleAndBig((char *)a,4*sizeof(float));
int bandsss= setem.BandNum;
#ifdef ARDUINO
Serial.print("a0:");
Serial.print(a[0]);
Serial.print(" a1:");
Serial.print(a[1]);
Serial.print(" a2:");
Serial.print(a[2]);
Serial.print(" a3:");
Serial.println(a[3]);
#endif
std::cout<<"a0:"<<a[0]<<" a1:"<<a[1]<<" a2:"<<a[2]<<" a3:"<<a[3]<<std::endl;
setem.a1=a[0];
setem.a2=a[1];
setem.a3=a[2];
setem.a4=a[3];
for ( int i = 1; i <=bandsss ; i++)
{
setem.wavelenthlist[i-1] = a[0] * i*i*i + a[1] * i*i + a[2] * i + a[3];
setem.WavelenthStr=setem.WavelenthStr+std::to_string( setem.wavelenthlist[i-1])+",";
}
// delay(500);
// 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));
// Serial.println("init ok");
return setem;
}
void SensorIS3::SetShutter(int id)
{
#ifdef ARDUINO
switch (id) {
case 0:
{
digitalWrite(22,LOW);
digitalWrite(23,LOW);
delay(200);
break;
}
case 1:{
digitalWrite(23,HIGH);
digitalWrite(22,LOW);
delay(200);
break;
}
case 2:{
digitalWrite(22,HIGH);
digitalWrite(23,LOW);
delay(200);
break;
}
}
#endif
}
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));
}
shutternow=msc;
size_t retsize= SendGetData(shutternow);
memcpy(DATABUFF,DataRetrun+4,4096);
shortLittletoBiG(DATABUFF, SensorInfo.BandNum*2);
}
int SensorIS3::OptSnenser(int persent)
{
long maxtime = 20000;
int maxvalue=SensorInfo.maxValue*1.0*persent / 100;
int maxvaluenow = 0;
float shutternow = 10;
GetOneDate(shutternow);
maxvaluenow= Getmaxvalue(DATABUFF, SensorInfo.BandNum);
int numberoftry = 0;
while (maxvaluenow<maxvalue*0.95 || maxvaluenow>maxvalue) {
if (maxvaluenow > maxvalue)
{
shutternow = shutternow *0.7;
}
else
{
shutternow = maxvalue * 0.98 / (maxvaluenow * 1.0)*shutternow + 1;
}
if (shutternow > maxtime)
{
shutternow = maxtime;
break;
}
GetOneDate(shutternow);
maxvaluenow= Getmaxvalue(DATABUFF, SensorInfo.BandNum);
#ifdef ARDUINO
Serial.print("now Shutter is :");
Serial.print(shutternow);
Serial.print(" maxvalue is :");
Serial.println(maxvaluenow);
#else
std::cout<<"now Shutter is :"<<shutternow<<" maxvalue is :"<<maxvaluenow<<std::endl;
#endif
numberoftry++;
if (numberoftry > 200)
{
return maxtime;
}
if (shutternow == maxtime)
{
return maxtime;
}
}
#ifdef ARDUINO
Serial.print("zi dong value:");
Serial.println(shutternow);
#endif
if (shutternow<0)
{
shutternow=maxtime;
/* code */
}
return shutternow;
}
void SensorIS3::shortLittletoBiG(unsigned short *data,int lenth)
{
CoverLittleAndBig((char *)data,lenth);
}
int SensorIS3::Getmaxvalue(unsigned short *data,int lenth)
{
int ret=-1;
for (int i = 0; i < lenth; ++i) {
if (data[i]>ret){
ret=data[i];
}
}
return ret;
}
void SensorIS3::TakeOneJob()
{
SetShutter(1);
int shutter=OptSnenser(90);
shutterup=shutter;
GetOneDate(shutter);
// Serial.println("Finish Up ------Green2313123");
if (UpData==nullptr)
{
UpData=new unsigned short[SensorInfo.BandNum*2];
/* code */
}
memcpy(UpData,DATABUFF,SensorInfo.BandNum*2);
SetShutter(0);
GetOneDate(shutter);
for (int i = 0; i < SensorInfo.BandNum; ++i) {
// UpData[i]=UpData[i]-DATABUFF[i];
}
shutterup=shutter;
bool dingbing=false;
#ifdef DINBIAO
String strout="1 shutteruo is "+String(shutterup)+" Finish Up ------Green change the fiber";
PrintFunc(strout );
digitalWrite(21, LOW);
delay(60000);
SensorInfo.SensorName=SensorInfo.SensorName+"cali";
Serial.println("begindown");
digitalWrite(21, HIGH);
#endif
SetShutter(2);
shutter=OptSnenser(90);
shutterdown=shutter;
GetOneDate(shutter);
if (DownData==nullptr)
{
DownData=new unsigned short[SensorInfo.BandNum*2];
/* code */
}
memcpy(DownData,DATABUFF,SensorInfo.BandNum*2);
SetShutter(0);
GetOneDate(shutter);
for (int i = 0; i < SensorInfo.BandNum; ++i) {
// DownData[i]=DownData[i]-DATABUFF[i];
}
shutterdown=shutter;
#ifdef DINBIAO
String strout1="2 shutterdown is "+String(shutterdown)+" Down Finish ------Blue";
PrintFunc(strout1 );
#endif
}
SensorIS3::SensorIS3()
{
shutternow=0;
// DataRetrun=GetDataBufferPTR();
}

View File

@ -0,0 +1,43 @@
#ifndef SENSORIS3_H
#define SENSORIS3_H
#include "comon.h"
#include "IS3Comon.h"
class SensorIS3 {
public:
SensorIS3();
STRSensorInfo SensorInfo;
bool initSensor(int id = 2);
STRSensorInfo GetSensorInfo();
void SetShutter(int id);// 0 dark 1 green 2 blue
void GetOneDate(int msc);
int OptSnenser(int percent);
unsigned short DATABUFF[2048];
int shutterup,shutterdown;
unsigned short *DownData=nullptr;
unsigned short *UpData=nullptr;
void shortLittletoBiG( unsigned short *data,int lenth);
int Getmaxvalue(unsigned short *data,int lenth);
void TakeOneJob();
PRINTFUNC PrintFunc;
int shutternow;
//uint16_t result[2048];
u_char *DataRetrun;
};
#endif

1
myis11/src/third Submodule

Submodule myis11/src/third added at 74b80c24b8