init
This commit is contained in:
141
device/SerialPort/Barometer.cpp
Normal file
141
device/SerialPort/Barometer.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "Barometer.h"
|
||||
|
||||
|
||||
/* CRC 高位字节值表 */
|
||||
static unsigned char auchCRCHi[] = {
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
|
||||
0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
|
||||
0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
|
||||
0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
|
||||
0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
|
||||
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
|
||||
};
|
||||
/* CRC低位字节值表*/
|
||||
static unsigned char auchCRCLo[] = {
|
||||
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06,
|
||||
0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD,
|
||||
0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
|
||||
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A,
|
||||
0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4,
|
||||
0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
|
||||
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3,
|
||||
0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
|
||||
0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
|
||||
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29,
|
||||
0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED,
|
||||
0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
|
||||
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60,
|
||||
0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67,
|
||||
0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
|
||||
0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
|
||||
0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E,
|
||||
0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
|
||||
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71,
|
||||
0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92,
|
||||
0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
|
||||
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,
|
||||
0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,
|
||||
0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
|
||||
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,
|
||||
0x43, 0x83, 0x41, 0x81, 0x80, 0x40
|
||||
};
|
||||
|
||||
|
||||
Barometer* Barometer::uniqueInstance = nullptr;
|
||||
Barometer* Barometer::instance()
|
||||
{
|
||||
if (!uniqueInstance) {
|
||||
uniqueInstance = new Barometer();
|
||||
}
|
||||
return uniqueInstance;
|
||||
}
|
||||
Barometer::Barometer()
|
||||
{
|
||||
|
||||
}
|
||||
Barometer::~Barometer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
unsigned short Barometer::CRC16(unsigned char *puchMsg, unsigned short usDataLen)
|
||||
{
|
||||
unsigned char uchCRCHi = 0xFF; /* 高CRC字节初始化 */
|
||||
unsigned char uchCRCLo = 0xFF; /* 低CRC 字节初始化 */
|
||||
unsigned uIndex; /* CRC循环中的索引 */
|
||||
while (usDataLen--) /* 传输消息缓冲区 */
|
||||
{
|
||||
uIndex = uchCRCHi ^ *puchMsg++; /* 计算CRC */
|
||||
uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex];
|
||||
uchCRCLo = auchCRCLo[uIndex];
|
||||
}
|
||||
return static_cast<unsigned short>(uchCRCHi << 8 | uchCRCLo);
|
||||
}
|
||||
int Barometer::GetHeightValue(int deviceID,unsigned short addr,short *value)
|
||||
{
|
||||
unsigned char cmd[50];
|
||||
unsigned short crcresult;
|
||||
int ret;
|
||||
|
||||
cmd[0] = static_cast<unsigned char>(deviceID);
|
||||
cmd[1] = 4;
|
||||
cmd[2] = addr >> 8;
|
||||
cmd[3] = addr & 0xff;
|
||||
//cmd[2] = 00;
|
||||
//cmd[3] = 0x10;
|
||||
cmd[4] = 0;
|
||||
cmd[5] = 1;
|
||||
crcresult = CRC16(cmd, 6);
|
||||
cmd[6] = (crcresult >> 8) & 0xff;
|
||||
cmd[7] = crcresult & 0xff;
|
||||
|
||||
|
||||
ret = SendCmd(reinterpret_cast<char*>(cmd), 8, reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret == 0)
|
||||
{
|
||||
crcresult = CRC16(reinterpret_cast<unsigned char*>(revData), 3 + static_cast<unsigned char>(revData[2]));
|
||||
cmd[1] = crcresult & 0xff;
|
||||
cmd[0] = (crcresult >> 8) & 0xff;
|
||||
//if ((revData[4 + revData[2]] == cmd[1]) && (revData[3 + revData[2]] == cmd[0]))
|
||||
if ((static_cast<unsigned char>(revData[revDataLen-1]) == cmd[1]) && (static_cast<unsigned char>(revData[revDataLen-2]) == cmd[0]))
|
||||
{
|
||||
|
||||
//*value = (revData[3] << 24) + (revData[4] << 16) + (revData[5] << 8) + revData[6];
|
||||
// short value1;
|
||||
// *value = (revData[3] << 8) + revData[4];
|
||||
// value1 = (revData[3] << 8) + revData[4];
|
||||
// short value2;
|
||||
char buftmp[4];
|
||||
buftmp[0] = revData[4];
|
||||
buftmp[1] = revData[3];
|
||||
memcpy_s(value,2,&buftmp[0],2);
|
||||
//*value = (revData[3] << 8) + (revData[4]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
// int SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len);
|
||||
22
device/SerialPort/Barometer.h
Normal file
22
device/SerialPort/Barometer.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef BAROMETER_H
|
||||
#define BAROMETER_H
|
||||
#include "SerialPort.h"
|
||||
|
||||
|
||||
#define BAROMETER Barometer::instance()
|
||||
class Barometer:public Comm
|
||||
{
|
||||
private:
|
||||
char revData[4096];
|
||||
int revDataLen;
|
||||
|
||||
static Barometer* uniqueInstance;
|
||||
public:
|
||||
static Barometer* instance();
|
||||
Barometer();
|
||||
~Barometer();
|
||||
unsigned short CRC16(unsigned char *puchMsg, unsigned short usDataLen);
|
||||
int GetHeightValue(int deviceID,unsigned short addr,short *value);
|
||||
// int SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len);
|
||||
};
|
||||
#endif
|
||||
488
device/SerialPort/IPG_laser.cpp
Normal file
488
device/SerialPort/IPG_laser.cpp
Normal file
@@ -0,0 +1,488 @@
|
||||
#include "IPG_laser.h"
|
||||
#include "deviceinfo.h"
|
||||
#include "deviceproxy.h"
|
||||
|
||||
|
||||
IPGLaser* IPGLaser::uniqueInstance = nullptr;
|
||||
IPGLaser* IPGLaser::instance()
|
||||
{
|
||||
if (!uniqueInstance) {
|
||||
uniqueInstance = new IPGLaser();
|
||||
}
|
||||
return uniqueInstance;
|
||||
}
|
||||
IPGLaser::IPGLaser()
|
||||
{
|
||||
|
||||
}
|
||||
IPGLaser::~IPGLaser()
|
||||
{
|
||||
|
||||
}
|
||||
int IPGLaser::LaserClose()
|
||||
{
|
||||
/*****写入数据*****/
|
||||
/*激光器关闭*/
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
char WriteBuff1[20] = {0};
|
||||
WriteBuff1[0] = '$';
|
||||
WriteBuff1[1] = '3';
|
||||
WriteBuff1[2] = '1';
|
||||
WriteBuff1[3] = 0x0D;
|
||||
WriteBuff1[4] = 0;
|
||||
int ret = SendCmd(reinterpret_cast<char*>(WriteBuff1), strlen(WriteBuff1) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret != 0)
|
||||
{
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*激光器使能关闭*/
|
||||
char WriteBuff2[20] = {0};
|
||||
WriteBuff2[0] = '$';
|
||||
WriteBuff2[1] = '4';
|
||||
WriteBuff2[2] = '3';
|
||||
WriteBuff2[3] = 0x0D;
|
||||
WriteBuff2[4] = 0;
|
||||
ret = SendCmd(reinterpret_cast<char*>(WriteBuff2), strlen(WriteBuff2) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret != 0)
|
||||
{
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return -1;
|
||||
}
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
DEVICE_INFO->printDeviceSystemInfo(QString("激光器关闭"));
|
||||
return ret;
|
||||
}
|
||||
int IPGLaser::LaserOpen()
|
||||
{
|
||||
/*****写入数据*****/
|
||||
/*激光使能打开*/
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
char WriteBuff1[20] = {0};
|
||||
WriteBuff1[0] = '$';
|
||||
WriteBuff1[1] = '4';
|
||||
WriteBuff1[2] = '2';
|
||||
WriteBuff1[3] = 0x0D;
|
||||
WriteBuff1[4] = 0;
|
||||
int ret = SendCmd(reinterpret_cast<char*>(WriteBuff1), strlen(WriteBuff1) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret != 0)
|
||||
{
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return -1;
|
||||
}
|
||||
/*激光器出光*/
|
||||
char WriteBuff2[20] = {0};
|
||||
WriteBuff2[0] = '$';
|
||||
WriteBuff2[1] = '3';
|
||||
WriteBuff2[2] = '0';
|
||||
WriteBuff2[3] = 0x0D;
|
||||
WriteBuff2[4] = 0;
|
||||
ret = SendCmd(reinterpret_cast<char*>(WriteBuff2), strlen(WriteBuff2) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret != 0)
|
||||
{
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return -1;
|
||||
}
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
DEVICE_INFO->printDeviceSystemInfo(QString("激光器打开"));
|
||||
return ret;
|
||||
}
|
||||
int IPGLaser::SetSingleParam(QString strCmd,QString Strvalue)
|
||||
{
|
||||
char WriteBuff[50] = {0};
|
||||
if ((Strvalue.count() > 20) || (Strvalue.count() <= 0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if ((strCmd.count() > 20) || (strCmd.count() <= 1))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
Sleep(20);
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
WriteBuff[0] = '$';
|
||||
WriteBuff[1] = strCmd.at(0).toLatin1();
|
||||
WriteBuff[2] = strCmd.at(1).toLatin1();
|
||||
WriteBuff[3] = ';';
|
||||
|
||||
int i;
|
||||
for (i=0;i<Strvalue.count();i++)
|
||||
{
|
||||
//if (Strvalue.at(i).toLatin1() != '\r')
|
||||
WriteBuff[4 + i] = Strvalue.at(i).toLatin1();
|
||||
}
|
||||
WriteBuff[4 + i] = 0x0D;
|
||||
|
||||
int ret = SendCmd(reinterpret_cast<char*>(WriteBuff), strlen(WriteBuff) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret == 0)
|
||||
{
|
||||
// if (revData[0] != '#')
|
||||
// return -1;
|
||||
}
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return ret;
|
||||
}
|
||||
int IPGLaser::SwitchMode(bool flag)
|
||||
{
|
||||
char WriteBuff[50] = {0};
|
||||
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
if (flag)
|
||||
{
|
||||
WriteBuff[0] = '$';
|
||||
WriteBuff[1] = 32;
|
||||
WriteBuff[2] = 34;
|
||||
WriteBuff[3] = ';';
|
||||
WriteBuff[4] = 31;
|
||||
WriteBuff[5] = 31;
|
||||
WriteBuff[6] = 34;
|
||||
WriteBuff[7] = 30;
|
||||
WriteBuff[8] = 34;
|
||||
WriteBuff[9] = 33;
|
||||
WriteBuff[10] = 36;
|
||||
WriteBuff[11] = 38;
|
||||
WriteBuff[12] = 0x0D;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteBuff[0] = '$';
|
||||
WriteBuff[1] = 32;
|
||||
WriteBuff[2] = 34;
|
||||
WriteBuff[3] = ';';
|
||||
WriteBuff[4] = 31;
|
||||
WriteBuff[5] = 31;
|
||||
WriteBuff[6] = 34;
|
||||
WriteBuff[7] = 31;
|
||||
WriteBuff[8] = 32;
|
||||
WriteBuff[9] = 36;
|
||||
WriteBuff[10] = 38;
|
||||
WriteBuff[11] = 38;
|
||||
WriteBuff[12] = 0x0D;
|
||||
}
|
||||
|
||||
Sleep(20);
|
||||
|
||||
int ret = SendCmd(reinterpret_cast<char*>(WriteBuff), strlen(WriteBuff) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret == 0)
|
||||
{
|
||||
// if (revData[0] != '#')
|
||||
// return -1;
|
||||
}
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return ret;
|
||||
}
|
||||
int IPGLaser::SetParam(int index)
|
||||
{
|
||||
int ret =0;
|
||||
if (index == 1)
|
||||
{
|
||||
ret = IPGLASER->SetSingleParam("69",PulseDuration1);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("28",PulseRepetition1);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("32",Power1);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("64",Prepump1);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
else if (index == 2)
|
||||
{
|
||||
ret = IPGLASER->SetSingleParam("69",PulseDuration2);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("28",PulseRepetition2);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("32",Power2);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("64",Prepump2);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
else if (index == 3)
|
||||
{
|
||||
if (PulseDuration3 == "")
|
||||
return -1;
|
||||
ret = IPGLASER->SetSingleParam("69",PulseDuration3);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("28",PulseRepetition3);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("32",Power3);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("64",Prepump3);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
else if (index == 4)
|
||||
{
|
||||
if (PulseDuration4 == "")
|
||||
return -1;
|
||||
ret = IPGLASER->SetSingleParam("69",PulseDuration4);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("28",PulseRepetition4);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("32",Power4);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("64",Prepump4);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
else if (index == 5)
|
||||
{
|
||||
if (PulseDuration5 == "")
|
||||
return -1;
|
||||
ret = IPGLASER->SetSingleParam("69",PulseDuration5);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("28",PulseRepetition5);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("32",Power5);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("64",Prepump5);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
else if (index == 6)
|
||||
{
|
||||
if (PulseDuration6 == "")
|
||||
return -1;
|
||||
ret = IPGLASER->SetSingleParam("69",PulseDuration6);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("28",PulseRepetition6);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("32",Power6);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("64",Prepump6);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
else if (index == 7)
|
||||
{
|
||||
if (PulseDuration7 == "")
|
||||
return -1;
|
||||
ret = IPGLASER->SetSingleParam("69",PulseDuration7);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("28",PulseRepetition7);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("32",Power7);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("64",Prepump7);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
else //if (index == 8)
|
||||
{
|
||||
if (PulseDuration8 == "")
|
||||
return -1;
|
||||
ret = IPGLASER->SetSingleParam("69",PulseDuration8);//68
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("28",PulseRepetition8);//29
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("32",Power8);//33
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = IPGLASER->SetSingleParam("64",Prepump8);//65
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
int IPGLaser::GetLaserSts()
|
||||
{
|
||||
char WriteBuff[50] = {0};
|
||||
|
||||
memset(revData,0,4096);
|
||||
char tmpbuf[10] = {0};
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
WriteBuff[0] = '$';
|
||||
WriteBuff[1] = '4';
|
||||
WriteBuff[2] = 0x0D;
|
||||
|
||||
int ret = SendCmd(reinterpret_cast<char*>(WriteBuff), strlen(WriteBuff) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret == 0)
|
||||
{
|
||||
if (revDataLen < 3)
|
||||
return -1;
|
||||
memcpy_s(tmpbuf,10,&revData[2],revDataLen-3);
|
||||
int value = atoi(tmpbuf);
|
||||
return value;
|
||||
}
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return ret;
|
||||
}
|
||||
int IPGLaser::getIPGLaerPara(QString DevName)
|
||||
{
|
||||
QSettings *settings;//申明一个QSetting类函数
|
||||
settings = new QSettings ("SerialDevSet.ini", QSettings::IniFormat);//构建函数
|
||||
|
||||
QString strKey;
|
||||
strKey = "/"+DevName+"/com";
|
||||
com = settings->value(strKey).toString();
|
||||
if (com.length() > 4)
|
||||
{
|
||||
com = "\\\\.\\" + com ;
|
||||
}
|
||||
// strKey = "/"+DevName+"/baud";
|
||||
// nBaudRate = settings->value(strKey).toInt();
|
||||
// strKey = "/"+DevName+"/nParity";
|
||||
// nParity = settings->value(strKey).toInt();
|
||||
|
||||
// strKey = "/"+DevName+"/nByteSize";
|
||||
// nByteSize = settings->value(strKey).toInt();
|
||||
// strKey = "/"+DevName+"/nStopBits";
|
||||
// nStopBits = settings->value(strKey).toInt();
|
||||
// if (nStopBits == 1)
|
||||
// nStopBits = 0;
|
||||
nBaudRate = 57600;
|
||||
nParity = 0;
|
||||
nByteSize = 8;
|
||||
nStopBits = 0; //停止位1
|
||||
|
||||
//int ret = DEV->deCode_file(".\\Data\\laser_para1.txt");
|
||||
int ret = DEV->deCode_file(".\\Data\\data.txt");
|
||||
if (ret != 0)
|
||||
return -1;
|
||||
// Mode 1
|
||||
// AM 50
|
||||
// PP 10
|
||||
// PG 6500
|
||||
//QStringList list = DEV->deCodeString.split("\n"); // 按","为分隔符分割字符串,list的值为["apple", "banana", "pear"]
|
||||
Power1 = getValueFromList(DEV->deCodeString,"PP1");
|
||||
Power1_set= Power1;
|
||||
Prepump1 = getValueFromList(DEV->deCodeString,"PG1");
|
||||
PulseDuration1 = getValueFromList(DEV->deCodeString,"Mode1");
|
||||
int tmp;
|
||||
tmp = PulseDuration1.toInt() -1;
|
||||
PulseDuration1 = QString::number(tmp);
|
||||
PulseRepetition1 = getValueFromList(DEV->deCodeString,"AM1");
|
||||
QString str;
|
||||
str = getValueFromList(DEV->deCodeString,"PW1");
|
||||
dstPower1 = str.toDouble();
|
||||
PP_Enable = getValueFromList(DEV->deCodeString,"PP_Enable");
|
||||
|
||||
|
||||
// ret = DEV->deCode_file(".\\Data\\laser_para2.txt");
|
||||
// if (ret != 0)
|
||||
// return -1;
|
||||
Power2 = getValueFromList(DEV->deCodeString,"PP2");
|
||||
Power2_set= Power2;
|
||||
Prepump2 = getValueFromList(DEV->deCodeString,"PG2");
|
||||
PulseDuration2 = getValueFromList(DEV->deCodeString,"Mode2");
|
||||
PulseRepetition2 = getValueFromList(DEV->deCodeString,"AM2");
|
||||
tmp = PulseDuration2.toInt() -1;
|
||||
PulseDuration2 = QString::number(tmp);
|
||||
str = getValueFromList(DEV->deCodeString,"PW2");
|
||||
dstPower2 = str.toDouble();
|
||||
|
||||
|
||||
Power3 = getValueFromList(DEV->deCodeString,"PP3");
|
||||
Prepump3 = getValueFromList(DEV->deCodeString,"PG3");
|
||||
PulseDuration3 = getValueFromList(DEV->deCodeString,"Mode3");
|
||||
PulseRepetition3 = getValueFromList(DEV->deCodeString,"AM3");
|
||||
tmp = PulseDuration3.toInt() -1;
|
||||
PulseDuration3 = QString::number(tmp);
|
||||
str = getValueFromList(DEV->deCodeString,"PW3");
|
||||
dstPower3 = str.toDouble();
|
||||
|
||||
Power4 = getValueFromList(DEV->deCodeString,"PP4");
|
||||
Prepump4 = getValueFromList(DEV->deCodeString,"PG4");
|
||||
PulseDuration4 = getValueFromList(DEV->deCodeString,"Mode4");
|
||||
PulseRepetition4 = getValueFromList(DEV->deCodeString,"AM4");
|
||||
tmp = PulseDuration4.toInt() -1;
|
||||
PulseDuration4 = QString::number(tmp);
|
||||
str = getValueFromList(DEV->deCodeString,"PW4");
|
||||
dstPower4 = str.toDouble();
|
||||
|
||||
Power5 = getValueFromList(DEV->deCodeString,"PP5");
|
||||
Prepump5 = getValueFromList(DEV->deCodeString,"PG5");
|
||||
PulseDuration5 = getValueFromList(DEV->deCodeString,"Mode5");
|
||||
PulseRepetition5 = getValueFromList(DEV->deCodeString,"AM5");
|
||||
tmp = PulseDuration5.toInt() -1;
|
||||
PulseDuration5 = QString::number(tmp);
|
||||
str = getValueFromList(DEV->deCodeString,"PW5");
|
||||
dstPower5 = str.toDouble();
|
||||
|
||||
Power6 = getValueFromList(DEV->deCodeString,"PP6");
|
||||
Prepump6 = getValueFromList(DEV->deCodeString,"PG6");
|
||||
PulseDuration6 = getValueFromList(DEV->deCodeString,"Mode6");
|
||||
PulseRepetition6 = getValueFromList(DEV->deCodeString,"AM6");
|
||||
tmp = PulseDuration6.toInt() -1;
|
||||
PulseDuration6 = QString::number(tmp);
|
||||
str = getValueFromList(DEV->deCodeString,"PW6");
|
||||
dstPower6 = str.toDouble();
|
||||
|
||||
Power7 = getValueFromList(DEV->deCodeString,"PP7");
|
||||
Prepump7 = getValueFromList(DEV->deCodeString,"PG7");
|
||||
PulseDuration7 = getValueFromList(DEV->deCodeString,"Mode7");
|
||||
PulseRepetition7 = getValueFromList(DEV->deCodeString,"AM7");
|
||||
tmp = PulseDuration7.toInt() -1;
|
||||
PulseDuration7 = QString::number(tmp);
|
||||
str = getValueFromList(DEV->deCodeString,"PW7");
|
||||
dstPower7 = str.toDouble();
|
||||
|
||||
Power8 = getValueFromList(DEV->deCodeString,"PP8");
|
||||
Prepump8 = getValueFromList(DEV->deCodeString,"PG8");
|
||||
PulseDuration8 = getValueFromList(DEV->deCodeString,"Mode8");
|
||||
PulseRepetition8 = getValueFromList(DEV->deCodeString,"AM8");
|
||||
tmp = PulseDuration8.toInt() -1;
|
||||
PulseDuration8 = QString::number(tmp);
|
||||
str = getValueFromList(DEV->deCodeString,"PW8");
|
||||
dstPower8 = str.toDouble();
|
||||
|
||||
// strKey = "/"+DevName+"/Power1";
|
||||
// Power1 = settings->value(strKey).toString();
|
||||
// strKey = "/"+DevName+"/Prepump1";
|
||||
// Prepump1 = settings->value(strKey).toString();
|
||||
// strKey = "/"+DevName+"/PulseDuration1";
|
||||
// PulseDuration1 = settings->value(strKey).toString();
|
||||
// strKey = "/"+DevName+"/PulseRepetition1";
|
||||
// PulseRepetition1 = settings->value(strKey).toString();
|
||||
|
||||
// strKey = "/"+DevName+"/Power2";
|
||||
// Power2 = settings->value(strKey).toString();
|
||||
// strKey = "/"+DevName+"/Prepump2";
|
||||
// Prepump2 = settings->value(strKey).toString();
|
||||
// strKey = "/"+DevName+"/PulseDuration2";
|
||||
// PulseDuration2 = settings->value(strKey).toString();
|
||||
// strKey = "/"+DevName+"/PulseRepetition2";
|
||||
// PulseRepetition2 = settings->value(strKey).toString();
|
||||
|
||||
return 0;
|
||||
}
|
||||
QString IPGLaser::getValueFromList(QString strDecode,QString strName)
|
||||
{
|
||||
QStringList list = strDecode.split("\n"); // 按","为分隔符分割字符串,list的值为["apple", "banana", "pear"]
|
||||
for (int i=0;i<list.count();i++)
|
||||
{
|
||||
if (list[i].indexOf(strName) >=0)
|
||||
{
|
||||
QStringList list_son = list[i].split("=");
|
||||
return list_son[1];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
79
device/SerialPort/IPG_laser.h
Normal file
79
device/SerialPort/IPG_laser.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef IPGLASER_H
|
||||
#define IPGLASER_H
|
||||
#include "SerialPort.h"
|
||||
|
||||
|
||||
#define IPGLASER IPGLaser::instance()
|
||||
class IPGLaser:public Comm
|
||||
{
|
||||
private:
|
||||
char revData[4096];
|
||||
int revDataLen;
|
||||
|
||||
|
||||
|
||||
|
||||
static IPGLaser* uniqueInstance;
|
||||
public:
|
||||
QString PP_Enable;
|
||||
QString Power1;
|
||||
QString Prepump1;
|
||||
QString PulseDuration1;
|
||||
QString PulseRepetition1;
|
||||
double dstPower1;
|
||||
QString Power1_set;
|
||||
|
||||
QString Power2;
|
||||
QString Prepump2;
|
||||
QString PulseDuration2;
|
||||
QString PulseRepetition2;
|
||||
double dstPower2;
|
||||
QString Power2_set;
|
||||
|
||||
|
||||
QString Power3;
|
||||
QString Prepump3;
|
||||
QString PulseDuration3;
|
||||
QString PulseRepetition3;
|
||||
double dstPower3;
|
||||
QString Power4;
|
||||
QString Prepump4;
|
||||
QString PulseDuration4;
|
||||
QString PulseRepetition4;
|
||||
double dstPower4;
|
||||
QString Power5;
|
||||
QString Prepump5;
|
||||
QString PulseDuration5;
|
||||
QString PulseRepetition5;
|
||||
double dstPower5;
|
||||
QString Power6;
|
||||
QString Prepump6;
|
||||
QString PulseDuration6;
|
||||
QString PulseRepetition6;
|
||||
double dstPower6;
|
||||
QString Power7;
|
||||
QString Prepump7;
|
||||
QString PulseDuration7;
|
||||
QString PulseRepetition7;
|
||||
double dstPower7;
|
||||
QString Power8;
|
||||
QString Prepump8;
|
||||
QString PulseDuration8;
|
||||
QString PulseRepetition8;
|
||||
double dstPower8;
|
||||
|
||||
|
||||
static IPGLaser* instance();
|
||||
IPGLaser();
|
||||
~IPGLaser();
|
||||
int SetSingleParam(QString strCmd,QString Strvalue);
|
||||
int SetParam(int index);
|
||||
int GetLaserSts();
|
||||
int LaserOpen();
|
||||
int LaserClose();
|
||||
int SwitchMode(bool flag);
|
||||
int getIPGLaerPara(QString DevName);
|
||||
QString getValueFromList(QString strDecode,QString strName);
|
||||
// int SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len);
|
||||
};
|
||||
#endif
|
||||
62
device/SerialPort/PanasonicHeightFind.cpp
Normal file
62
device/SerialPort/PanasonicHeightFind.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "PanasonicHeightFind.h"
|
||||
|
||||
|
||||
PanasonicHeightFind* PanasonicHeightFind::uniqueInstance = nullptr;
|
||||
PanasonicHeightFind* PanasonicHeightFind::instance()
|
||||
{
|
||||
if (!uniqueInstance) {
|
||||
uniqueInstance = new PanasonicHeightFind();
|
||||
}
|
||||
return uniqueInstance;
|
||||
}
|
||||
PanasonicHeightFind::PanasonicHeightFind()
|
||||
{
|
||||
|
||||
}
|
||||
PanasonicHeightFind::~PanasonicHeightFind()
|
||||
{
|
||||
|
||||
}
|
||||
int PanasonicHeightFind::SetLaser(int deviceID,int value)
|
||||
{
|
||||
int ret;
|
||||
int CR = 0xd;
|
||||
char cmd[50];//%03#WLR+00000**D %03$WLR**D %03!XX**D
|
||||
sprintf_s(cmd,50,"%%%02dWLR+%05d**%X",deviceID,value,CR);
|
||||
ret = SendCmd(cmd, static_cast<unsigned short>(strlen(cmd)) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret== 0)
|
||||
{
|
||||
if (revData[3] == '$')
|
||||
ret = 0;
|
||||
else
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
int PanasonicHeightFind::GetHeightValue(int deviceID,double *value)
|
||||
{
|
||||
//% 0 3 # R M D * * CR % 0 3 $ R M D - 0 1 2 3 4 5 6 * * CR
|
||||
int ret;
|
||||
int CR = 0xd;
|
||||
char cmd[50];
|
||||
sprintf_s(cmd,50,"%%%02dRMD**%X",deviceID,CR);
|
||||
ret = SendCmd(cmd, static_cast<unsigned short>(strlen(cmd)) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret== 0)
|
||||
{
|
||||
if (revData[3] == '$')
|
||||
{
|
||||
memset(cmd,0,50);
|
||||
|
||||
memcpy_s(cmd,50,&revData[7],8);
|
||||
*value = atof(cmd);
|
||||
*value = *value / 10000;
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
// int SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len);
|
||||
22
device/SerialPort/PanasonicHeightFind.h
Normal file
22
device/SerialPort/PanasonicHeightFind.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef PANASONICHEIGHTFIND_H
|
||||
#define PANASONICHEIGHTFIND_H
|
||||
#include "SerialPort.h"
|
||||
|
||||
|
||||
#define PANHEIGHTFIND PanasonicHeightFind::instance()
|
||||
class PanasonicHeightFind:public Comm
|
||||
{
|
||||
private:
|
||||
char revData[4096];
|
||||
int revDataLen;
|
||||
|
||||
static PanasonicHeightFind* uniqueInstance;
|
||||
public:
|
||||
static PanasonicHeightFind* instance();
|
||||
PanasonicHeightFind();
|
||||
~PanasonicHeightFind();
|
||||
int SetLaser(int deviceID,int value);
|
||||
int GetHeightValue(int deviceID,double *value);
|
||||
// int SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len);
|
||||
};
|
||||
#endif
|
||||
73
device/SerialPort/PowerAttenuator.cpp
Normal file
73
device/SerialPort/PowerAttenuator.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "PowerAttenuator.h"
|
||||
|
||||
|
||||
|
||||
PowerAttenuator* PowerAttenuator::uniqueInstance = nullptr;
|
||||
PowerAttenuator* PowerAttenuator::instance()
|
||||
{
|
||||
if (!uniqueInstance) {
|
||||
uniqueInstance = new PowerAttenuator();
|
||||
}
|
||||
return uniqueInstance;
|
||||
}
|
||||
PowerAttenuator::PowerAttenuator()
|
||||
{
|
||||
|
||||
}
|
||||
PowerAttenuator::~PowerAttenuator()
|
||||
{
|
||||
|
||||
}
|
||||
int PowerAttenuator::GetSts(int * value)
|
||||
{
|
||||
int ret;
|
||||
char cmd[50] = "o\r";
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
memset(revData,0,4096);
|
||||
ret = SendCmd(cmd, 2,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
//revData[revDataLen - 2] = 0;
|
||||
if (revData[1] == '0')
|
||||
*value = 0;
|
||||
else
|
||||
*value = 1;
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return ret;
|
||||
}
|
||||
int PowerAttenuator::GetPos(int * value)
|
||||
{
|
||||
int ret;
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
|
||||
char cmd[50] = "o\r";
|
||||
memset(revData,0,4096);
|
||||
ret = SendCmd(cmd, 2,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
revData[revDataLen - 2] = 0;
|
||||
//if (revData[1] == '0')
|
||||
*value = atoi(&revData[3]);
|
||||
//else
|
||||
// *value = 1;
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return ret;
|
||||
}
|
||||
int PowerAttenuator::setPos(int value)
|
||||
{
|
||||
int ret;
|
||||
char cmd[50];
|
||||
|
||||
sprintf_s(cmd, "g %d\r", value);
|
||||
ret = SendCmd(cmd, static_cast<unsigned short>(strlen(cmd)) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
return ret;
|
||||
}
|
||||
int PowerAttenuator::setRPos(int value)
|
||||
{
|
||||
int ret;
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
|
||||
char cmd[50];
|
||||
|
||||
sprintf_s(cmd, "m %d\r", value);
|
||||
ret = SendCmd(cmd, static_cast<unsigned short>(strlen(cmd)) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return ret;
|
||||
}
|
||||
// int SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len);
|
||||
23
device/SerialPort/PowerAttenuator.h
Normal file
23
device/SerialPort/PowerAttenuator.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef POWERATTENUATOR_H
|
||||
#define POWERATTENUATOR_H
|
||||
#include "SerialPort.h"
|
||||
|
||||
|
||||
#define POWERMATT PowerAttenuator::instance()
|
||||
class PowerAttenuator:public Comm
|
||||
{
|
||||
private:
|
||||
char revData[4096];
|
||||
int revDataLen;
|
||||
static PowerAttenuator* uniqueInstance;
|
||||
public:
|
||||
static PowerAttenuator* instance();
|
||||
PowerAttenuator();
|
||||
~PowerAttenuator();
|
||||
int GetSts(int * value);
|
||||
int GetPos(int * value);
|
||||
int setPos(int value);
|
||||
int setRPos(int value);
|
||||
// int SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len);
|
||||
};
|
||||
#endif
|
||||
105
device/SerialPort/PowerMeter.cpp
Normal file
105
device/SerialPort/PowerMeter.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include "PowerMeter.h"
|
||||
|
||||
|
||||
PowerMeter* PowerMeter::uniqueInstanceMach = nullptr;
|
||||
PowerMeter* PowerMeter::uniqueInstanceLight = nullptr;
|
||||
|
||||
PowerMeter* PowerMeter::MachInstance()
|
||||
{
|
||||
if (!uniqueInstanceMach) {
|
||||
uniqueInstanceMach = new PowerMeter();
|
||||
}
|
||||
return uniqueInstanceMach;
|
||||
}
|
||||
PowerMeter* PowerMeter::LightInstance()
|
||||
{
|
||||
if (!uniqueInstanceLight) {
|
||||
uniqueInstanceLight = new PowerMeter();
|
||||
}
|
||||
return uniqueInstanceLight;
|
||||
}
|
||||
|
||||
PowerMeter::PowerMeter()
|
||||
{
|
||||
|
||||
}
|
||||
PowerMeter::~PowerMeter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//int PowerMeter::GetValue(char *data, unsigned short data_len,float * Value)
|
||||
int PowerMeter::GetValue(float * Value)
|
||||
{
|
||||
int ret;
|
||||
char cmd[50];
|
||||
char revBuf[50] = {0};
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
|
||||
|
||||
memset(revData,0,4096);
|
||||
sprintf_s(cmd, "$POW\r\n");
|
||||
ret = SendCmd(reinterpret_cast<char*>(cmd), strlen(cmd) ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret == 0)
|
||||
{
|
||||
//revData[strlen(revData) - 2] = 0;
|
||||
memcpy_s(revBuf,50,revData,strlen(revData));
|
||||
for (int i=0;i<(int)strlen(revData);i++)
|
||||
{
|
||||
if ((revData[i] == '\r') || (revData[i] == '\n'))
|
||||
revBuf[i] = 0;
|
||||
}
|
||||
*Value = convert(revBuf);
|
||||
}
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return ret;
|
||||
}
|
||||
float PowerMeter::convert(char *num)
|
||||
{
|
||||
//printf("开始转换%s\n", num);
|
||||
float num1 = 0.0, num2 = 0.0;
|
||||
int sign = 1;
|
||||
int exp = 1, cishu = 0;
|
||||
//表示e后面是正号还是负号,正号为1,负号为-1
|
||||
//cishu表示是几次饭
|
||||
char *p = num;
|
||||
if (*p == '-') {
|
||||
sign = -1;
|
||||
p++;
|
||||
//如果小数是复数
|
||||
}
|
||||
while (isdigit(*p)) {
|
||||
num1 = num1 * 10 + *p - '0';
|
||||
p++;
|
||||
//小数点前面的部分
|
||||
}
|
||||
//printf("num1:%f\n", num1);
|
||||
float i = 0.1;
|
||||
p++;
|
||||
while (isdigit(*p)) {
|
||||
num2 += i * (*p - '0');
|
||||
i *= 0.1;
|
||||
p++;
|
||||
}
|
||||
//小数点后面的部分
|
||||
//printf("num2:%f\n", num2);
|
||||
if (*p == 'e' || *p == 'E')
|
||||
p++;
|
||||
if (*p == '-') {
|
||||
exp = -1;
|
||||
p++;
|
||||
}
|
||||
else if (*p == '+')p++;
|
||||
|
||||
while (*p != '\0') {
|
||||
cishu = cishu * 10 + *p - '0';
|
||||
p++;
|
||||
}
|
||||
//printf("cishu:%d\n", cishu);
|
||||
float result = sign * (num1 + num2);
|
||||
if (exp == -1) i = 0.1;
|
||||
else i = 10;
|
||||
for (int j = 0; j < cishu; j++) result *= i;
|
||||
return result;
|
||||
|
||||
}
|
||||
24
device/SerialPort/PowerMeter.h
Normal file
24
device/SerialPort/PowerMeter.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef POWERMETER_H
|
||||
#define POWERMETER_H
|
||||
#include "SerialPort.h"
|
||||
|
||||
|
||||
#define POWERMETERMACH PowerMeter::MachInstance()
|
||||
#define POWERMETERLIGHT PowerMeter::LightInstance()
|
||||
class PowerMeter:public Comm
|
||||
{
|
||||
private:
|
||||
char revData[4096];
|
||||
int revDataLen;
|
||||
static PowerMeter* uniqueInstanceMach;
|
||||
static PowerMeter* uniqueInstanceLight;
|
||||
public:
|
||||
static PowerMeter* MachInstance();
|
||||
static PowerMeter* LightInstance();
|
||||
PowerMeter();
|
||||
~PowerMeter();
|
||||
int GetValue(float * Value);
|
||||
float convert(char *num);
|
||||
// int SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len);
|
||||
};
|
||||
#endif
|
||||
189
device/SerialPort/SerialPort.cpp
Normal file
189
device/SerialPort/SerialPort.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#include "SerialPort.h"
|
||||
#include <assert.h>
|
||||
|
||||
#define RETURN_ACK 0xac
|
||||
Comm::Comm()
|
||||
{
|
||||
m_hComm = nullptr;
|
||||
InitializeCriticalSection(&mCsRead);
|
||||
}
|
||||
|
||||
Comm::~Comm()
|
||||
{
|
||||
if (m_hComm != nullptr)
|
||||
{
|
||||
CloseComm();
|
||||
}
|
||||
|
||||
m_hComm = nullptr;
|
||||
|
||||
}
|
||||
int Comm::getSerialSet(QString DevName)
|
||||
{
|
||||
QSettings *settings;//申明一个QSetting类函数
|
||||
settings = new QSettings ("SerialDevSet.ini", QSettings::IniFormat);//构建函数
|
||||
|
||||
QString strKey;
|
||||
strKey = "/"+DevName+"/com";
|
||||
com = settings->value(strKey).toString();
|
||||
if (com.length() > 4)
|
||||
{
|
||||
com = "\\\\.\\" + com ;
|
||||
}
|
||||
strKey = "/"+DevName+"/baud";
|
||||
nBaudRate = settings->value(strKey).toInt();
|
||||
strKey = "/"+DevName+"/nParity";
|
||||
nParity = settings->value(strKey).toInt();
|
||||
|
||||
strKey = "/"+DevName+"/nByteSize";
|
||||
nByteSize = settings->value(strKey).toInt();
|
||||
strKey = "/"+DevName+"/nStopBits";
|
||||
nStopBits = settings->value(strKey).toInt();
|
||||
if (nStopBits == 1)
|
||||
nStopBits = 0;
|
||||
strKey = "/"+DevName+"/pidP";
|
||||
pidP = settings->value(strKey).toFloat();
|
||||
strKey = "/"+DevName+"/dstPower";
|
||||
dstPower = settings->value(strKey).toFloat();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
nParity: 0-4=None,Odd,Even,Mark,Space 校验位
|
||||
nByteSize: Number of bits/byte, 4-8 数据位
|
||||
nStopBits: 0,1,2 = 1, 1.5, 2 停止位
|
||||
|
||||
*/
|
||||
bool Comm::OpenComm()
|
||||
{
|
||||
if (m_hComm != nullptr)
|
||||
return true;
|
||||
DCB dcb; // 串口控制块
|
||||
COMMTIMEOUTS timeouts = { // 串口超时控制参数
|
||||
100, // 读字符间隔超时时间: 100 ms
|
||||
10, // 读操作时每字符的时间: 1 ms (n个字符总共为n ms)
|
||||
500, // 基本的(额外的)读超时时间: 500 ms
|
||||
10, // 写操作时每字符的时间: 1 ms (n个字符总共为n ms)
|
||||
100 }; // 基本的(额外的)写超时时间: 100 ms
|
||||
m_hComm = CreateFile(reinterpret_cast<const wchar_t *>(com.utf16()), // 串口名称或设备路径
|
||||
GENERIC_READ | GENERIC_WRITE, // 读写方式
|
||||
0, // 共享方式:独占
|
||||
nullptr, // 默认的安全描述符
|
||||
OPEN_EXISTING, // 创建方式
|
||||
0, // 不需设置文件属性
|
||||
nullptr); // 不需参照模板文件
|
||||
|
||||
if (m_hComm == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
//printf("open error\n");
|
||||
m_hComm = nullptr;
|
||||
return FALSE; // 打开串口失败 这里要发送失败消息
|
||||
}
|
||||
if (!SetCommTimeouts(m_hComm, &timeouts)) // 设置超时
|
||||
{
|
||||
//printf("SetCommTimeouts error\n");
|
||||
CloseComm();
|
||||
return false;
|
||||
}
|
||||
if (!GetCommState(m_hComm, &dcb)) // 取DCB
|
||||
{
|
||||
//printf("GetCommState error\n");
|
||||
CloseComm();
|
||||
return false;
|
||||
}
|
||||
|
||||
dcb.BaudRate = static_cast<unsigned long>(nBaudRate);
|
||||
dcb.ByteSize = static_cast<unsigned char>(nByteSize);
|
||||
dcb.Parity = static_cast<unsigned char>(nParity);
|
||||
dcb.StopBits = static_cast<unsigned char>(nStopBits);
|
||||
|
||||
if (!SetCommState(m_hComm, &dcb)) // 设置DCB
|
||||
{
|
||||
//printf("SetCommState error\n");
|
||||
CloseComm();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SetupComm(m_hComm, 4096, 2048)) // 设置输入输出缓冲区大小
|
||||
{
|
||||
//printf("SetupComm error\n");
|
||||
CloseComm();
|
||||
return false;
|
||||
}
|
||||
|
||||
PurgeComm(m_hComm, PURGE_TXABORT | PURGE_RXABORT |
|
||||
PURGE_TXCLEAR | PURGE_RXCLEAR);
|
||||
|
||||
return TRUE;//这里发送成功消息
|
||||
}
|
||||
|
||||
|
||||
// 关闭串口
|
||||
bool Comm::CloseComm()
|
||||
{
|
||||
bool ret = true;
|
||||
if (m_hComm != nullptr)
|
||||
ret = CloseHandle(m_hComm);
|
||||
m_hComm = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int Comm::SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len)
|
||||
{
|
||||
DWORD dwNumWrite; // 串口发出的数据长度
|
||||
DWORD dwNumRead; // 串口收到的数据长度
|
||||
unsigned char rev_buf[4096];
|
||||
DWORD RevDataLen = 0;
|
||||
DWORD dwError = 0;
|
||||
COMSTAT ComStat;
|
||||
int count = 0;
|
||||
|
||||
if (data == nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
dwNumRead = 0;
|
||||
|
||||
memset(rev_buf, 0, sizeof(rev_buf));
|
||||
PurgeComm(m_hComm, PURGE_TXABORT | PURGE_RXABORT |
|
||||
PURGE_TXCLEAR | PURGE_RXCLEAR);
|
||||
|
||||
if (!WriteFile(m_hComm, data, static_cast<unsigned long>(data_len), &dwNumWrite, nullptr))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// if (strcmp("mon\r", data) != 0)
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
|
||||
Sleep(100);
|
||||
ClearCommError(m_hComm, &dwError, &ComStat);
|
||||
if ((ComStat.cbInQue >= 1))
|
||||
{
|
||||
if (!::ReadFile(m_hComm, rev_buf, ComStat.cbInQue, &RevDataLen, nullptr))
|
||||
{
|
||||
return -3;
|
||||
}
|
||||
else
|
||||
{
|
||||
*revData_len = static_cast<int>(RevDataLen);
|
||||
memcpy_s(revData,RevDataLen,rev_buf,RevDataLen);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
count++;
|
||||
if (count >= 20)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
44
device/SerialPort/SerialPort.h
Normal file
44
device/SerialPort/SerialPort.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
#include <tchar.h>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include <process.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <conio.h>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
|
||||
|
||||
|
||||
|
||||
#include<QObject>
|
||||
#include"base.h"
|
||||
|
||||
|
||||
|
||||
class Comm{
|
||||
public:
|
||||
HANDLE m_hComm;// 串口设备句柄
|
||||
CRITICAL_SECTION mCsRead;
|
||||
QString com;
|
||||
int nBaudRate;
|
||||
int nParity;
|
||||
int nByteSize;
|
||||
int nStopBits;
|
||||
private:
|
||||
|
||||
|
||||
public:
|
||||
Comm(void);
|
||||
~Comm(void);
|
||||
float pidP;
|
||||
float dstPower;
|
||||
public:
|
||||
//bool OpenComm(wchar_t* pPort);
|
||||
bool OpenComm();
|
||||
bool CloseComm();
|
||||
int SendCmd(char *data, unsigned short data_len ,unsigned char * revData, int * revData_len);
|
||||
int getSerialSet(QString DevName);
|
||||
};
|
||||
246
device/SerialPort/lightsource.cpp
Normal file
246
device/SerialPort/lightsource.cpp
Normal file
@@ -0,0 +1,246 @@
|
||||
#include "lightsource.h"
|
||||
#include "rs_settings.h"
|
||||
|
||||
LightSource* LightSource::UniqueInstance = nullptr;
|
||||
|
||||
LightSource* LightSource::Instance()
|
||||
{
|
||||
if (!UniqueInstance) {
|
||||
UniqueInstance = new LightSource();
|
||||
}
|
||||
return UniqueInstance;
|
||||
}
|
||||
LightSource::~LightSource()
|
||||
{
|
||||
|
||||
}
|
||||
LightSource::LightSource()
|
||||
{
|
||||
|
||||
}
|
||||
int LightSource::getCheck(char * buf, int len,char * strAscii)
|
||||
{
|
||||
unsigned char data = 0;
|
||||
data = static_cast<unsigned char>(buf[0]);
|
||||
for (int i = 1;i < len; i++)
|
||||
{
|
||||
data = static_cast<unsigned char>(data ^ buf[i]);
|
||||
}
|
||||
getValueAscii(data, strAscii);
|
||||
return 0;
|
||||
}
|
||||
int LightSource::getValueAscii(unsigned char value,char * strAscii)
|
||||
{
|
||||
char ascii_buf[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',};
|
||||
int high,low;
|
||||
high = (value & 0xf0) >> 4;
|
||||
low = value & 0x0f;
|
||||
strAscii[0] = ascii_buf[high];
|
||||
strAscii[1] = ascii_buf[low];
|
||||
return 0;
|
||||
}
|
||||
int LightSource::SetBrightness(int chn)
|
||||
{
|
||||
int ret;
|
||||
unsigned char data;
|
||||
char cmd[50] = {0};
|
||||
char ascii_buf[2];
|
||||
|
||||
if (m_hComm == nullptr)
|
||||
{
|
||||
bool ret = OpenComm();
|
||||
if (!ret)
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int brightness;
|
||||
RS_SETTINGS->beginGroup("device/LightSource");
|
||||
brightness = RS_SETTINGS->readNumEntry("/brightnessFind");
|
||||
RS_SETTINGS->endGroup();
|
||||
|
||||
data = static_cast<unsigned char>(brightness);
|
||||
getValueAscii(data,ascii_buf);
|
||||
|
||||
cmd[0] = '#';
|
||||
cmd[1] = '3';
|
||||
cmd[2] = static_cast<char>(0x30 + chn);
|
||||
cmd[3] = 0x30;
|
||||
cmd[4] = ascii_buf[0];
|
||||
cmd[5] = ascii_buf[1];
|
||||
getCheck(cmd, 6, ascii_buf);
|
||||
cmd[6] = ascii_buf[0];
|
||||
cmd[7] = ascii_buf[1];
|
||||
|
||||
|
||||
|
||||
ret = SendCmd(reinterpret_cast<char*>(cmd), 8 ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret == 0)
|
||||
{
|
||||
if (revData[0] != '#')
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int LightSource::LightOn(int chn)
|
||||
{
|
||||
int ret;
|
||||
char cmd[50] = {0};
|
||||
char ascii_buf[10];
|
||||
char chn_char;
|
||||
int chnNumber;
|
||||
|
||||
if (m_hComm == nullptr)
|
||||
{
|
||||
bool ret = OpenComm();
|
||||
if (!ret)
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int brightness;
|
||||
if (chn == 1)
|
||||
{
|
||||
RS_SETTINGS->beginGroup("device/LightSource");
|
||||
brightness = RS_SETTINGS->readNumEntry("/brightnessFind");
|
||||
RS_SETTINGS->endGroup();
|
||||
chnNumber = chnFind;
|
||||
}
|
||||
else
|
||||
{
|
||||
RS_SETTINGS->beginGroup("device/LightSource");
|
||||
brightness = RS_SETTINGS->readNumEntry("/brightnessGlobal");
|
||||
RS_SETTINGS->endGroup();
|
||||
chnNumber = chnGlobal;
|
||||
}
|
||||
|
||||
sprintf_s(ascii_buf,10,"%04d",brightness);
|
||||
if (chnNumber == 1)
|
||||
{
|
||||
chn_char = 'A';
|
||||
}
|
||||
else if (chnNumber == 2)
|
||||
{
|
||||
chn_char = 'B';
|
||||
}
|
||||
else if (chnNumber == 3)
|
||||
{
|
||||
chn_char = 'C';
|
||||
}
|
||||
else
|
||||
{
|
||||
chn_char = 'D';
|
||||
}
|
||||
|
||||
cmd[0] = 'S';
|
||||
cmd[1] = chn_char;
|
||||
memcpy_s(&cmd[2],4,ascii_buf,4);
|
||||
cmd[6] = '#';
|
||||
|
||||
|
||||
|
||||
ret = SendCmd(reinterpret_cast<char*>(cmd), 7 ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret == 0)
|
||||
{
|
||||
if (revData[0] != chn_char)
|
||||
{
|
||||
ret = SendCmd(reinterpret_cast<char*>(cmd), 8 ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (revData[0] != chn_char)
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = SendCmd(reinterpret_cast<char*>(cmd), 7 ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int LightSource::LightOff(int chn)
|
||||
{
|
||||
int ret;
|
||||
char cmd[50] = {0};
|
||||
char ascii_buf[10];
|
||||
char chn_char;
|
||||
int chnNumber;
|
||||
|
||||
if (m_hComm == nullptr)
|
||||
{
|
||||
bool ret = OpenComm();
|
||||
if (!ret)
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int brightness = 0;
|
||||
if (chn == 1)
|
||||
{
|
||||
chnNumber = chnFind;
|
||||
}
|
||||
else
|
||||
{
|
||||
chnNumber = chnGlobal;
|
||||
}
|
||||
|
||||
sprintf_s(ascii_buf,10,"%04d",brightness);
|
||||
if (chnNumber == 1)
|
||||
{
|
||||
chn_char = 'A';
|
||||
}
|
||||
else if (chnNumber == 2)
|
||||
{
|
||||
chn_char = 'B';
|
||||
}
|
||||
else if (chnNumber == 3)
|
||||
{
|
||||
chn_char = 'C';
|
||||
}
|
||||
else
|
||||
{
|
||||
chn_char = 'D';
|
||||
}
|
||||
|
||||
cmd[0] = 'S';
|
||||
cmd[1] = chn_char;
|
||||
memcpy_s(&cmd[2],4,ascii_buf,4);
|
||||
cmd[6] = '#';
|
||||
|
||||
|
||||
|
||||
ret = SendCmd(reinterpret_cast<char*>(cmd), 7 ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (ret == 0)
|
||||
{
|
||||
if (revData[0] != chn_char)
|
||||
{
|
||||
ret = SendCmd(reinterpret_cast<char*>(cmd), 8 ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
if (revData[0] != chn_char)
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = SendCmd(reinterpret_cast<char*>(cmd), 7 ,reinterpret_cast<unsigned char*>(revData), &revDataLen);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LightSource::getChnId(QString DevName)
|
||||
{
|
||||
QSettings *settings;//申明一个QSetting类函数
|
||||
settings = new QSettings ("SerialDevSet.ini", QSettings::IniFormat);//构建函数
|
||||
|
||||
QString strKey;
|
||||
strKey = "/"+DevName+"/chnFind";
|
||||
chnFind = settings->value(strKey).toInt();
|
||||
strKey = "/"+DevName+"/chnGlobal";
|
||||
chnGlobal = settings->value(strKey).toInt();
|
||||
|
||||
return 0;
|
||||
}
|
||||
30
device/SerialPort/lightsource.h
Normal file
30
device/SerialPort/lightsource.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef LIGHTSOURCE_H
|
||||
#define LIGHTSOURCE_H
|
||||
#include "SerialPort.h"
|
||||
|
||||
|
||||
|
||||
#define LIGHTSOURCEFIND LightSource::Instance()
|
||||
class LightSource:public Comm
|
||||
{
|
||||
|
||||
private:
|
||||
char revData[4096];
|
||||
int revDataLen;
|
||||
|
||||
static LightSource* UniqueInstance;
|
||||
int chnFind;
|
||||
int chnGlobal;
|
||||
public:
|
||||
LightSource();
|
||||
~LightSource();
|
||||
static LightSource* Instance();
|
||||
int SetBrightness(int chn);
|
||||
int getValueAscii(unsigned char value,char * strAscii);
|
||||
int getCheck(char * buf, int len,char * strAscii);
|
||||
int LightOn(int chn);
|
||||
int LightOff(int chn);
|
||||
int getChnId(QString DevName);
|
||||
};
|
||||
|
||||
#endif // LIGHTSOURCE_H
|
||||
831
device/SerialPort/modbustcp.cpp
Normal file
831
device/SerialPort/modbustcp.cpp
Normal file
@@ -0,0 +1,831 @@
|
||||
#include "modbustcp.h"
|
||||
|
||||
#include "deviceproxy.h"
|
||||
|
||||
|
||||
ModbusTCP* ModbusTCP::uniqueInstance = nullptr;
|
||||
ModbusTCP* ModbusTCP::instance()
|
||||
{
|
||||
if (!uniqueInstance) {
|
||||
uniqueInstance = new ModbusTCP();
|
||||
}
|
||||
return uniqueInstance;
|
||||
}
|
||||
ModbusTCP::ModbusTCP()
|
||||
{
|
||||
sockfd = INVALID_SOCKET;
|
||||
sockfd_fl = INVALID_SOCKET;
|
||||
sockfd_record = INVALID_SOCKET;
|
||||
port = 502;
|
||||
ipAddr = "";
|
||||
ipAddr_fl = "";
|
||||
ipAddr_record = "";
|
||||
ipAddr_electric_resistance = "";
|
||||
_seq_modbus = 0;
|
||||
_seq_modbus_fl = 0;
|
||||
stopFlag = false;
|
||||
memset(RFID,0,50);
|
||||
PLCSts[0] = -1;
|
||||
PLCSts[1] = -1;
|
||||
TransferPLCCmd.cmdAddr = 0;
|
||||
TransferPLCCmd.cmdDelay = 0;
|
||||
TransferPLCCmd.cmdWriteFlag = false;
|
||||
SeparatePLCCmd.cmdAddr = 0;
|
||||
SeparatePLCCmd.cmdDelay = 0;
|
||||
SeparatePLCCmd.cmdWriteFlag = false;
|
||||
WORD sockVersion = MAKEWORD(2, 2);
|
||||
WSADATA data;
|
||||
WSAStartup(sockVersion, &data);
|
||||
|
||||
InitializeCriticalSection(&mCsRead);
|
||||
InitializeCriticalSection(&mCsRead_fl);
|
||||
}
|
||||
|
||||
ModbusTCP::~ModbusTCP(void)
|
||||
{
|
||||
if (sockfd != INVALID_SOCKET)
|
||||
{
|
||||
CloseConn();
|
||||
}
|
||||
if (sockfd_fl != INVALID_SOCKET)
|
||||
{
|
||||
CloseConn_fl();
|
||||
}
|
||||
if (sockfd_record != INVALID_SOCKET)
|
||||
{
|
||||
CloseConn_record();
|
||||
}
|
||||
|
||||
sockfd = INVALID_SOCKET;
|
||||
sockfd_fl = INVALID_SOCKET;
|
||||
sockfd_record = INVALID_SOCKET;
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
bool ModbusTCP::ConnPLC()
|
||||
{
|
||||
struct sockaddr_in server_addr;
|
||||
char* ip;
|
||||
QByteArray ba = ipAddr.toLatin1(); // must
|
||||
ip=ba.data();
|
||||
|
||||
|
||||
|
||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sockfd == INVALID_SOCKET) {
|
||||
//printf("Failed to create socket: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = htons(port);
|
||||
//inet_pton(AF_INET, "server_ip", &server_addr.sin_addr.s_addr);
|
||||
server_addr.sin_addr.s_addr = inet_addr(ip);
|
||||
if (connect(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) {
|
||||
//printf("Failed to connect to server: %s\n", strerror(errno));
|
||||
closesocket(sockfd);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModbusTCP::ConnPLC_fl()
|
||||
{
|
||||
struct sockaddr_in server_addr;
|
||||
char* ip;
|
||||
QByteArray ba = ipAddr_fl.toLatin1(); // must
|
||||
ip=ba.data();
|
||||
|
||||
|
||||
sockfd_fl = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sockfd_fl == INVALID_SOCKET) {
|
||||
//printf("Failed to create socket: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = htons(port);
|
||||
//inet_pton(AF_INET, "server_ip", &server_addr.sin_addr.s_addr);
|
||||
server_addr.sin_addr.s_addr = inet_addr(ip);
|
||||
if (connect(sockfd_fl, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) {
|
||||
//printf("Failed to connect to server: %s\n", strerror(errno));
|
||||
closesocket(sockfd_fl);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool ModbusTCP::ConnPLC_force()
|
||||
{
|
||||
struct sockaddr_in server_addr;
|
||||
char* ip;
|
||||
QByteArray ba = ipAddr_record.toLatin1(); // must
|
||||
ip=ba.data();
|
||||
|
||||
sockfd_record = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sockfd_record == INVALID_SOCKET) {
|
||||
//printf("Failed to create socket: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = htons(6000);
|
||||
//inet_pton(AF_INET, "server_ip", &server_addr.sin_addr.s_addr);
|
||||
server_addr.sin_addr.s_addr = inet_addr(ip);
|
||||
if (connect(sockfd_record, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) {
|
||||
//printf("Failed to connect to server: %s\n", strerror(errno));
|
||||
closesocket(sockfd_record);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool ModbusTCP::ConnPLC_electric_resistance()
|
||||
{
|
||||
struct sockaddr_in server_addr;
|
||||
char* ip;
|
||||
//ipAddr_electric_resistance = "192.168.30.6";
|
||||
QByteArray ba = ipAddr_electric_resistance.toLatin1(); // must AF_LOCAL
|
||||
ip=ba.data();
|
||||
|
||||
sockfd_electric_resistance = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sockfd_electric_resistance == INVALID_SOCKET) {
|
||||
//printf("Failed to create socket: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = htons(6677);
|
||||
//inet_pton(AF_INET, "server_ip", &server_addr.sin_addr.s_addr);
|
||||
server_addr.sin_addr.s_addr = inet_addr(ip);
|
||||
if (connect(sockfd_electric_resistance, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) {
|
||||
//printf("Failed to connect to server: %s\n", strerror(errno));
|
||||
closesocket(sockfd_electric_resistance);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool ModbusTCP::CloseConn()
|
||||
{
|
||||
bool ret = true;
|
||||
if (sockfd != INVALID_SOCKET)
|
||||
closesocket(sockfd);
|
||||
sockfd = INVALID_SOCKET;
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
bool ModbusTCP::CloseConn_fl()
|
||||
{
|
||||
bool ret = true;
|
||||
if (sockfd_fl != INVALID_SOCKET)
|
||||
closesocket(sockfd_fl);
|
||||
sockfd_fl = INVALID_SOCKET;
|
||||
|
||||
return ret;
|
||||
}
|
||||
bool ModbusTCP::CloseConn_record()
|
||||
{
|
||||
bool ret = true;
|
||||
if (sockfd_record != INVALID_SOCKET)
|
||||
closesocket(sockfd_record);
|
||||
sockfd_record = INVALID_SOCKET;
|
||||
|
||||
return ret;
|
||||
}
|
||||
bool ModbusTCP::CloseConn_electric_resistance()
|
||||
{
|
||||
bool ret = true;
|
||||
if (sockfd_electric_resistance != INVALID_SOCKET)
|
||||
closesocket(sockfd_electric_resistance);
|
||||
sockfd_electric_resistance = INVALID_SOCKET;
|
||||
|
||||
return ret;
|
||||
}
|
||||
int ModbusTCP::SendCmdRead(unsigned int sockfd,char *data, unsigned short data_len)
|
||||
{
|
||||
//可能存在问题。
|
||||
//1、接收按照数据长度接收,然后校验接收长度是否正确
|
||||
//2、返回的数据,是否正确,是否要进行判断?
|
||||
char rev_buf[4096];
|
||||
int RevDataLen = 0;
|
||||
|
||||
//发送modbus请求
|
||||
if (send(sockfd, data, data_len, 0) == -1) {
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
|
||||
}
|
||||
//printf("Sent request successfully.\n");
|
||||
//接收modbus请求
|
||||
RevDataLen = recv(sockfd, rev_buf, 4096, 0);
|
||||
if (RevDataLen == -1) {
|
||||
//printf("Failed to receive response: %s\n", strerror(errno));
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
int ret = DataDecode(rev_buf, RevDataLen);
|
||||
return ret;
|
||||
}
|
||||
int ModbusTCP::SendCmdWrite(unsigned int sockfd,char *data, unsigned short data_len)
|
||||
{
|
||||
//可能存在问题。
|
||||
//1、接收按照数据长度接收,然后校验接收长度是否正确
|
||||
//2、返回的数据,是否正确,是否要进行判断?
|
||||
|
||||
char rev_buf[4096];
|
||||
int RevDataLen = 0;
|
||||
|
||||
//发送modbus请求
|
||||
if (send(sockfd, data, data_len, 0) == -1) {
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
//printf("Sent request successfully.\n");
|
||||
//接收modbus请求
|
||||
RevDataLen = recv(sockfd, rev_buf, 4096, 0);
|
||||
if (RevDataLen == -1) {
|
||||
//printf("Failed to receive response: %s\n", strerror(errno));
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
//int ret = Com_decode(rev_buf, RevDataLen);
|
||||
return 0;
|
||||
}
|
||||
int ModbusTCP::SendCmdRead_fl(unsigned int sockfd,char *data, unsigned short data_len)
|
||||
{
|
||||
//可能存在问题。
|
||||
//1、接收按照数据长度接收,然后校验接收长度是否正确
|
||||
//2、返回的数据,是否正确,是否要进行判断?
|
||||
char rev_buf[4096];
|
||||
int RevDataLen = 0;
|
||||
|
||||
//发送modbus请求
|
||||
if (send(sockfd, data, data_len, 0) == -1) {
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
|
||||
}
|
||||
//printf("Sent request successfully.\n");
|
||||
//接收modbus请求
|
||||
RevDataLen = recv(sockfd, rev_buf, 4096, 0);
|
||||
if (RevDataLen == -1) {
|
||||
//printf("Failed to receive response: %s\n", strerror(errno));
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
int ret = DataDecode(rev_buf, RevDataLen);
|
||||
return ret;
|
||||
}
|
||||
int ModbusTCP::SendCmdWrite_fl(unsigned int sockfd,char *data, unsigned short data_len)
|
||||
{
|
||||
//可能存在问题。
|
||||
//1、接收按照数据长度接收,然后校验接收长度是否正确
|
||||
//2、返回的数据,是否正确,是否要进行判断?
|
||||
|
||||
char rev_buf[4096];
|
||||
int RevDataLen = 0;
|
||||
|
||||
//发送modbus请求
|
||||
if (send(sockfd, data, data_len, 0) == -1) {
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
//printf("Sent request successfully.\n");
|
||||
//接收modbus请求
|
||||
RevDataLen = recv(sockfd, rev_buf, 4096, 0);
|
||||
if (RevDataLen == -1) {
|
||||
//printf("Failed to receive response: %s\n", strerror(errno));
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
//int ret = Com_decode(rev_buf, RevDataLen);
|
||||
return 0;
|
||||
}
|
||||
int ModbusTCP::DataDecode(char *data, int len)
|
||||
{
|
||||
if ((len >= 10) && (len <= 11))
|
||||
{
|
||||
return data[len-1];
|
||||
}
|
||||
else if (len > 11)
|
||||
{
|
||||
memset(MODBUSTCP->RFID,0,50);
|
||||
memcpy(RFID,&data[9],len-9);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ModbusTCP::ModbusWrite(unsigned char cmd,unsigned short addr, unsigned short data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
||||
unsigned char sendBuf[50];//发送缓存
|
||||
unsigned short temps = _seq_modbus++;//类似于TCP的seq序列号,让其自增即可
|
||||
unsigned char* temp = reinterpret_cast<unsigned char*>(&temps);
|
||||
//协议头
|
||||
sendBuf[0] = *(temp + 1);//前两位为事务处理标识,2个字节的序列号
|
||||
sendBuf[1] = *(temp);
|
||||
|
||||
sendBuf[2] = 0;//协议标识,两个字节,0000即为Modbus TCP协议
|
||||
sendBuf[3] = 0;
|
||||
|
||||
sendBuf[4] = 0;//长度字段(前半部分字节)
|
||||
sendBuf[5] = 6;//随后字节数
|
||||
|
||||
sendBuf[6] = 1;//单元标志,定义连接目的节点的其他设备(这个设备是1号,所以是0x01)
|
||||
//以上是Modbus协议头部分
|
||||
//协议体
|
||||
sendBuf[7] = cmd;//Modbus功能码 ,这里是 写多个保持寄存器 操作
|
||||
temps = addr;
|
||||
sendBuf[8] = *(temp + 1); //写寄存器起始地址高字节
|
||||
sendBuf[9] = *(temp); //写寄存器起始地址低字节(所以这里是往0x0100地址写寄存器)
|
||||
|
||||
//sendBuf[10] = 0x00; //写寄存器数量高字节
|
||||
//sendBuf[11] = 0x01; //写寄存器数量低字节
|
||||
|
||||
//sendBuf[12] = 0x01; //数据长度
|
||||
|
||||
//写1个值到报文中
|
||||
temps = data;
|
||||
//sendBuf[10] = data;
|
||||
sendBuf[10] = *(temp + 1);
|
||||
sendBuf[11] = *(temp);
|
||||
|
||||
|
||||
bool ret_conn = true;
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
ret_conn = ConnPLC();
|
||||
if (ret_conn)
|
||||
ret = SendCmdWrite(sockfd,reinterpret_cast<char*>(sendBuf), 12);
|
||||
else
|
||||
{
|
||||
CloseConn();
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return -1;
|
||||
}
|
||||
CloseConn();
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int ModbusTCP::ModbusWrite_fl(unsigned char cmd,unsigned short addr, unsigned short data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
||||
unsigned char sendBuf[50];//发送缓存
|
||||
unsigned short temps = _seq_modbus_fl++;//类似于TCP的seq序列号,让其自增即可
|
||||
unsigned char* temp = reinterpret_cast<unsigned char*>(&temps);
|
||||
//协议头
|
||||
sendBuf[0] = *(temp + 1);//前两位为事务处理标识,2个字节的序列号
|
||||
sendBuf[1] = *(temp);
|
||||
|
||||
sendBuf[2] = 0;//协议标识,两个字节,0000即为Modbus TCP协议
|
||||
sendBuf[3] = 0;
|
||||
|
||||
sendBuf[4] = 0;//长度字段(前半部分字节)
|
||||
sendBuf[5] = 6;//随后字节数
|
||||
|
||||
sendBuf[6] = 1;//单元标志,定义连接目的节点的其他设备(这个设备是1号,所以是0x01)
|
||||
//以上是Modbus协议头部分
|
||||
//协议体
|
||||
sendBuf[7] = cmd;//Modbus功能码 ,这里是 写多个保持寄存器 操作
|
||||
temps = addr;
|
||||
sendBuf[8] = *(temp + 1); //写寄存器起始地址高字节
|
||||
sendBuf[9] = *(temp); //写寄存器起始地址低字节(所以这里是往0x0100地址写寄存器)
|
||||
|
||||
//sendBuf[10] = 0x00; //写寄存器数量高字节
|
||||
//sendBuf[11] = 0x01; //写寄存器数量低字节
|
||||
|
||||
//sendBuf[12] = 0x01; //数据长度
|
||||
|
||||
//写1个值到报文中
|
||||
temps = data;
|
||||
//sendBuf[10] = data;
|
||||
sendBuf[10] = *(temp + 1);
|
||||
sendBuf[11] = *(temp);
|
||||
|
||||
|
||||
bool ret_conn = true;
|
||||
::EnterCriticalSection(&mCsRead_fl);
|
||||
ret_conn = ConnPLC_fl();
|
||||
if (ret_conn)
|
||||
ret = SendCmdWrite_fl(sockfd_fl,reinterpret_cast<char*>(sendBuf), 12);
|
||||
else
|
||||
{
|
||||
CloseConn_fl();
|
||||
::LeaveCriticalSection(&mCsRead_fl);
|
||||
return -1;
|
||||
}
|
||||
CloseConn_fl();
|
||||
::LeaveCriticalSection(&mCsRead_fl);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int ModbusTCP::ModbusWrite_force(char * data, int len)
|
||||
{
|
||||
|
||||
bool ret_conn = true;
|
||||
//::EnterCriticalSection(&mCsRead_fl);
|
||||
ret_conn = ConnPLC_force();
|
||||
if (ret_conn)
|
||||
{
|
||||
if (send(sockfd_record, data, len, 0) == -1)
|
||||
{
|
||||
CloseConn_record();
|
||||
qDebug()<< "result1: "<<data;
|
||||
//::LeaveCriticalSection(&mCsRead_fl);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<< "result: "<<data;
|
||||
CloseConn_record();
|
||||
//::LeaveCriticalSection(&mCsRead_fl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
CloseConn_record();
|
||||
qDebug()<< "result2: "<<data;
|
||||
//::LeaveCriticalSection(&mCsRead_fl);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
int ModbusTCP::ModbusWrite_electric_resistance(char * data, int len, char * rev_buf)
|
||||
{
|
||||
|
||||
int RevDataLen = 0;
|
||||
bool ret_conn = true;
|
||||
|
||||
// if (data[0] == 'G')
|
||||
// {
|
||||
// memset(array_pos,0,sizeof(array_pos));
|
||||
// }
|
||||
|
||||
// ret_conn = ConnPLC_electric_resistance();
|
||||
// if (ret_conn)
|
||||
{
|
||||
if (send(sockfd_electric_resistance, data, len, 0) == -1)
|
||||
{
|
||||
CloseConn_electric_resistance();
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strcmp(data,"***") == 0)
|
||||
return 0;
|
||||
RevDataLen = recv(sockfd_electric_resistance, rev_buf, 4096, 0);
|
||||
if (RevDataLen == -1) {
|
||||
closesocket(sockfd_electric_resistance);
|
||||
return -1;
|
||||
}
|
||||
return RevDataLen;
|
||||
}
|
||||
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// CloseConn_electric_resistance();
|
||||
// qDebug()<< "result2: "<<data;
|
||||
// //::LeaveCriticalSection(&mCsRead_fl);
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
int ModbusTCP::ModbusRead(unsigned short addr,int dataLen)
|
||||
{
|
||||
|
||||
int ret;
|
||||
|
||||
|
||||
unsigned char sendBuf[50];//发送缓存
|
||||
unsigned short temps = _seq_modbus++;//类似于TCP的seq序列号,让其自增即可
|
||||
unsigned char* temp = reinterpret_cast<unsigned char*>(&temps);
|
||||
//协议头
|
||||
sendBuf[0] = *(temp + 1);//前两位为事务处理标识,2个字节的序列号
|
||||
sendBuf[1] = *(temp);
|
||||
|
||||
sendBuf[2] = 0;//协议标识,两个字节,0000即为Modbus TCP协议
|
||||
sendBuf[3] = 0;
|
||||
|
||||
sendBuf[4] = 0;//长度字段(前半部分字节)
|
||||
sendBuf[5] = 6;//随后字节数
|
||||
|
||||
sendBuf[6] = 0x01;//单元标志,定义连接目的节点的其他设备(这个设备是1号,所以是0x01)
|
||||
//以上是Modbus协议头部分
|
||||
//协议体
|
||||
sendBuf[7] = 0x03;//Modbus功能码 ,这里是读
|
||||
temps = addr;
|
||||
sendBuf[8] = *(temp + 1); //写寄存器起始地址高字节
|
||||
sendBuf[9] = *(temp); //写寄存器起始地址低字节(所以这里是往0x0100地址写寄存器)
|
||||
sendBuf[10] = 0x00; //长度
|
||||
sendBuf[11] = dataLen; //写寄存器数量低字节
|
||||
|
||||
bool ret_conn = true;
|
||||
::EnterCriticalSection(&mCsRead);
|
||||
ret_conn = ConnPLC();
|
||||
if (ret_conn)
|
||||
ret = SendCmdRead(sockfd,reinterpret_cast<char*>(sendBuf), 12);
|
||||
else
|
||||
{
|
||||
CloseConn();
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return -1;
|
||||
}
|
||||
CloseConn();
|
||||
::LeaveCriticalSection(&mCsRead);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int ModbusTCP::ModbusRead_fl(unsigned short addr,int dataLen)
|
||||
{
|
||||
|
||||
int ret;
|
||||
|
||||
|
||||
unsigned char sendBuf[50];//发送缓存
|
||||
unsigned short temps = _seq_modbus_fl++;//类似于TCP的seq序列号,让其自增即可
|
||||
unsigned char* temp = reinterpret_cast<unsigned char*>(&temps);
|
||||
//协议头
|
||||
sendBuf[0] = *(temp + 1);//前两位为事务处理标识,2个字节的序列号
|
||||
sendBuf[1] = *(temp);
|
||||
|
||||
sendBuf[2] = 0;//协议标识,两个字节,0000即为Modbus TCP协议
|
||||
sendBuf[3] = 0;
|
||||
|
||||
sendBuf[4] = 0;//长度字段(前半部分字节)
|
||||
sendBuf[5] = 6;//随后字节数
|
||||
|
||||
sendBuf[6] = 0x01;//单元标志,定义连接目的节点的其他设备(这个设备是1号,所以是0x01)
|
||||
//以上是Modbus协议头部分
|
||||
//协议体
|
||||
sendBuf[7] = 0x03;//Modbus功能码 ,这里是读
|
||||
temps = addr;
|
||||
sendBuf[8] = *(temp + 1); //写寄存器起始地址高字节
|
||||
sendBuf[9] = *(temp); //写寄存器起始地址低字节(所以这里是往0x0100地址写寄存器)
|
||||
sendBuf[10] = 0x00; //长度
|
||||
sendBuf[11] = dataLen; //写寄存器数量低字节
|
||||
|
||||
bool ret_conn = true;
|
||||
::EnterCriticalSection(&mCsRead_fl);
|
||||
ret_conn = ConnPLC_fl();
|
||||
if (ret_conn)
|
||||
ret = SendCmdRead_fl(sockfd_fl,reinterpret_cast<char*>(sendBuf), 12);
|
||||
else
|
||||
{
|
||||
CloseConn_fl();
|
||||
::LeaveCriticalSection(&mCsRead_fl);
|
||||
return -1;
|
||||
}
|
||||
CloseConn_fl();
|
||||
::LeaveCriticalSection(&mCsRead_fl);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int ModbusTCP::TransferPLCRun(unsigned short addr,int delay)
|
||||
{
|
||||
if ((addr == 0) || (delay <= 0))
|
||||
return -1;
|
||||
if (TransferPLCCmd.cmdAddr != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
TransferPLCCmd.cmdAddr = addr;
|
||||
TransferPLCCmd.cmdDelay = delay;
|
||||
TransferPLCCmd.cmdWriteFlag = false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ModbusTCP::SeparatePLCRun(unsigned short addr,int delay)
|
||||
{
|
||||
if ((addr == 0) || (delay <= 0))
|
||||
return -1;
|
||||
if (SeparatePLCCmd.cmdAddr != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
SeparatePLCCmd.cmdAddr = addr;
|
||||
SeparatePLCCmd.cmdDelay = delay;
|
||||
SeparatePLCCmd.cmdWriteFlag = false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ModbusTCP::getModbusPara(QString DevName)
|
||||
{
|
||||
QSettings *settings;//申明一个QSetting类函数
|
||||
settings = new QSettings ("SerialDevSet.ini", QSettings::IniFormat);//构建函数
|
||||
|
||||
QString strKey;
|
||||
strKey = "/"+DevName+"/ipAddr";
|
||||
ipAddr = settings->value(strKey).toString();
|
||||
strKey = "/"+DevName+"/ipAddr_fl";
|
||||
ipAddr_fl = settings->value(strKey).toString();
|
||||
|
||||
strKey = "/"+DevName+"/ipAddr_record";
|
||||
ipAddr_record = settings->value(strKey).toString();
|
||||
|
||||
strKey = "/"+DevName+"/ipAddr_electric_resistance";
|
||||
ipAddr_electric_resistance = settings->value(strKey).toString();
|
||||
|
||||
strKey = "/"+DevName+"/shangReadAddr";
|
||||
shangReadAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
strKey = "/"+DevName+"/shangWriteAddr";
|
||||
shangWriteAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
|
||||
strKey = "/"+DevName+"/shangReadRFIDAddr";
|
||||
shangReadRFIDAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
|
||||
strKey = "/"+DevName+"/shangReadVacuumAddr";
|
||||
shangReadVacuumAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
strKey = "/"+DevName+"/shangWriteHeartbeatAddr";
|
||||
shangWriteHeartbeatAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
|
||||
strKey = "/"+DevName+"/shangWriteVacuumAddr";
|
||||
shangWriteVacuumAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
|
||||
strKey = "/"+DevName+"/xiaReadAddr";
|
||||
xiaReadAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
strKey = "/"+DevName+"/xiaWriteAddr";
|
||||
xiaWriteAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
|
||||
strKey = "/"+DevName+"/xiaReadStsAddr";
|
||||
xiaReadStsAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
strKey = "/"+DevName+"/ReadTransferPLCStsAddr";
|
||||
ReadTransferPLCStsAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
|
||||
strKey = "/"+DevName+"/xiaWriteVacuumAddr";
|
||||
xiaWriteVacuumAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
|
||||
strKey = "/"+DevName+"/InitAddr";
|
||||
InitAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
strKey = "/"+DevName+"/RunAddr";
|
||||
RunAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
strKey = "/"+DevName+"/StopAddr";
|
||||
StopAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
strKey = "/"+DevName+"/ClearAlarmAddr";
|
||||
ClearAlarmAddr = static_cast<unsigned short>(settings->value(strKey).toInt());
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ModbusTCP::Heartbeat(void)
|
||||
{
|
||||
int internal_read = 0;
|
||||
int internal_write = 0;
|
||||
int internal_sts = 0;
|
||||
int ret_modbus;
|
||||
int count = 0;
|
||||
bool readFlag = false;
|
||||
int fail_count[2] = {0};
|
||||
int internal_TransferPLCCmd_sts = 0;
|
||||
while (1)
|
||||
{
|
||||
internal_read++;
|
||||
internal_write++;
|
||||
internal_sts++;
|
||||
if ((internal_read >= 240) && (readFlag))
|
||||
{
|
||||
ret_modbus = MODBUSTCP->ModbusRead(MODBUSTCP->shangWriteHeartbeatAddr, 1);
|
||||
if (ret_modbus != 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0;
|
||||
MODBUSTCP->connFlag = true;
|
||||
}
|
||||
if (count >= 3)
|
||||
{
|
||||
MODBUSTCP->connFlag = false;
|
||||
}
|
||||
readFlag = false;
|
||||
internal_write = 0;
|
||||
}
|
||||
if ((internal_write >= 20) && (!readFlag))
|
||||
{
|
||||
ret_modbus = MODBUSTCP->ModbusWrite(0x06,MODBUSTCP->shangWriteHeartbeatAddr, 1);
|
||||
internal_read = 0;
|
||||
readFlag = true;
|
||||
}
|
||||
|
||||
if (internal_sts >= 20)
|
||||
{
|
||||
ret_modbus = MODBUSTCP->ModbusRead(MODBUSTCP->xiaReadStsAddr, 1);
|
||||
if (ret_modbus == -1)
|
||||
{
|
||||
fail_count[0]++;
|
||||
if (fail_count[0] >= 3)
|
||||
{
|
||||
PLCSts[0] = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fail_count[0] = 0;
|
||||
PLCSts[0] = ret_modbus;
|
||||
}
|
||||
ret_modbus = MODBUSTCP->ModbusRead(MODBUSTCP->ReadTransferPLCStsAddr, 1);
|
||||
TransferPLCSts = ret_modbus;
|
||||
emit DEV->TransferPLCSGL(PLCSts[0]);
|
||||
internal_sts = 0;
|
||||
|
||||
}
|
||||
|
||||
if (TransferPLCCmd.cmdAddr != 0)
|
||||
{
|
||||
if (TransferPLCCmd.cmdWriteFlag == false)
|
||||
{
|
||||
//发送写命令
|
||||
ret_modbus = MODBUSTCP->ModbusWrite(0x05,TransferPLCCmd.cmdAddr, 0xff00);
|
||||
TransferPLCCmd.cmdWriteFlag = true;
|
||||
}
|
||||
internal_TransferPLCCmd_sts++;
|
||||
if ((internal_TransferPLCCmd_sts * 5) >= TransferPLCCmd.cmdDelay)
|
||||
{
|
||||
//发送清除命令
|
||||
ret_modbus = MODBUSTCP->ModbusWrite(0x05,TransferPLCCmd.cmdAddr, 0);
|
||||
TransferPLCCmd.cmdWriteFlag = false;
|
||||
TransferPLCCmd.cmdAddr = 0;
|
||||
TransferPLCCmd.cmdDelay = 0;
|
||||
internal_TransferPLCCmd_sts = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
int ModbusTCP::Heartbeat_fl(void)
|
||||
{
|
||||
int internal_sts = 0;
|
||||
int ret_modbus;
|
||||
int fail_count[2] = {0};
|
||||
int internal_SeparatePLCCmd_sts = 0;
|
||||
while (1)
|
||||
{
|
||||
|
||||
internal_sts++;
|
||||
|
||||
if (internal_sts >= 20)
|
||||
{
|
||||
ret_modbus = MODBUSTCP->ModbusRead_fl(MODBUSTCP->xiaReadStsAddr, 1);
|
||||
if (ret_modbus == -1)
|
||||
{
|
||||
fail_count[1]++;
|
||||
if (fail_count[1] >= 3)
|
||||
{
|
||||
PLCSts[1] = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fail_count[1] = 0;
|
||||
PLCSts[1] = ret_modbus;
|
||||
}
|
||||
emit DEV->SeparatePLCSGL(PLCSts[1]);
|
||||
internal_sts = 0;
|
||||
|
||||
}
|
||||
|
||||
if (SeparatePLCCmd.cmdAddr != 0)
|
||||
{
|
||||
if (SeparatePLCCmd.cmdWriteFlag == false)
|
||||
{
|
||||
ret_modbus = MODBUSTCP->ModbusWrite_fl(0x05,SeparatePLCCmd.cmdAddr, 0xff00);
|
||||
SeparatePLCCmd.cmdWriteFlag = true;
|
||||
}
|
||||
internal_SeparatePLCCmd_sts++;
|
||||
if ((internal_SeparatePLCCmd_sts * 5) >= SeparatePLCCmd.cmdDelay)
|
||||
{
|
||||
//发送清除命令
|
||||
ret_modbus = MODBUSTCP->ModbusWrite_fl(0x05,SeparatePLCCmd.cmdAddr, 0);
|
||||
SeparatePLCCmd.cmdWriteFlag = false;
|
||||
SeparatePLCCmd.cmdAddr = 0;
|
||||
SeparatePLCCmd.cmdDelay = 0;
|
||||
internal_SeparatePLCCmd_sts = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 1、正常自动加工时,在工作线程跑上下料
|
||||
* 2、在测试界面,使用线程(CreateThread),有运行标记
|
||||
*/
|
||||
111
device/SerialPort/modbustcp.h
Normal file
111
device/SerialPort/modbustcp.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#ifndef MODBUSTCP_H
|
||||
#define MODBUSTCP_H
|
||||
#include <tchar.h>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include <process.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <conio.h>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include<QObject>
|
||||
#include"base.h"
|
||||
|
||||
struct PLC_COMMAND{
|
||||
unsigned short cmdAddr;
|
||||
bool cmdWriteFlag;
|
||||
int cmdDelay;
|
||||
};
|
||||
|
||||
#define MODBUSTCP ModbusTCP::instance()
|
||||
class ModbusTCP
|
||||
{
|
||||
static ModbusTCP* uniqueInstance;
|
||||
public:
|
||||
static ModbusTCP* instance();
|
||||
QString ipAddr_electric_resistance;
|
||||
unsigned int sockfd;
|
||||
unsigned int sockfd_fl;
|
||||
unsigned int sockfd_record;
|
||||
unsigned int sockfd_electric_resistance;
|
||||
char RFID[50];
|
||||
unsigned short height;
|
||||
unsigned short shangReadAddr;
|
||||
unsigned short shangWriteAddr;
|
||||
unsigned short shangReadRFIDAddr;
|
||||
unsigned short xiaWriteHeightAddr;
|
||||
unsigned short shangWriteHeartbeatAddr;
|
||||
unsigned short xiaReadAddr;
|
||||
unsigned short xiaWriteAddr;
|
||||
unsigned short xiaReadStsAddr;
|
||||
unsigned short ReadTransferPLCStsAddr;
|
||||
|
||||
unsigned short InitAddr;
|
||||
unsigned short RunAddr;
|
||||
unsigned short StopAddr;
|
||||
unsigned short ClearAlarmAddr;
|
||||
|
||||
|
||||
bool connFlag{true};
|
||||
int PLCSts[2];
|
||||
int TransferPLCSts;
|
||||
PLC_COMMAND TransferPLCCmd;
|
||||
PLC_COMMAND SeparatePLCCmd;
|
||||
CRITICAL_SECTION mCsRead;
|
||||
CRITICAL_SECTION mCsRead_fl;
|
||||
|
||||
float array_pos[1000][2];
|
||||
private:
|
||||
QString ipAddr;
|
||||
QString ipAddr_fl;
|
||||
QString ipAddr_record;
|
||||
|
||||
unsigned short port;
|
||||
|
||||
unsigned short shangReadVacuumAddr;
|
||||
unsigned short shangWriteVacuumAddr;
|
||||
|
||||
|
||||
unsigned short xiaWriteVacuumAddr;
|
||||
|
||||
unsigned short _seq_modbus;
|
||||
unsigned short _seq_modbus_fl;
|
||||
public:
|
||||
ModbusTCP();
|
||||
~ModbusTCP(void);
|
||||
public:
|
||||
bool ConnPLC();
|
||||
bool ConnPLC_fl();
|
||||
bool ConnPLC_force();
|
||||
bool ConnPLC_electric_resistance();
|
||||
bool CloseConn();
|
||||
bool CloseConn_fl();
|
||||
bool CloseConn_record();
|
||||
bool CloseConn_electric_resistance();
|
||||
int SendCmdRead(unsigned int sockfd,char *data, unsigned short data_len);
|
||||
int SendCmdWrite(unsigned int sockfd,char *data, unsigned short data_len);
|
||||
int SendCmdRead_fl(unsigned int sockfd,char *data, unsigned short data_len);
|
||||
int SendCmdWrite_fl(unsigned int sockfd,char *data, unsigned short data_len);
|
||||
int DataDecode(char *data, int len);
|
||||
int ModbusWrite(unsigned char cmd,unsigned short addr, unsigned short data);
|
||||
int ModbusWrite_fl(unsigned char cmd,unsigned short addr, unsigned short data);
|
||||
int ModbusWrite_force(char * data, int len);
|
||||
int ModbusWrite_electric_resistance(char * data, int len, char * rev_buf);
|
||||
int ModbusRead(unsigned short addr,int dataLen);
|
||||
int ModbusRead_fl(unsigned short addr,int dataLen);
|
||||
int getModbusPara(QString DevName);
|
||||
int Heartbeat(void);
|
||||
int Heartbeat_fl(void);
|
||||
int TransferPLCRun(unsigned short addr,int delay);
|
||||
int SeparatePLCRun(unsigned short addr,int delay);
|
||||
bool stopFlag;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // MODBUSTCP_H
|
||||
16
device/base.h
Normal file
16
device/base.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef BASE_H
|
||||
#define BASE_H
|
||||
|
||||
|
||||
|
||||
enum SYS_INFO_LEVEL { D_NOTHING,
|
||||
D_WARNING,
|
||||
D_CRITICAL};
|
||||
|
||||
enum LIMIT_STATE {LEFT_LIMIT,
|
||||
LEFT_SLIMIT,
|
||||
RIGHT_LIMIT,
|
||||
RIGHT_SLIMIT,
|
||||
NORMAL };
|
||||
|
||||
#endif // BASE_H
|
||||
14
device/bridgesgl.cpp
Normal file
14
device/bridgesgl.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "bridgesgl.h"
|
||||
|
||||
BridgeSGL* BridgeSGL::uniqueInstance = nullptr;
|
||||
|
||||
BridgeSGL::BridgeSGL()
|
||||
{
|
||||
}
|
||||
|
||||
BridgeSGL* BridgeSGL::instance() {
|
||||
if (!uniqueInstance) {
|
||||
uniqueInstance = new BridgeSGL();
|
||||
}
|
||||
return uniqueInstance;
|
||||
}
|
||||
28
device/bridgesgl.h
Normal file
28
device/bridgesgl.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef BRIDGESGL_H
|
||||
#define BRIDGESGL_H
|
||||
#include <QObject>
|
||||
|
||||
#define BDGSGL BridgeSGL::instance()
|
||||
class BridgeSGL:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static BridgeSGL* instance();
|
||||
|
||||
signals:
|
||||
void addZAAxisCPosSGL(QString textValue,double value);
|
||||
void deleteZAAxisCPosSGL(QString value);
|
||||
void ZAAxisCPosListChangedSGL(QStringList value);
|
||||
|
||||
private:
|
||||
BridgeSGL();
|
||||
BridgeSGL(BridgeSGL const&) = delete;
|
||||
BridgeSGL& operator = (BridgeSGL const&) = delete;
|
||||
|
||||
protected:
|
||||
static BridgeSGL* uniqueInstance;
|
||||
};
|
||||
|
||||
#endif // BRIDGESGL_H
|
||||
|
||||
13
device/camera.pri
Normal file
13
device/camera.pri
Normal file
@@ -0,0 +1,13 @@
|
||||
win32:CONFIG(release, debug|release): LIBS += -LD:/03LaserCut_V00.00.01/MVS/Libraries/win32/ -lMvCameraControl
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -LD:/03LaserCut_V00.00.01/MVS/Libraries/win32/ -lMvCameraControl
|
||||
|
||||
INCLUDEPATH += D:/03LaserCut_V00.00.01/MVS/Includes
|
||||
DEPENDPATH += D:/03LaserCut_V00.00.01/MVS/Includes
|
||||
|
||||
LIBS += D:\03LaserCut_V00.00.01\bulid32\lib\libopencv_*.a
|
||||
|
||||
#win32:CONFIG(release, debug|release): LIBS += -LD:/ProgramFiles/opencv/bulid32/lib/ -llibopencv_*.a
|
||||
#else:win32:CONFIG(debug, debug|release): LIBS += -LD:/ProgramFiles/opencv/bulid32/lib/ -llibopencv_*.a
|
||||
|
||||
INCLUDEPATH += D:/03LaserCut_V00.00.01/bulid32/install/include
|
||||
DEPENDPATH += D:/03LaserCut_V00.00.01/bulid32/install/include
|
||||
1351
device/camera/cmvcamera.cpp
Normal file
1351
device/camera/cmvcamera.cpp
Normal file
File diff suppressed because it is too large
Load Diff
190
device/camera/cmvcamera.h
Normal file
190
device/camera/cmvcamera.h
Normal file
@@ -0,0 +1,190 @@
|
||||
/************************************************************************/
|
||||
/* <20><>C++<2B>ӿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD><D4B3>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>η<EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ʹ<EFBFBD><CAB9> */
|
||||
/************************************************************************/
|
||||
|
||||
#ifndef _MV_CAMERA_H_
|
||||
#define _MV_CAMERA_H_
|
||||
|
||||
#include "MvCameraControl.h"
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
#ifndef MV_NULL
|
||||
#define MV_NULL 0
|
||||
#endif
|
||||
|
||||
#define CAMERAFIND CMvCamera::instance()
|
||||
|
||||
class CMvCamera
|
||||
{
|
||||
public:
|
||||
CMvCamera();
|
||||
~CMvCamera();
|
||||
static CMvCamera* instance();
|
||||
// ch:<3A><>ȡSDK<44>汾<EFBFBD><E6B1BE> | en:Get SDK Version
|
||||
static int GetSDKVersion();
|
||||
|
||||
// ch:ö<><C3B6><EFBFBD>豸 | en:Enumerate Device
|
||||
static int EnumDevices(unsigned int nTLayerType, MV_CC_DEVICE_INFO_LIST* pstDevList);
|
||||
|
||||
// ch:<3A>ж<EFBFBD><D0B6>豸<EFBFBD>Ƿ<EFBFBD><C7B7>ɴ<EFBFBD> | en:Is the device accessible
|
||||
static bool IsDeviceAccessible(MV_CC_DEVICE_INFO* pstDevInfo, unsigned int nAccessMode);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD><EFBFBD>豸 | en:Open Device
|
||||
int Open(MV_CC_DEVICE_INFO* pstDeviceInfo);
|
||||
|
||||
// ch:<3A>ر<EFBFBD><D8B1>豸 | en:Close Device
|
||||
int Close();
|
||||
|
||||
// ch:<3A>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ | en:Is The Device Connected
|
||||
bool IsDeviceConnected();
|
||||
|
||||
// ch:ע<><D7A2>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ݻص<DDBB> | en:Register Image Data CallBack
|
||||
int RegisterImageCallBack(void(__stdcall* cbOutput)(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser), void* pUser);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>ץͼ | en:Start Grabbing
|
||||
int StartGrabbing();
|
||||
|
||||
// ch:ֹͣץͼ | en:Stop Grabbing
|
||||
int StopGrabbing();
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡһ֡ͼ<D6A1><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | en:Get one frame initiatively
|
||||
int GetImageBuffer(MV_FRAME_OUT* pFrame, int nMsec);
|
||||
|
||||
// ch:<3A>ͷ<EFBFBD>ͼ<EFBFBD><EFBFBD> | en:Free image buffer
|
||||
int FreeImageBuffer(MV_FRAME_OUT* pFrame);
|
||||
|
||||
// ch:<3A><>ʾһ֡ͼ<D6A1><CDBC> | en:Display one frame image
|
||||
int DisplayOneFrame(MV_DISPLAY_FRAME_INFO* pDisplayInfo);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>SDK<44>ڲ<EFBFBD>ͼ<EFBFBD><EFBFBD><F1BBBAB4>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> | en:Set the number of the internal image cache nodes in SDK
|
||||
int SetImageNodeNum(unsigned int nNum);
|
||||
|
||||
// ch:<3A><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8>Ϣ | en:Get device information
|
||||
int GetDeviceInfo(MV_CC_DEVICE_INFO* pstDevInfo);
|
||||
|
||||
// ch:<3A><>ȡGEV<45><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ϣ | en:Get detect info of GEV camera
|
||||
int GetGevAllMatchInfo(MV_MATCH_INFO_NET_DETECT* pMatchInfoNetDetect);
|
||||
|
||||
// ch:<3A><>ȡU3V<33><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ϣ | en:Get detect info of U3V camera
|
||||
int GetU3VAllMatchInfo(MV_MATCH_INFO_USB_DETECT* pMatchInfoUSBDetect);
|
||||
|
||||
// ch:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Int<6E>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Width<74><68>Height<68><74><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// en:Get Int type parameters, such as Width and Height, for details please refer to MvCameraNode.xlsx file under SDK installation directory
|
||||
int GetIntValue(IN const char* strKey, OUT MVCC_INTVALUE_EX *pIntValue);
|
||||
int SetIntValue(IN const char* strKey, IN int64_t nValue);
|
||||
|
||||
// ch:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Enum<75>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PixelFormat<61><74><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// en:Get Enum type parameters, such as PixelFormat, for details please refer to MvCameraNode.xlsx file under SDK installation directory
|
||||
int GetEnumValue(IN const char* strKey, OUT MVCC_ENUMVALUE *pEnumValue);
|
||||
int SetEnumValue(IN const char* strKey, IN unsigned int nValue);
|
||||
int SetEnumValueByString(IN const char* strKey, IN const char* sValue);
|
||||
int GetEnumEntrySymbolic(IN const char* strKey, IN MVCC_ENUMENTRY* pstEnumEntry);
|
||||
|
||||
// ch:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Float<61>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ExposureTime<6D><65>Gain<69><6E><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// en:Get Float type parameters, such as ExposureTime and Gain, for details please refer to MvCameraNode.xlsx file under SDK installation directory
|
||||
int GetFloatValue(IN const char* strKey, OUT MVCC_FLOATVALUE *pFloatValue);
|
||||
int SetFloatValue(IN const char* strKey, IN float fValue);
|
||||
|
||||
// ch:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Bool<6F>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ReverseX<65><58><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// en:Get Bool type parameters, such as ReverseX, for details please refer to MvCameraNode.xlsx file under SDK installation directory
|
||||
int GetBoolValue(IN const char* strKey, OUT bool *pbValue);
|
||||
int SetBoolValue(IN const char* strKey, IN bool bValue);
|
||||
|
||||
// ch:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>String<6E>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DeviceUserID<49><44><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>UserSetSave
|
||||
// en:Get String type parameters, such as DeviceUserID, for details please refer to MvCameraNode.xlsx file under SDK installation directory
|
||||
int GetStringValue(IN const char* strKey, MVCC_STRINGVALUE *pStringValue);
|
||||
int SetStringValue(IN const char* strKey, IN const char * strValue);
|
||||
|
||||
// ch:ִ<><D6B4>һ<EFBFBD><D2BB>Command<6E><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEA3AC> UserSetSave<76><65><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// en:Execute Command once, such as UserSetSave, for details please refer to MvCameraNode.xlsx file under SDK installation directory
|
||||
int CommandExecute(IN const char* strKey);
|
||||
|
||||
// ch:̽<><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱ<EFBFBD><D1B0><EFBFBD>С(ֻ<><D6BB>GigE<67><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч) | en:Detection network optimal package size(It only works for the GigE camera)
|
||||
int GetOptimalPacketSize(unsigned int* pOptimalPacketSize);
|
||||
|
||||
// ch:ע<><D7A2><EFBFBD><EFBFBD>Ϣ<EFBFBD>쳣<EFBFBD>ص<EFBFBD> | en:Register Message Exception CallBack
|
||||
int RegisterExceptionCallBack(void(__stdcall* cbException)(unsigned int nMsgType, void* pUser), void* pUser);
|
||||
|
||||
// ch:ע<>ᵥ<EFBFBD><E1B5A5><EFBFBD>¼<EFBFBD><C2BC>ص<EFBFBD> | en:Register Event CallBack
|
||||
int RegisterEventCallBack(const char* pEventName, void(__stdcall* cbEvent)(MV_EVENT_OUT_INFO * pEventInfo, void* pUser), void* pUser);
|
||||
|
||||
// ch:ǿ<><C7BF>IP | en:Force IP
|
||||
int ForceIp(unsigned int nIP, unsigned int nSubNetMask, unsigned int nDefaultGateWay);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>IP<49><50>ʽ | en:IP configuration method
|
||||
int SetIpConfig(unsigned int nType);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>紫<EFBFBD><E7B4AB>ģʽ | en:Set Net Transfer Mode
|
||||
int SetNetTransMode(unsigned int nType);
|
||||
|
||||
// ch:<3A><><EFBFBD>ظ<EFBFBD>ʽת<CABD><D7AA> | en:Pixel format conversion
|
||||
int ConvertPixelType(MV_CC_PIXEL_CONVERT_PARAM* pstCvtParam);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>ͼƬ | en:save image
|
||||
int SaveImage(MV_SAVE_IMAGE_PARAM_EX* pstParam);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>ͼƬΪ<C6AC>ļ<EFBFBD> | en:Save the image as a file
|
||||
int SaveImageToFile(MV_SAVE_IMG_TO_FILE_PARAM* pstParam);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>Բ<EFBFBD>θ<EFBFBD><CEB8><EFBFBD><EFBFBD><EFBFBD> | en:Draw circle auxiliary line
|
||||
int DrawCircle(MVCC_CIRCLE_INFO* pCircleInfo);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>θ<EFBFBD><CEB8><EFBFBD><EFBFBD><EFBFBD> | en:Draw lines auxiliary line
|
||||
int DrawLines(MVCC_LINES_INFO* pLinesInfo);
|
||||
|
||||
// <20><>ȡbuffer
|
||||
int ReadBuffer(Mat &image);
|
||||
|
||||
// <20><>ȡbuffer
|
||||
int GetImage(Mat &image,bool FindFlag);
|
||||
|
||||
int setPoints(std::vector<cv::Point> points, cv::Mat &image);
|
||||
std::vector<cv::Point> getPoints(cv::Mat &image, int value);
|
||||
//bool SortByX(Point &v1, Point &v2);
|
||||
//bool SortByY(Point &v1, Point &v2);
|
||||
int GetLineSlope(Mat &src,bool &result,double *slope);
|
||||
int GetGap(Mat &src,bool &result,int *xPos);
|
||||
int getCameraPara(QString DevName);
|
||||
int ClearImageBuffer();
|
||||
int GetCrossPoint(Mat& src, bool left,int * top);
|
||||
int getLinePoints_bottom(Mat& img);
|
||||
int calc_arc_bypoints3(double* points0, double* points1, double* points2, double* center, double* radius);
|
||||
std::vector<cv::Point> getLinePoints(Mat img);
|
||||
private:
|
||||
|
||||
void* m_hDevHandle;
|
||||
unsigned int m_nBufSizeForSaveImage;
|
||||
static CMvCamera* uniqueInstance;
|
||||
CRITICAL_SECTION mCsRead;
|
||||
//<2F><><EFBFBD><EFBFBD>7<EFBFBD><37>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>6<EFBFBD><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>5<EFBFBD><35>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
//<2F><><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ų<EFBFBD><C5B3><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>3<EFBFBD><33>Y<EFBFBD><59><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>ֵ
|
||||
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼֵ
|
||||
//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>ֵ
|
||||
public:
|
||||
int ParaThreshold;
|
||||
int YOffsetPos;
|
||||
int ContinuePointSum;
|
||||
int YPointValueDiff;
|
||||
int YPointValueDiff_6;
|
||||
int ContoursPointSum;
|
||||
int LinePointCount;
|
||||
int SumValueThresh;
|
||||
int StepOfFalse;
|
||||
int StepOfTrue;
|
||||
int ExposureTimeFindEdge;
|
||||
int ExposureTime;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif//_MV_CAMERA_H_
|
||||
85
device/camera/readcameraimagethread.cpp
Normal file
85
device/camera/readcameraimagethread.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "readcameraimagethread.h"
|
||||
|
||||
ReadCameraImageThread::ReadCameraImageThread(QObject *parent)
|
||||
:QThread(parent)
|
||||
{
|
||||
myImage = new QImage();
|
||||
}
|
||||
|
||||
ReadCameraImageThread::~ReadCameraImageThread()
|
||||
{
|
||||
delete myImage;
|
||||
if(NULL == cameraPtr)
|
||||
{
|
||||
delete cameraPtr;
|
||||
}
|
||||
if(NULL == imagePtr)
|
||||
{
|
||||
delete imagePtr;
|
||||
}
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::run()
|
||||
{
|
||||
if(NULL==cameraPtr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(NULL==imagePtr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while(!isInterruptionRequested())
|
||||
{
|
||||
// qDebug()<<"SoftTrigger:"<<cameraPtr->CommandExecute("TriggerSoftware");
|
||||
// qDebug()<<"ReadBuffer:"<<cameraPtr->ReadBuffer(*imagePtr);
|
||||
//cameraPtr->CommandExecute("TriggerSoftware");
|
||||
//cameraPtr->ReadBuffer(*imagePtr);
|
||||
cameraPtr->GetImage(*imagePtr,false);
|
||||
if(isEnableCrossHairLine)
|
||||
{
|
||||
drawCrossHairLine();
|
||||
}
|
||||
|
||||
if(imagePtr->channels()>1)
|
||||
{
|
||||
*myImage = QImage((const unsigned char*)(imagePtr->data),imagePtr->cols,imagePtr->rows,QImage::Format_RGB888);
|
||||
}
|
||||
else
|
||||
{
|
||||
*myImage = QImage((const unsigned char*)(imagePtr->data),imagePtr->cols,imagePtr->rows,QImage::Format_Indexed8);
|
||||
}
|
||||
|
||||
emit messageImageSGL(*myImage);
|
||||
msleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::getCameraPtr(CMvCamera *camera)
|
||||
{
|
||||
cameraPtr = camera;
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::getImagePtr(cv::Mat *image)
|
||||
{
|
||||
imagePtr = image;
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::drawCrossHairLine(Scalar lineColor,int lineWidth)
|
||||
{
|
||||
int heigh = imagePtr->rows;
|
||||
int width = imagePtr->cols;
|
||||
// 水平线
|
||||
Point startPH(0,int(heigh/2)),endPH(int(width),int(heigh/2));
|
||||
line(*imagePtr,startPH,endPH,lineColor,lineWidth);
|
||||
// 垂直线
|
||||
Point startPV(int(width/2),0),endPV(int(width/2),int(heigh));
|
||||
line(*imagePtr,startPV,endPV,lineColor,lineWidth);
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::setEnableCrossHairLine(bool value )
|
||||
{
|
||||
isEnableCrossHairLine = value;
|
||||
|
||||
}
|
||||
38
device/camera/readcameraimagethread.h
Normal file
38
device/camera/readcameraimagethread.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef READCAMERAIMAGETHREAD_H
|
||||
#define READCAMERAIMAGETHREAD_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QImage>
|
||||
#include <QDebug>
|
||||
#include "cmvcamera.h"
|
||||
|
||||
class ReadCameraImageThread:public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ReadCameraImageThread(QObject *parent = nullptr);
|
||||
~ReadCameraImageThread();
|
||||
|
||||
void run();
|
||||
void getCameraPtr(CMvCamera *camera);
|
||||
void getImagePtr(cv::Mat *image);
|
||||
void setEnableCrossHairLine(bool value = true);
|
||||
|
||||
|
||||
signals:
|
||||
void messageSGL();
|
||||
void messageImageSGL(QImage myImage);
|
||||
private:
|
||||
void drawCrossHairLine(Scalar lineColor = Scalar(255,0,0),int lineWidth = 2);
|
||||
|
||||
private:
|
||||
CMvCamera *cameraPtr = nullptr;
|
||||
cv::Mat *imagePtr = nullptr;
|
||||
QImage *myImage = nullptr;
|
||||
bool isEnableCrossHairLine{true};
|
||||
|
||||
};
|
||||
|
||||
#endif // RAADCAMRAIMAGETHREAD_H
|
||||
4468
device/control/acs/ACSC.h
Normal file
4468
device/control/acs/ACSC.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
device/control/acs/ACSCL_x64.LIB
Normal file
BIN
device/control/acs/ACSCL_x64.LIB
Normal file
Binary file not shown.
BIN
device/control/acs/ACSCL_x86.LIB
Normal file
BIN
device/control/acs/ACSCL_x86.LIB
Normal file
Binary file not shown.
22
device/control/acs/ACSVariable.h
Normal file
22
device/control/acs/ACSVariable.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef ACSVARIABLE_H
|
||||
#define ACSVARIABLE_H
|
||||
#define ACSCTL_ALLTOHOMEF_V "toHomeF"
|
||||
#define ACSCTL_XTOHOMEF_V "X_ToHomeF"
|
||||
#define ACSCTL_YTOHOMEF_V "Y_ToHomeF"
|
||||
#define ACSCTL_ZTOHOMEF_V "Z_ToHomeF"
|
||||
#define ACSCTL_ZATOHOMEF_V "ZA_ToHomeF"
|
||||
#define ACSCTL_DTOHOMEF_V "D_ToHomeF"
|
||||
#define ACSCTL_Z0TOHOMEF_V "Z0_ToHomeF"
|
||||
#define ACSCTL_Z2TOHOMEF_V "Z2_ToHomeF"
|
||||
#define ACSCTL_RUNF_V "runF"
|
||||
#define ACSCTL_RCECATADDR_V "RangeSAddr"
|
||||
#define ACSCTL_RSVALUE_V "RangeV"
|
||||
#define ACSCTL_DI1_V "DI1"
|
||||
#define ACSCTL_DI2_V "DI2"
|
||||
#define ACSCTL_DO1_V "DO1"
|
||||
#define ACSCTL_DO2_V "DO2"
|
||||
#define ACSCTL_RSDATA_V "RSData"
|
||||
#define ACSCTL_XPOSDATA_V "xPosData"
|
||||
#define ACSCTL_SAMPTOTALNUM "SampTotalNum"
|
||||
#define ACSCTL_DUILING_F "DuiLingF"
|
||||
#endif // ACSVARIABLE_H
|
||||
764
device/control/acs/acscontroller.cpp
Normal file
764
device/control/acs/acscontroller.cpp
Normal file
@@ -0,0 +1,764 @@
|
||||
#include "acscontroller.h"
|
||||
#include <QString>
|
||||
#include "myexception.h"
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
ACSController::ACSController()
|
||||
{
|
||||
}
|
||||
|
||||
ACSController::~ACSController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ACSController::connect(char* Address, int Port)
|
||||
{
|
||||
// 关闭掉非ACS.Framework.exe应用的连接
|
||||
// terminatePrevConnect();
|
||||
disconnect();
|
||||
m_hComm = ACSC_INVALID;
|
||||
m_hComm = acsc_OpenCommEthernetTCP(Address,Port);
|
||||
// m_hComm 为void* 指针,无效时放置的地址值为-1
|
||||
if(m_hComm == ACSC_INVALID)
|
||||
{
|
||||
throw MyException("网络连接失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::disconnect()
|
||||
{
|
||||
if(m_hComm != ACSC_INVALID)
|
||||
{
|
||||
if(!acsc_CloseComm(m_hComm))
|
||||
{
|
||||
throw MyException("关闭网络连接失败。",acsc_GetLastError());
|
||||
}
|
||||
m_hComm = ACSC_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ACSController::getConnectState()
|
||||
{
|
||||
ACSC_CONNECTION_INFO ConnectionInfo;
|
||||
if(!acsc_GetConnectionInfo(m_hComm,&ConnectionInfo))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ACSController::getBufferRunState(int AxisNum)
|
||||
{
|
||||
int programState;
|
||||
if(!acsc_GetProgramState(m_hComm, AxisNum, &programState, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException(QString("读取buffer%1运行状态失败").arg(AxisNum),acsc_GetLastError());
|
||||
}
|
||||
return bool(programState&ACSC_PST_RUN);
|
||||
}
|
||||
|
||||
bool ACSController::getMotorState(int AxisNum)
|
||||
{
|
||||
int motorState;
|
||||
if(!acsc_GetMotorState(m_hComm, AxisNum, &motorState, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException(QString("读取电机状态失败"),acsc_GetLastError());
|
||||
}
|
||||
return bool(motorState&ACSC_MST_INPOS);
|
||||
}
|
||||
|
||||
void ACSController::terminatePrevConnect()
|
||||
{
|
||||
// 转义字符“\”
|
||||
char pSeperator[] = "\\";
|
||||
char *pToken = nullptr;
|
||||
char pApplicationName[256] = { 0x00, };
|
||||
int nConnections;
|
||||
// 定义一个已连接应用的列表,最大数量为10
|
||||
ACSC_CONNECTION_DESC ConnectionList[MAX_CONNECT_NUM];
|
||||
//10为最大连接数
|
||||
// 第三个参数为实际连接数的指针
|
||||
if(!acsc_GetConnectionsList(ConnectionList, MAX_CONNECT_NUM, &nConnections))
|
||||
{
|
||||
throw MyException("获取连接列表失败。",acsc_GetLastError());
|
||||
}
|
||||
for (int i = 0; i < nConnections; i++)
|
||||
{
|
||||
//原型 char *strtok(char s[], const char *delim);
|
||||
//第一个参数为待分割的字符串,第二个参数为分割符
|
||||
//功能在原字符串第一个分割符处打断,返回值为打断处之前的部分的指针
|
||||
pToken = strtok(ConnectionList[i].Application, pSeperator);
|
||||
//发送格式化输出到PApplicationName
|
||||
//把pToKen指向的文本发送到pApplicationName指向的地址
|
||||
sprintf(pApplicationName, pToken);
|
||||
//只留下应用名,去掉多余的路径信息
|
||||
while (pToken)
|
||||
{
|
||||
// 空指针可以转换为任意类型的指针
|
||||
pToken = strtok(nullptr, pSeperator); // Find next
|
||||
if(pToken != nullptr)
|
||||
{
|
||||
sprintf(pApplicationName, pToken);
|
||||
}
|
||||
}
|
||||
// 关闭掉非ACS.Framework.exe的句柄
|
||||
if((strcmp(pApplicationName, "ACS.Framework.exe")) != 0)
|
||||
{
|
||||
if(!acsc_CloseComm(ConnectionList[i].Handle))
|
||||
{
|
||||
throw MyException("关闭已连接应用失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVector<double> ACSController::getVELParams(int axisNum)
|
||||
{
|
||||
QVector<double> velParams;
|
||||
velParams.append(getVEL(axisNum));
|
||||
velParams.append(getACC(axisNum));
|
||||
velParams.append(getDEC(axisNum));
|
||||
velParams.append(getJERK(axisNum));
|
||||
velParams.append(getKDEC(axisNum));
|
||||
return velParams;
|
||||
}
|
||||
|
||||
double ACSController::getVEL(int axisNum)
|
||||
{
|
||||
double Vel;
|
||||
if(!acsc_GetVelocity(m_hComm, axisNum, &Vel, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取轴速度失败。",acsc_GetLastError());
|
||||
}
|
||||
return Vel;
|
||||
}
|
||||
|
||||
|
||||
double ACSController::getACC(int axisNum)
|
||||
{
|
||||
double Acc;
|
||||
if(!acsc_GetAcceleration(m_hComm, axisNum, &Acc, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取轴加速度失败。",acsc_GetLastError());
|
||||
}
|
||||
return Acc;
|
||||
}
|
||||
|
||||
|
||||
double ACSController::getDEC(int axisNum)
|
||||
{
|
||||
double Dec;
|
||||
if(!acsc_GetDeceleration(m_hComm, axisNum, &Dec, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取减速速度失败。",acsc_GetLastError());
|
||||
}
|
||||
return Dec;
|
||||
}
|
||||
|
||||
|
||||
double ACSController::getJERK(int axisNum)
|
||||
{
|
||||
double Jerk;
|
||||
if(!acsc_GetJerk(m_hComm, axisNum, &Jerk,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取加加速度失败。",acsc_GetLastError());
|
||||
}
|
||||
return Jerk;
|
||||
}
|
||||
|
||||
|
||||
double ACSController::getKDEC(int axisNum)
|
||||
{
|
||||
double KDec;
|
||||
if(!acsc_GetKillDeceleration(m_hComm, axisNum, &KDec, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取减减速度失败。",acsc_GetLastError());
|
||||
}
|
||||
return KDec;
|
||||
}
|
||||
|
||||
void ACSController::setVEL(int axisNum, double Vel)
|
||||
{
|
||||
if(!acsc_SetVelocity(m_hComm, axisNum, Vel,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("设置速度失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::setACC(int axisNum,double Acc)
|
||||
{
|
||||
if(!acsc_SetAcceleration(m_hComm, axisNum, Acc,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("设置加速度失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::setDEC(int axisNum,double Dec)
|
||||
{
|
||||
if(!acsc_SetDeceleration(m_hComm, axisNum, Dec,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("设置减速度失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::setJERK(int axisNum, double Jerk)
|
||||
{
|
||||
if(!acsc_SetJerk(m_hComm, axisNum, Jerk,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("设置加加速度失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::setKDEC(int axisNum,double KDec)
|
||||
{
|
||||
if(!acsc_SetKillDeceleration(m_hComm, axisNum, KDec,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("设置减减速度失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::setVELParams(int axisNum, double Vel)
|
||||
{
|
||||
setVEL(axisNum,Vel);
|
||||
setACC(axisNum,Vel*10);
|
||||
setDEC(axisNum,Vel*10);
|
||||
setJERK(axisNum,Vel*100);
|
||||
setKDEC(axisNum,Vel*100);
|
||||
}
|
||||
|
||||
|
||||
void ACSController::enable(int axisNum)
|
||||
{
|
||||
if(!acsc_Enable(m_hComm, axisNum, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("使能失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::disable(int axisNum)
|
||||
{
|
||||
if(!acsc_Disable(m_hComm, axisNum, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("取消使能失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
if(!acsc_WaitMotorEnabled(m_hComm, axisNum, 0, TIMEOUT_MOTOR_ENABLED))
|
||||
{
|
||||
throw MyException("等待取消使能失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ACSController::halt(int axisNum)
|
||||
{
|
||||
// 减速停止
|
||||
if(!acsc_Halt(m_hComm, axisNum, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("停止轴运动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ACSController::jogNeg(int axisNum)
|
||||
{
|
||||
// Jog command without velocity
|
||||
if(!acsc_Jog(m_hComm, 0, axisNum, ACSC_NEGATIVE_DIRECTION, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("负方向点动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ACSController::jogNeg(int axisNum, double vel)
|
||||
{
|
||||
// Jog command with velocity
|
||||
if(!acsc_Jog(m_hComm, ACSC_AMF_VELOCITY, axisNum, vel * (-1), ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("负方向点动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::jogPos(int axisNum)
|
||||
{
|
||||
if(!acsc_Jog(m_hComm, 0, axisNum, ACSC_POSITIVE_DIRECTION, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("正方向点动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ACSController::jogPos(int axisNum,double vel)
|
||||
{
|
||||
if(!acsc_Jog(m_hComm, ACSC_AMF_VELOCITY, axisNum, vel, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("正方向点动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ACSController::ABSToPoint(int axisNum,double point)
|
||||
{
|
||||
|
||||
//第二个参数‘0’,绝对;立即执行,2 为相对的
|
||||
if(!acsc_ToPoint(m_hComm,0,axisNum, point,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("点到点绝对运动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::ABSToPoint(int axisNum1,double point1,int axisNum2,double point2)
|
||||
{
|
||||
//第二个参数‘0’,绝对;立即执行,2 为相对的
|
||||
int Axes[] = {axisNum1,axisNum2,-1};
|
||||
double Points[] = {point1,point2};
|
||||
if(!acsc_ToPointM(m_hComm,0,Axes, Points,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("点到点绝对运动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::RToPointNeg(int axisNum,double point)
|
||||
{
|
||||
// 移动相对位置(从当前位置)
|
||||
if(!acsc_ToPoint(m_hComm, ACSC_AMF_RELATIVE,axisNum, point*(-1),ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("点到点相对运动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ACSController::RToPointPos(int axisNum,double point)
|
||||
{
|
||||
// Move relative position (from current position)
|
||||
if(!acsc_ToPoint(m_hComm, ACSC_AMF_RELATIVE, axisNum, point, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("点到点相对运动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::RToPoint(int axisNum1,double point1,int axisNum2,double point2)
|
||||
{
|
||||
//第二个参数‘0’,绝对;立即执行,2 为相对的
|
||||
int Axes[] = {axisNum1,axisNum2,-1};
|
||||
double Points[] = {point1,point2};
|
||||
if(!acsc_ToPointM(m_hComm,ACSC_AMF_RELATIVE,Axes, Points,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("点到点相对运动失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
double ACSController::getFPOS(int AxisNum)
|
||||
{
|
||||
double FPos;
|
||||
char vName[] = "FPOS";
|
||||
if(!acsc_ReadReal(m_hComm, -1, vName, AxisNum, AxisNum, -1, -1, &FPos, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取轴当前位置失败。",acsc_GetLastError());
|
||||
}
|
||||
return FPos;
|
||||
}
|
||||
void ACSController::SetFPOS(int AxisNum,double fPos)
|
||||
{
|
||||
if(!acsc_SetFPosition(m_hComm, AxisNum, fPos, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("设置轴当前位置失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ACSController::getEnable(int AxisNum)
|
||||
{
|
||||
double mst = getAxesMST(AxisNum);
|
||||
return bool(int(mst)&ACSC_MST_ENABLE);
|
||||
}
|
||||
|
||||
LIMIT_STATE ACSController::getAxesLimitState(int AxisNum)
|
||||
{
|
||||
int m_FaultMask;
|
||||
int m_MotorFault;
|
||||
LIMIT_STATE temp = NORMAL;
|
||||
if(!acsc_GetFaultMask(m_hComm, AxisNum, &m_FaultMask, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取FaultMask失败。",acsc_GetLastError());
|
||||
}
|
||||
if(!acsc_GetFault(m_hComm, AxisNum, &m_MotorFault, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取Fault失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
if(m_MotorFault & ACSC_SAFETY_SRL)
|
||||
temp = RIGHT_SLIMIT;
|
||||
if(m_MotorFault& ACSC_SAFETY_SLL)
|
||||
temp = LEFT_SLIMIT;
|
||||
if(m_MotorFault & ACSC_SAFETY_LL)
|
||||
temp = LEFT_LIMIT;
|
||||
if(m_MotorFault& ACSC_SAFETY_RL)
|
||||
temp = RIGHT_LIMIT;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
bool ACSController::getEmergencyStopState()
|
||||
{
|
||||
int m_EmergencyMask;
|
||||
int m_EmergencyFault;
|
||||
if(!acsc_GetFaultMask(m_hComm, ACSC_NONE, &m_EmergencyMask, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取FaultMask失败。",acsc_GetLastError());
|
||||
}
|
||||
if(!acsc_GetFault(m_hComm, ACSC_NONE, &m_EmergencyFault, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取Fault失败。",acsc_GetLastError());
|
||||
}
|
||||
if(m_EmergencyMask & ACSC_SAFETY_ES)
|
||||
return m_EmergencyFault & ACSC_SAFETY_ES;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
double ACSController::getAxesMST(int AxisNum)
|
||||
{
|
||||
double reValue;
|
||||
char vName[] = "MST";
|
||||
if(!acsc_ReadReal(m_hComm, -1, vName, AxisNum, AxisNum, -1, -1, &reValue,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取轴MST失败。",acsc_GetLastError());
|
||||
}
|
||||
return reValue;
|
||||
}
|
||||
|
||||
|
||||
void ACSController::runBuffer(int bufferNum)
|
||||
{
|
||||
// Run buffer program from first line 从第一行开始运行buffer程序
|
||||
// 第三个参数为程序label标签
|
||||
if(!acsc_RunBuffer(m_hComm, bufferNum, nullptr, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取buffer运行状态失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::stopBuffer(int bufferNum)
|
||||
{
|
||||
|
||||
if(!acsc_StopBuffer(m_hComm, bufferNum, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("停止buffer失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ACSController::SuspendBuffer(int bufferNum)
|
||||
{
|
||||
|
||||
if(!acsc_SuspendBuffer(m_hComm, bufferNum, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("暂停buffer失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ACSController::appendBuffer(char* codeText,int bufferNum)
|
||||
{
|
||||
// 无符号整型和有符号整型转换时,考虑最高位是否为1,如果为1则转换值会变
|
||||
if(!acsc_AppendBuffer(m_hComm,bufferNum,codeText,int(strlen(codeText)),ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("追加buffer代码失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::clearBuffer(int bufferNum)
|
||||
{
|
||||
if(!acsc_ClearBuffer(m_hComm,bufferNum,1,100000,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("清除buffer代码失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::compileBuffer(int bufferNum)
|
||||
{
|
||||
if(!acsc_CompileBuffer(m_hComm,bufferNum, ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("编译buffer代码失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::loadBuffer(int bufferNum,char* program)
|
||||
{
|
||||
if(!acsc_LoadBuffer(m_hComm,bufferNum,program,int(strlen(program)),ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("下载buffer代码失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::loadBuffersFromFile(char* fileName)
|
||||
{
|
||||
if(!acsc_LoadBuffersFromFile(m_hComm,fileName,ACSC_SYNCHRONOUS))//fileName
|
||||
{
|
||||
|
||||
throw MyException("把文件中代码下载到buffer失败。",acsc_GetLastError());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::suspendBuffer(int bufferNum)
|
||||
{
|
||||
if(!acsc_SuspendBuffer(m_hComm,bufferNum,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("暂停buffer运行失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QByteArray ACSController::uploadBuffer(int bufferNum)
|
||||
{
|
||||
char bufferData[10000];
|
||||
int Received;
|
||||
if(!acsc_UploadBuffer(m_hComm,bufferNum,0,bufferData,10000,&Received,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("上传buffer代码失败。",acsc_GetLastError());
|
||||
}
|
||||
return QByteArray(bufferData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::setDO(int port,int bit,bool value)
|
||||
{
|
||||
if(!acsc_SetOutput(m_hComm,port,bit,int(value),ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("设置DO失败。",acsc_GetLastError());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool ACSController::getDO(int port,int bit)
|
||||
{
|
||||
int value=0;
|
||||
if(!acsc_GetOutput(m_hComm,port,bit,&value,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取DO失败。",acsc_GetLastError());
|
||||
|
||||
}
|
||||
|
||||
return bool(value);
|
||||
}
|
||||
|
||||
|
||||
bool ACSController::getDI(int port,int bit)
|
||||
{
|
||||
int state;
|
||||
// 第2参数为port
|
||||
// 第3个参数为bit
|
||||
// 第4个参数为指向返回值的指针
|
||||
if(!acsc_GetInput(m_hComm,port,bit,&state,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取DI失败。",acsc_GetLastError());
|
||||
}
|
||||
return bool(state);
|
||||
}
|
||||
|
||||
|
||||
double ACSController::getGlobalReal(char* realName)
|
||||
{
|
||||
double reValue;
|
||||
if(!acsc_ReadReal(m_hComm,ACSC_NONE,realName,0,0,-1,-1,&reValue,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("读取变量失败。",acsc_GetLastError());
|
||||
}
|
||||
return reValue;
|
||||
}
|
||||
|
||||
QVector<double> ACSController::getGlobalReal(char* realName,int bufNum,int from1,int end1)
|
||||
{
|
||||
QVector<double> reValue(end1-from1+1);
|
||||
double *reValue_ptr = reValue.data();
|
||||
if(!acsc_ReadReal(m_hComm,bufNum,realName,from1,end1,-1,-1,reValue_ptr,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("读取变量失败。",acsc_GetLastError());
|
||||
}
|
||||
return reValue;
|
||||
}
|
||||
|
||||
void ACSController::setGlobalReal(char* realName,double value)
|
||||
{
|
||||
if(!acsc_WriteReal(m_hComm,ACSC_NONE,realName,0,0,-1,-1,&value,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("写变量失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::setGlobalReal(char* realName,int from1,int end1,QVector<double> value)
|
||||
{
|
||||
double *value_ptr = value.data();
|
||||
if(!acsc_WriteReal(m_hComm,ACSC_NONE,realName,from1,end1,-1,-1,value_ptr,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("写变量失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::setGlobalReal(char* realName,int from1,int end1,int from2,int end2,double* value)
|
||||
{
|
||||
if(!acsc_WriteReal(m_hComm,ACSC_NONE,realName,from1,end1,from2,end2,value,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
int errorCode =acsc_GetLastError();
|
||||
throw MyException(QString("写全局浮点变量%1失败。").arg(QString(realName)),errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ACSController::getGlobalInt(char *name)
|
||||
{
|
||||
int temp;
|
||||
if(!acsc_ReadInteger(m_hComm,ACSC_NONE,name,0,0,-1,-1,&temp,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("读变量值失败。",acsc_GetLastError());
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
// 读取多个全局整型
|
||||
QVector<int> ACSController::getGlobalInt(char* name,int from1,int end1)
|
||||
{
|
||||
QVector<int> reValue(end1-from1+1);
|
||||
int *reValue_ptr = reValue.data();
|
||||
if(!acsc_ReadInteger(m_hComm,ACSC_NONE,name,from1,end1,-1,-1,reValue_ptr,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("读变量值失败。",acsc_GetLastError());
|
||||
}
|
||||
return reValue;
|
||||
}
|
||||
|
||||
void ACSController::setGlobalInt(char* intName,int value)
|
||||
{
|
||||
if(!acsc_WriteInteger(m_hComm,ACSC_NONE,intName,0,0,-1,-1,&value,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("写变量失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::setGlobalInt(char* intName,int from1,int to1,QVector<int> value)
|
||||
{
|
||||
int *value_ptr = value.data();
|
||||
if(!acsc_WriteInteger(m_hComm,ACSC_NONE,intName,from1,to1,-1,-1,value_ptr,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("写变量失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ACSController::getBufferLines(int bufferNum)
|
||||
{
|
||||
int temp[10];
|
||||
char vName[] = "PLINES";
|
||||
if(!acsc_ReadInteger(m_hComm,ACSC_NONE,vName,0,9,-1,-1,temp,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取buffer代码行数失败。",acsc_GetLastError());
|
||||
}
|
||||
return temp[bufferNum];
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ACSController::mapEtherCatInput(int offset,QString vbName)
|
||||
{
|
||||
QByteArray qbVbName = vbName.toLatin1();
|
||||
char* cVBName = qbVbName.data();
|
||||
if(! acsc_MapEtherCATInput(m_hComm,0,offset,cVBName,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("EtherCat地址映射失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::mapEtherCatOutput(int offset,QString vbName)
|
||||
{
|
||||
QByteArray qbVbName = vbName.toLatin1();
|
||||
char* cVBName = qbVbName.data();
|
||||
if(!acsc_MapEtherCATOutput(m_hComm,0,offset,cVBName,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("EtherCat地址映射失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::resetMapEtherCatInputOutput()
|
||||
{
|
||||
if(!acsc_UnmapEtherCATInputsOutputs(m_hComm,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("重置EtherCat地址映射失败。",acsc_GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void ACSController::disableComp(int axisNum)
|
||||
{
|
||||
int temp;
|
||||
const int DISABLE_CONNECT_MASK = 131072;
|
||||
char vName[] = "MFLAGS";
|
||||
if(!acsc_ReadInteger(m_hComm,ACSC_NONE,vName,axisNum,axisNum,-1,-1,&temp,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("禁用补偿失败。",acsc_GetLastError());
|
||||
}
|
||||
temp = (temp|DISABLE_CONNECT_MASK);
|
||||
if(!acsc_WriteInteger(m_hComm,ACSC_NONE,vName,axisNum,axisNum,-1,-1,&temp,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("禁用补偿失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
if(!acsc_ReadInteger(m_hComm,ACSC_NONE,vName,axisNum,axisNum,-1,-1,&temp,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("禁用补偿失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int ACSController::getProgramError(int bufferNum)
|
||||
{
|
||||
int errorCode;
|
||||
if(!acsc_GetProgramError(m_hComm,bufferNum,&errorCode,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("禁用补偿失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
int ACSController::getMotorError(int AxisNum)
|
||||
{
|
||||
int errorCode;
|
||||
if(!acsc_GetMotorError(m_hComm,AxisNum,&errorCode,ACSC_SYNCHRONOUS))
|
||||
{
|
||||
throw MyException("获取电机状态失败。",acsc_GetLastError());
|
||||
}
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
||||
bool ACSController::getMoveState(int AxisNum)
|
||||
{
|
||||
double mst = getAxesMST(AxisNum);//
|
||||
return bool(int(mst)&ACSC_MST_MOVE);
|
||||
}
|
||||
|
||||
173
device/control/acs/acscontroller.h
Normal file
173
device/control/acs/acscontroller.h
Normal file
@@ -0,0 +1,173 @@
|
||||
#ifndef ACSCONTROLLER_H
|
||||
#define ACSCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "ACSC.h"
|
||||
|
||||
#include <QVector>
|
||||
#include "myexception.h"
|
||||
#include <QMap>
|
||||
#include "base.h"
|
||||
|
||||
#define TIMEOUT_MOTOR_ENABLED 3000 // 使能电机超时
|
||||
#define TIMEOUT_MOTOR_DISABLE 3000 // 关闭电机使能超时
|
||||
#define MAX_CONNECT_NUM 10
|
||||
|
||||
|
||||
class ACSController:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
~ACSController();
|
||||
ACSController();
|
||||
|
||||
void connect(char* Address, int Port);
|
||||
void disconnect();
|
||||
|
||||
// 获取连接状态
|
||||
bool getConnectState();
|
||||
|
||||
// 获取速度参数
|
||||
QVector<double> getVELParams(int axisNum);
|
||||
|
||||
double getVEL(int axisNum);
|
||||
double getACC(int axisNum);
|
||||
double getDEC(int axisNum);
|
||||
double getJERK(int axisNum);
|
||||
double getKDEC(int axisNum);
|
||||
|
||||
// 设置速度参数
|
||||
void setVEL(int axisNum,double Vel);
|
||||
void setACC(int axisNum,double Acc);
|
||||
void setDEC(int axisNum,double Dec);
|
||||
void setJERK(int axisNum,double Jerk);
|
||||
void setKDEC(int axisNum,double KDec);
|
||||
|
||||
// 设置指定轴的速度参数的便捷方法
|
||||
void setVELParams(int axisNum,double Vel);
|
||||
|
||||
void enable(int axisNum);
|
||||
void disable(int axisNum);
|
||||
void halt(int axisNum);
|
||||
|
||||
//JOG
|
||||
// 负方向
|
||||
void jogNeg(int axisNum);
|
||||
void jogNeg(int axisNum, double vel);
|
||||
// 正方向
|
||||
void jogPos(int axisNum);
|
||||
void jogPos(int axisNum,double vel);
|
||||
|
||||
//PTP
|
||||
// 绝对
|
||||
void ABSToPoint(int axisNum,double point);
|
||||
// 两个轴绝对
|
||||
void ABSToPoint(int axisNum1,double point1,int axisNum2,double point2);
|
||||
// 相对 负方向
|
||||
void RToPointNeg(int axisNum,double point);
|
||||
// 相对 正方向
|
||||
void RToPointPos(int axisNum,double point);
|
||||
|
||||
// 两个轴相对
|
||||
void RToPoint(int axisNum1,double point1,int axisNum2,double point2);
|
||||
|
||||
// 获取当前反馈位置
|
||||
double getFPOS(int AxisNum);
|
||||
void SetFPOS(int AxisNum,double fPos);
|
||||
|
||||
// 获取使能状态
|
||||
bool getEnable(int AxisNum);
|
||||
|
||||
LIMIT_STATE getAxesLimitState(int AxisNum);
|
||||
|
||||
// 获取急停状态
|
||||
bool getEmergencyStopState();
|
||||
|
||||
// 运行指定buffer
|
||||
void runBuffer(int bufferNum);
|
||||
// 暂停指定buffer代码运行
|
||||
void SuspendBuffer(int bufferNum);
|
||||
// 停止指定buffer代码运行
|
||||
void stopBuffer(int bufferNum);
|
||||
// 添加代码到指定buffer
|
||||
void appendBuffer(char* codeText,int bufferNum);
|
||||
// 清除指定buffer代码
|
||||
void clearBuffer(int bufferNum);
|
||||
// 编译指定buffer代码
|
||||
void compileBuffer(int bufferNum);
|
||||
// 清空并下载代码到指定buffer
|
||||
void loadBuffer(int bufferNum,char* program);
|
||||
// 把文件中代码加载到指定buffer
|
||||
void loadBuffersFromFile(char* fileName);
|
||||
// 暂停buffer代码运行
|
||||
void suspendBuffer(int bufferNum);
|
||||
// 上传指定buffer程序
|
||||
QByteArray uploadBuffer(int bufferNum);
|
||||
|
||||
bool getBufferRunState(int AxisNum);
|
||||
|
||||
bool getMotorState(int AxisNum);
|
||||
|
||||
|
||||
// 设置DO
|
||||
void setDO(int port,int bit,bool value);
|
||||
// 读取DO
|
||||
bool getDO(int port,int bit);
|
||||
// 读取DI
|
||||
bool getDI(int port,int bit);
|
||||
|
||||
|
||||
// 读取单个全局实数变量
|
||||
double getGlobalReal(char* realName);
|
||||
// 读取实数全局变量
|
||||
QVector<double> getGlobalReal(char* realName,int bufNum,int from1,int end1);
|
||||
// 写单个全局实数变量
|
||||
void setGlobalReal(char* realName,double value);
|
||||
// 写实数全局变量
|
||||
void setGlobalReal(char* realName,int from1,int end1,QVector<double> value);
|
||||
|
||||
void setGlobalReal(char* realName,int from1,int end1,int from2,int end2,double* value);
|
||||
|
||||
|
||||
|
||||
|
||||
// 读取单个全局整型
|
||||
int getGlobalInt(char* name);
|
||||
// 读取多个全局整型
|
||||
QVector<int> getGlobalInt(char* name,int from1,int end1);
|
||||
// 写单个全局整型
|
||||
void setGlobalInt(char* name,int value);
|
||||
// 写多个全局整型
|
||||
void setGlobalInt(char* name,int from1,int end1,QVector<int> value);
|
||||
|
||||
|
||||
// 读取指定buffer代码总行数
|
||||
int getBufferLines(int bufferNum);
|
||||
// EtherCAT 输入变量和变量映射
|
||||
void mapEtherCatInput(int offset,QString vbName);
|
||||
// EtherCAT 输出变量和变量映射
|
||||
void mapEtherCatOutput(int offset,QString vbName);
|
||||
// 重置EthCat映射
|
||||
void resetMapEtherCatInputOutput();
|
||||
// 禁用补偿
|
||||
void disableComp(int axisNum);
|
||||
|
||||
int getProgramError(int bufferNum);
|
||||
|
||||
int getMotorError(int AxisNum);
|
||||
|
||||
bool getMoveState(int AxisNum);
|
||||
|
||||
private:
|
||||
void terminatePrevConnect();
|
||||
double getAxesMST(int AxisNum);
|
||||
|
||||
private:
|
||||
/* void* m_hComm = (void*) -1;
|
||||
* m_hComm 中用于存放地址的空间存放了-1
|
||||
*/
|
||||
HANDLE m_hComm= HANDLE(-1);
|
||||
};
|
||||
|
||||
#endif // ACSCONTROLLER_H
|
||||
28
device/control/acs/buffercode/buffer0autoexecode.cpp
Normal file
28
device/control/acs/buffercode/buffer0autoexecode.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "buffer0autoexecode.h"
|
||||
|
||||
Buffer0AutoExeCode::Buffer0AutoExeCode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString Buffer0AutoExeCode::getCode()
|
||||
{
|
||||
QString code("\n");
|
||||
/*
|
||||
* ECUNMAPIN 此函数用于将ECIN定义的所有映射重置为特定偏移量
|
||||
* ECIN 将EtherCAT偏移地址的值映射到变量
|
||||
*/
|
||||
code+=
|
||||
"AUTOEXEC:\n"
|
||||
"ECUNMAPIN(RangeSAddr)\n"
|
||||
// 禁用报警
|
||||
"SAFETYCONF ALL,#NT,\"-\"\n"
|
||||
"ECIN(RangeSAddr, RangeVInt)\n"
|
||||
"WAIT 50\n"
|
||||
"WHILE 1\n"
|
||||
// 测距值换算为mm
|
||||
"RangeV=RangeVInt/10000\n"
|
||||
"END\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
12
device/control/acs/buffercode/buffer0autoexecode.h
Normal file
12
device/control/acs/buffercode/buffer0autoexecode.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef BUFFER0AUTOEXECODE_H
|
||||
#define BUFFER0AUTOEXECODE_H
|
||||
#include<QString>
|
||||
|
||||
class Buffer0AutoExeCode
|
||||
{
|
||||
public:
|
||||
Buffer0AutoExeCode();
|
||||
QString getCode();
|
||||
};
|
||||
|
||||
#endif // BUFFER0AUTOEXECODE_H
|
||||
190
device/control/acs/buffercode/csscancode.cpp
Normal file
190
device/control/acs/buffercode/csscancode.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
#include "csscancode.h"
|
||||
|
||||
CSScanCode::CSScanCode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSScanCode::~CSScanCode()
|
||||
{
|
||||
|
||||
}
|
||||
void CSScanCode::setRSToZeroXPos(double value)
|
||||
{
|
||||
RSToZeroXPos = value;
|
||||
}
|
||||
void CSScanCode::setRSToZeroYPos(double value)
|
||||
{
|
||||
RSToZeroYPos = value;
|
||||
}
|
||||
void CSScanCode::setRSToZeroZ1Pos(double value)
|
||||
{
|
||||
RSToZeroZ1Pos = value;
|
||||
}
|
||||
|
||||
void CSScanCode::setXWorkRange(double value)
|
||||
{
|
||||
xWorkRange = value;
|
||||
}
|
||||
|
||||
void CSScanCode::setYWorkRange(double value)
|
||||
{
|
||||
yWorkRange = value;
|
||||
}
|
||||
|
||||
void CSScanCode::setXSampInterval(double value)
|
||||
{
|
||||
xSampInterval = value;
|
||||
}
|
||||
|
||||
void CSScanCode::setYSampInterval(double value)
|
||||
{
|
||||
ySampInterval = value;
|
||||
}
|
||||
|
||||
int CSScanCode::getSampTotalNum()
|
||||
{
|
||||
int xLineSegmentCounts,yLineSegmentCounts;
|
||||
// y线段数比x线段数多1
|
||||
yLineSegmentCounts = int(yWorkRange/ySampInterval);
|
||||
xLineSegmentCounts = yLineSegmentCounts+1;
|
||||
int xSampCounts,ySampCounts;
|
||||
xSampCounts = (accDecSampCount+int(xWorkRange*xNumberOfUnitSamples))*xLineSegmentCounts;
|
||||
ySampCounts = int(yWorkRange*yNumberOfUnitSamples)+yNumberOfLineSegmentSamples*(yLineSegmentCounts-1);
|
||||
return ySampCounts + xSampCounts;
|
||||
}
|
||||
|
||||
|
||||
QString CSScanCode::getCode()
|
||||
{
|
||||
QString code = QString("GLOBAL REAL scanData(2)(%1),RSData(%1),xPosData(%1),xWorkRange\n").arg(getSampTotalNum())+
|
||||
QString("GLOBAL INT SampTotalNum=%1\n").arg(getSampTotalNum())+
|
||||
QString("GLOBAL REAL RSToZeroXPos=%1,RSToZeroYPos=%2\n").arg(RSToZeroXPos).arg(RSToZeroYPos)+
|
||||
//QString("GLOBAL REAL RSToZeroZ1Pos=%1\n").arg(RSToZeroZ1Pos)+
|
||||
"REAL xPos,yPos\n"+
|
||||
//"REAL xStartPos,yStartPos\n"+
|
||||
QString("REAL yInterval = %1\n").arg(ySampInterval)+
|
||||
"ENABLE (X,Y)\n"
|
||||
// 禁用Z1轴补偿
|
||||
"MFLAGS(Z).#DEFCON=1\n"
|
||||
// 停止buffer0运行
|
||||
"STOP 0\n"
|
||||
"START 0,1\n"+
|
||||
// 初始化数组
|
||||
QString("FILL(%1,scanData,0,0,0,%2); FILL(0, scanData,1,1,0,%2)\n").arg(rangeInitValue).arg(getSampTotalNum()-1)+
|
||||
//"ACC(X)=8000;DEC(X)=8000;KDEC(X)=120000;JERK(X)=120000; ACC(Y)=8000;DEC(Y)=8000;KDEC(Y)=120000;JERK(Y)=120000;\n "
|
||||
"ACC(X)=8000;DEC(X)=8000;KDEC(X)=120000;JERK(X)=120000; ACC(Y)=500;DEC(Y)=500;KDEC(Y)=5000;JERK(Y)=5000;\n "
|
||||
// 设置X、Y轴到位精度,会对INPOS什么时候变为1有影响
|
||||
"TARGRAD(X) = 0.0001; TARGRAD(Y) = 0.0001\n"
|
||||
"WAIT 200\n"+
|
||||
//"xStartPos = FPOS(X);yStartPos = FPOS(Y)\n"+
|
||||
// 设置X,Y轴起始位置。Y轴的起始位置把加减速段考虑进去
|
||||
QString("xPos = FPOS(X)-%1;yPos = FPOS(Y)\n").arg(AccDecDist)+
|
||||
// X、Y轴走到起始位置,速度为60mm/s
|
||||
"PTP/EV (X,Y),xPos,yPos,100\n"+
|
||||
// Y轴的工作范围等于设置的工作范围+加速距离+减速距离
|
||||
QString("xWorkRange = %1\n").arg(xWorkRange+2*AccDecDist)+
|
||||
// 定义同步采集,采集测距传感器值、Y轴坐标,采集间隔为0.1ms,采集总数为sampTotalNum
|
||||
QString("DC/s X,scanData,%1,1,RangeV,FPOS(X)\n").arg(getSampTotalNum())+
|
||||
// 定义分段运动,起始位置为xStart,yStart,结束速度为vel
|
||||
QString("XSEG/vy (X,Y),xPos,yPos,%1\n").arg(xAxisVel)+
|
||||
// 循环次数等于Y线段数
|
||||
QString("LOOP %1\n").arg(yWorkRange/ySampInterval+1)+
|
||||
// X轴位置不变,Y轴移动工作范围距离
|
||||
// 第1段运动,Y轴向正方向移动(测距头向Y负方向移动)
|
||||
"xPos = xPos+xWorkRange\n"+
|
||||
QString("LINE/v (X,Y),xPos,yPos,%1\n").arg(xAxisVel)+
|
||||
// Y轴位置不变,X轴向正向移动一个步距
|
||||
"yPos = yPos+yInterval\n"+
|
||||
|
||||
// /v参数定义当前和后续线段的速度,/f 定义当前线段结束时的速度
|
||||
// 意思就是说X轴运动时速度为20,Y轴运动时速度为100
|
||||
QString("LINE/v (X,Y),xPos,yPos,%1\n").arg(yAxisVel)+
|
||||
//QString("LINE/vf (X,Y),xPos,yPos,%1,%2\n").arg(xAxisVel).arg(yAxisVel)+
|
||||
|
||||
// Y轴移动工作距离范围取反
|
||||
"xWorkRange=(-1)*xWorkRange\n"
|
||||
"END\n"
|
||||
"ENDS (X,Y)\n"
|
||||
|
||||
// 阻塞,等待多段运动结束
|
||||
"TILL ^AST(X).5 & ^AST(Y).5 & GSEG(Y) = -1\n"
|
||||
// 停止采集
|
||||
"STOPDC/s X\n"
|
||||
"INT validDataEndIndex\n"+
|
||||
// 在0~(sampTotalNum-1)范围内找到第一个最大值并返回其索引(最大值为数组初始化值,索引为采集的测距值最后一个的索引+1)
|
||||
QString("validDataEndIndex=MAXI(scanData,0,0,0,%1)\n").arg(getSampTotalNum()-1)+
|
||||
// 把采集的测距值拷贝到 RSData数组中,把采集的Y轴的坐标放到xPosData数组中
|
||||
"COPY(scanData,RSData,0,0,0,validDataEndIndex,0,validDataEndIndex); COPY(scanData,xPosData,1,1,0,validDataEndIndex,0,validDataEndIndex)\n"
|
||||
"PTP/EV (X,Y),RSToZeroXPos,RSToZeroYPos,100\n"
|
||||
//"PTP/ERV (Z),RSToZeroZ1Pos,1\n"
|
||||
"WAIT 200\n"
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
//{
|
||||
// QString code = QString("GLOBAL REAL scanData(2)(%1),RSData(%1),yPosData(%1),yWorkRange\n").arg(getSampTotalNum())+
|
||||
// QString("GLOBAL INT SampTotalNum=%1\n").arg(getSampTotalNum())+
|
||||
// QString("GLOBAL REAL RSToZeroXPos=%1,RSToZeroYPos=%2\n").arg(RSToZeroXPos).arg(RSToZeroYPos)+
|
||||
// "REAL xPos,yPos\n"+
|
||||
// //"REAL xStartPos,yStartPos\n"+
|
||||
// QString("REAL xInterval = %1\n").arg(xSampInterval)+
|
||||
// "ENABLE (X,Y)\n"
|
||||
// // 禁用Z1轴补偿
|
||||
// "MFLAGS(Z).#DEFCON=1\n"
|
||||
// // 停止buffer0运行
|
||||
// "STOP 0\n"
|
||||
// "START 0,1\n"+
|
||||
// // 初始化数组
|
||||
// QString("FILL(%1,scanData,0,0,0,%2); FILL(0, scanData,1,1,0,%2)\n").arg(rangeInitValue).arg(getSampTotalNum()-1)+
|
||||
// //"ACC(X)=8000;DEC(X)=8000;KDEC(X)=120000;JERK(X)=120000; ACC(Y)=8000;DEC(Y)=8000;KDEC(Y)=120000;JERK(Y)=120000;\n "
|
||||
// "ACC(X)=5000;DEC(X)=5000;KDEC(X)=5000;JERK(X)=5000; ACC(Y)=8000;DEC(Y)=8000;KDEC(Y)=120000;JERK(Y)=120000;\n "
|
||||
// // 设置X、Y轴到位精度,会对INPOS什么时候变为1有影响
|
||||
// "TARGRAD(X) = 0.0001; TARGRAD(Y) = 0.0001\n"
|
||||
// "WAIT 200\n"+
|
||||
// //"xStartPos = FPOS(X);yStartPos = FPOS(Y)\n"+
|
||||
// // 设置X,Y轴起始位置。Y轴的起始位置把加减速段考虑进去
|
||||
// QString("xPos = FPOS(X);yPos = FPOS(Y)-%1\n").arg(AccDecDist)+
|
||||
// // X、Y轴走到起始位置,速度为60mm/s
|
||||
// "PTP/EV (X,Y),xPos,yPos,60\n"+
|
||||
// // Y轴的工作范围等于设置的工作范围+加速距离+减速距离
|
||||
// QString("yWorkRange = %1\n").arg(yWorkRange+2*AccDecDist)+
|
||||
// // 定义同步采集,采集测距传感器值、Y轴坐标,采集间隔为0.1ms,采集总数为sampTotalNum
|
||||
// QString("DC/s Y,scanData,%1,1,RangeV,FPOS(Y)\n").arg(getSampTotalNum())+
|
||||
// // 定义分段运动,起始位置为xStart,yStart,结束速度为vel
|
||||
// QString("XSEG/vy (X,Y),xPos,yPos,%1\n").arg(yAxisVel)+
|
||||
// // 循环次数等于Y线段数
|
||||
// QString("LOOP %1\n").arg(xWorkRange/xSampInterval+1)+
|
||||
// // X轴位置不变,Y轴移动工作范围距离
|
||||
// // 第1段运动,Y轴向正方向移动(测距头向Y负方向移动)
|
||||
// "yPos = yPos+yWorkRange\n"+
|
||||
// QString("LINE/v (X,Y),xPos,yPos,%1\n").arg(yAxisVel)+
|
||||
// // Y轴位置不变,X轴向正向移动一个步距
|
||||
// "xPos = xPos+xInterval\n"+
|
||||
|
||||
// // /v参数定义当前和后续线段的速度,/f 定义当前线段结束时的速度
|
||||
// // 意思就是说X轴运动时速度为20,Y轴运动时速度为100
|
||||
// QString("LINE/vf (X,Y),xPos,yPos,%1,%2\n").arg(xAxisVel).arg(yAxisVel)+
|
||||
|
||||
// // Y轴移动工作距离范围取反
|
||||
// "yWorkRange=(-1)*yWorkRange\n"
|
||||
// "END\n"
|
||||
// "ENDS (X,Y)\n"
|
||||
|
||||
// // 阻塞,等待多段运动结束
|
||||
// "TILL ^AST(Y).5 & ^AST(X).5 & GSEG(X) = -1\n"
|
||||
// // 停止采集
|
||||
// "STOPDC/s Y\n"
|
||||
// "INT validDataEndIndex\n"+
|
||||
// // 在0~(sampTotalNum-1)范围内找到第一个最大值并返回其索引(最大值为数组初始化值,索引为采集的测距值最后一个的索引+1)
|
||||
// QString("validDataEndIndex=MAXI(scanData,0,0,0,%1)\n").arg(getSampTotalNum()-1)+
|
||||
// // 把采集的测距值拷贝到 RSData数组中,把采集的Y轴的坐标放到yPosData数组中
|
||||
// "COPY(scanData,RSData,0,0,0,validDataEndIndex,0,validDataEndIndex); COPY(scanData,yPosData,1,1,0,validDataEndIndex,0,validDataEndIndex)\n"
|
||||
// "PTP/EV (X,Y),RSToZeroXPos,RSToZeroYPos,60\n"
|
||||
// "runF = 1\n"
|
||||
// "STOP";
|
||||
// return code;
|
||||
//}
|
||||
57
device/control/acs/buffercode/csscancode.h
Normal file
57
device/control/acs/buffercode/csscancode.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef CSSCANCODE_H
|
||||
#define CSSCANCODE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
|
||||
class CSScanCode
|
||||
{
|
||||
public:
|
||||
explicit CSScanCode();
|
||||
~CSScanCode();
|
||||
QString getCode();
|
||||
void setXWorkRange(double value);
|
||||
void setYWorkRange(double value);
|
||||
void setXSampInterval(double value);
|
||||
void setYSampInterval(double value);
|
||||
int getSampTotalNum();
|
||||
void setRSToZeroXPos(double value);
|
||||
void setRSToZeroYPos(double value);
|
||||
void setRSToZeroZ1Pos(double value);
|
||||
|
||||
private:
|
||||
double xWorkRange{1.0};
|
||||
double yWorkRange{1.0};
|
||||
double xSampInterval{1.0};
|
||||
double ySampInterval{1.0};
|
||||
|
||||
const int yNumberOfUnitSamples{20};
|
||||
const int xNumberOfUnitSamples{12};
|
||||
const int yNumberOfLineSegmentSamples{600};
|
||||
const int accDecSampCount{2000};
|
||||
// rangeInitValue 用于初始化保存测距值的数组
|
||||
double rangeInitValue{100.0};
|
||||
// 加减速距离
|
||||
double AccDecDist{70};
|
||||
double xAxisVel{500.0};
|
||||
double yAxisVel{50.0};
|
||||
double RSToZeroXPos{1.0};
|
||||
double RSToZeroYPos{1.0};
|
||||
double RSToZeroZ1Pos{0.0};
|
||||
|
||||
|
||||
// const int yNumberOfUnitSamples{12};
|
||||
// const int xNumberOfUnitSamples{20};
|
||||
// const int xNumberOfLineSegmentSamples{200};
|
||||
// const int accDecSampCount{1500};
|
||||
// // rangeInitValue 用于初始化保存测距值的数组
|
||||
// double rangeInitValue{100.0};
|
||||
// // 加减速距离
|
||||
// double AccDecDist{45.0};
|
||||
// double xAxisVel{20.0};
|
||||
// double yAxisVel{100.0};
|
||||
// double RSToZeroXPos{1.0};
|
||||
// double RSToZeroYPos{1.0};
|
||||
};
|
||||
|
||||
#endif // CSSCANCODE_H
|
||||
24
device/control/acs/buffercode/machcode.cpp
Normal file
24
device/control/acs/buffercode/machcode.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "machcode.h"
|
||||
|
||||
MachCode::MachCode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString MachCode::getCode()
|
||||
{
|
||||
QString code("\n");
|
||||
code+=
|
||||
"ENABLE (Z)\n"
|
||||
"VEL(Z) = 2.000\n"
|
||||
"ACC(Z) = 20.00\n"
|
||||
"DEC(Z) = 20.00\n"
|
||||
"JERK(Z) = 200.0\n"
|
||||
"KDEC(Z) = 200.0\n"
|
||||
"PTP/e Z,2.2\n"
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
12
device/control/acs/buffercode/machcode.h
Normal file
12
device/control/acs/buffercode/machcode.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef MACHCODE_H
|
||||
#define MACHCODE_H
|
||||
#include <QString>
|
||||
|
||||
class MachCode
|
||||
{
|
||||
public:
|
||||
MachCode();
|
||||
QString getCode();
|
||||
};
|
||||
|
||||
#endif // MACHCODE_H
|
||||
668
device/control/acs/buffercode/maxisabsmovecode.cpp
Normal file
668
device/control/acs/buffercode/maxisabsmovecode.cpp
Normal file
@@ -0,0 +1,668 @@
|
||||
#include "maxisabsmovecode.h"
|
||||
|
||||
MAxisABSMoveCode::MAxisABSMoveCode()
|
||||
{
|
||||
|
||||
}
|
||||
QString MAxisABSMoveCode::getCode_L()
|
||||
{
|
||||
QString code("\n");
|
||||
code =
|
||||
|
||||
getSurCode_L()+
|
||||
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
QString MAxisABSMoveCode::getCode()
|
||||
{
|
||||
QString code("\n");
|
||||
code =
|
||||
|
||||
getSurCode()+
|
||||
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
QString MAxisABSMoveCode::getLaserMarkCode()
|
||||
{
|
||||
QString code("\n");
|
||||
code =
|
||||
|
||||
getAutoToLaserMarkCode()+
|
||||
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
QString MAxisABSMoveCode::getToCameraCode()
|
||||
{
|
||||
QString code("\n");
|
||||
code =
|
||||
|
||||
getAutoToCameraCode()+
|
||||
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void MAxisABSMoveCode::setXAxisTGPos(double value)
|
||||
{
|
||||
XTargetPos = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setYAxisTGPos(double value)
|
||||
{
|
||||
YTargetPos = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZAxisTGPos(double value)
|
||||
{
|
||||
ZTargetPos = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZAAxisTGPos(double value)
|
||||
{
|
||||
ZATargetPos = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZ2AxisTGPos(double value)
|
||||
{
|
||||
Z2TargetPos = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZ0AxisTGPos(double value)
|
||||
{
|
||||
Z0TargetPos = value;
|
||||
}
|
||||
|
||||
void MAxisABSMoveCode::setZAAxisSafePos(double value)
|
||||
{
|
||||
ZASafePos = value;
|
||||
}
|
||||
|
||||
void MAxisABSMoveCode::setZAAxisToSafePosVel(double value)
|
||||
{
|
||||
ZAAxisToSafePosVel = value;
|
||||
}
|
||||
|
||||
void MAxisABSMoveCode::setXAxisVel(double value)
|
||||
{
|
||||
XAxisVel = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setYAxisVel(double value)
|
||||
{
|
||||
YAxisVel = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZAAxisVel(double value)
|
||||
{
|
||||
ZAAxisVel = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZ2AxisVel(double value)
|
||||
{
|
||||
Z2AxisVel = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZ0AxisVel(double value)
|
||||
{
|
||||
Z0AxisVel = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZAxisVel(double value)
|
||||
{
|
||||
ZAxisVel = value;
|
||||
}
|
||||
|
||||
void MAxisABSMoveCode::setXAxisIsMove(bool value)
|
||||
{
|
||||
XAxisIsMove = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setYAxisIsMove(bool value)
|
||||
{
|
||||
YAxisIsMove = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZAxisIsMove(bool value)
|
||||
{
|
||||
ZAxisIsMove = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZAAxisIsMove(bool value)
|
||||
{
|
||||
ZAAxisIsMove = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZ2AxisIsMove(bool value)
|
||||
{
|
||||
Z2AxisIsMove = value;
|
||||
}
|
||||
void MAxisABSMoveCode::setZ0AxisIsMove(bool value)
|
||||
{
|
||||
Z0AxisIsMove = value;
|
||||
}
|
||||
void MAxisABSMoveCode::disableZAAxisToSafePos(bool value)
|
||||
{
|
||||
disabelZAToSafePos = value;
|
||||
}
|
||||
|
||||
void MAxisABSMoveCode::setCMRSwitch(bool value)
|
||||
{
|
||||
CMRHSwitch = value;
|
||||
}
|
||||
/***************************************************************
|
||||
* 修改码:1008610010
|
||||
* 日期:
|
||||
* 2024.3.4
|
||||
* 功能:
|
||||
* 添加新接口,先移动Z0
|
||||
**************************************************************/
|
||||
QString MAxisABSMoveCode::getSurCode_L()
|
||||
{
|
||||
QString moveAxis;
|
||||
if(XAxisIsMove)
|
||||
moveAxis+="X";
|
||||
if(YAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Y";
|
||||
else
|
||||
moveAxis+=",Y";
|
||||
}
|
||||
if(ZAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Z";
|
||||
else
|
||||
moveAxis+=",Z";
|
||||
}
|
||||
if(ZAAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="ZA";
|
||||
else
|
||||
moveAxis+=",ZA";
|
||||
}
|
||||
if(Z2AxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Z2";
|
||||
else
|
||||
moveAxis+=",Z2";
|
||||
}
|
||||
if(Z0AxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Z0";
|
||||
else
|
||||
moveAxis+=",Z0";
|
||||
}
|
||||
|
||||
|
||||
surCode+=
|
||||
QString("ENABLE (%1)\n").arg(moveAxis);
|
||||
// "REAL ZAFPos\n"
|
||||
// "ZAFPos = FPOS(ZA)\n";
|
||||
if(Z0AxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(Z0) = %1\n").arg(Z0AxisVel)+
|
||||
QString("ACC(Z0) = %1\n").arg(Z0AxisVel*10)+
|
||||
QString("DEC(Z0) = %1\n").arg(Z0AxisVel*10)+
|
||||
QString("JERK(Z0) = %1\n").arg(Z0AxisVel*100)+
|
||||
QString("KDEC(Z0) = %1\n").arg(Z0AxisVel*100)+
|
||||
QString("PTP/e Z0,%1\n").arg(Z0TargetPos,0,'f',4);
|
||||
Z0AxisIsMove = false;
|
||||
}
|
||||
if(!disabelZAToSafePos)
|
||||
{
|
||||
surCode+=
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToSafePosVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
QString("PTP/e ZA,%1\n").arg(ZASafePos,0,'f',4);
|
||||
}
|
||||
|
||||
if(XAxisIsMove&&YAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(X) = %1\n").arg(XAxisVel)+
|
||||
QString("ACC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("DEC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("JERK(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("KDEC(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("VEL(Y) = %1\n").arg(YAxisVel)+
|
||||
QString("ACC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("DEC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("JERK(Y) = %1\n").arg(YAxisVel*100)+
|
||||
QString("KDEC(Y) = %1\n").arg(YAxisVel*100);
|
||||
if(CMRHSwitch)
|
||||
{
|
||||
surCode += QString("PTP/re (X,Y),%1,%2\n").arg(XTargetPos,0,'f',4).arg(YTargetPos,0,'f',4);
|
||||
}
|
||||
else
|
||||
{
|
||||
surCode += QString("PTP/e (X,Y),%1,%2\n").arg(XTargetPos,0,'f',4).arg(YTargetPos,0,'f',4);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(XAxisIsMove)
|
||||
{
|
||||
surCode+=
|
||||
QString("VEL(X) = %1\n").arg(XAxisVel)+
|
||||
QString("ACC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("DEC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("JERK(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("KDEC(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("PTP/e (X),%1\n").arg(XTargetPos,0,'f',4);
|
||||
}
|
||||
if(YAxisIsMove)
|
||||
{
|
||||
surCode+=
|
||||
QString("VEL(Y) = %1\n").arg(YAxisVel)+
|
||||
QString("ACC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("DEC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("JERK(Y) = %1\n").arg(YAxisVel*100)+
|
||||
QString("KDEC(Y) = %1\n").arg(YAxisVel*100)+
|
||||
QString("PTP/e (Y),%1\n").arg(YTargetPos,0,'f',4);
|
||||
}
|
||||
}
|
||||
|
||||
if(ZAAxisIsMove&&ZAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
QString("VEL(Z) = %1\n").arg(ZAxisVel)+
|
||||
QString("ACC(Z) = %1\n").arg(ZAxisVel*10)+
|
||||
QString("DEC(Z) = %1\n").arg(ZAxisVel*10)+
|
||||
QString("JERK(Z) = %1\n").arg(ZAxisVel*100)+
|
||||
QString("KDEC(Z) = %1\n").arg(ZAxisVel*100)+
|
||||
QString("PTP/e (ZA,Z),%1,%2\n").arg(ZATargetPos,0,'f',4).arg(ZTargetPos,0,'f',4);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ZAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(Z) = %1\n").arg(ZAxisVel)+
|
||||
QString("ACC(Z) = %1\n").arg(ZAxisVel*10)+
|
||||
QString("DEC(Z) = %1\n").arg(ZAxisVel*10)+
|
||||
QString("JERK(Z) = %1\n").arg(ZAxisVel*100)+
|
||||
QString("KDEC(Z) = %1\n").arg(ZAxisVel*100)+
|
||||
QString("PTP/e Z,%1\n").arg(ZTargetPos,0,'f',4);
|
||||
}
|
||||
|
||||
if(ZAAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
QString("PTP/e ZA,%1\n").arg(ZATargetPos,0,'f',4);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// surCode +=
|
||||
// QString("VEL(ZA) = %1\n").arg(ZAAxisVel)+
|
||||
// QString("ACC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
// QString("DEC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
// QString("JERK(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
// QString("KDEC(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
|
||||
// //ZA回到原来位置
|
||||
// "PTP/e ZA,ZAFPos\n";
|
||||
// }
|
||||
|
||||
}
|
||||
if(Z2AxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(Z2) = %1\n").arg(Z2AxisVel)+
|
||||
QString("ACC(Z2) = %1\n").arg(Z2AxisVel*10)+
|
||||
QString("DEC(Z2) = %1\n").arg(Z2AxisVel*10)+
|
||||
QString("JERK(Z2) = %1\n").arg(Z2AxisVel*100)+
|
||||
QString("KDEC(Z2) = %1\n").arg(Z2AxisVel*100)+
|
||||
QString("PTP/e Z2,%1\n").arg(Z2TargetPos,0,'f',4);
|
||||
Z2AxisIsMove = false;
|
||||
}
|
||||
|
||||
return surCode;
|
||||
}
|
||||
QString MAxisABSMoveCode::getSurCode()
|
||||
{
|
||||
QString moveAxis;
|
||||
if(XAxisIsMove)
|
||||
moveAxis+="X";
|
||||
if(YAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Y";
|
||||
else
|
||||
moveAxis+=",Y";
|
||||
}
|
||||
if(ZAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Z";
|
||||
else
|
||||
moveAxis+=",Z";
|
||||
}
|
||||
if(ZAAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="ZA";
|
||||
else
|
||||
moveAxis+=",ZA";
|
||||
}
|
||||
if(Z2AxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Z2";
|
||||
else
|
||||
moveAxis+=",Z2";
|
||||
}
|
||||
|
||||
|
||||
surCode+=
|
||||
QString("ENABLE (%1)\n").arg(moveAxis);
|
||||
// "REAL ZAFPos\n"
|
||||
// "ZAFPos = FPOS(ZA)\n";
|
||||
if(!disabelZAToSafePos)
|
||||
{
|
||||
surCode+=
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToSafePosVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
QString("PTP/e ZA,%1\n").arg(ZASafePos,0,'f',4);
|
||||
}
|
||||
|
||||
if(XAxisIsMove&&YAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(X) = %1\n").arg(XAxisVel)+
|
||||
QString("ACC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("DEC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("JERK(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("KDEC(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("VEL(Y) = %1\n").arg(YAxisVel)+
|
||||
QString("ACC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("DEC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("JERK(Y) = %1\n").arg(YAxisVel*100)+
|
||||
QString("KDEC(Y) = %1\n").arg(YAxisVel*100);
|
||||
if(CMRHSwitch)
|
||||
{
|
||||
surCode += QString("PTP/re (X,Y),%1,%2\n").arg(XTargetPos,0,'f',4).arg(YTargetPos,0,'f',4);
|
||||
}
|
||||
else
|
||||
{
|
||||
surCode += QString("PTP/e (X,Y),%1,%2\n").arg(XTargetPos,0,'f',4).arg(YTargetPos,0,'f',4);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(XAxisIsMove)
|
||||
{
|
||||
surCode+=
|
||||
QString("VEL(X) = %1\n").arg(XAxisVel)+
|
||||
QString("ACC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("DEC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("JERK(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("KDEC(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("PTP/e (X),%1\n").arg(XTargetPos,0,'f',4);
|
||||
}
|
||||
if(YAxisIsMove)
|
||||
{
|
||||
surCode+=
|
||||
QString("VEL(Y) = %1\n").arg(YAxisVel)+
|
||||
QString("ACC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("DEC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("JERK(Y) = %1\n").arg(YAxisVel*100)+
|
||||
QString("KDEC(Y) = %1\n").arg(YAxisVel*100)+
|
||||
QString("PTP/e (Y),%1\n").arg(YTargetPos,0,'f',4);
|
||||
}
|
||||
}
|
||||
|
||||
if(ZAAxisIsMove&&ZAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
QString("VEL(Z) = %1\n").arg(ZAxisVel)+
|
||||
QString("ACC(Z) = %1\n").arg(ZAxisVel*10)+
|
||||
QString("DEC(Z) = %1\n").arg(ZAxisVel*10)+
|
||||
QString("JERK(Z) = %1\n").arg(ZAxisVel*100)+
|
||||
QString("KDEC(Z) = %1\n").arg(ZAxisVel*100)+
|
||||
QString("PTP/e (ZA,Z),%1,%2\n").arg(ZATargetPos,0,'f',4).arg(ZTargetPos,0,'f',4);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ZAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(Z) = %1\n").arg(ZAxisVel)+
|
||||
QString("ACC(Z) = %1\n").arg(ZAxisVel*10)+
|
||||
QString("DEC(Z) = %1\n").arg(ZAxisVel*10)+
|
||||
QString("JERK(Z) = %1\n").arg(ZAxisVel*100)+
|
||||
QString("KDEC(Z) = %1\n").arg(ZAxisVel*100)+
|
||||
QString("PTP/e Z,%1\n").arg(ZTargetPos,0,'f',4);
|
||||
}
|
||||
|
||||
if(ZAAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
QString("PTP/e ZA,%1\n").arg(ZATargetPos,0,'f',4);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// surCode +=
|
||||
// QString("VEL(ZA) = %1\n").arg(ZAAxisVel)+
|
||||
// QString("ACC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
// QString("DEC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
// QString("JERK(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
// QString("KDEC(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
|
||||
// //ZA回到原来位置
|
||||
// "PTP/e ZA,ZAFPos\n";
|
||||
// }
|
||||
|
||||
}
|
||||
if(Z2AxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(Z2) = %1\n").arg(Z2AxisVel)+
|
||||
QString("ACC(Z2) = %1\n").arg(Z2AxisVel*10)+
|
||||
QString("DEC(Z2) = %1\n").arg(Z2AxisVel*10)+
|
||||
QString("JERK(Z2) = %1\n").arg(Z2AxisVel*100)+
|
||||
QString("KDEC(Z2) = %1\n").arg(Z2AxisVel*100)+
|
||||
QString("PTP/e Z2,%1\n").arg(Z2TargetPos,0,'f',4);
|
||||
Z2AxisIsMove = false;
|
||||
}
|
||||
if(Z0AxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(Z0) = %1\n").arg(Z0AxisVel)+
|
||||
QString("ACC(Z0) = %1\n").arg(Z0AxisVel*10)+
|
||||
QString("DEC(Z0) = %1\n").arg(Z0AxisVel*10)+
|
||||
QString("JERK(Z0) = %1\n").arg(Z0AxisVel*100)+
|
||||
QString("KDEC(Z0) = %1\n").arg(Z0AxisVel*100)+
|
||||
QString("PTP/e Z0,%1\n").arg(Z0TargetPos,0,'f',4);
|
||||
Z0AxisIsMove = false;
|
||||
}
|
||||
return surCode;
|
||||
}
|
||||
|
||||
|
||||
QString MAxisABSMoveCode::getAutoToCameraCode()
|
||||
{
|
||||
QString moveAxis;
|
||||
if(XAxisIsMove)
|
||||
moveAxis+="X";
|
||||
if(YAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Y";
|
||||
else
|
||||
moveAxis+=",Y";
|
||||
}
|
||||
if(ZAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Z";
|
||||
else
|
||||
moveAxis+=",Z";
|
||||
}
|
||||
if(ZAAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="ZA";
|
||||
else
|
||||
moveAxis+=",ZA";
|
||||
}
|
||||
if(Z2AxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Z2";
|
||||
else
|
||||
moveAxis+=",Z2";
|
||||
}
|
||||
|
||||
|
||||
surCode+=
|
||||
QString("ENABLE (%1)\n").arg(moveAxis);
|
||||
// "REAL ZAFPos\n"
|
||||
// "ZAFPos = FPOS(ZA)\n";
|
||||
|
||||
|
||||
if(XAxisIsMove&&YAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(X) = %1\n").arg(XAxisVel)+
|
||||
QString("ACC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("DEC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("JERK(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("KDEC(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("VEL(Y) = %1\n").arg(YAxisVel)+
|
||||
QString("ACC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("DEC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("JERK(Y) = %1\n").arg(YAxisVel*100)+
|
||||
QString("KDEC(Y) = %1\n").arg(YAxisVel*100);
|
||||
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
|
||||
|
||||
if(ZAAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisVel*100);
|
||||
}
|
||||
surCode += QString("PTP/e (X,Y,ZA),%1,%2,%3\n").arg(XTargetPos).arg(YTargetPos).arg(ZATargetPos);
|
||||
|
||||
}
|
||||
|
||||
return surCode;
|
||||
}
|
||||
|
||||
|
||||
QString MAxisABSMoveCode::getAutoToLaserMarkCode()
|
||||
{
|
||||
QString moveAxis;
|
||||
if(XAxisIsMove)
|
||||
moveAxis+="X";
|
||||
if(YAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Y";
|
||||
else
|
||||
moveAxis+=",Y";
|
||||
}
|
||||
if(ZAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Z";
|
||||
else
|
||||
moveAxis+=",Z";
|
||||
}
|
||||
if(ZAAxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="ZA";
|
||||
else
|
||||
moveAxis+=",ZA";
|
||||
}
|
||||
if(Z2AxisIsMove)
|
||||
{
|
||||
if(moveAxis.isEmpty())
|
||||
moveAxis+="Z2";
|
||||
else
|
||||
moveAxis+=",Z2";
|
||||
}
|
||||
|
||||
|
||||
surCode+=
|
||||
QString("ENABLE (%1)\n").arg(moveAxis);
|
||||
// "REAL ZAFPos\n"
|
||||
// "ZAFPos = FPOS(ZA)\n";
|
||||
//if(!disabelZAToSafePos)
|
||||
{
|
||||
surCode+=
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToSafePosVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
QString("PTP/e ZA,%1\n").arg(ZASafePos);
|
||||
}
|
||||
|
||||
//if(XAxisIsMove&&YAxisIsMove)
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(X) = %1\n").arg(XAxisVel)+
|
||||
QString("ACC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("DEC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("JERK(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("KDEC(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("VEL(Y) = %1\n").arg(YAxisVel)+
|
||||
QString("ACC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("DEC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("JERK(Y) = %1\n").arg(YAxisVel*100)+
|
||||
QString("KDEC(Y) = %1\n").arg(YAxisVel*100);
|
||||
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
surCode +=
|
||||
QString("VEL(Z2) = %1\n").arg(Z2AxisVel)+
|
||||
QString("ACC(Z2) = %1\n").arg(Z2AxisVel*10)+
|
||||
QString("DEC(Z2) = %1\n").arg(Z2AxisVel*10)+
|
||||
QString("JERK(Z2) = %1\n").arg(Z2AxisVel*100)+
|
||||
QString("KDEC(Z2) = %1\n").arg(Z2AxisVel*100)+
|
||||
|
||||
QString("PTP/e (X,Y,Z2),%1,%2,%3\n").arg(XTargetPos).arg(YTargetPos).arg(Z2TargetPos);
|
||||
|
||||
}
|
||||
return surCode;
|
||||
}
|
||||
68
device/control/acs/buffercode/maxisabsmovecode.h
Normal file
68
device/control/acs/buffercode/maxisabsmovecode.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef MAXISABSMOVECODE_H
|
||||
#define MAXISABSMOVECODE_H
|
||||
#include <QString>
|
||||
|
||||
class MAxisABSMoveCode
|
||||
{
|
||||
public:
|
||||
explicit MAxisABSMoveCode();
|
||||
QString getCode();
|
||||
QString getCode_L();
|
||||
QString getToCameraCode();
|
||||
QString getLaserMarkCode();
|
||||
void setXAxisTGPos(double value);
|
||||
void setYAxisTGPos(double value);
|
||||
void setZAxisTGPos(double value);
|
||||
void setZAAxisTGPos(double value);
|
||||
void setZ2AxisTGPos(double value);
|
||||
void setZ0AxisTGPos(double value);
|
||||
void setZAAxisSafePos(double value);
|
||||
void setZAAxisToSafePosVel(double value);
|
||||
void setXAxisVel(double value);
|
||||
void setYAxisVel(double value);
|
||||
void setZAAxisVel(double value);
|
||||
void setZ2AxisVel(double value);
|
||||
void setZ0AxisVel(double value);
|
||||
void setZAxisVel(double value);
|
||||
void setXAxisIsMove(bool value);
|
||||
void setYAxisIsMove(bool value);
|
||||
void setZAxisIsMove(bool value);
|
||||
void setZAAxisIsMove(bool value);
|
||||
void setZ2AxisIsMove(bool value);
|
||||
void setZ0AxisIsMove(bool value);
|
||||
void disableZAAxisToSafePos(bool value);
|
||||
void setCMRSwitch(bool value);
|
||||
|
||||
|
||||
private:
|
||||
QString getSurCode();
|
||||
QString getSurCode_L();//1008610010,光路检测绝对移动,先移动Z0
|
||||
QString getAutoToLaserMarkCode();
|
||||
QString getAutoToCameraCode();
|
||||
private:
|
||||
bool disabelZAToSafePos{false};
|
||||
bool XAxisIsMove{false};
|
||||
bool YAxisIsMove{false};
|
||||
bool ZAxisIsMove{false};
|
||||
bool ZAAxisIsMove{false};
|
||||
bool Z2AxisIsMove{false};
|
||||
bool Z0AxisIsMove{false};
|
||||
double XTargetPos{0.0};
|
||||
double YTargetPos{0.0};
|
||||
double ZTargetPos{0.0};
|
||||
double ZATargetPos{0.0};
|
||||
double Z2TargetPos{0.0};
|
||||
double Z0TargetPos{0.0};
|
||||
QString surCode{""};
|
||||
double ZASafePos{0.0};
|
||||
double ZAAxisToSafePosVel{0.0};
|
||||
double XAxisVel{0.0};
|
||||
double YAxisVel{0.0};
|
||||
double ZAAxisVel{0.0};
|
||||
double Z2AxisVel{0.0};
|
||||
double Z0AxisVel{0.0};
|
||||
double ZAxisVel{0.0};
|
||||
bool CMRHSwitch{false};
|
||||
};
|
||||
|
||||
#endif // MAXISABSMOVECODE_H
|
||||
141
device/control/acs/buffercode/mhcompcode.cpp
Normal file
141
device/control/acs/buffercode/mhcompcode.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "mhcompcode.h"
|
||||
#include <QString>
|
||||
|
||||
MHCompCode::MHCompCode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MHCompCode::setXStartPos(double value)
|
||||
{
|
||||
xStartPos = value;
|
||||
}
|
||||
|
||||
void MHCompCode::setYStartPos(double value)
|
||||
{
|
||||
yStartPos = value;
|
||||
}
|
||||
|
||||
void MHCompCode::setXWorkRange(double value)
|
||||
{
|
||||
xWorkRange = value;
|
||||
}
|
||||
|
||||
void MHCompCode::setYWorkRange(double value)
|
||||
{
|
||||
yWorkRange = value;
|
||||
}
|
||||
|
||||
void MHCompCode::setXInterval(double value)
|
||||
{
|
||||
xInterval = value;
|
||||
}
|
||||
void MHCompCode::setYInterval(double value)
|
||||
{
|
||||
yInterval = value;
|
||||
}
|
||||
|
||||
int MHCompCode::getLookupRows()
|
||||
{
|
||||
// 比如范围为3,间隔为1,Y方向会有4条线段
|
||||
return int(xWorkRange/xInterval)+1;
|
||||
}
|
||||
|
||||
int MHCompCode::getLookupCols()
|
||||
{
|
||||
return int(yWorkRange/yInterval)+1;
|
||||
}
|
||||
|
||||
|
||||
void MHCompCode::setMHRHYOffset(double value)
|
||||
{
|
||||
MHRHYOffset = value;
|
||||
}
|
||||
void MHCompCode::setMHRHXOffset(double value)
|
||||
{
|
||||
MHRHXOffset = value;
|
||||
}
|
||||
|
||||
|
||||
void MHCompCode::setLookupRows(int value)
|
||||
{
|
||||
rows = value;
|
||||
}
|
||||
void MHCompCode::setLookupCols(int value)
|
||||
{
|
||||
cols = value;
|
||||
}
|
||||
QString MHCompCode::getCode()
|
||||
{
|
||||
QString code = QString("global real LookupTable(%1)(%2),xStart,yStart\n").arg(rows).arg(cols);
|
||||
code+=
|
||||
"MFLAGS(Z).#DEFCON = 0\n"
|
||||
"CONNECT RPOS(Z) = RPOS(Z)\n"
|
||||
"DEPENDS Z, Z\n"+
|
||||
//QString("SET APOS(Z) = RPOS(Z) - MAP2(FPOS(Y), FPOS(X), LookupTable, %1, %2, %3, %4)\n").arg(yStartPos+MHRHYOffset-yInterval).arg(yInterval).arg(xStartPos+MHRHXOffset-xInterval).arg(xInterval)+
|
||||
//QString("CONNECT RPOS(Z) = APOS(Z) + MAP2(FPOS(Y), FPOS(X), LookupTable, %1, %2, %3, %4)\n").arg(yStartPos+MHRHYOffset-yInterval).arg(yInterval).arg(xStartPos+MHRHXOffset-xInterval).arg(xInterval)+
|
||||
//QString("SET APOS(Z) = RPOS(Z) - MAP2(FPOS(Y), FPOS(X), LookupTable, %1, %2, %3, %4)\n").arg(yStartPos+MHRHYOffset).arg(yInterval).arg(xStartPos+MHRHXOffset).arg(xInterval)+
|
||||
//QString("CONNECT RPOS(Z) = APOS(Z) + MAP2(FPOS(Y), FPOS(X), LookupTable, %1, %2, %3, %4)\n").arg(yStartPos+MHRHYOffset).arg(yInterval).arg(xStartPos+MHRHXOffset).arg(xInterval)+
|
||||
QString("SET APOS(Z) = RPOS(Z) - MAP2(FPOS(X), FPOS(Y), LookupTable, %1, %2, %3, %4)\n").arg(xStartPos+MHRHXOffset).arg(xInterval).arg(yStartPos+MHRHYOffset).arg(yInterval)+
|
||||
QString("CONNECT RPOS(Z) = APOS(Z) + MAP2(FPOS(X), FPOS(Y), LookupTable, %1, %2, %3, %4)\n").arg(xStartPos+MHRHXOffset).arg(xInterval).arg(yStartPos+MHRHYOffset).arg(yInterval)+
|
||||
|
||||
"DEPENDS Z, Z\n"
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
|
||||
QString MHCompCode::getCode_motion()
|
||||
{
|
||||
QString code = QString("GLOBAL REAL MAXINlhc=%1,MAXPOS_Xlhc=%2,MINPOS_Xlhc=%3,X_OFFSETlhc=%4,myRange\n").arg(MaxCmp).arg(MaxPos_x).arg(MinPos_x).arg(x_offset);
|
||||
code+=
|
||||
"GLOBAL REAL XPOINT(10000),ERR_Z1(10000)\n"
|
||||
"REAL tmp_data\n"
|
||||
"INT i,flag,count_data\n"
|
||||
"i=9999\n"
|
||||
"FILL(0,ERR_Z1,0,9999)\n"
|
||||
"FILL(MINPOS_Xlhc,XPOINT,0,9999)\n"
|
||||
"tmp_data=0;count_data=0\n"
|
||||
"MFLAGS(Z).17=0\n"
|
||||
"CONNECT RPOS(Z)=APOS(Z)+MAPNS((FPOS(X)+X_OFFSETlhc),XPOINT,ERR_Z1)\n"
|
||||
"DEPENDS Z, Z\n"
|
||||
"WHILE 1\n"
|
||||
"IF FPOS(X)>MINPOS_Xlhc & FPOS(X)<MAXPOS_Xlhc\n"
|
||||
"IF MST(X).#MOVE & RVEL(X) < 0\n"
|
||||
"XPOINT(i)=FPOS(X); myRange=RangeV\n"
|
||||
"IF ABS(myRange)>MAXINlhc\n"
|
||||
"if i<9999\n"
|
||||
"myRange=ERR_Z1(i+1)\n"
|
||||
"else\n"
|
||||
"myRange=tmp_data\n"
|
||||
"end\n"
|
||||
"ELSE\n"
|
||||
"IF count_data<1\n"
|
||||
"tmp_data=myRange\n"
|
||||
"count_data=count_data+1\n"
|
||||
"END\n"
|
||||
"END\n"
|
||||
"ERR_Z1(i)=myRange\n"
|
||||
"i=i-1\n"
|
||||
"if i<0\n"
|
||||
"i=0\n"
|
||||
"END\n"
|
||||
"END\n"
|
||||
"END\n"
|
||||
"IF FPOS(X)>MAXPOS_Xlhc\n"
|
||||
"i=9999\n"
|
||||
"count_data=0\n"
|
||||
"FILL(tmp_data,ERR_Z1,0,9999)\n"
|
||||
"FILL(MINPOS_Xlhc,XPOINT,0,9999)\n"
|
||||
"END\n"
|
||||
"END\n"
|
||||
"MFLAGS(Z).17=1\n"
|
||||
"STOP\n";
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
48
device/control/acs/buffercode/mhcompcode.h
Normal file
48
device/control/acs/buffercode/mhcompcode.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef MHCOMPCODE_H
|
||||
#define MHCOMPCODE_H
|
||||
|
||||
#include<QString>
|
||||
|
||||
class MHCompCode
|
||||
{
|
||||
public:
|
||||
MHCompCode();
|
||||
QString getCode();
|
||||
QString getCode_motion();
|
||||
void setXStartPos(double value);
|
||||
void setYStartPos(double value);
|
||||
void setXWorkRange(double value);
|
||||
void setYWorkRange(double value);
|
||||
void setXInterval(double value);
|
||||
void setYInterval(double value);
|
||||
void setMHRHYOffset(double value);
|
||||
void setMHRHXOffset(double value);
|
||||
|
||||
void setLookupRows(int value);
|
||||
void setLookupCols(int value);
|
||||
double MaxCmp{0.0};
|
||||
double MaxPos_x{0.0};
|
||||
double MinPos_x{0.0};
|
||||
double x_offset{0.0};
|
||||
|
||||
private:
|
||||
int getLookupRows();
|
||||
int getLookupCols();
|
||||
|
||||
|
||||
private:
|
||||
double xStartPos{0.0};
|
||||
double yStartPos{0.0};
|
||||
double xInterval{0.1};
|
||||
double yInterval{0.1};
|
||||
double xWorkRange{1.0};
|
||||
double yWorkRange{1.0};
|
||||
// 加工头和测距头之间Y方向偏移
|
||||
double MHRHYOffset{0.0};
|
||||
// 加工头和测距头之间X方向偏移
|
||||
double MHRHXOffset{0.0};
|
||||
double cols{0};
|
||||
double rows{0};
|
||||
};
|
||||
|
||||
#endif // MHCOMPCODE_H
|
||||
45
device/control/acs/buffercode/ptpcode.cpp
Normal file
45
device/control/acs/buffercode/ptpcode.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "ptpcode.h"
|
||||
|
||||
PTPCode::PTPCode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString PTPCode::getCode()
|
||||
{
|
||||
QString code("\n");
|
||||
code +=
|
||||
QString("ENABLE (%1)\n").arg(moveAxis)+
|
||||
QString("%1 (%2),%3\n").arg(getMoveCMDText()).arg(moveAxis).arg(targetPos)+
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
|
||||
void PTPCode::setMoveType(bool value)
|
||||
{
|
||||
moveType = value;
|
||||
}
|
||||
|
||||
QString PTPCode::getMoveCMDText()
|
||||
{
|
||||
if(moveType)
|
||||
{
|
||||
return ABSMove;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RMove;
|
||||
}
|
||||
}
|
||||
|
||||
void PTPCode::setTargetPos(QString value)
|
||||
{
|
||||
targetPos = value;
|
||||
}
|
||||
|
||||
|
||||
void PTPCode::setMoveAxis(QString value)
|
||||
{
|
||||
moveAxis = value;
|
||||
}
|
||||
24
device/control/acs/buffercode/ptpcode.h
Normal file
24
device/control/acs/buffercode/ptpcode.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef PTPCODE_H
|
||||
#define PTPCODE_H
|
||||
#include<QString>
|
||||
|
||||
class PTPCode
|
||||
{
|
||||
public:
|
||||
explicit PTPCode();
|
||||
QString getCode();
|
||||
void setMoveType(bool value);
|
||||
void setTargetPos(QString value);
|
||||
void setMoveAxis(QString value);
|
||||
private:
|
||||
QString getMoveCMDText();
|
||||
|
||||
private:
|
||||
QString RMove{"PTP/ER"};
|
||||
QString ABSMove{"PTP/E"};
|
||||
QString moveAxis{""};
|
||||
QString targetPos{""};
|
||||
bool moveType{false};
|
||||
};
|
||||
|
||||
#endif // PTPCODE_H
|
||||
59
device/control/acs/buffercode/rmcposswitchcode.cpp
Normal file
59
device/control/acs/buffercode/rmcposswitchcode.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "rmcposswitchcode.h"
|
||||
|
||||
RMCPosSwitchCode::RMCPosSwitchCode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString RMCPosSwitchCode::getCode()
|
||||
{
|
||||
QString code("\n");
|
||||
code +=
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToSafePosVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
"ENABLE ZA\n"+
|
||||
QString("PTP/e ZA,%1\n").arg(ZAAxisSafePos)+
|
||||
QString("VEL(X) = %1\n").arg(XAxisVel)+
|
||||
QString("ACC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("DEC(X) = %1\n").arg(XAxisVel*10)+
|
||||
QString("JERK(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("KDEC(X) = %1\n").arg(XAxisVel*100)+
|
||||
QString("VEL(Y) = %1\n").arg(YAxisVel)+
|
||||
QString("ACC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("DEC(Y) = %1\n").arg(YAxisVel*10)+
|
||||
QString("JERK(Y) = %1\n").arg(YAxisVel*100)+
|
||||
QString("KDEC(Y) = %1\n").arg(YAxisVel*100)+
|
||||
"ENABLE (X,Y)\n"+
|
||||
QString("PTP/er (X,Y),%1,%2\n").arg(XAxisTgPos).arg(YAxisTgPos)+
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void RMCPosSwitchCode::setTargetPos(double XPos,double YPos)
|
||||
{
|
||||
XAxisTgPos=XPos;
|
||||
YAxisTgPos=YPos;
|
||||
}
|
||||
|
||||
void RMCPosSwitchCode::setZAAxisSafePos(double value)
|
||||
{
|
||||
ZAAxisSafePos = value;
|
||||
}
|
||||
|
||||
void RMCPosSwitchCode::setZAAxisToSafePosVel(double value)
|
||||
{
|
||||
ZAAxisToSafePosVel = value;
|
||||
}
|
||||
|
||||
void RMCPosSwitchCode::setXYAxisVel(double XVel,double YVel)
|
||||
{
|
||||
XAxisVel = XVel;
|
||||
YAxisVel = YVel;
|
||||
}
|
||||
|
||||
|
||||
24
device/control/acs/buffercode/rmcposswitchcode.h
Normal file
24
device/control/acs/buffercode/rmcposswitchcode.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef RMCPOSSWITCHCODE_H
|
||||
#define RMCPOSSWITCHCODE_H
|
||||
#include<QString>
|
||||
|
||||
class RMCPosSwitchCode
|
||||
{
|
||||
public:
|
||||
RMCPosSwitchCode();
|
||||
QString getCode();
|
||||
void setTargetPos(double XPos,double YPos);
|
||||
void setZAAxisSafePos(double value);
|
||||
void setZAAxisToSafePosVel(double value);
|
||||
void setXYAxisVel(double XVel,double YVel);
|
||||
|
||||
private:
|
||||
double XAxisTgPos{0.0};
|
||||
double YAxisTgPos{0.0};
|
||||
double ZAAxisSafePos{0.0};
|
||||
double ZAAxisToSafePosVel{0.0};
|
||||
double XAxisVel{0.0};
|
||||
double YAxisVel{0.0};
|
||||
};
|
||||
|
||||
#endif // RMCPOSSWITCHCODE_H
|
||||
74
device/control/acs/buffercode/rscompcode.cpp
Normal file
74
device/control/acs/buffercode/rscompcode.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "rscompcode.h"
|
||||
|
||||
RSCompCode::RSCompCode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void RSCompCode::setXStartPos(double value)
|
||||
{
|
||||
xStartPos = value;
|
||||
}
|
||||
|
||||
void RSCompCode::setYStartPos(double value)
|
||||
{
|
||||
yStartPos = value;
|
||||
}
|
||||
|
||||
void RSCompCode::setXInterval(double value)
|
||||
{
|
||||
xInterval = value;
|
||||
}
|
||||
void RSCompCode::setYInterval(double value)
|
||||
{
|
||||
yInterval = value;
|
||||
}
|
||||
|
||||
void RSCompCode::setXWorkRange(double value)
|
||||
{
|
||||
xWorkRange = value;
|
||||
}
|
||||
|
||||
void RSCompCode::setYWorkRange(double value)
|
||||
{
|
||||
yWorkRange = value;
|
||||
}
|
||||
|
||||
int RSCompCode::getLookupRows()
|
||||
{
|
||||
// 比如范围为3,间隔为1,Y方向会有4条线段
|
||||
return int(xWorkRange/xInterval)+1;
|
||||
}
|
||||
|
||||
int RSCompCode::getLookupCols()
|
||||
{
|
||||
return int(yWorkRange/yInterval)+1;
|
||||
}
|
||||
|
||||
|
||||
QString RSCompCode::getCode()
|
||||
{
|
||||
|
||||
QString code = QString("global real LookupTable(%1)(%2)\n").arg(getLookupRows()).arg(getLookupCols());
|
||||
code +=
|
||||
// 设置APOS和RPOS非默认连接
|
||||
"MFLAGS(Z).#DEFCON = 0\n"
|
||||
"CONNECT RPOS(Z) = RPOS(Z)\n"
|
||||
// 执行connect命令后控制其将电机依赖重置为默认值
|
||||
// 如果连接公式实际上导致电机依赖于另一轴,则需要重新指定依赖
|
||||
"DEPENDS Z, Z\n"+
|
||||
// 防止开启补偿的瞬间Z1轴跳动
|
||||
//QString("SET APOS(Z) = RPOS(Z) - MAP2(FPOS(Y), FPOS(X), LookupTable, %1, %2, %3, %4)\n").arg(yStartPos-yInterval).arg(yInterval).arg(xStartPos-xInterval).arg(xInterval)+
|
||||
//QString("CONNECT RPOS(Z) = APOS(Z) + MAP2(FPOS(Y), FPOS(X), LookupTable,%1, %2, %3, %4)\n").arg(yStartPos-yInterval).arg(yInterval).arg(xStartPos-xInterval).arg(xInterval)+
|
||||
QString("SET APOS(Z) = RPOS(Z) - MAP2(FPOS(Y), FPOS(X), LookupTable, %1, %2, %3, %4)\n").arg(yStartPos).arg(yInterval).arg(xStartPos).arg(xInterval)+
|
||||
QString("CONNECT RPOS(Z) = APOS(Z) + MAP2(FPOS(Y), FPOS(X), LookupTable,%1, %2, %3, %4)\n").arg(yStartPos).arg(yInterval).arg(xStartPos).arg(xInterval)+
|
||||
"DEPENDS Z, Z\n"
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
32
device/control/acs/buffercode/rscompcode.h
Normal file
32
device/control/acs/buffercode/rscompcode.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef RSCOMPCODE_H
|
||||
#define RSCOMPCODE_H
|
||||
#include<QString>
|
||||
|
||||
class RSCompCode
|
||||
{
|
||||
public:
|
||||
RSCompCode();
|
||||
QString getCode();
|
||||
void setXStartPos(double value);
|
||||
void setYStartPos(double value);
|
||||
void setXWorkRange(double value);
|
||||
void setYWorkRange(double value);
|
||||
void setXInterval(double value);
|
||||
void setYInterval(double value);
|
||||
|
||||
private:
|
||||
int getLookupRows();
|
||||
int getLookupCols();
|
||||
|
||||
|
||||
private:
|
||||
double xStartPos{0.0};
|
||||
double yStartPos{0.0};
|
||||
double xInterval{0.1};
|
||||
double yInterval{0.1};
|
||||
double xWorkRange{1.0};
|
||||
double yWorkRange{1.0};
|
||||
|
||||
};
|
||||
|
||||
#endif // RSCOMPCODE_H
|
||||
193
device/control/acs/buffercode/rsensortozero.cpp
Normal file
193
device/control/acs/buffercode/rsensortozero.cpp
Normal file
@@ -0,0 +1,193 @@
|
||||
#include "rsensortozero.h"
|
||||
|
||||
RSensorToZero::RSensorToZero()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void RSensorToZero::setZAAxisSafePos(double value)
|
||||
{
|
||||
ZAAxisSafePos = value;
|
||||
}
|
||||
|
||||
void RSensorToZero::setZAAxisToSafePosVel(double value)
|
||||
{
|
||||
ZAAxisToSafePosVel = value;
|
||||
}
|
||||
void RSensorToZero::setZAAxisToZero1Vel(double value)
|
||||
{
|
||||
ZAAxisToZero1Vel = value;
|
||||
}
|
||||
void RSensorToZero::setZAAxisToZero2Vel(double value)
|
||||
{
|
||||
ZAAxisToZero2Vel = value;
|
||||
}
|
||||
void RSensorToZero::setZAAxisToZero3Vel(double value)
|
||||
{
|
||||
ZAAxisToZero3Vel = value;
|
||||
}
|
||||
|
||||
|
||||
//QString RSensorToZero::getCode()
|
||||
//{
|
||||
// QString code;
|
||||
// code+=
|
||||
// QString("VEL(Z) = 2\n")+
|
||||
// QString("ACC(Z) = 20\n")+
|
||||
// QString("DEC(Z) = 20\n")+
|
||||
// QString("JERK(Z) = 200\n")+
|
||||
// QString("KDEC(Z) = 200\n")+
|
||||
// QString("PTP/e Z, 0\n")+
|
||||
// "IF RangeV<-1.5\n"+
|
||||
// QString("VEL(ZA) = %1\n").arg(ZAAxisToSafePosVel)+
|
||||
// QString("ACC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
// QString("DEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
// QString("JERK(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
// QString("KDEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
// QString("PTP/e ZA, %1\n").arg(ZAAxisSafePos)+
|
||||
// QString("VEL(ZA) = %1\n").arg(ZAAxisToZero1Vel)+
|
||||
// QString("ACC(ZA) = %1\n").arg(ZAAxisToZero1Vel*10)+
|
||||
// QString("DEC(ZA) = %1\n").arg(ZAAxisToZero1Vel*10)+
|
||||
// QString("JERK(ZA) = %1\n").arg(ZAAxisToZero1Vel*100)+
|
||||
// QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero1Vel*100)+
|
||||
// "PTP ZA, -30\n"
|
||||
// "TILL ABS(RangeV) < 0.1\n"
|
||||
// "HALT ZA\n"
|
||||
// "WAIT 1000\n"+
|
||||
// QString("VEL(ZA) = %1\n").arg(ZAAxisToZero2Vel)+
|
||||
// QString("ACC(ZA) = %1\n").arg(ZAAxisToZero2Vel*10)+
|
||||
// QString("DEC(ZA) = %1\n").arg(ZAAxisToZero2Vel*10)+
|
||||
// QString("JERK(ZA) = %1\n").arg(ZAAxisToZero2Vel*100)+
|
||||
// QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero2Vel*100)+
|
||||
// "PTP/er ZA, RangeV\n"
|
||||
// "WAIT 1000\n"
|
||||
// "ELSE\n"+
|
||||
// QString("VEL(ZA) = %1\n").arg(ZAAxisToZero1Vel)+
|
||||
// QString("ACC(ZA) = %1\n").arg(ZAAxisToZero1Vel*10)+
|
||||
// QString("DEC(ZA) = %1\n").arg(ZAAxisToZero1Vel*10)+
|
||||
// QString("JERK(ZA) = %1\n").arg(ZAAxisToZero1Vel*100)+
|
||||
// QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero1Vel*100)+
|
||||
// "PTP/ER ZA,RangeV\n"
|
||||
// "WAIT 1800\n"+
|
||||
// QString("VEL(ZA) = %1\n").arg(ZAAxisToZero2Vel)+
|
||||
// QString("ACC(ZA) = %1\n").arg(ZAAxisToZero2Vel*10)+
|
||||
// QString("DEC(ZA) = %1\n").arg(ZAAxisToZero2Vel*10)+
|
||||
// QString("JERK(ZA) = %1\n").arg(ZAAxisToZero2Vel*100)+
|
||||
// QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero2Vel*100)+
|
||||
// "PTP/ER ZA,RangeV\n"
|
||||
// "WAIT 600\n"
|
||||
// "END\n"
|
||||
// "IF ABS(RangeV) >= 0.0003\n"+
|
||||
// QString("VEL(ZA) = %1\n").arg(ZAAxisToZero3Vel)+
|
||||
// QString("ACC(ZA) = %1\n").arg(ZAAxisToZero3Vel*10)+
|
||||
// QString("DEC(ZA) = %1\n").arg(ZAAxisToZero3Vel*10)+
|
||||
// QString("JERK(ZA) = %1\n").arg(ZAAxisToZero3Vel*100)+
|
||||
// QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero3Vel*100)+
|
||||
// "PTP/er ZA, RangeV\n"
|
||||
// "END\n"
|
||||
// "runF = 1\n"
|
||||
// "STOP";
|
||||
// return code;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
QString RSensorToZero::getCode()
|
||||
{
|
||||
QString strDoOpen,strDiSts1,strDoClose,strDiSts0;
|
||||
if (CuCeGaoDiNum < 8)
|
||||
strDiSts1 = QString("DI1.%1=1\n").arg(CuCeGaoDiNum);
|
||||
else
|
||||
strDiSts1 = QString("DI2.%1=1\n").arg(CuCeGaoDiNum-8);
|
||||
if (CuCeGaoDiNum < 8)
|
||||
strDiSts0 = QString("DI1.%1=0\n").arg(CuCeGaoDiNum);
|
||||
else
|
||||
strDiSts0 = QString("DI2.%1=0\n").arg(CuCeGaoDiNum-8);
|
||||
|
||||
if (CuCeGaoDoNum < 8)
|
||||
strDoOpen = QString("DO1.%1=1\n").arg(CuCeGaoDoNum);
|
||||
else
|
||||
strDoOpen = QString("DO2.%1=1\n").arg(CuCeGaoDoNum-8);
|
||||
if (CuCeGaoDoNum < 8)
|
||||
strDoClose = QString("DO1.%1=0\n").arg(CuCeGaoDoNum);
|
||||
else
|
||||
strDoClose = QString("DO2.%1=0\n").arg(CuCeGaoDoNum-8);
|
||||
|
||||
QString code;
|
||||
code+=
|
||||
QString("GLOBAL INT DuiLingF=-1\n")+
|
||||
QString("VEL(Z) = 2\n")+
|
||||
QString("ACC(Z) = 20\n")+
|
||||
QString("DEC(Z) = 20\n")+
|
||||
QString("JERK(Z) = 200\n")+
|
||||
QString("KDEC(Z) = 200\n")+
|
||||
QString("PTP/e Z, 0\n")+
|
||||
QString("VEL(Z0) = 5\n")+
|
||||
QString("ACC(Z0) = 50\n")+
|
||||
QString("DEC(Z0) = 50\n")+
|
||||
QString("JERK(Z0) = 500\n")+
|
||||
QString("KDEC(Z0) = 500\n")+
|
||||
QString("PTP/e Z0, 0\n")+
|
||||
strDoClose+
|
||||
QString("TILL %1\n").arg(strDiSts1)+
|
||||
"IF RangeV<-1.5\n"+
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToSafePosVel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToSafePosVel*100)+
|
||||
QString("PTP/e ZA, %1\n").arg(ZAAxisSafePos+1)+
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToZero1Vel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToZero1Vel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToZero1Vel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToZero1Vel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero1Vel*100)+
|
||||
"PTP ZA, -30\n"
|
||||
"TILL ABS(RangeV) < 0.5 | "+
|
||||
strDiSts0+
|
||||
"HALT ZA\n"
|
||||
"WAIT 1000\n"
|
||||
"if RangeV < -10\n"
|
||||
"DuiLingF=0\n"
|
||||
"goto duiling\n"
|
||||
"end\n"+
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToZero2Vel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToZero2Vel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToZero2Vel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToZero2Vel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero2Vel*100)+
|
||||
"PTP/er ZA, RangeV\n"
|
||||
"WAIT 1000\n"
|
||||
"ELSE\n"+
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToZero1Vel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToZero1Vel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToZero1Vel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToZero1Vel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero1Vel*100)+
|
||||
"PTP/ER ZA,RangeV\n"
|
||||
"WAIT 1800\n"+
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToZero2Vel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToZero2Vel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToZero2Vel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToZero2Vel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero2Vel*100)+
|
||||
"PTP/ER ZA,RangeV\n"
|
||||
"WAIT 600\n"
|
||||
"END\n"
|
||||
"IF ABS(RangeV) >= 0.0003\n"+
|
||||
QString("VEL(ZA) = %1\n").arg(ZAAxisToZero3Vel)+
|
||||
QString("ACC(ZA) = %1\n").arg(ZAAxisToZero3Vel*10)+
|
||||
QString("DEC(ZA) = %1\n").arg(ZAAxisToZero3Vel*10)+
|
||||
QString("JERK(ZA) = %1\n").arg(ZAAxisToZero3Vel*100)+
|
||||
QString("KDEC(ZA) = %1\n").arg(ZAAxisToZero3Vel*100)+
|
||||
"PTP/er ZA, RangeV\n"
|
||||
"END\n"
|
||||
"DuiLingF=1\n"
|
||||
"duiling:\n"+
|
||||
strDoOpen+
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
25
device/control/acs/buffercode/rsensortozero.h
Normal file
25
device/control/acs/buffercode/rsensortozero.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef RSENSORTOZERO_H
|
||||
#define RSENSORTOZERO_H
|
||||
#include<QString>
|
||||
|
||||
class RSensorToZero{
|
||||
public:
|
||||
RSensorToZero();
|
||||
QString getCode();
|
||||
void setZAAxisSafePos(double value);
|
||||
void setZAAxisToSafePosVel(double value);
|
||||
void setZAAxisToZero1Vel(double value);
|
||||
void setZAAxisToZero2Vel(double value);
|
||||
void setZAAxisToZero3Vel(double value);
|
||||
int CuCeGaoDoNum{0};
|
||||
int CuCeGaoDiNum{0};
|
||||
|
||||
private:
|
||||
double ZAAxisSafePos{0.0};
|
||||
double ZAAxisToSafePosVel{0.0};
|
||||
double ZAAxisToZero1Vel{0.0};
|
||||
double ZAAxisToZero2Vel{0.0};
|
||||
double ZAAxisToZero3Vel{0.0};
|
||||
};
|
||||
|
||||
#endif // RSENSORTOZERO_H
|
||||
100
device/control/acs/buffercode/sscancode.cpp
Normal file
100
device/control/acs/buffercode/sscancode.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "sscancode.h"
|
||||
|
||||
SScanCode::SScanCode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SScanCode::setXWorkRange(double value)
|
||||
{
|
||||
xWorkRange = value;
|
||||
}
|
||||
|
||||
void SScanCode::setYWorkRange(double value)
|
||||
{
|
||||
yWorkRange = value;
|
||||
}
|
||||
|
||||
void SScanCode::setXSampInterval(double value)
|
||||
{
|
||||
xSampInterval = value;
|
||||
}
|
||||
|
||||
void SScanCode::setYSampInterval(double value)
|
||||
{
|
||||
ySampInterval = value;
|
||||
}
|
||||
|
||||
int SScanCode::getSampTotalNum()
|
||||
{
|
||||
int xLineSegmentCounts,yLineSegmentCounts;
|
||||
// y线段数比x线段数多1
|
||||
xLineSegmentCounts = int(xWorkRange/xSampInterval);
|
||||
yLineSegmentCounts = xLineSegmentCounts+1;
|
||||
int xSampCounts,ySampCounts;
|
||||
ySampCounts = (accDecSampCount+int(yWorkRange*yNumberOfUnitSamples))*yLineSegmentCounts;
|
||||
xSampCounts = int(xWorkRange*xNumberOfUnitSamples)+xNumberOfLineSegmentSamples*(xLineSegmentCounts-1);
|
||||
return ySampCounts + xSampCounts;
|
||||
|
||||
}
|
||||
|
||||
QString SScanCode::getCode()
|
||||
{
|
||||
|
||||
QString code = QString("GLOBAL REAL scanData(2)(%1),rangeData(%1),yPosData(%1),yWorkRange\n").arg(getSampTotalNum());
|
||||
code +="REAL xPos,yPos\n"+
|
||||
QString("REAL xInterval = %1\n").arg(xSampInterval)+
|
||||
"ENABLE (X,Y)\n"
|
||||
// 停止buffer0运行
|
||||
"STOP 0\n"
|
||||
"START 0,1\n"+
|
||||
// 初始化数组
|
||||
QString("FILL(%1,scanData,0,0,0,%2); FILL(0, scanData,1,1,0,%2)\n").arg(rangeInitValue).arg(getSampTotalNum()-1)+
|
||||
"ACC(X)=8000;DEC(X)=8000;KDEC(X)=120000;JERK(X)=120000; ACC(Y)=8000;DEC(Y)=8000;KDEC(Y)=120000;JERK(Y)=120000;\n "
|
||||
// 设置X、Y轴到位精度,会对INPOS什么时候变为1有影响
|
||||
"TARGRAD(X) = 0.0001; TARGRAD(Y) = 0.0001\n"
|
||||
"WAIT 200\n"+
|
||||
// 设置X,Y轴起始位置。Y轴的起始位置把加减速段考虑进去
|
||||
QString("xPos = FPOS(X);yPos = FPOS(Y)-%1\n").arg(AccDecDist)+
|
||||
// X、Y轴走到起始位置,速度为60mm/s
|
||||
"PTP/EV (X,Y),xPos,yPos,60\n"+
|
||||
// Y轴的工作范围等于设置的工作范围+加速距离+减速距离
|
||||
QString("yWorkRange = %1\n").arg(yWorkRange+2*AccDecDist)+
|
||||
// 定义同步采集,采集测距传感器值、Y轴坐标,采集间隔为0.1ms,采集总数为sampTotalNum
|
||||
QString("DC/s Y,scanData,%1,1,RangeV,FPOS(Y)\n").arg(getSampTotalNum())+
|
||||
// 定义分段运动,起始位置为xStart,yStart,结束速度为vel
|
||||
QString("XSEG/vy (X,Y),xPos,yPos,%1\n").arg(yAxisVel)+
|
||||
// 循环次数等于Y线段数
|
||||
QString("LOOP %1\n").arg(xWorkRange/xSampInterval+1)+
|
||||
// X轴位置不变,Y轴移动工作范围距离
|
||||
// 第1段运动,Y轴向正方向移动(测距头向Y负方向移动)
|
||||
"yPos = yPos+yWorkRange\n"+
|
||||
QString("LINE/v (X,Y),xPos,yPos,%1\n").arg(yAxisVel)+
|
||||
// Y轴位置不变,X轴向正向移动一个步距
|
||||
"xPos = xPos+xInterval\n"+
|
||||
// /v参数定义当前和后续线段的速度,/f 定义当前线段结束时的速度
|
||||
// 意思就是说X轴运动时速度为20,Y轴运动时速度为100
|
||||
QString("LINE/vf (X,Y),xPos,yPos,%1,%2\n").arg(xAxisVel).arg(yAxisVel)+
|
||||
// Y轴移动工作距离范围取反
|
||||
"yWorkRange=(-1)*yWorkRange\n"
|
||||
"END\n"
|
||||
"ENDS (X,Y)\n"
|
||||
// 阻塞,等待多段运动结束
|
||||
"TILL ^AST(Y).5 & ^AST(X).5 & GSEG(X) = -1\n"
|
||||
// 停止采集
|
||||
"STOPDC/s Y\n"
|
||||
"INT validDataEndIndex\n"+
|
||||
// 在0~(sampTotalNum-1)范围内找到第一个最大值并返回其索引(最大值为数组初始化值,索引为采集的测距值最后一个的索引+1)
|
||||
QString("validDataEndIndex=MAXI(scanData,0,0,0,%1)\n").arg(getSampTotalNum()-1)+
|
||||
// 把采集的测距值拷贝到 rangeData数组中,把采集的Y轴的坐标放到yPosData数组中
|
||||
"COPY(scanData,rangeData,0,0,0,validDataEndIndex,0,validDataEndIndex); COPY(scanData,yPosData,1,1,0,validDataEndIndex,0,validDataEndIndex)\n"
|
||||
"runF = 1\n"
|
||||
"STOP";
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
40
device/control/acs/buffercode/sscancode.h
Normal file
40
device/control/acs/buffercode/sscancode.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef SSCANCODE_H
|
||||
#define SSCANCODE_H
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
class SScanCode
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
SScanCode();
|
||||
QString getCode();
|
||||
void setXWorkRange(double value);
|
||||
void setYWorkRange(double value);
|
||||
void setXSampInterval(double value);
|
||||
void setYSampInterval(double value);
|
||||
private:
|
||||
int getSampTotalNum();
|
||||
|
||||
private:
|
||||
double xWorkRange{1.0};
|
||||
double yWorkRange{1.0};
|
||||
double xSampInterval{1.0};
|
||||
double ySampInterval{1.0};
|
||||
|
||||
const int yNumberOfUnitSamples{12};
|
||||
const int xNumberOfUnitSamples{20};
|
||||
const int xNumberOfLineSegmentSamples{200};
|
||||
const int accDecSampCount{1500};
|
||||
// rangeInitValue 用于初始化保存测距值的数组
|
||||
double rangeInitValue{100.0};
|
||||
// 加减速距离
|
||||
double AccDecDist{45.0};
|
||||
double xAxisVel{20.0};
|
||||
double yAxisVel{100.0};
|
||||
};
|
||||
|
||||
#endif // SSCANCODE_H
|
||||
1333
device/control/acs/buffercode/tohomecode.cpp
Normal file
1333
device/control/acs/buffercode/tohomecode.cpp
Normal file
File diff suppressed because it is too large
Load Diff
114
device/control/acs/buffercode/tohomecode.h
Normal file
114
device/control/acs/buffercode/tohomecode.h
Normal file
@@ -0,0 +1,114 @@
|
||||
#ifndef TOHOMECODE_H
|
||||
#define TOHOMECODE_H
|
||||
#include <QString>
|
||||
#include "deviceproxy.h"
|
||||
class ToHomeCode
|
||||
{
|
||||
public:
|
||||
explicit ToHomeCode();
|
||||
QString getCode();
|
||||
|
||||
void setZAAxisToSafePosVel(double value);
|
||||
|
||||
void setXAxisToHomePos(double value);
|
||||
void setYAxisToHomePos(double value);
|
||||
void setZAxisToHomePos(double value);
|
||||
void setZAAxisToHomePos(double value);
|
||||
void setDAxisToHomePos(double value);
|
||||
void setZ0AxisToHomePos(double value);
|
||||
void setZ2AxisToHomePos(double value);
|
||||
|
||||
void setXAxisFindINDVel(double value);
|
||||
void setYAxisFindINDVel(double value);
|
||||
void setZAxisFindINDVel(double value);
|
||||
void setZAAxisFindINDVel(double value);
|
||||
void setDAxisFindINDVel(double value);
|
||||
void setZ0AxisFindINDVel(double value);
|
||||
void setZ2AxisFindINDVel(double value);
|
||||
|
||||
|
||||
void setXAxisINDZeroOffset(double value);
|
||||
void setYAxisINDZeroOffset(double value);
|
||||
void setZAxisINDZeroOffset(double value);
|
||||
void setZAAxisINDZeroOffset(double value);
|
||||
void setDAxisINDZeroOffset(double value);
|
||||
void setZ0AxisINDZeroOffset(double value);
|
||||
void setZ2AxisINDZeroOffset(double value);
|
||||
|
||||
void setXAxisSLLimit(double value);
|
||||
void setXAxisSRLimit(double value);
|
||||
void setYAxisSLLimit(double value);
|
||||
void setYAxisSRLimit(double value);
|
||||
void setZAxisSLLimit(double value);
|
||||
void setZAxisSRLimit(double value);
|
||||
void setZAAxisSLLimit(double value);
|
||||
void setZAAxisSRLimit(double value);
|
||||
void setDAxisSLLimit(double value);
|
||||
void setDAxisSRLimit(double value);
|
||||
void setZ0AxisSLLimit(double value);
|
||||
void setZ0AxisSRLimit(double value);
|
||||
void setZ2AxisSLLimit(double value);
|
||||
void setZ2AxisSRLimit(double value);
|
||||
|
||||
void setXAxisVel(double value);
|
||||
void setYAxisVel(double value);
|
||||
void setZAxisVel(double value);
|
||||
void setZAAxisVel(double value);
|
||||
void setDAxisVel(double value);
|
||||
void setZ0AxisVel(double value);
|
||||
void setZ2AxisVel(double value);
|
||||
|
||||
private:
|
||||
|
||||
double ZAAxisToSafePosVel{0.0};
|
||||
|
||||
double XAxisToHomePos{0.0};
|
||||
double YAxisToHomePos{0.0};
|
||||
double ZAxisToHomePos{0.0};
|
||||
double ZAAxisToHomePos{0.0};
|
||||
double DAxisToHomePos{0.0};
|
||||
double Z0AxisToHomePos{0.0};
|
||||
double Z2AxisToHomePos{0.0};
|
||||
|
||||
double XAxisFindINDVel{0.0};
|
||||
double YAxisFindINDVel{0.0};
|
||||
double ZAxisFindINDVel{0.0};
|
||||
double ZAAxisFindINDVel{0.0};
|
||||
double DAxisFindINDVel{0.0};
|
||||
double Z0AxisFindINDVel{0.0};
|
||||
double Z2AxisFindINDVel{0.0};
|
||||
|
||||
double XAxisINDZeroOffset{0.0};
|
||||
double YAxisINDZeroOffset{0.0};
|
||||
double ZAxisINDZeroOffset{0.0};
|
||||
double ZAAxisINDZeroOffset{0.0};
|
||||
double DAxisINDZeroOffset{0.0};
|
||||
double Z0AxisINDZeroOffset{0.0};
|
||||
double Z2AxisINDZeroOffset{0.0};
|
||||
|
||||
double XAxisSLLimit{0.0};
|
||||
double XAxisSRLimit{0.0};
|
||||
double YAxisSLLimit{0.0};
|
||||
double YAxisSRLimit{0.0};
|
||||
double ZAxisSLLimit{0.0};
|
||||
double ZAxisSRLimit{0.0};
|
||||
double ZAAxisSLLimit{0.0};
|
||||
double ZAAxisSRLimit{0.0};
|
||||
double DAxisSLLimit{0.0};
|
||||
double DAxisSRLimit{0.0};
|
||||
double Z0AxisSLLimit{0.0};
|
||||
double Z0AxisSRLimit{0.0};
|
||||
double Z2AxisSLLimit{0.0};
|
||||
double Z2AxisSRLimit{0.0};
|
||||
|
||||
|
||||
double XAxisVel{0.0};
|
||||
double YAxisVel{0.0};
|
||||
double ZAxisVel{0.0};
|
||||
double ZAAxisVel{0.0};
|
||||
double DAxisVel{0.0};
|
||||
double Z0AxisVel{0.0};
|
||||
double Z2AxisVel{0.0};
|
||||
};
|
||||
|
||||
#endif // TOHOMECODE_H
|
||||
BIN
device/coordinate/coordinate.dll
Normal file
BIN
device/coordinate/coordinate.dll
Normal file
Binary file not shown.
24
device/coordinate/coordinate.h
Normal file
24
device/coordinate/coordinate.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef COORDINATE_H
|
||||
#define COORDINATE_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(COORDINATE_LIBRARY)
|
||||
# define COORDINATESHARED_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define COORDINATESHARED_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
class COORDINATESHARED_EXPORT Coordinate
|
||||
{
|
||||
|
||||
public:
|
||||
Coordinate();
|
||||
|
||||
int add(int a,int b);
|
||||
void getCoordinate(QVector<QVector<int>> **vec,int *row,int *col);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // COORDINATE_H
|
||||
91
device/cppcodec/base32_crockford.hpp
Normal file
91
device/cppcodec/base32_crockford.hpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE32_CROCKFORD
|
||||
#define CPPCODEC_BASE32_CROCKFORD
|
||||
|
||||
#include "detail/codec.hpp"
|
||||
#include "detail/base32.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
|
||||
namespace detail {
|
||||
|
||||
static constexpr const char base32_crockford_alphabet[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // at index 10
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 18 - no I
|
||||
'J', 'K', // 20 - no L
|
||||
'M', 'N', // 22 - no O
|
||||
'P', 'Q', 'R', 'S', 'T', // 27 - no U
|
||||
'V', 'W', 'X', 'Y', 'Z' // 32
|
||||
};
|
||||
|
||||
class base32_crockford_base
|
||||
{
|
||||
public:
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
|
||||
static_assert(sizeof(base32_crockford_alphabet) == 32, "base32 alphabet must have 32 values");
|
||||
return sizeof(base32_crockford_alphabet);
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
|
||||
{
|
||||
return base32_crockford_alphabet[idx];
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c)
|
||||
{
|
||||
// Hex decoding is always case-insensitive (even in RFC 4648), the question
|
||||
// is only for encoding whether to use upper-case or lower-case letters.
|
||||
return (c == 'O' || c == 'o') ? '0'
|
||||
: (c == 'I' || c == 'i' || c == 'L' || c == 'l') ? '1'
|
||||
: (c >= 'a' && c <= 'z') ? (c - 'a' + 'A')
|
||||
: c;
|
||||
}
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return false; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return false; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char) { return false; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char c) {
|
||||
return c == '-'; // "Hyphens (-) can be inserted into strings [for readability]."
|
||||
}
|
||||
};
|
||||
|
||||
// base32_crockford is a concatenative iterative (i.e. streaming) interpretation of Crockford base32.
|
||||
// It interprets the statement "zero-extend the number to make its bit-length a multiple of 5"
|
||||
// to mean zero-extending it on the right.
|
||||
// (The other possible interpretation is base32_crockford_num, a place-based single number encoding system.
|
||||
// See http://merrigrove.blogspot.ca/2014/04/what-heck-is-base64-encoding-really.html for more info.)
|
||||
class base32_crockford : public base32_crockford_base
|
||||
{
|
||||
public:
|
||||
template <typename Codec> using codec_impl = stream_codec<Codec, base32_crockford>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using base32_crockford = detail::codec<detail::base32<detail::base32_crockford>>;
|
||||
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_BASE32_CROCKFORD
|
||||
31
device/cppcodec/base32_default_crockford.hpp
Normal file
31
device/cppcodec/base32_default_crockford.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE32_DEFAULT_CROCKFORD
|
||||
#define CPPCODEC_BASE32_DEFAULT_CROCKFORD
|
||||
|
||||
#include "base32_crockford.hpp"
|
||||
|
||||
using base32 = cppcodec::base32_crockford;
|
||||
|
||||
#endif // CPPCODEC_BASE32_DEFAULT_CROCKFORD
|
||||
31
device/cppcodec/base32_default_hex.hpp
Normal file
31
device/cppcodec/base32_default_hex.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2015, 2016 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE32_DEFAULT_HEX
|
||||
#define CPPCODEC_BASE32_DEFAULT_HEX
|
||||
|
||||
#include "base32_hex.hpp"
|
||||
|
||||
using base32 = cppcodec::base32_hex;
|
||||
|
||||
#endif // CPPCODEC_BASE32_DEFAULT_HEX
|
||||
31
device/cppcodec/base32_default_rfc4648.hpp
Normal file
31
device/cppcodec/base32_default_rfc4648.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE32_DEFAULT_RFC4648
|
||||
#define CPPCODEC_BASE32_DEFAULT_RFC4648
|
||||
|
||||
#include "base32_rfc4648.hpp"
|
||||
|
||||
using base32 = cppcodec::base32_rfc4648;
|
||||
|
||||
#endif // CPPCODEC_BASE32_DEFAULT_RFC4648
|
||||
76
device/cppcodec/base32_hex.hpp
Normal file
76
device/cppcodec/base32_hex.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (C) 2015, 2016 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE32_HEX
|
||||
#define CPPCODEC_BASE32_HEX
|
||||
|
||||
#include "detail/codec.hpp"
|
||||
#include "detail/base32.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
|
||||
namespace detail {
|
||||
|
||||
// RFC 4648 also specifies a hex encoding system which uses 0-9, then A-V.
|
||||
static constexpr const char base32_hex_alphabet[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
|
||||
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V'
|
||||
};
|
||||
|
||||
class base32_hex
|
||||
{
|
||||
public:
|
||||
template <typename Codec> using codec_impl = stream_codec<Codec, base32_hex>;
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
|
||||
static_assert(sizeof(base32_hex_alphabet) == 32, "base32 alphabet must have 32 values");
|
||||
return sizeof(base32_hex_alphabet);
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
|
||||
{
|
||||
return base32_hex_alphabet[idx];
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c)
|
||||
{
|
||||
// Lower-case letters are accepted, though not generally expected.
|
||||
return (c >= 'a' && c <= 'v') ? (c - 'a' + 'A') : c;
|
||||
}
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return true; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return true; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char padding_symbol() { return '='; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char c) { return c == '='; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
|
||||
|
||||
// RFC4648 does not specify any whitespace being allowed in base32 encodings.
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using base32_hex = detail::codec<detail::base32<detail::base32_hex>>;
|
||||
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_BASE32_HEX
|
||||
76
device/cppcodec/base32_rfc4648.hpp
Normal file
76
device/cppcodec/base32_rfc4648.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE32_RFC4648
|
||||
#define CPPCODEC_BASE32_RFC4648
|
||||
|
||||
#include "detail/codec.hpp"
|
||||
#include "detail/base32.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
|
||||
namespace detail {
|
||||
|
||||
// RFC 4648 uses a simple alphabet: A-Z starting at index 0, then 2-7 starting at index 26.
|
||||
static constexpr const char base32_rfc4648_alphabet[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', // at index 26
|
||||
'2', '3', '4', '5', '6', '7'
|
||||
};
|
||||
|
||||
class base32_rfc4648
|
||||
{
|
||||
public:
|
||||
template <typename Codec> using codec_impl = stream_codec<Codec, base32_rfc4648>;
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
|
||||
static_assert(sizeof(base32_rfc4648_alphabet) == 32, "base32 alphabet must have 32 values");
|
||||
return sizeof(base32_rfc4648_alphabet);
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
|
||||
{
|
||||
return base32_rfc4648_alphabet[idx];
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c)
|
||||
{
|
||||
// Lower-case letters are accepted, though not generally expected.
|
||||
return (c >= 'a' && c <= 'z') ? (c - 'a' + 'A') : c;
|
||||
}
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return true; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return true; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char padding_symbol() { return '='; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char c) { return c == '='; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
|
||||
|
||||
// RFC4648 does not specify any whitespace being allowed in base32 encodings.
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using base32_rfc4648 = detail::codec<detail::base32<detail::base32_rfc4648>>;
|
||||
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_BASE32_RFC4648
|
||||
31
device/cppcodec/base64_default_rfc4648.hpp
Normal file
31
device/cppcodec/base64_default_rfc4648.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE64_DEFAULT_RFC4648
|
||||
#define CPPCODEC_BASE64_DEFAULT_RFC4648
|
||||
|
||||
#include "base64_rfc4648.hpp"
|
||||
|
||||
using base64 = cppcodec::base64_rfc4648;
|
||||
|
||||
#endif // CPPCODEC_BASE64_DEFAULT_RFC4648
|
||||
31
device/cppcodec/base64_default_url.hpp
Normal file
31
device/cppcodec/base64_default_url.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE64_DEFAULT_URL
|
||||
#define CPPCODEC_BASE64_DEFAULT_URL
|
||||
|
||||
#include "base64_url.hpp"
|
||||
|
||||
using base64 = cppcodec::base64_url;
|
||||
|
||||
#endif // CPPCODEC_BASE64_DEFAULT_URL
|
||||
31
device/cppcodec/base64_default_url_unpadded.hpp
Normal file
31
device/cppcodec/base64_default_url_unpadded.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE64_DEFAULT_URL_UNPADDED
|
||||
#define CPPCODEC_BASE64_DEFAULT_URL_UNPADDED
|
||||
|
||||
#include "base64_url_unpadded.hpp"
|
||||
|
||||
using base64 = cppcodec::base64_url_unpadded;
|
||||
|
||||
#endif // CPPCODEC_BASE64_DEFAULT_URL_UNPADDED
|
||||
73
device/cppcodec/base64_rfc4648.hpp
Normal file
73
device/cppcodec/base64_rfc4648.hpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE64_RFC4648
|
||||
#define CPPCODEC_BASE64_RFC4648
|
||||
|
||||
#include "detail/codec.hpp"
|
||||
#include "detail/base64.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
|
||||
namespace detail {
|
||||
|
||||
static constexpr const char base64_rfc4648_alphabet[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
class base64_rfc4648
|
||||
{
|
||||
public:
|
||||
template <typename Codec> using codec_impl = stream_codec<Codec, base64_rfc4648>;
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
|
||||
static_assert(sizeof(base64_rfc4648_alphabet) == 64, "base64 alphabet must have 64 values");
|
||||
return sizeof(base64_rfc4648_alphabet);
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
|
||||
{
|
||||
return base64_rfc4648_alphabet[idx];
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c) { return c; }
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return true; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return true; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char padding_symbol() { return '='; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char c) { return c == '='; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
|
||||
|
||||
// RFC4648 does not specify any whitespace being allowed in base64 encodings.
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using base64_rfc4648 = detail::codec<detail::base64<detail::base64_rfc4648>>;
|
||||
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_BASE64_RFC4648
|
||||
75
device/cppcodec/base64_url.hpp
Normal file
75
device/cppcodec/base64_url.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE64_URL
|
||||
#define CPPCODEC_BASE64_URL
|
||||
|
||||
#include "detail/codec.hpp"
|
||||
#include "detail/base64.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
|
||||
namespace detail {
|
||||
|
||||
// The URL and filename safe alphabet is also specified by RFC4648, named "base64url".
|
||||
// We keep the underscore ("base64_url") for consistency with the other codec variants.
|
||||
static constexpr const char base64_url_alphabet[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'
|
||||
};
|
||||
|
||||
class base64_url
|
||||
{
|
||||
public:
|
||||
template <typename Codec> using codec_impl = stream_codec<Codec, base64_url>;
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
|
||||
static_assert(sizeof(base64_url_alphabet) == 64, "base64 alphabet must have 64 values");
|
||||
return sizeof(base64_url_alphabet);
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
|
||||
{
|
||||
return base64_url_alphabet[idx];
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c) { return c; }
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return true; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return true; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char padding_symbol() { return '='; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char c) { return c == '='; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
|
||||
|
||||
// RFC4648 does not specify any whitespace being allowed in base64 encodings.
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using base64_url = detail::codec<detail::base64<detail::base64_url>>;
|
||||
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_BASE64_URL
|
||||
48
device/cppcodec/base64_url_unpadded.hpp
Normal file
48
device/cppcodec/base64_url_unpadded.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_BASE64_URL_UNPADDED
|
||||
#define CPPCODEC_BASE64_URL_UNPADDED
|
||||
|
||||
#include "base64_url.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
|
||||
namespace detail {
|
||||
|
||||
class base64_url_unpadded : public base64_url
|
||||
{
|
||||
public:
|
||||
template <typename Codec> using codec_impl = stream_codec<Codec, base64_url_unpadded>;
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return false; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return false; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using base64_url_unpadded = detail::codec<detail::base64<detail::base64_url_unpadded>>;
|
||||
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_BASE64_URL_UNPADDED
|
||||
328
device/cppcodec/data/access.hpp
Normal file
328
device/cppcodec/data/access.hpp
Normal file
@@ -0,0 +1,328 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* Copyright (C) 2018 Jakob Petsovits
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_DETAIL_DATA_ACCESS
|
||||
#define CPPCODEC_DETAIL_DATA_ACCESS
|
||||
|
||||
#include <stdint.h> // for size_t
|
||||
#include <string> // for static_assert() checking that string will be optimized
|
||||
#include <type_traits> // for std::enable_if, std::remove_reference, and such
|
||||
#include <utility> // for std::declval
|
||||
#include <vector> // for static_assert() checking that vector will be optimized
|
||||
|
||||
#include "../detail/config.hpp" // for CPPCODEC_ALWAYS_INLINE
|
||||
|
||||
namespace cppcodec {
|
||||
namespace data {
|
||||
|
||||
// This file contains a number of templated data accessors that can be
|
||||
// implemented in the cppcodec::data namespace for types that don't fulfill
|
||||
// the default type requirements:
|
||||
// For result types: init(Result&, ResultState&, size_t capacity),
|
||||
// put(Result&, ResultState&, char), finish(Result&, State&)
|
||||
// For const (read-only) types: char_data(const T&)
|
||||
// For both const and result types: size(const T&)
|
||||
|
||||
template <typename T>
|
||||
CPPCODEC_ALWAYS_INLINE size_t size(const T& t) { return t.size(); }
|
||||
|
||||
template <typename T, size_t N>
|
||||
CPPCODEC_ALWAYS_INLINE constexpr size_t size(const T (&t)[N]) noexcept {
|
||||
return (void)t, N * sizeof(t[0]);
|
||||
}
|
||||
|
||||
class general_t {};
|
||||
class specific_t : public general_t {};
|
||||
|
||||
class empty_result_state {
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void size(const Result& result) { return size(result); }
|
||||
};
|
||||
|
||||
// SFINAE: Generic fallback in case no specific state function applies.
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE empty_result_state create_state(Result&, general_t)
|
||||
{
|
||||
return empty_result_state();
|
||||
}
|
||||
|
||||
//
|
||||
// Generic templates for containers: Use these init()/put()/finish()
|
||||
// implementations if no specialization was found.
|
||||
//
|
||||
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void init(Result& result, empty_result_state&, size_t capacity)
|
||||
{
|
||||
result.resize(0);
|
||||
result.reserve(capacity);
|
||||
}
|
||||
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void finish(Result&, empty_result_state&)
|
||||
{
|
||||
// Default is to push_back(), which already increases the size.
|
||||
}
|
||||
|
||||
// For the put() default implementation, we try calling push_back() with either uint8_t or char,
|
||||
// whichever compiles. Scary-fancy template magic from http://stackoverflow.com/a/1386390.
|
||||
namespace fallback {
|
||||
struct flag { char c[2]; }; // sizeof > 1
|
||||
flag put_uint8(...);
|
||||
|
||||
int operator,(flag, flag);
|
||||
template <typename T> void operator,(flag, T&); // map everything else to void
|
||||
char operator,(int, flag); // sizeof 1
|
||||
}
|
||||
|
||||
template <typename Result> inline void put_uint8(Result& result, uint8_t c) { result.push_back(c); }
|
||||
|
||||
template <bool> struct put_impl;
|
||||
template <> struct put_impl<true> { // put_uint8() available
|
||||
template<typename Result>
|
||||
static CPPCODEC_ALWAYS_INLINE void put(Result& result, uint8_t c)
|
||||
{
|
||||
put_uint8(result, c);
|
||||
}
|
||||
};
|
||||
template <> struct put_impl<false> { // put_uint8() not available
|
||||
template<typename Result>
|
||||
static CPPCODEC_ALWAYS_INLINE void put(Result& result, uint8_t c)
|
||||
{
|
||||
result.push_back(static_cast<char>(c));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void put(Result& result, empty_result_state&, uint8_t c)
|
||||
{
|
||||
using namespace fallback;
|
||||
put_impl<sizeof(fallback::flag(), put_uint8(result, c), fallback::flag()) != 1>::put(result, c);
|
||||
}
|
||||
|
||||
//
|
||||
// Specialization for container types with direct mutable data access,
|
||||
// e.g. std::vector<uint8_t>.
|
||||
//
|
||||
// The expected way to specialize is to draft a new xyz_result_state type and
|
||||
// return an instance of it from a create_state() template specialization.
|
||||
// You can then create overloads for init(), put() and finish()
|
||||
// for the new result state type.
|
||||
//
|
||||
// If desired, a non-templated overload for both specific types
|
||||
// (result & state) can be added to tailor it to that particular result type.
|
||||
//
|
||||
|
||||
template <typename T>
|
||||
constexpr auto data_is_mutable(T* t) -> decltype(t->data()[size_t(0)] = 'x', bool())
|
||||
{
|
||||
return (void)t, true;
|
||||
}
|
||||
constexpr bool data_is_mutable(...) { return false; }
|
||||
|
||||
template <typename Result>
|
||||
class direct_data_access_result_state
|
||||
{
|
||||
public:
|
||||
CPPCODEC_ALWAYS_INLINE void init(Result& result, size_t capacity)
|
||||
{
|
||||
// reserve() may not actually allocate the storage right away,
|
||||
// and it isn't guaranteed that it will be untouched upon the
|
||||
//.next resize(). In that light, resize from the start and
|
||||
// slightly reduce the size at the end if necessary.
|
||||
result.resize(capacity);
|
||||
|
||||
// result.data() may perform a calculation to retrieve the address.
|
||||
// E.g. std::string (since C++11) will use small string optimization,
|
||||
// so it needs to check if it's using allocated data or (ab)using
|
||||
// its own member variables interpreted as char array.
|
||||
// (This result_state is used for std::string starting with C++17.)
|
||||
// Conditional code paths are slow so we only do it once, at the start.
|
||||
m_buffer = result.data();
|
||||
}
|
||||
CPPCODEC_ALWAYS_INLINE void put(Result&, char c)
|
||||
{
|
||||
m_buffer[m_offset++] = c;
|
||||
}
|
||||
CPPCODEC_ALWAYS_INLINE void finish(Result& result)
|
||||
{
|
||||
result.resize(m_offset);
|
||||
}
|
||||
CPPCODEC_ALWAYS_INLINE size_t size(const Result&)
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
private:
|
||||
// Make sure to get the mutable buffer decltype by using assignment.
|
||||
typename std::remove_reference<
|
||||
decltype(std::declval<Result>().data()[size_t(0)] = 'x')>::type* m_buffer;
|
||||
size_t m_offset = 0;
|
||||
};
|
||||
|
||||
// SFINAE: Select a specific state based on the result type and possible result state type.
|
||||
// Implement this if direct data access (`result.data()[0] = 'x') isn't already possible
|
||||
// and you want to specialize it for your own result type.
|
||||
// Note: The enable_if should ideally be part of the class declaration,
|
||||
// but Visual Studio C++ will not compile it that way.
|
||||
// Have it here in the factory function instead.
|
||||
template <typename Result,
|
||||
typename = typename std::enable_if<
|
||||
data_is_mutable(static_cast<Result*>(nullptr))>::type>
|
||||
CPPCODEC_ALWAYS_INLINE direct_data_access_result_state<Result> create_state(Result&, specific_t)
|
||||
{
|
||||
return direct_data_access_result_state<Result>();
|
||||
}
|
||||
|
||||
static_assert(std::is_same<
|
||||
decltype(create_state(*static_cast<std::vector<uint8_t>*>(nullptr), specific_t())),
|
||||
direct_data_access_result_state<std::vector<uint8_t>>>::value,
|
||||
"std::vector<uint8_t> must be handled by direct_data_access_result_state");
|
||||
|
||||
// Specialized init(), put() and finish() functions for direct_data_access_result_state.
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void init(Result& result, direct_data_access_result_state<Result>& state, size_t capacity)
|
||||
{
|
||||
state.init(result, capacity);
|
||||
}
|
||||
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void put(Result& result, direct_data_access_result_state<Result>& state, char c)
|
||||
{
|
||||
state.put(result, c);
|
||||
}
|
||||
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void finish(Result& result, direct_data_access_result_state<Result>& state)
|
||||
{
|
||||
state.finish(result);
|
||||
}
|
||||
|
||||
//
|
||||
// Specialization for container types with direct mutable array access,
|
||||
// e.g. std::string. This is generally faster because bound checks are
|
||||
// minimal and operator[] is more likely noexcept. In addition,
|
||||
// std::string::push_back() needs to write a null character on every
|
||||
// expansion, which should be more efficient when done in bulk by resize().
|
||||
//
|
||||
// Compared to the above, tracking an extra offset variable is cheap.
|
||||
//
|
||||
|
||||
template <typename T>
|
||||
constexpr auto array_access_is_mutable(T* t) -> decltype((*t)[size_t(0)] = 'x', bool())
|
||||
{
|
||||
return (void)t, true;
|
||||
}
|
||||
constexpr bool array_access_is_mutable(...) { return false; }
|
||||
|
||||
template <typename Result>
|
||||
class array_access_result_state
|
||||
{
|
||||
public:
|
||||
CPPCODEC_ALWAYS_INLINE void init(Result& result, size_t capacity)
|
||||
{
|
||||
// reserve() may not actually allocate the storage right away,
|
||||
// and it isn't guaranteed that it will be untouched upon the
|
||||
//.next resize(). In that light, resize from the start and
|
||||
// slightly reduce the size at the end if necessary.
|
||||
result.resize(capacity);
|
||||
}
|
||||
CPPCODEC_ALWAYS_INLINE void put(Result& result, char c)
|
||||
{
|
||||
result[m_offset++] = c;
|
||||
}
|
||||
CPPCODEC_ALWAYS_INLINE void finish(Result& result)
|
||||
{
|
||||
result.resize(m_offset);
|
||||
}
|
||||
CPPCODEC_ALWAYS_INLINE size_t size(const Result&)
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
private:
|
||||
size_t m_offset = 0;
|
||||
};
|
||||
|
||||
// SFINAE: Select a specific state based on the result type and possible result state type.
|
||||
// Note: The enable_if should ideally be part of the class declaration,
|
||||
// but Visual Studio C++ will not compile it that way.
|
||||
// Have it here in the factory function instead.
|
||||
template <typename Result,
|
||||
typename = typename std::enable_if<
|
||||
!data_is_mutable(static_cast<Result*>(nullptr)) // no more than one template option
|
||||
&& array_access_is_mutable(static_cast<Result*>(nullptr))>::type>
|
||||
CPPCODEC_ALWAYS_INLINE array_access_result_state<Result> create_state(Result&, specific_t)
|
||||
{
|
||||
return array_access_result_state<Result>();
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG > 201703L)
|
||||
static_assert(std::is_same<
|
||||
decltype(create_state(*static_cast<std::string*>(nullptr), specific_t())),
|
||||
direct_data_access_result_state<std::string>>::value,
|
||||
"std::string (C++17 and later) must be handled by direct_data_access_result_state");
|
||||
#elif __cplusplus < 201703 && !defined(_MSVC_LANG) // we can't trust MSVC to set this right
|
||||
static_assert(std::is_same<
|
||||
decltype(create_state(*static_cast<std::string*>(nullptr), specific_t())),
|
||||
array_access_result_state<std::string>>::value,
|
||||
"std::string (pre-C++17) must be handled by array_access_result_state");
|
||||
#endif
|
||||
|
||||
// Specialized init(), put() and finish() functions for array_access_result_state.
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void init(Result& result, array_access_result_state<Result>& state, size_t capacity)
|
||||
{
|
||||
state.init(result, capacity);
|
||||
}
|
||||
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void put(Result& result, array_access_result_state<Result>& state, char c)
|
||||
{
|
||||
state.put(result, c);
|
||||
}
|
||||
|
||||
template <typename Result>
|
||||
CPPCODEC_ALWAYS_INLINE void finish(Result& result, array_access_result_state<Result>& state)
|
||||
{
|
||||
state.finish(result);
|
||||
}
|
||||
|
||||
// char_data() is only used to read, not for result buffers.
|
||||
template <typename T> inline const char* char_data(const T& t)
|
||||
{
|
||||
return reinterpret_cast<const char*>(t.data());
|
||||
}
|
||||
template <typename T, size_t N> inline const char* char_data(const T (&t)[N]) noexcept
|
||||
{
|
||||
return reinterpret_cast<const char*>(&(t[0]));
|
||||
}
|
||||
|
||||
template <typename T> inline const uint8_t* uchar_data(const T& t)
|
||||
{
|
||||
return reinterpret_cast<const uint8_t*>(char_data(t));
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif
|
||||
70
device/cppcodec/data/raw_result_buffer.hpp
Normal file
70
device/cppcodec/data/raw_result_buffer.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_DETAIL_RAW_RESULT_BUFFER
|
||||
#define CPPCODEC_DETAIL_RAW_RESULT_BUFFER
|
||||
|
||||
#include <stdint.h> // for size_t
|
||||
#include <stdlib.h> // for abort()
|
||||
|
||||
#include "access.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
namespace data {
|
||||
|
||||
class raw_result_buffer
|
||||
{
|
||||
public:
|
||||
raw_result_buffer(char* data, size_t capacity)
|
||||
: m_ptr(data + capacity)
|
||||
, m_begin(data)
|
||||
{
|
||||
}
|
||||
|
||||
CPPCODEC_ALWAYS_INLINE void push_back(char c) { *m_ptr = c; ++m_ptr; }
|
||||
CPPCODEC_ALWAYS_INLINE size_t size() const { return m_ptr - m_begin; }
|
||||
CPPCODEC_ALWAYS_INLINE void resize(size_t size) { m_ptr = m_begin + size; }
|
||||
|
||||
private:
|
||||
char* m_ptr;
|
||||
char* m_begin;
|
||||
};
|
||||
|
||||
|
||||
template <> inline void init<raw_result_buffer>(
|
||||
raw_result_buffer& result, empty_result_state&, size_t capacity)
|
||||
{
|
||||
// This version of init() doesn't do a reserve(), and instead checks whether the
|
||||
// initial size (capacity) is enough before resetting m_ptr to m_begin.
|
||||
// The codec is expected not to exceed this capacity.
|
||||
if (capacity > result.size()) {
|
||||
abort();
|
||||
}
|
||||
result.resize(0);
|
||||
}
|
||||
template <> inline void finish<raw_result_buffer>(raw_result_buffer&, empty_result_state&) { }
|
||||
|
||||
} // namespace data
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif
|
||||
166
device/cppcodec/detail/base32.hpp
Normal file
166
device/cppcodec/detail/base32.hpp
Normal file
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Trustifier Inc.
|
||||
* Copyright (C) 2015 Ahmed Masud
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* Copyright (C) 2018 Jakob Petsovits
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Adapted from https://github.com/ahmed-masud/libbase32,
|
||||
* commit 79761b2b79b0545697945efe0987a8d3004512f9.
|
||||
* Quite different now.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_DETAIL_BASE32
|
||||
#define CPPCODEC_DETAIL_BASE32
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h> // for abort()
|
||||
|
||||
#include "../data/access.hpp"
|
||||
#include "../parse_error.hpp"
|
||||
#include "config.hpp"
|
||||
#include "stream_codec.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
namespace detail {
|
||||
|
||||
template <typename CodecVariant>
|
||||
class base32 : public CodecVariant::template codec_impl<base32<CodecVariant>>
|
||||
{
|
||||
public:
|
||||
static inline constexpr uint8_t binary_block_size() { return 5; }
|
||||
static inline constexpr uint8_t encoded_block_size() { return 8; }
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr uint8_t num_encoded_tail_symbols(uint8_t num_bytes)
|
||||
{
|
||||
return (num_bytes == 1) ? 2 // 2 symbols, 6 padding characters
|
||||
: (num_bytes == 2) ? 4 // 4 symbols, 4 padding characters
|
||||
: (num_bytes == 3) ? 5 // 5 symbols, 3 padding characters
|
||||
: (num_bytes == 4) ? 7 // 7 symbols, 1 padding characters
|
||||
: throw std::domain_error("invalid number of bytes in a tail block");
|
||||
}
|
||||
|
||||
template <uint8_t I>
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr uint8_t index(
|
||||
const uint8_t* b /*binary block*/) noexcept
|
||||
{
|
||||
static_assert(I >= 0 && I < encoded_block_size(),
|
||||
"invalid encoding symbol index in a block");
|
||||
|
||||
return (I == 0) ? ((b[0] >> 3) & 0x1F) // first 5 bits
|
||||
: (I == 1) ? (((b[0] << 2) & 0x1C) | ((b[1] >> 6) & 0x3))
|
||||
: (I == 2) ? ((b[1] >> 1) & 0x1F)
|
||||
: (I == 3) ? (((b[1] << 4) & 0x10) | ((b[2] >> 4) & 0xF))
|
||||
: (I == 4) ? (((b[2] << 1) & 0x1E) | ((b[3] >> 7) & 0x1))
|
||||
: (I == 5) ? ((b[3] >> 2) & 0x1F)
|
||||
: (I == 6) ? (((b[3] << 3) & 0x18) | ((b[4] >> 5) & 0x7))
|
||||
: /*I == 7*/ (b[4] & 0x1F); // last 5 bits;
|
||||
}
|
||||
|
||||
template <bool B>
|
||||
using uint8_if = typename std::enable_if<B, uint8_t>::type;
|
||||
|
||||
template <uint8_t I>
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr
|
||||
uint8_if<I == 1 || I == 3 || I == 4 || I == 6> index_last(
|
||||
const uint8_t* b /*binary block*/) noexcept
|
||||
{
|
||||
return (I == 1) ? ((b[0] << 2) & 0x1C) // abbreviated 2nd symbol
|
||||
: (I == 3) ? ((b[1] << 4) & 0x10) // abbreviated 4th symbol
|
||||
: (I == 4) ? ((b[2] << 1) & 0x1E) // abbreviated 5th symbol
|
||||
: /*I == 6*/ ((b[3] << 3) & 0x18); // abbreviated 7th symbol
|
||||
}
|
||||
|
||||
template <uint8_t I>
|
||||
static CPPCODEC_ALWAYS_INLINE
|
||||
uint8_if<I != 1 && I != 3 && I != 4 && I != 6> index_last(
|
||||
const uint8_t* /*binary block*/)
|
||||
{
|
||||
throw std::domain_error("invalid last encoding symbol index in a tail");
|
||||
}
|
||||
|
||||
template <typename Result, typename ResultState>
|
||||
static CPPCODEC_ALWAYS_INLINE void decode_block(
|
||||
Result& decoded, ResultState&, const alphabet_index_t* idx);
|
||||
|
||||
template <typename Result, typename ResultState>
|
||||
static CPPCODEC_ALWAYS_INLINE void decode_tail(
|
||||
Result& decoded, ResultState&, const alphabet_index_t* idx, size_t idx_len);
|
||||
};
|
||||
|
||||
//
|
||||
// 11111111 10101010 10110011 10111100 10010100
|
||||
// => 11111 11110 10101 01011 00111 01111 00100 10100
|
||||
//
|
||||
|
||||
template <typename CodecVariant>
|
||||
template <typename Result, typename ResultState>
|
||||
CPPCODEC_ALWAYS_INLINE void base32<CodecVariant>::decode_block(
|
||||
Result& decoded, ResultState& state, const alphabet_index_t* idx)
|
||||
{
|
||||
put(decoded, state, static_cast<uint8_t>(((idx[0] << 3) & 0xF8) | ((idx[1] >> 2) & 0x7)));
|
||||
put(decoded, state, static_cast<uint8_t>(((idx[1] << 6) & 0xC0) | ((idx[2] << 1) & 0x3E) | ((idx[3] >> 4) & 0x1)));
|
||||
put(decoded, state, static_cast<uint8_t>(((idx[3] << 4) & 0xF0) | ((idx[4] >> 1) & 0xF)));
|
||||
put(decoded, state, static_cast<uint8_t>(((idx[4] << 7) & 0x80) | ((idx[5] << 2) & 0x7C) | ((idx[6] >> 3) & 0x3)));
|
||||
put(decoded, state, static_cast<uint8_t>(((idx[6] << 5) & 0xE0) | (idx[7] & 0x1F)));
|
||||
}
|
||||
|
||||
template <typename CodecVariant>
|
||||
template <typename Result, typename ResultState>
|
||||
CPPCODEC_ALWAYS_INLINE void base32<CodecVariant>::decode_tail(
|
||||
Result& decoded, ResultState& state, const alphabet_index_t* idx, size_t idx_len)
|
||||
{
|
||||
if (idx_len == 1) {
|
||||
throw invalid_input_length(
|
||||
"invalid number of symbols in last base32 block: found 1, expected 2, 4, 5 or 7");
|
||||
}
|
||||
if (idx_len == 3) {
|
||||
throw invalid_input_length(
|
||||
"invalid number of symbols in last base32 block: found 3, expected 2, 4, 5 or 7");
|
||||
}
|
||||
if (idx_len == 6) {
|
||||
throw invalid_input_length(
|
||||
"invalid number of symbols in last base32 block: found 6, expected 2, 4, 5 or 7");
|
||||
}
|
||||
|
||||
// idx_len == 2: decoded size 1
|
||||
put(decoded, state, static_cast<uint8_t>(((idx[0] << 3) & 0xF8) | ((idx[1] >> 2) & 0x7)));
|
||||
if (idx_len == 2) {
|
||||
return;
|
||||
}
|
||||
// idx_len == 4: decoded size 2
|
||||
put(decoded, state, static_cast<uint8_t>(((idx[1] << 6) & 0xC0) | ((idx[2] << 1) & 0x3E) | ((idx[3] >> 4) & 0x1)));
|
||||
if (idx_len == 4) {
|
||||
return;
|
||||
}
|
||||
// idx_len == 5: decoded size 3
|
||||
put(decoded, state, static_cast<uint8_t>(((idx[3] << 4) & 0xF0) | ((idx[4] >> 1) & 0xF)));
|
||||
if (idx_len == 5) {
|
||||
return;
|
||||
}
|
||||
// idx_len == 7: decoded size 4
|
||||
put(decoded, state, static_cast<uint8_t>(((idx[4] << 7) & 0x80) | ((idx[5] << 2) & 0x7C) | ((idx[6] >> 3) & 0x3)));
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_DETAIL_BASE32
|
||||
132
device/cppcodec/detail/base64.hpp
Normal file
132
device/cppcodec/detail/base64.hpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* Copyright (C) 2013 Adam Rudd (bit calculations)
|
||||
* Copyright (C) 2018 Jakob Petsovits
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Bit calculations adapted from https://github.com/adamvr/arduino-base64,
|
||||
* commit 999595783185a0afcba156d7276dfeaa9cb5382f.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_DETAIL_BASE64
|
||||
#define CPPCODEC_DETAIL_BASE64
|
||||
|
||||
#include <stdexcept>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../data/access.hpp"
|
||||
#include "../parse_error.hpp"
|
||||
#include "config.hpp"
|
||||
#include "stream_codec.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
namespace detail {
|
||||
|
||||
template <typename CodecVariant>
|
||||
class base64 : public CodecVariant::template codec_impl<base64<CodecVariant>>
|
||||
{
|
||||
public:
|
||||
static inline constexpr uint8_t binary_block_size() { return 3; }
|
||||
static inline constexpr uint8_t encoded_block_size() { return 4; }
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr uint8_t num_encoded_tail_symbols(uint8_t num_bytes)
|
||||
{
|
||||
return (num_bytes == 1) ? 2 // 2 symbols, 2 padding characters
|
||||
: (num_bytes == 2) ? 3 // 3 symbols, 1 padding character
|
||||
: throw std::domain_error("invalid number of bytes in a tail block");
|
||||
}
|
||||
|
||||
template <uint8_t I>
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr uint8_t index(
|
||||
const uint8_t* b /*binary block*/) noexcept
|
||||
{
|
||||
static_assert(I >= 0 && I < encoded_block_size(),
|
||||
"invalid encoding symbol index in a block");
|
||||
|
||||
return (I == 0) ? (b[0] >> 2) // first 6 bits
|
||||
: (I == 1) ? (((b[0] & 0x3) << 4) | (b[1] >> 4))
|
||||
: (I == 2) ? (((b[1] & 0xF) << 2) | (b[2] >> 6))
|
||||
: /*I == 3*/ (b[2] & 0x3F); // last 6 bits
|
||||
}
|
||||
|
||||
template <bool B>
|
||||
using uint8_if = typename std::enable_if<B, uint8_t>::type;
|
||||
|
||||
template <uint8_t I>
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr uint8_if<I == 1 || I == 2> index_last(
|
||||
const uint8_t* b /*binary block*/) noexcept
|
||||
{
|
||||
return (I == 1) ? ((b[0] & 0x3) << 4) // abbreviated 2nd symbol
|
||||
: /*I == 2*/ ((b[1] & 0xF) << 2); // abbreviated 3rd symbol
|
||||
}
|
||||
|
||||
template <uint8_t I>
|
||||
static CPPCODEC_ALWAYS_INLINE uint8_if<I != 1 && I != 2> index_last(
|
||||
const uint8_t* /*binary block*/)
|
||||
{
|
||||
throw std::domain_error("invalid last encoding symbol index in a tail");
|
||||
}
|
||||
|
||||
template <typename Result, typename ResultState>
|
||||
static CPPCODEC_ALWAYS_INLINE void decode_block(
|
||||
Result& decoded, ResultState&, const alphabet_index_t* idx);
|
||||
|
||||
template <typename Result, typename ResultState>
|
||||
static CPPCODEC_ALWAYS_INLINE void decode_tail(
|
||||
Result& decoded, ResultState&, const alphabet_index_t* idx, size_t idx_len);
|
||||
};
|
||||
|
||||
|
||||
template <typename CodecVariant>
|
||||
template <typename Result, typename ResultState>
|
||||
CPPCODEC_ALWAYS_INLINE void base64<CodecVariant>::decode_block(
|
||||
Result& decoded, ResultState& state, const alphabet_index_t* idx)
|
||||
{
|
||||
uint_fast32_t dec = (idx[0] << 18) | (idx[1] << 12) | (idx[2] << 6) | idx[3];
|
||||
data::put(decoded, state, static_cast<uint8_t>(dec >> 16));
|
||||
data::put(decoded, state, static_cast<uint8_t>((dec >> 8) & 0xFF));
|
||||
data::put(decoded, state, static_cast<uint8_t>(dec & 0xFF));
|
||||
}
|
||||
|
||||
template <typename CodecVariant>
|
||||
template <typename Result, typename ResultState>
|
||||
CPPCODEC_ALWAYS_INLINE void base64<CodecVariant>::decode_tail(
|
||||
Result& decoded, ResultState& state, const alphabet_index_t* idx, size_t idx_len)
|
||||
{
|
||||
if (idx_len == 1) {
|
||||
throw invalid_input_length(
|
||||
"invalid number of symbols in last base64 block: found 1, expected 2 or 3");
|
||||
}
|
||||
|
||||
// idx_len == 2: decoded size 1
|
||||
data::put(decoded, state, static_cast<uint8_t>((idx[0] << 2) + ((idx[1] & 0x30) >> 4)));
|
||||
if (idx_len == 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
// idx_len == 3: decoded size 2
|
||||
data::put(decoded, state, static_cast<uint8_t>(((idx[1] & 0xF) << 4) + ((idx[2] & 0x3C) >> 2)));
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_DETAIL_BASE64
|
||||
327
device/cppcodec/detail/codec.hpp
Normal file
327
device/cppcodec/detail/codec.hpp
Normal file
@@ -0,0 +1,327 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_DETAIL_CODEC
|
||||
#define CPPCODEC_DETAIL_CODEC
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../data/access.hpp"
|
||||
#include "../data/raw_result_buffer.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
namespace detail {
|
||||
|
||||
// SFINAE: Templates sometimes beat sensible overloads - make sure we don't call the wrong one.
|
||||
template <typename T>
|
||||
struct non_numeric : std::enable_if<!std::is_arithmetic<T>::value> { };
|
||||
|
||||
|
||||
/**
|
||||
* Public interface for all the codecs. For API documentation, see README.md.
|
||||
*/
|
||||
template <typename CodecImpl>
|
||||
class codec
|
||||
{
|
||||
public:
|
||||
//
|
||||
// Encoding
|
||||
|
||||
// Convenient version, returns an std::string.
|
||||
static std::string encode(const uint8_t* binary, size_t binary_size);
|
||||
static std::string encode(const char* binary, size_t binary_size);
|
||||
// static std::string encode(const T& binary); -> provided by template below
|
||||
|
||||
// Convenient version with templated result type.
|
||||
template <typename Result> static Result encode(const uint8_t* binary, size_t binary_size);
|
||||
template <typename Result> static Result encode(const char* binary, size_t binary_size);
|
||||
template <typename Result = std::string, typename T = std::vector<uint8_t>>
|
||||
static Result encode(const T& binary);
|
||||
|
||||
// Reused result container version. Resizes encoded_result before writing to it.
|
||||
template <typename Result>
|
||||
static void encode(Result& encoded_result, const uint8_t* binary, size_t binary_size);
|
||||
template <typename Result>
|
||||
static void encode(Result& encoded_result, const char* binary, size_t binary_size);
|
||||
template <typename Result, typename T, typename non_numeric<T>::type* = nullptr>
|
||||
static void encode(Result& encoded_result, const T& binary);
|
||||
|
||||
// Raw pointer output, assumes pre-allocated memory with size > encoded_size(binary_size).
|
||||
static size_t encode(
|
||||
char* encoded_result, size_t encoded_buffer_size,
|
||||
const uint8_t* binary, size_t binary_size) noexcept;
|
||||
static size_t encode(
|
||||
char* encoded_result, size_t encoded_buffer_size,
|
||||
const char* binary, size_t binary_size) noexcept;
|
||||
template<typename T>
|
||||
static size_t encode(
|
||||
char* encoded_result, size_t encoded_buffer_size,
|
||||
const T& binary) noexcept;
|
||||
|
||||
// Calculate the exact length of the encoded string based on binary size.
|
||||
static constexpr size_t encoded_size(size_t binary_size) noexcept;
|
||||
|
||||
//
|
||||
// Decoding
|
||||
|
||||
// Convenient version, returns an std::vector<uint8_t>.
|
||||
static std::vector<uint8_t> decode(const char* encoded, size_t encoded_size);
|
||||
// static std::vector<uint8_t> decode(const T& encoded); -> provided by template below
|
||||
|
||||
// Convenient version with templated result type.
|
||||
template <typename Result> static Result decode(const char* encoded, size_t encoded_size);
|
||||
template <typename Result = std::vector<uint8_t>, typename T = std::string>
|
||||
static Result decode(const T& encoded);
|
||||
|
||||
// Reused result container version. Resizes binary_result before writing to it.
|
||||
template <typename Result>
|
||||
static void decode(Result& binary_result, const char* encoded, size_t encoded_size);
|
||||
template <typename Result, typename T, typename non_numeric<T>::type* = nullptr>
|
||||
static void decode(Result& binary_result, const T& encoded);
|
||||
|
||||
// Raw pointer output, assumes pre-allocated memory with size > decoded_max_size(encoded_size).
|
||||
static size_t decode(
|
||||
uint8_t* binary_result, size_t binary_buffer_size,
|
||||
const char* encoded, size_t encoded_size);
|
||||
static size_t decode(
|
||||
char* binary_result, size_t binary_buffer_size,
|
||||
const char* encoded, size_t encoded_size);
|
||||
template<typename T> static size_t decode(
|
||||
uint8_t* binary_result, size_t binary_buffer_size, const T& encoded);
|
||||
template<typename T> static size_t decode(
|
||||
char* binary_result, size_t binary_buffer_size, const T& encoded);
|
||||
|
||||
// Calculate the maximum size of the decoded binary buffer based on the encoded string length.
|
||||
static constexpr size_t decoded_max_size(size_t encoded_size) noexcept;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Inline definitions of the above functions, using CRTP to call into CodecImpl
|
||||
//
|
||||
|
||||
//
|
||||
// Encoding
|
||||
|
||||
template <typename CodecImpl>
|
||||
inline std::string codec<CodecImpl>::encode(const uint8_t* binary, size_t binary_size)
|
||||
{
|
||||
return encode<std::string>(binary, binary_size);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
inline std::string codec<CodecImpl>::encode(const char* binary, size_t binary_size)
|
||||
{
|
||||
return encode<std::string>(reinterpret_cast<const uint8_t*>(binary), binary_size);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result>
|
||||
inline Result codec<CodecImpl>::encode(const uint8_t* binary, size_t binary_size)
|
||||
{
|
||||
Result encoded_result;
|
||||
encode(encoded_result, binary, binary_size);
|
||||
return encoded_result;
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result>
|
||||
inline Result codec<CodecImpl>::encode(const char* binary, size_t binary_size)
|
||||
{
|
||||
return encode<Result>(reinterpret_cast<const uint8_t*>(binary), binary_size);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result, typename T>
|
||||
inline Result codec<CodecImpl>::encode(const T& binary)
|
||||
{
|
||||
return encode<Result>(data::uchar_data(binary), data::size(binary));
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result>
|
||||
inline void codec<CodecImpl>::encode(
|
||||
Result& encoded_result, const uint8_t* binary, size_t binary_size)
|
||||
{
|
||||
// This overload is where we reserve buffer capacity and call into CodecImpl.
|
||||
size_t encoded_buffer_size = encoded_size(binary_size);
|
||||
auto state = data::create_state(encoded_result, data::specific_t());
|
||||
data::init(encoded_result, state, encoded_buffer_size);
|
||||
|
||||
CodecImpl::encode(encoded_result, state, binary, binary_size);
|
||||
data::finish(encoded_result, state);
|
||||
assert(data::size(encoded_result) == encoded_buffer_size);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result>
|
||||
inline void codec<CodecImpl>::encode(
|
||||
Result& encoded_result, const char* binary, size_t binary_size)
|
||||
{
|
||||
encode(encoded_result, reinterpret_cast<const uint8_t*>(binary), binary_size);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result, typename T, typename non_numeric<T>::type*>
|
||||
inline void codec<CodecImpl>::encode(Result& encoded_result, const T& binary)
|
||||
{
|
||||
encode(encoded_result, data::uchar_data(binary), data::size(binary));
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
inline size_t codec<CodecImpl>::encode(
|
||||
char* encoded_result, size_t encoded_buffer_size,
|
||||
const uint8_t* binary, size_t binary_size) noexcept
|
||||
{
|
||||
// This overload is where we wrap the result pointer & size.
|
||||
data::raw_result_buffer encoded(encoded_result, encoded_buffer_size);
|
||||
encode(encoded, binary, binary_size);
|
||||
|
||||
size_t encoded_size = data::size(encoded);
|
||||
if (encoded_size < encoded_buffer_size) {
|
||||
encoded_result[encoded_size] = '\0';
|
||||
}
|
||||
return encoded_size;
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
inline size_t codec<CodecImpl>::encode(
|
||||
char* encoded_result, size_t encoded_buffer_size,
|
||||
const char* binary, size_t binary_size) noexcept
|
||||
{
|
||||
// This overload is where we wrap the result pointer & size.
|
||||
return encode(encoded_result, encoded_buffer_size,
|
||||
reinterpret_cast<const uint8_t*>(binary), binary_size);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename T>
|
||||
inline size_t codec<CodecImpl>::encode(
|
||||
char* encoded_result, size_t encoded_buffer_size,
|
||||
const T& binary) noexcept
|
||||
{
|
||||
return encode(encoded_result, encoded_buffer_size, data::uchar_data(binary), data::size(binary));
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
inline constexpr size_t codec<CodecImpl>::encoded_size(size_t binary_size) noexcept
|
||||
{
|
||||
return CodecImpl::encoded_size(binary_size);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Decoding
|
||||
|
||||
template <typename CodecImpl>
|
||||
inline std::vector<uint8_t> codec<CodecImpl>::decode(const char* encoded, size_t encoded_size)
|
||||
{
|
||||
return decode<std::vector<uint8_t>>(encoded, encoded_size);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result>
|
||||
inline Result codec<CodecImpl>::decode(const char* encoded, size_t encoded_size)
|
||||
{
|
||||
Result result;
|
||||
decode(result, encoded, encoded_size);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result, typename T>
|
||||
inline Result codec<CodecImpl>::decode(const T& encoded)
|
||||
{
|
||||
return decode<Result>(data::char_data(encoded), data::size(encoded));
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result>
|
||||
inline void codec<CodecImpl>::decode(Result& binary_result, const char* encoded, size_t encoded_size)
|
||||
{
|
||||
// This overload is where we reserve buffer capacity and call into CodecImpl.
|
||||
size_t binary_buffer_size = decoded_max_size(encoded_size);
|
||||
auto state = data::create_state(binary_result, data::specific_t());
|
||||
data::init(binary_result, state, binary_buffer_size);
|
||||
|
||||
CodecImpl::decode(binary_result, state, encoded, encoded_size);
|
||||
data::finish(binary_result, state);
|
||||
assert(data::size(binary_result) <= binary_buffer_size);
|
||||
}
|
||||
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename Result, typename T, typename non_numeric<T>::type*>
|
||||
inline void codec<CodecImpl>::decode(Result& binary_result, const T& encoded)
|
||||
{
|
||||
decode(binary_result, data::char_data(encoded), data::size(encoded));
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
inline size_t codec<CodecImpl>::decode(
|
||||
uint8_t* binary_result, size_t binary_buffer_size,
|
||||
const char* encoded, size_t encoded_size)
|
||||
{
|
||||
return decode(reinterpret_cast<char*>(binary_result), binary_buffer_size, encoded, encoded_size);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
inline size_t codec<CodecImpl>::decode(
|
||||
char* binary_result, size_t binary_buffer_size,
|
||||
const char* encoded, size_t encoded_size)
|
||||
{
|
||||
// This overload is where we wrap the result pointer & size.
|
||||
data::raw_result_buffer binary(binary_result, binary_buffer_size);
|
||||
decode(binary, encoded, encoded_size);
|
||||
return data::size(binary);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename T>
|
||||
inline size_t codec<CodecImpl>::decode(
|
||||
uint8_t* binary_result, size_t binary_buffer_size, const T& encoded)
|
||||
{
|
||||
return decode(reinterpret_cast<char*>(binary_result), binary_buffer_size, encoded);
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
template <typename T>
|
||||
inline size_t codec<CodecImpl>::decode(char* binary_result, size_t binary_buffer_size, const T& encoded)
|
||||
{
|
||||
return decode(binary_result, binary_buffer_size, data::char_data(encoded), data::size(encoded));
|
||||
}
|
||||
|
||||
template <typename CodecImpl>
|
||||
inline constexpr size_t codec<CodecImpl>::decoded_max_size(size_t encoded_size) noexcept
|
||||
{
|
||||
return CodecImpl::decoded_max_size(encoded_size);
|
||||
}
|
||||
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif
|
||||
40
device/cppcodec/detail/config.hpp
Normal file
40
device/cppcodec/detail/config.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_DETAIL_CONFIG_HPP
|
||||
#define CPPCODEC_DETAIL_CONFIG_HPP
|
||||
|
||||
#ifndef __has_attribute
|
||||
#define __has_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#if __GNUC__ || __has_attribute(always_inline)
|
||||
#define CPPCODEC_ALWAYS_INLINE inline __attribute__((always_inline))
|
||||
#elif defined(_MSC_VER) && !defined(__INTEL_COMPILER)
|
||||
#define CPPCODEC_ALWAYS_INLINE inline __forceinline
|
||||
#else
|
||||
#define CPPCODEC_ALWAYS_INLINE inline
|
||||
#endif
|
||||
|
||||
#endif // CPPCODEC_DETAIL_CONFIG_HPP
|
||||
|
||||
114
device/cppcodec/detail/hex.hpp
Normal file
114
device/cppcodec/detail/hex.hpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* Copyright (C) 2018 Jakob Petsovits
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_DETAIL_HEX
|
||||
#define CPPCODEC_DETAIL_HEX
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h> // for abort()
|
||||
|
||||
#include "../data/access.hpp"
|
||||
#include "../parse_error.hpp"
|
||||
#include "stream_codec.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
namespace detail {
|
||||
|
||||
template <typename CodecVariant>
|
||||
class hex : public CodecVariant::template codec_impl<hex<CodecVariant>>
|
||||
{
|
||||
public:
|
||||
static inline constexpr uint8_t binary_block_size() { return 1; }
|
||||
static inline constexpr uint8_t encoded_block_size() { return 2; }
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr uint8_t num_encoded_tail_symbols(uint8_t /*num_bytes*/) noexcept
|
||||
{
|
||||
// Hex encoding only works on full bytes so there are no tails,
|
||||
// no padding characters, and this function should (must) never be called.
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <uint8_t I>
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr uint8_t index(
|
||||
const uint8_t* b /*binary block*/) noexcept
|
||||
{
|
||||
static_assert(I >= 0 && I < encoded_block_size(),
|
||||
"invalid encoding symbol index in a block");
|
||||
|
||||
return (I == 0) ? (b[0] >> 4) // first 4 bits
|
||||
: /*I == 1*/ (b[0] & 0xF); // last 4 bits
|
||||
}
|
||||
|
||||
// With only 2 bytes, enc<1> will always result in a full index() call and
|
||||
// enc<0> will be protected by a not-reached assertion, so we don't actually
|
||||
// care about index_last() except optimizing it out as good as possible.
|
||||
template <bool B>
|
||||
using uint8_if = typename std::enable_if<B, uint8_t>::type;
|
||||
|
||||
template <uint8_t I>
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr uint8_if<I == 0> index_last(
|
||||
const uint8_t* /*binary block*/) noexcept
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <uint8_t I>
|
||||
static CPPCODEC_ALWAYS_INLINE uint8_if<I != 0> index_last(
|
||||
const uint8_t* /*binary block*/)
|
||||
{
|
||||
throw std::domain_error("invalid last encoding symbol index in a tail");
|
||||
}
|
||||
|
||||
template <typename Result, typename ResultState>
|
||||
static CPPCODEC_ALWAYS_INLINE void decode_block(
|
||||
Result& decoded, ResultState&, const alphabet_index_t* idx);
|
||||
|
||||
template <typename Result, typename ResultState>
|
||||
static CPPCODEC_ALWAYS_INLINE void decode_tail(
|
||||
Result& decoded, ResultState&, const alphabet_index_t* idx, size_t idx_len);
|
||||
};
|
||||
|
||||
|
||||
template <typename CodecVariant>
|
||||
template <typename Result, typename ResultState>
|
||||
CPPCODEC_ALWAYS_INLINE void hex<CodecVariant>::decode_block(
|
||||
Result& decoded, ResultState& state, const alphabet_index_t* idx)
|
||||
{
|
||||
data::put(decoded, state, static_cast<uint8_t>((idx[0] << 4) | idx[1]));
|
||||
}
|
||||
|
||||
template <typename CodecVariant>
|
||||
template <typename Result, typename ResultState>
|
||||
CPPCODEC_ALWAYS_INLINE void hex<CodecVariant>::decode_tail(
|
||||
Result&, ResultState&, const alphabet_index_t*, size_t)
|
||||
{
|
||||
throw invalid_input_length(
|
||||
"odd-length hex input is not supported by the streaming octet decoder, "
|
||||
"use a place-based number decoder instead");
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_DETAIL_HEX
|
||||
439
device/cppcodec/detail/stream_codec.hpp
Normal file
439
device/cppcodec/detail/stream_codec.hpp
Normal file
@@ -0,0 +1,439 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* Copyright (C) 2018 Jakob Petsovits
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_DETAIL_STREAM_CODEC
|
||||
#define CPPCODEC_DETAIL_STREAM_CODEC
|
||||
|
||||
#include <limits>
|
||||
#include <stdlib.h> // for abort()
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../parse_error.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
namespace detail {
|
||||
|
||||
using alphabet_index_t = uint_fast16_t;
|
||||
|
||||
template <typename Codec, typename CodecVariant>
|
||||
class stream_codec
|
||||
{
|
||||
public:
|
||||
template <typename Result, typename ResultState> static void encode(
|
||||
Result& encoded_result, ResultState&, const uint8_t* binary, size_t binary_size);
|
||||
|
||||
template <typename Result, typename ResultState> static void decode(
|
||||
Result& binary_result, ResultState&, const char* encoded, size_t encoded_size);
|
||||
|
||||
static constexpr size_t encoded_size(size_t binary_size) noexcept;
|
||||
static constexpr size_t decoded_max_size(size_t encoded_size) noexcept;
|
||||
};
|
||||
|
||||
template <bool GeneratesPadding> // default for CodecVariant::generates_padding() == false
|
||||
struct padder {
|
||||
template <typename CodecVariant, typename Result, typename ResultState, typename SizeT>
|
||||
static CPPCODEC_ALWAYS_INLINE void pad(Result&, ResultState&, SizeT) { }
|
||||
};
|
||||
|
||||
template<> // specialization for CodecVariant::generates_padding() == true
|
||||
struct padder<true> {
|
||||
template <typename CodecVariant, typename Result, typename ResultState, typename SizeT>
|
||||
static CPPCODEC_ALWAYS_INLINE void pad(
|
||||
Result& encoded, ResultState& state, SizeT num_padding_characters)
|
||||
{
|
||||
for (SizeT i = 0; i < num_padding_characters; ++i) {
|
||||
data::put(encoded, state, CodecVariant::padding_symbol());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t I>
|
||||
struct enc {
|
||||
// Block encoding: Go from 0 to (block size - 1), append a symbol for each iteration unconditionally.
|
||||
template <typename Codec, typename CodecVariant, typename Result, typename ResultState>
|
||||
static CPPCODEC_ALWAYS_INLINE void block(Result& encoded, ResultState& state, const uint8_t* src)
|
||||
{
|
||||
using EncodedBlockSizeT = decltype(Codec::encoded_block_size());
|
||||
constexpr static const EncodedBlockSizeT SymbolIndex = static_cast<EncodedBlockSizeT>(I - 1);
|
||||
|
||||
enc<I - 1>().template block<Codec, CodecVariant>(encoded, state, src);
|
||||
data::put(encoded, state, CodecVariant::symbol(Codec::template index<SymbolIndex>(src)));
|
||||
}
|
||||
|
||||
// Tail encoding: Go from 0 until (runtime) num_symbols, append a symbol for each iteration.
|
||||
template <typename Codec, typename CodecVariant, typename Result, typename ResultState,
|
||||
typename EncodedBlockSizeT = decltype(Codec::encoded_block_size())>
|
||||
static CPPCODEC_ALWAYS_INLINE void tail(
|
||||
Result& encoded, ResultState& state, const uint8_t* src, EncodedBlockSizeT num_symbols)
|
||||
{
|
||||
constexpr static const EncodedBlockSizeT SymbolIndex = Codec::encoded_block_size() - I;
|
||||
constexpr static const EncodedBlockSizeT NumSymbols = SymbolIndex + static_cast<EncodedBlockSizeT>(1);
|
||||
|
||||
if (num_symbols == NumSymbols) {
|
||||
data::put(encoded, state, CodecVariant::symbol(Codec::template index_last<SymbolIndex>(src)));
|
||||
return;
|
||||
}
|
||||
data::put(encoded, state, CodecVariant::symbol(Codec::template index<SymbolIndex>(src)));
|
||||
enc<I - 1>().template tail<Codec, CodecVariant>(encoded, state, src, num_symbols);
|
||||
}
|
||||
};
|
||||
|
||||
template<> // terminating specialization
|
||||
struct enc<0> {
|
||||
template <typename Codec, typename CodecVariant, typename Result, typename ResultState>
|
||||
static CPPCODEC_ALWAYS_INLINE void block(Result&, ResultState&, const uint8_t*) { }
|
||||
|
||||
template <typename Codec, typename CodecVariant, typename Result, typename ResultState,
|
||||
typename EncodedBlockSizeT = decltype(Codec::encoded_block_size())>
|
||||
static CPPCODEC_ALWAYS_INLINE void tail(Result&, ResultState&, const uint8_t*, EncodedBlockSizeT)
|
||||
{
|
||||
abort(); // Not reached: block() should be called if num_symbols == block size, not tail().
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Codec, typename CodecVariant>
|
||||
template <typename Result, typename ResultState>
|
||||
inline void stream_codec<Codec, CodecVariant>::encode(
|
||||
Result& encoded_result, ResultState& state,
|
||||
const uint8_t* src, size_t src_size)
|
||||
{
|
||||
using encoder = enc<Codec::encoded_block_size()>;
|
||||
|
||||
const uint8_t* src_end = src + src_size;
|
||||
|
||||
if (src_size >= Codec::binary_block_size()) {
|
||||
src_end -= Codec::binary_block_size();
|
||||
|
||||
for (; src <= src_end; src += Codec::binary_block_size()) {
|
||||
encoder::template block<Codec, CodecVariant>(encoded_result, state, src);
|
||||
}
|
||||
src_end += Codec::binary_block_size();
|
||||
}
|
||||
|
||||
if (src_end > src) {
|
||||
auto remaining_src_len = src_end - src;
|
||||
if (!remaining_src_len || remaining_src_len >= Codec::binary_block_size()) {
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
|
||||
auto num_symbols = Codec::num_encoded_tail_symbols(
|
||||
static_cast<uint8_t>(remaining_src_len));
|
||||
|
||||
encoder::template tail<Codec, CodecVariant>(encoded_result, state, src, num_symbols);
|
||||
|
||||
padder<CodecVariant::generates_padding()>::template pad<CodecVariant>(
|
||||
encoded_result, state, Codec::encoded_block_size() - num_symbols);
|
||||
}
|
||||
}
|
||||
|
||||
// Range & lookup table generation, see
|
||||
// http://stackoverflow.com/questions/13313980/populate-an-array-using-constexpr-at-compile-time
|
||||
// and http://cplusadd.blogspot.ca/2013/02/c11-compile-time-lookup-tablearray-with.html
|
||||
|
||||
template<unsigned... Is> struct seq {};
|
||||
|
||||
template<unsigned N, unsigned... Is>
|
||||
struct gen_seq : gen_seq<N - 4, N - 4, N - 3, N - 2, N - 1, Is...> {
|
||||
// Clang up to 3.6 has a limit of 256 for template recursion,
|
||||
// so pass a few more symbols at once to make it work.
|
||||
static_assert(N % 4 == 0, "I must be divisible by 4 to eventually end at 0");
|
||||
};
|
||||
template<unsigned... Is>
|
||||
struct gen_seq<0, Is...> : seq<Is...> {};
|
||||
|
||||
template <size_t N>
|
||||
struct lookup_table_t {
|
||||
alphabet_index_t lookup[N];
|
||||
static constexpr size_t size = N;
|
||||
};
|
||||
|
||||
template<typename LambdaType, unsigned... Is>
|
||||
constexpr lookup_table_t<sizeof...(Is)> make_lookup_table(seq<Is...>, LambdaType value_for_index) {
|
||||
return { { value_for_index(Is)... } };
|
||||
}
|
||||
|
||||
template<unsigned N, typename LambdaType>
|
||||
constexpr lookup_table_t<N> make_lookup_table(LambdaType evalFunc) {
|
||||
return make_lookup_table(gen_seq<N>(), evalFunc);
|
||||
}
|
||||
|
||||
// CodecVariant::symbol() provides a symbol for an index.
|
||||
// Use recursive templates to get the inverse lookup table for fast decoding.
|
||||
|
||||
template <typename T>
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr size_t num_possible_values()
|
||||
{
|
||||
return static_cast<size_t>(
|
||||
static_cast<intmax_t>((std::numeric_limits<T>::max)())
|
||||
- static_cast<intmax_t>((std::numeric_limits<T>::min)()) + 1);
|
||||
}
|
||||
|
||||
template <typename CodecVariant, alphabet_index_t InvalidIdx, size_t I>
|
||||
struct index_if_in_alphabet {
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr alphabet_index_t for_symbol(char symbol)
|
||||
{
|
||||
return (CodecVariant::symbol(
|
||||
static_cast<alphabet_index_t>(CodecVariant::alphabet_size() - I)) == symbol)
|
||||
? static_cast<alphabet_index_t>(CodecVariant::alphabet_size() - I)
|
||||
: index_if_in_alphabet<CodecVariant, InvalidIdx, I - 1>::for_symbol(symbol);
|
||||
}
|
||||
};
|
||||
template <typename CodecVariant, alphabet_index_t InvalidIdx>
|
||||
struct index_if_in_alphabet<CodecVariant, InvalidIdx, 0> { // terminating specialization
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr alphabet_index_t for_symbol(char)
|
||||
{
|
||||
return InvalidIdx;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CodecVariant, size_t I>
|
||||
struct padding_searcher {
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool exists_padding_symbol()
|
||||
{
|
||||
// Clang up to 3.6 has a limit of 256 for template recursion,
|
||||
// so pass a few more symbols at once to make it work.
|
||||
static_assert(I % 4 == 0, "I must be divisible by 4 to eventually end at 0");
|
||||
|
||||
return CodecVariant::is_padding_symbol(
|
||||
static_cast<char>(num_possible_values<char>() - I - 4))
|
||||
|| CodecVariant::is_padding_symbol(
|
||||
static_cast<char>(num_possible_values<char>() - I - 3))
|
||||
|| CodecVariant::is_padding_symbol(
|
||||
static_cast<char>(num_possible_values<char>() - I - 2))
|
||||
|| CodecVariant::is_padding_symbol(
|
||||
static_cast<char>(num_possible_values<char>() - I - 1))
|
||||
|| padding_searcher<CodecVariant, I - 4>::exists_padding_symbol();
|
||||
}
|
||||
};
|
||||
template <typename CodecVariant>
|
||||
struct padding_searcher<CodecVariant, 0> { // terminating specialization
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool exists_padding_symbol() { return false; }
|
||||
};
|
||||
|
||||
template <typename CodecVariant>
|
||||
struct alphabet_index_info
|
||||
{
|
||||
static constexpr const size_t num_possible_symbols = num_possible_values<char>();
|
||||
|
||||
static constexpr const alphabet_index_t padding_idx = 1 << 8;
|
||||
static constexpr const alphabet_index_t invalid_idx = 1 << 9;
|
||||
static constexpr const alphabet_index_t eof_idx = 1 << 10;
|
||||
static constexpr const alphabet_index_t stop_character_mask = static_cast<alphabet_index_t>(~0xFFu);
|
||||
|
||||
static constexpr const bool padding_allowed = padding_searcher<
|
||||
CodecVariant, num_possible_symbols>::exists_padding_symbol();
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool allows_padding()
|
||||
{
|
||||
return padding_allowed;
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding(alphabet_index_t idx)
|
||||
{
|
||||
return allows_padding() ? (idx == padding_idx) : false;
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_invalid(alphabet_index_t idx) { return idx == invalid_idx; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof(alphabet_index_t idx) { return idx == eof_idx; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_stop_character(alphabet_index_t idx)
|
||||
{
|
||||
return (idx & stop_character_mask) != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr
|
||||
alphabet_index_t valid_index_or(alphabet_index_t a, alphabet_index_t b)
|
||||
{
|
||||
return a == invalid_idx ? b : a;
|
||||
}
|
||||
|
||||
using idx_if_in_alphabet = index_if_in_alphabet<
|
||||
CodecVariant, invalid_idx, CodecVariant::alphabet_size()>;
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr alphabet_index_t index_of(char symbol)
|
||||
{
|
||||
return valid_index_or(idx_if_in_alphabet::for_symbol(symbol),
|
||||
CodecVariant::is_eof_symbol(symbol) ? eof_idx
|
||||
: CodecVariant::is_padding_symbol(symbol) ? padding_idx
|
||||
: invalid_idx);
|
||||
}
|
||||
|
||||
// GCC <= 4.9 has a bug with retaining constexpr when passing a function pointer.
|
||||
// To get around this, we'll create a callable with operator() and pass that one.
|
||||
// Unfortunately, MSVC prior to VS 2017 (for MinSizeRel or Release builds)
|
||||
// chokes on this by compiling the project in 20 minutes instead of seconds.
|
||||
// So let's define two separate variants and remove the old GCC one whenever we
|
||||
// decide not to support GCC < 5.0 anymore.
|
||||
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
|
||||
struct index_at {
|
||||
CPPCODEC_ALWAYS_INLINE constexpr alphabet_index_t operator()(size_t symbol) const {
|
||||
return index_of(CodecVariant::normalized_symbol(static_cast<char>(symbol)));
|
||||
}
|
||||
};
|
||||
#else
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr alphabet_index_t index_at(size_t symbol)
|
||||
{
|
||||
return index_of(CodecVariant::normalized_symbol(static_cast<char>(symbol)));
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
struct lookup {
|
||||
static CPPCODEC_ALWAYS_INLINE alphabet_index_t for_symbol(char symbol)
|
||||
{
|
||||
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
|
||||
static constexpr const auto t = make_lookup_table<num_possible_symbols>(index_at());
|
||||
#else
|
||||
static constexpr const auto t = make_lookup_table<num_possible_symbols>(&index_at);
|
||||
#endif
|
||||
static_assert(t.size == num_possible_symbols,
|
||||
"lookup table must cover each possible (character) symbol");
|
||||
return t.lookup[static_cast<uint8_t>(symbol)];
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// At long last! The actual decode/encode functions.
|
||||
|
||||
template <typename Codec, typename CodecVariant>
|
||||
template <typename Result, typename ResultState>
|
||||
inline void stream_codec<Codec, CodecVariant>::decode(
|
||||
Result& binary_result, ResultState& state,
|
||||
const char* src_encoded, size_t src_size)
|
||||
{
|
||||
using alphabet_index_lookup = typename alphabet_index_info<CodecVariant>::lookup;
|
||||
const char* src = src_encoded;
|
||||
const char* src_end = src + src_size;
|
||||
|
||||
alphabet_index_t alphabet_indexes[Codec::encoded_block_size()] = {};
|
||||
alphabet_indexes[0] = alphabet_index_info<CodecVariant>::eof_idx;
|
||||
|
||||
alphabet_index_t* const alphabet_index_start = &alphabet_indexes[0];
|
||||
alphabet_index_t* const alphabet_index_end = &alphabet_indexes[Codec::encoded_block_size()];
|
||||
alphabet_index_t* alphabet_index_ptr = &alphabet_indexes[0];
|
||||
|
||||
while (src < src_end) {
|
||||
if (CodecVariant::should_ignore(*src)) {
|
||||
++src;
|
||||
continue;
|
||||
}
|
||||
*alphabet_index_ptr = alphabet_index_lookup::for_symbol(*src);
|
||||
if (alphabet_index_info<CodecVariant>::is_stop_character(*alphabet_index_ptr)) {
|
||||
break;
|
||||
}
|
||||
++src;
|
||||
++alphabet_index_ptr;
|
||||
|
||||
if (alphabet_index_ptr == alphabet_index_end) {
|
||||
Codec::decode_block(binary_result, state, alphabet_indexes);
|
||||
alphabet_index_ptr = alphabet_index_start;
|
||||
}
|
||||
}
|
||||
|
||||
if (alphabet_index_info<CodecVariant>::is_invalid(*alphabet_index_ptr)) {
|
||||
throw symbol_error(*src);
|
||||
}
|
||||
++src;
|
||||
|
||||
alphabet_index_t* last_index_ptr = alphabet_index_ptr;
|
||||
if (alphabet_index_info<CodecVariant>::is_padding(*last_index_ptr)) {
|
||||
if (last_index_ptr == alphabet_index_start) {
|
||||
// Don't accept padding at the start of a block.
|
||||
// The encoder should have omitted that padding altogether.
|
||||
throw padding_error();
|
||||
}
|
||||
// We're in here because we just read a (first) padding character. Try to read more.
|
||||
// Count with last_index_ptr, but store in alphabet_index_ptr so we don't
|
||||
// overflow the array in case the input data is too long.
|
||||
++last_index_ptr;
|
||||
while (src < src_end) {
|
||||
*alphabet_index_ptr = alphabet_index_lookup::for_symbol(*(src++));
|
||||
|
||||
if (alphabet_index_info<CodecVariant>::is_eof(*alphabet_index_ptr)) {
|
||||
*alphabet_index_ptr = alphabet_index_info<CodecVariant>::padding_idx;
|
||||
break;
|
||||
}
|
||||
if (!alphabet_index_info<CodecVariant>::is_padding(*alphabet_index_ptr)) {
|
||||
throw padding_error();
|
||||
}
|
||||
|
||||
++last_index_ptr;
|
||||
if (last_index_ptr > alphabet_index_end) {
|
||||
throw padding_error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (last_index_ptr != alphabet_index_start) {
|
||||
if ((CodecVariant::requires_padding()
|
||||
|| alphabet_index_info<CodecVariant>::is_padding(*alphabet_index_ptr)
|
||||
) && last_index_ptr != alphabet_index_end)
|
||||
{
|
||||
// If the input is not a multiple of the block size then the input is incorrect.
|
||||
throw padding_error();
|
||||
}
|
||||
if (alphabet_index_ptr >= alphabet_index_end) {
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
Codec::decode_tail(binary_result, state, alphabet_indexes,
|
||||
static_cast<size_t>(alphabet_index_ptr - alphabet_index_start));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Codec, typename CodecVariant>
|
||||
inline constexpr size_t stream_codec<Codec, CodecVariant>::encoded_size(size_t binary_size) noexcept
|
||||
{
|
||||
using C = Codec;
|
||||
|
||||
// constexpr rules make this a lot harder to read than it actually is.
|
||||
return CodecVariant::generates_padding()
|
||||
// With padding, the encoded size is a multiple of the encoded block size.
|
||||
// To calculate that, round the binary size up to multiple of the binary block size,
|
||||
// then convert to encoded by multiplying with { base32: 8/5, base64: 4/3 }.
|
||||
? (binary_size + (C::binary_block_size() - 1)
|
||||
- ((binary_size + (C::binary_block_size() - 1)) % C::binary_block_size()))
|
||||
* C::encoded_block_size() / C::binary_block_size()
|
||||
// No padding: only pad to the next multiple of 5 bits, i.e. at most a single extra byte.
|
||||
: (binary_size * C::encoded_block_size() / C::binary_block_size())
|
||||
+ (((binary_size * C::encoded_block_size()) % C::binary_block_size()) ? 1 : 0);
|
||||
}
|
||||
|
||||
template <typename Codec, typename CodecVariant>
|
||||
inline constexpr size_t stream_codec<Codec, CodecVariant>::decoded_max_size(size_t encoded_size) noexcept
|
||||
{
|
||||
using C = Codec;
|
||||
|
||||
return CodecVariant::requires_padding()
|
||||
? (encoded_size / C::encoded_block_size() * C::binary_block_size())
|
||||
: (encoded_size / C::encoded_block_size() * C::binary_block_size())
|
||||
+ ((encoded_size % C::encoded_block_size())
|
||||
* C::binary_block_size() / C::encoded_block_size());
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_DETAIL_STREAM_CODEC
|
||||
31
device/cppcodec/hex_default_lower.hpp
Normal file
31
device/cppcodec/hex_default_lower.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_HEX_DEFAULT_LOWER
|
||||
#define CPPCODEC_HEX_DEFAULT_LOWER
|
||||
|
||||
#include "hex_lower.hpp"
|
||||
|
||||
using hex = cppcodec::hex_lower;
|
||||
|
||||
#endif // CPPCODEC_HEX_DEFAULT_LOWER
|
||||
31
device/cppcodec/hex_default_upper.hpp
Normal file
31
device/cppcodec/hex_default_upper.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_HEX_DEFAULT_UPPER
|
||||
#define CPPCODEC_HEX_DEFAULT_UPPER
|
||||
|
||||
#include "hex_upper.hpp"
|
||||
|
||||
using hex = cppcodec::hex_upper;
|
||||
|
||||
#endif // CPPCODEC_HEX_DEFAULT_UPPER
|
||||
75
device/cppcodec/hex_lower.hpp
Normal file
75
device/cppcodec/hex_lower.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_HEX_LOWER
|
||||
#define CPPCODEC_HEX_LOWER
|
||||
|
||||
#include "detail/codec.hpp"
|
||||
#include "detail/hex.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
|
||||
namespace detail {
|
||||
|
||||
static constexpr const char hex_lower_alphabet[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // at index 10
|
||||
'a', 'b', 'c', 'd', 'e', 'f'
|
||||
};
|
||||
|
||||
class hex_lower
|
||||
{
|
||||
public:
|
||||
template <typename Codec> using codec_impl = stream_codec<Codec, hex_lower>;
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
|
||||
static_assert(sizeof(hex_lower_alphabet) == 16, "hex alphabet must have 16 values");
|
||||
return sizeof(hex_lower_alphabet);
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t index)
|
||||
{
|
||||
return hex_lower_alphabet[index];
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c)
|
||||
{
|
||||
// Hex decoding is always case-insensitive (even in RFC 4648), the question
|
||||
// is only for encoding whether to use upper-case or lower-case letters.
|
||||
return (c >= 'A' && c <= 'F') ? (c - 'A' + 'a') : c;
|
||||
}
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return false; }
|
||||
// FIXME: doesn't require padding, but requires a multiple of the encoded block size (2)
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return false; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char) { return false; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
|
||||
|
||||
// Sometimes hex strings include whitespace, but this variant forbids it.
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using hex_lower = detail::codec<detail::hex<detail::hex_lower>>;
|
||||
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_HEX_LOWER
|
||||
75
device/cppcodec/hex_upper.hpp
Normal file
75
device/cppcodec/hex_upper.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_HEX_UPPER
|
||||
#define CPPCODEC_HEX_UPPER
|
||||
|
||||
#include "detail/codec.hpp"
|
||||
#include "detail/hex.hpp"
|
||||
|
||||
namespace cppcodec {
|
||||
|
||||
namespace detail {
|
||||
|
||||
static constexpr const char hex_upper_alphabet[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
class hex_upper
|
||||
{
|
||||
public:
|
||||
template <typename Codec> using codec_impl = stream_codec<Codec, hex_upper>;
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
|
||||
static_assert(sizeof(hex_upper_alphabet) == 16, "hex alphabet must have 16 values");
|
||||
return sizeof(hex_upper_alphabet);
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t index)
|
||||
{
|
||||
return hex_upper_alphabet[index];
|
||||
}
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c)
|
||||
{
|
||||
// Hex decoding is always case-insensitive (even in RFC 4648), the question
|
||||
// is only for encoding whether to use upper-case or lower-case letters.
|
||||
return (c >= 'a' && c <= 'f') ? (c - 'a' + 'A') : c;
|
||||
}
|
||||
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return false; }
|
||||
// FIXME: doesn't require padding, but requires a multiple of the encoded block size (2)
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return false; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char) { return false; }
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
|
||||
|
||||
// Sometimes hex strings include whitespace, but this variant forbids it.
|
||||
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using hex_upper = detail::codec<detail::hex<detail::hex_upper>>;
|
||||
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_HEX_UPPER
|
||||
109
device/cppcodec/parse_error.hpp
Normal file
109
device/cppcodec/parse_error.hpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Topology LP
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CPPCODEC_PARSE_ERROR
|
||||
#define CPPCODEC_PARSE_ERROR
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace cppcodec {
|
||||
|
||||
namespace detail {
|
||||
// <*stream> headers include a lot of code and noticeably increase compile times.
|
||||
// The only thing we want from them really is a char-to-string conversion.
|
||||
// That's easy to implement with many less lines of code, so let's do it ourselves.
|
||||
template <int N>
|
||||
static void uctoa(unsigned char n, char (&s)[N])
|
||||
{
|
||||
static_assert(N >= 4, "need at least 4 bytes to convert an unsigned char to string safely");
|
||||
int i = sizeof(s) - 1;
|
||||
int num_chars = 1;
|
||||
s[i--] = '\0';
|
||||
do { // generate digits in reverse order
|
||||
s[i--] = n % 10 + '0'; // get next digit
|
||||
++num_chars;
|
||||
} while ((n /= 10) > 0); // delete it
|
||||
|
||||
if (num_chars == sizeof(s)) {
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < num_chars; ++i) { // move chars to front of string
|
||||
s[i] = s[i + (sizeof(s) - num_chars)];
|
||||
}
|
||||
}
|
||||
} // end namespace detail
|
||||
|
||||
|
||||
class parse_error : public std::domain_error
|
||||
{
|
||||
public:
|
||||
using std::domain_error::domain_error;
|
||||
};
|
||||
|
||||
// Avoids memory allocation, so it can be used in constexpr functions.
|
||||
class symbol_error : public parse_error
|
||||
{
|
||||
public:
|
||||
symbol_error(char c)
|
||||
: parse_error(symbol_error::make_error_message(c))
|
||||
, m_symbol(c)
|
||||
{
|
||||
}
|
||||
|
||||
symbol_error(const symbol_error&) = default;
|
||||
|
||||
char symbol() const noexcept { return m_symbol; }
|
||||
|
||||
private:
|
||||
static std::string make_error_message(char c)
|
||||
{
|
||||
char s[4];
|
||||
detail::uctoa(*reinterpret_cast<unsigned char*>(&c), s);
|
||||
return std::string("parse error: character [") + &(s[0]) + " '" + c + "'] out of bounds";
|
||||
}
|
||||
|
||||
private:
|
||||
char m_symbol;
|
||||
};
|
||||
|
||||
class invalid_input_length : public parse_error
|
||||
{
|
||||
public:
|
||||
using parse_error::parse_error;
|
||||
};
|
||||
|
||||
class padding_error : public invalid_input_length
|
||||
{
|
||||
public:
|
||||
padding_error()
|
||||
: invalid_input_length("parse error: codec expects padded input string but padding was invalid")
|
||||
{
|
||||
}
|
||||
|
||||
padding_error(const padding_error&) = default;
|
||||
};
|
||||
|
||||
} // namespace cppcodec
|
||||
|
||||
#endif // CPPCODEC_PARSE_ERROR
|
||||
128
device/deviceinfo.cpp
Normal file
128
device/deviceinfo.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "deviceinfo.h"
|
||||
#include <QDateTime>
|
||||
#include "myexception.h"
|
||||
#include "exceptioncode.h"
|
||||
|
||||
|
||||
DeviceInfo* DeviceInfo::uniqueInstance = nullptr;
|
||||
DeviceInfo* DeviceInfo::instance() {
|
||||
if(!uniqueInstance) {
|
||||
uniqueInstance = new DeviceInfo;
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QString nowStr;
|
||||
nowStr = now.toString("yyyyMMdd_hhmmss");
|
||||
// 定义Info日志名称
|
||||
QString fNameInfo = QString("data/log/info/info_%1.log").arg(nowStr);
|
||||
QByteArray qbyInfo = fNameInfo.toLocal8Bit();
|
||||
char* fNameInfo_c = qbyInfo.data();
|
||||
// 获取日志文件句柄
|
||||
uniqueInstance->streamInfo = fopen(fNameInfo_c, "wt");
|
||||
if(uniqueInstance->streamInfo == nullptr)
|
||||
{
|
||||
fNameInfo = QString("info_%1.log").arg(nowStr);
|
||||
qbyInfo = fNameInfo.toLocal8Bit();
|
||||
char* fNameInfo_c = qbyInfo.data();
|
||||
// 获取日志文件句柄
|
||||
uniqueInstance->streamInfo = fopen(fNameInfo_c, "wt");
|
||||
}
|
||||
// 定义Alarm日志名称
|
||||
QString fNameAlarm = QString("data/log/alarm/alarm_%1.log").arg(nowStr);
|
||||
QByteArray qbyAlarm = fNameAlarm.toLocal8Bit();
|
||||
char* fNameAlarm_c = qbyAlarm.data();
|
||||
uniqueInstance->streamAlarm = fopen(fNameAlarm_c, "wt");
|
||||
if(uniqueInstance->streamAlarm == nullptr)
|
||||
{
|
||||
fNameAlarm = QString("alarm_%1.log").arg(nowStr);
|
||||
qbyAlarm = fNameAlarm.toLocal8Bit();
|
||||
char* fNameAlarm_c = qbyAlarm.data();
|
||||
uniqueInstance->streamAlarm = fopen(fNameAlarm_c, "wt");
|
||||
}
|
||||
}
|
||||
return uniqueInstance;
|
||||
}
|
||||
|
||||
|
||||
void DeviceInfo::deleteInstance() {
|
||||
if (uniqueInstance) {
|
||||
delete uniqueInstance;
|
||||
}
|
||||
}
|
||||
|
||||
DeviceInfo::DeviceInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现把文本字符串写入文件,并且文本字符可以带多个格式参数
|
||||
* 写信息日志
|
||||
*/
|
||||
void DeviceInfo::printInfo(const char* format ...) {
|
||||
if(uniqueInstance->streamInfo == nullptr)
|
||||
{
|
||||
throw MyException(QString("写入日志失败!异常代码为:%1").arg(WRITE_LOG_FAIL),WRITE_LOG_FAIL);
|
||||
}
|
||||
// 定义可变参数指针
|
||||
va_list ap;
|
||||
// 初始化可变参数指针,指向第一个可变参数
|
||||
va_start(ap, format);
|
||||
// 使用参数列表发送格式化输出到流 streamInfo 中
|
||||
// 参数1:这是指向 FILE 对象的指针,该 FILE 对象标识了流
|
||||
// 参数2:这是 C 字符串,包含了要被写入到流 streamInfo 中的文本。它可以包含嵌入的 format 标签,format 标签可被随后的附加参数中指定的值替换,并按需求进行格式化。
|
||||
// 参数3:可变参数指针
|
||||
vfprintf(streamInfo, format, ap);
|
||||
fprintf(streamInfo, "\n");
|
||||
va_end(ap);
|
||||
fflush(streamInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现把文本字符串写入文件,并且文本字符可以带多个格式参数
|
||||
* 写报警日志
|
||||
*/
|
||||
void DeviceInfo::printAlarm(const char* format ...) {
|
||||
// 定义可变参数指针
|
||||
va_list ap;
|
||||
// 初始化可变参数指针,指向第一个可变参数
|
||||
va_start(ap, format);
|
||||
// 使用参数列表发送格式化输出到流 streamInfo 中
|
||||
// 参数1:这是指向 FILE 对象的指针,该 FILE 对象标识了流
|
||||
// 参数2:这是 C 字符串,包含了要被写入到流 streamInfo 中的文本。它可以包含嵌入的 format 标签,format 标签可被随后的附加参数中指定的值替换,并按需求进行格式化。
|
||||
// 参数3:可变参数指针
|
||||
vfprintf(streamAlarm, format, ap);
|
||||
fprintf(streamAlarm, "\n");
|
||||
va_end(ap);
|
||||
fflush(streamAlarm);
|
||||
}
|
||||
|
||||
void DeviceInfo::printDeviceSystemInfo(const QString text,SYS_INFO_LEVEL level)
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QString nowStr;
|
||||
|
||||
nowStr = now.toString("yyyyMMdd_hh:mm:ss:zzz ");
|
||||
nowStr+=text;
|
||||
emit deviceSystemInfoSGL(nowStr,level);
|
||||
//记录日志
|
||||
QByteArray qbyInfo = nowStr.toLocal8Bit();
|
||||
char* info_c = qbyInfo.data();
|
||||
printInfo(info_c);
|
||||
}
|
||||
void DeviceInfo::printDeviceSalamInfo(const QString text,SYS_INFO_LEVEL level)
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QString nowStr;
|
||||
|
||||
nowStr = now.toString("yyyyMMdd_hh:mm:ss:zzz ");
|
||||
nowStr += text;
|
||||
emit deviceSalamInfoSGL(nowStr,level);
|
||||
emit deviceSystemInfoSGL(nowStr,level);
|
||||
|
||||
//记录日志
|
||||
QByteArray qbyInfo = nowStr.toLocal8Bit();
|
||||
char* info_c = qbyInfo.data();
|
||||
printInfo(info_c);
|
||||
printAlarm(info_c);
|
||||
}
|
||||
|
||||
|
||||
39
device/deviceinfo.h
Normal file
39
device/deviceinfo.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef DEVICEINFO_H
|
||||
#define DEVICEINFO_H
|
||||
#include<QObject>
|
||||
#include"base.h"
|
||||
|
||||
|
||||
#define DEVICE_INFO DeviceInfo::instance()
|
||||
class DeviceInfo:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static DeviceInfo* instance();
|
||||
static void deleteInstance();
|
||||
//dm add
|
||||
void printDeviceSystemInfo(const QString text,SYS_INFO_LEVEL level=D_NOTHING);
|
||||
void printDeviceSalamInfo(const QString text,SYS_INFO_LEVEL level=D_CRITICAL);
|
||||
|
||||
signals:
|
||||
void deviceSystemInfoSGL(const QString,SYS_INFO_LEVEL level);
|
||||
void deviceSalamInfoSGL(const QString,SYS_INFO_LEVEL level);
|
||||
|
||||
private:
|
||||
DeviceInfo();
|
||||
DeviceInfo(const DeviceInfo&)=delete;
|
||||
DeviceInfo& operator = (const DeviceInfo&)=delete;
|
||||
DeviceInfo(DeviceInfo&&)=delete;
|
||||
DeviceInfo& operator = (DeviceInfo&&)=delete;
|
||||
|
||||
void printAlarm(const char* format ...);
|
||||
void printInfo(const char* format ...);
|
||||
|
||||
private:
|
||||
static DeviceInfo* uniqueInstance;
|
||||
FILE* streamInfo;
|
||||
FILE* streamAlarm;
|
||||
};
|
||||
|
||||
#endif // DEVICEINFO_H
|
||||
15165
device/deviceproxy.cpp
Normal file
15165
device/deviceproxy.cpp
Normal file
File diff suppressed because it is too large
Load Diff
695
device/deviceproxy.h
Normal file
695
device/deviceproxy.h
Normal file
@@ -0,0 +1,695 @@
|
||||
#ifndef DEVICEPROXY_H
|
||||
#define DEVICEPROXY_H
|
||||
#include <QObject>
|
||||
#include "base.h"
|
||||
#include "ACSVariable.h"
|
||||
#include "acscontroller.h"
|
||||
#include "myexception.h"
|
||||
#include <QTimer>
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
|
||||
#include "LaserMark.h"
|
||||
#include "LaserMark_global.h"
|
||||
#include "MarkEzdDll.h"
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "bllaserlib.h"
|
||||
#include "BLLaserLib_global.h"
|
||||
#include "coordinate.h"
|
||||
#include"qtcpserver.h"
|
||||
#include"qtcpsocket.h"
|
||||
|
||||
#include "RMS_Dll_global.h"
|
||||
#include "rms_dll.h"
|
||||
|
||||
#define MACHINE001 1
|
||||
|
||||
|
||||
#ifdef MACHINE001
|
||||
#define XAXIS 0
|
||||
#define YAXIS 1
|
||||
#define ZAXIS 4
|
||||
#define ZAAXIS 2
|
||||
|
||||
#define DAXIS 5
|
||||
#define Z0AXIS 6
|
||||
#define Z2AXIS 7
|
||||
#else
|
||||
#define XAXIS 0
|
||||
#define YAXIS 1
|
||||
#define ZAXIS 4
|
||||
#define ZAAXIS 6
|
||||
|
||||
#define DAXIS 5
|
||||
#define Z0AXIS 7
|
||||
#define Z2AXIS 2
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#define LASERMARKFOCUS 120
|
||||
#define CAMERAFOCUS 120
|
||||
#define FINDHEIGHTFOCUS 10
|
||||
#define INCHES4 55
|
||||
#define INCHES6 80
|
||||
#define INCHES8 105
|
||||
#define MAXHEIGHT 55
|
||||
#define ZWORKPOS 0
|
||||
#define PIANYIJIAODU 0
|
||||
#define LASERMARKJIAODU 0
|
||||
|
||||
#define JIADINGJIAGONG 0
|
||||
|
||||
|
||||
class CDeviceProxyWorker;
|
||||
#define DEV DeviceProxy::instance()
|
||||
class DeviceProxy:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class CDeviceProxyWorker;
|
||||
public:
|
||||
static DeviceProxy* instance();
|
||||
static void setAxisName(QMap<int,QString> axisName);
|
||||
~DeviceProxy();
|
||||
void DEVInit();
|
||||
void reset();
|
||||
void setAlarm(bool flag);
|
||||
void setDataCheck(bool flag);
|
||||
int UpdateWorkData();
|
||||
|
||||
QTcpServer* server;
|
||||
QTcpSocket* socket;//一个客户端对应一个socket
|
||||
void ClientConnect();
|
||||
void ReadData1();
|
||||
double R_detection_pt{0};
|
||||
double mode;
|
||||
double R_detection_ps{0};
|
||||
double R_detection_pm{0};
|
||||
double R_detection_po{0};
|
||||
double R_detection_set_ppt{0};
|
||||
double R_detection_set_pps{0};
|
||||
cv::Mat Func_merge(int left,int right);
|
||||
std::vector<cv::Mat> srcImgs;
|
||||
int BiaoDingFlag{false};
|
||||
int PPValues[21];
|
||||
double p2tBuf[21];
|
||||
double p2sBuf[21];
|
||||
double getPP(double ap,bool flag);
|
||||
QImage imageR;
|
||||
RMS_Dll rms;
|
||||
QString StrPlotSixInch = "(0,-60)(-30,-50)(-20,-50)(-10,-50)(0,-50)(10,-50)(20,-50)(30,-50)(-40,-40)(-30,-40)(-20,-40)(-10,-40)(0,-40)(10,-40)"
|
||||
"(20,-40)(30,-40)(40,-40)(-50,-30)(-40,-30)(-30,-30)(-20,-30)(-10,-30)(0,-30)(10,-30)(20,-30)(30,-30)(40,-30)(50,-30)"
|
||||
"(-50,-20)(-40,-20)(-30,-20)(-20,-20)(-10,-20)(0,-20)(10,-20)(20,-20)(30,-20)(40,-20)(50,-20)(-50,-10)(-40,-10)(-30,-10)"
|
||||
"(-20,-10)(-10,-10)(0,-10)(10,-10)(20,-10)(30,-10)(40,-10)(50,-10)(-60,0)(-50,0)(-40,0)(-30,0)(-20,0)(-10,0)(0,0)(10,0)"
|
||||
"(20,0)(30,0)(40,0)(50,0)(60,0)(-50,10)(-40,10)(-30,10)(-20,10)(-10,10)(0,10)(10,10)(20,10)(30,10)(40,10)(50,10)(-50,20)"
|
||||
"(-40,20)(-30,20)(-20,20)(-10,20)(0,20)(10,20)(20,20)(30,20)(40,20)(50,20)(-50,30)(-40,30)(-30,30)(-20,30)(-10,30)(0,30)"
|
||||
"(10,30)(20,30)(30,30)(40,30)(50,30)(-40,40)(-30,40)(-20,40)(-10,40)(0,40)(10,40)(20,40)(30,40)(40,40)(-30,50)(-20,50)"
|
||||
"(-10,50)(0,50)(10,50)(20,50)(30,50)(0,60)";
|
||||
QString StrPlotEightInch = "(-44,-72)(-30,-72)(-16,-72)(-2,-72)(12,-72)(26,-72)(40,-72)(-58,-58)"
|
||||
"(-44,-58)(-30,-58)(-16,-58)(-2,-58)(12,-58)(26,-58)(40,-58)(54,-58)"
|
||||
"(-72,-44)(-58,-44)(-44,-44)(-30,-44)(-16,-44)(-2,-44)(12,-44)(26,-44)"
|
||||
"(40,-44)(54,-44)(68,-44)(-72,-30)(-58,-30)(-44,-30)(-30,-30)(-16,-30)"
|
||||
"(-2,-30)(12,-30)(26,-30)(40,-30)(54,-30)(68,-30)(-72,-16)(-58,-16)"
|
||||
"(-44,-16)(-30,-16)(-16,-16)(-2,-16)(12,-16)(26,-16)(40,-16)(54,-16)"
|
||||
"(68,-16)(82,-16)(-72,-2)(-58,-2)(-44,-2)(-30,-2)(-16,-2)(-2,-2)"
|
||||
"(12,-2)(26,-2)(40,-2)(54,-2)(68,-2)(82,-2)(-72,12)(-58,12)(-44,12)"
|
||||
"(-30,12)(-16,12)(-2,12)(12,12)(26,12)(40,12)(54,12)(68,12)(82,12)"
|
||||
"(-72,26)(-58,26)(-44,26)(-30,26)(-16,26)(-2,26)(12,26)(26,26)(40,26)"
|
||||
"(54,26)(68,26)(-72,40)(-58,40)(-44,40)(-30,40)(-16,40)(-2,40)(12,40)"
|
||||
"(26,40)(40,40)(54,40)(68,40)(-58,54)(-44,54)(-30,54)(-16,54)(-2,54)"
|
||||
"(12,54)(26,54)(40,54)(54,54)(-44,68)(-30,68)(-16,68)(-2,68)(12,68)"
|
||||
"(26,68)(40,68)(-16,82)(-2,82)(12,82)";
|
||||
QString StrPlotFourInch = "(-2,-44)(-30,-30)(-16,-30)(-2,-30)(12,-30)(26,-30)(-30,-16)(-16,-16)"
|
||||
"(-2,-16)(12,-16)(26,-16)(40,-16)(-44,-2)(-30,-2)(-16,-2)(-2,-2)(12,-2)"
|
||||
"(26,-2)(40,-2)(-30,12)(-16,12)(-2,12)(12,12)(26,12)(40,12)(-30,26)(-16,26)"
|
||||
"(-2,26)(12,26)(26,26)(-16,40)(-2,40)(12,40)";
|
||||
|
||||
|
||||
bool StopElectricResistanceCheckFlag{false};
|
||||
|
||||
|
||||
LaserMark * pLaserMark;
|
||||
double laserMarkHeight{1};
|
||||
double laserMarkWidth{1};
|
||||
double laserMarkInternal{1};
|
||||
int laserMarkFrequency{1};
|
||||
double laserMarkPulseWidth{1};
|
||||
//BLLaserLib * pBLLaserLib;
|
||||
bool bUserPower{false};
|
||||
bool SuspendFlag{false};
|
||||
void Record_xiao();
|
||||
void laserCtlCnn();
|
||||
void laserCtlClose();
|
||||
void laserCtlSet(QString strParam);
|
||||
void laserSetMode(int); //设置出发模式 =》 0为TOD模式, 1为GATE模式
|
||||
void laserSetEmissionOnOff(int); //设置内部激光器开光关光状态 =》 1为激光器出光, 0为激光器关光
|
||||
void laserSetExtTrigEnable(int); //设置外部激光器触发使能状态 =》 1为激光器使能开, 0为激光器使能关
|
||||
bool PidFlag{true};
|
||||
bool DataCheckFlag{false};
|
||||
QString strLaserMark_test;
|
||||
|
||||
// 连续相对运动
|
||||
void XAxisCMoveN();
|
||||
void XAxisCMoveNEnd();
|
||||
void XAxisCMoveP();
|
||||
void XAxisCMovePEnd();
|
||||
void YAxisCMoveN();
|
||||
void YAxisCMoveNEnd();
|
||||
void YAxisCMoveP();
|
||||
void YAxisCMovePEnd();
|
||||
void ZAxisCMoveN();
|
||||
void ZAxisCMoveNEnd();
|
||||
void ZAxisCMoveP();
|
||||
void ZAxisCMovePEnd();
|
||||
void ZAAxisCMoveN();
|
||||
void ZAAxisCMoveNEnd();
|
||||
void ZAAxisCMoveP();
|
||||
void ZAAxisCMovePEnd();
|
||||
|
||||
void Z0AxisCMoveN();
|
||||
void Z0AxisCMoveNEnd();
|
||||
void Z0AxisCMoveP();
|
||||
void Z0AxisCMovePEnd();
|
||||
|
||||
void Z2AxisCMoveN();
|
||||
void Z2AxisCMoveNEnd();
|
||||
void Z2AxisCMoveP();
|
||||
void Z2AxisCMovePEnd();
|
||||
|
||||
void DAxisCMoveN();
|
||||
void DAxisCMoveNEnd();
|
||||
void DAxisCMoveP();
|
||||
void DAxisCMovePEnd();
|
||||
|
||||
// 单步相对运动
|
||||
void XAxisSMoveN();
|
||||
void XAxisSMoveP();
|
||||
void YAxisSMoveN();
|
||||
void YAxisSMoveP();
|
||||
void ZAxisSMoveN();
|
||||
void ZAxisSMoveP();
|
||||
void ZAAxisSMoveN();
|
||||
void ZAAxisSMoveP();
|
||||
|
||||
void DAxisSMoveN();
|
||||
void DAxisSMoveP();
|
||||
void Z2AxisSMoveN();
|
||||
void Z2AxisSMoveP();
|
||||
void Z0AxisSMoveN();
|
||||
void Z0AxisSMoveP();
|
||||
|
||||
|
||||
|
||||
// 绝对运动
|
||||
void ABSMove();
|
||||
void ABSMove_DZ0Z2();
|
||||
void ABSMove_Z0_test();
|
||||
void RSToZero();
|
||||
void MachSmallArea();
|
||||
void SScan();
|
||||
void compSScan();
|
||||
int GetRatioP1P2Thread();
|
||||
int SaveRatioP1P2ToCSV(float ApValue_P1[30],float ApValue_P2[30], float ApPercentage[30],float kb[],bool flag);
|
||||
int ElectricResistanceCheckThread();
|
||||
void imageGet();
|
||||
int FindEdgeThread();
|
||||
int FindEdgeThread_6();
|
||||
void MHCompOpen();
|
||||
void MotionCompOpen(bool flag,double array[]);
|
||||
void MotionCompClose();
|
||||
void compClose();
|
||||
void FindEdge();
|
||||
void GetRatioP1P2();
|
||||
void ElectricResistanceCheck();
|
||||
void GetGlobalPhoto();
|
||||
void GetGlobalPhotoSide();
|
||||
int GetGlobalPhotoThread();
|
||||
|
||||
void stop();
|
||||
void Suspend();
|
||||
void ContinueBuffer();
|
||||
void EStop();
|
||||
|
||||
void SMach();
|
||||
void semiAutoMach();
|
||||
|
||||
void vacuumSuckerOpen();
|
||||
void vacuumSuckerClose();
|
||||
|
||||
// 三色灯
|
||||
void laserOpen();
|
||||
void laserClose();
|
||||
|
||||
void greenLightOpen();
|
||||
void greenLightClose();
|
||||
|
||||
void redLightOpen();
|
||||
void redLightClose();
|
||||
|
||||
void yellowLightOpen();
|
||||
void yellowLightClose();
|
||||
|
||||
void StopBtnOpen();
|
||||
void StopBtnClose();
|
||||
void RunBtnOpen();
|
||||
void RunBtnClose();
|
||||
void FanOpen();
|
||||
void FanClose();
|
||||
void VacuumBreakOpen();
|
||||
void VacuumBreakClose();
|
||||
void AirValveClose();
|
||||
void AirValveOpen();
|
||||
void CuCeGaoClose();
|
||||
void CuCeGaoOpen();
|
||||
void Pin18Close();
|
||||
void Pin18Open();
|
||||
void LightClose();
|
||||
void LightOpen();
|
||||
void AirValveClose2();
|
||||
void AirValveOpen2();
|
||||
|
||||
void setLight();
|
||||
|
||||
// 轴使能操作
|
||||
void enableDisableXAxis();
|
||||
void enableDisableYAxis();
|
||||
void enableDisableZAxis();
|
||||
void enableDisableZAAxis();
|
||||
void enableDisableDAxis();
|
||||
void enableDisableZ0Axis();
|
||||
void enableDisableZ2Axis();
|
||||
//设置轴状态
|
||||
void setAxisState();
|
||||
|
||||
// 相机,加工头,测距头位置转换
|
||||
void MHToCamera();
|
||||
void CameraToMH();
|
||||
void RHToCamera();
|
||||
void CameraToRH();
|
||||
void RHToMH();
|
||||
void MHToRH();
|
||||
|
||||
// 过程位置
|
||||
void toLoadAndUnloadPos();
|
||||
void toGloblaCameraPos();
|
||||
void toSScanStartPos();
|
||||
void toRSToZeroPos();
|
||||
//void toMachStartPos();
|
||||
void toZAAxisCPos();
|
||||
void toLaserApTestPos();
|
||||
void toLaserMarkPos();
|
||||
void toHeightFindPos();
|
||||
void toEdgeSearchPos();
|
||||
void toCompenTestPos();
|
||||
void toRecordPos();
|
||||
|
||||
void LoadFromCsv(QString fileName);
|
||||
int devLaserNum{0};
|
||||
int devLaserState{0};
|
||||
int devPlaneScanCompState{0};
|
||||
int devMotionCompState{0};
|
||||
int devWorkpieceLockState{0};
|
||||
int devLightingState{0};
|
||||
bool devLaserCheck{false};
|
||||
int devLaserOpenTime{0};
|
||||
bool checkZaxisAlarmFlag{true};
|
||||
bool LaserTestApFlag{false};
|
||||
int LaserTestApIndex{1};
|
||||
double LaserApValueP1{0};
|
||||
double ApPercentage{0};
|
||||
int Mach_T_S_flag{0};
|
||||
int devInState{0};
|
||||
int runBtnDINum;
|
||||
int stopBtnDINum;
|
||||
int estopBtnDINum;
|
||||
int door1DINum;
|
||||
int door2DINum;
|
||||
int airValveOpenNum{0};
|
||||
int airValveCloseNum{0};
|
||||
int CuCeGaoDINum{0};
|
||||
int airValveDoNum{0};
|
||||
int CuCeGaoDoNum{0};
|
||||
int airValveDoSts{0};
|
||||
int airValveDoNum2{0};
|
||||
int airValveDoSts2{0};
|
||||
int AllPressureDINum{0};
|
||||
int devLightNum{0};
|
||||
int UPSDINum{0};
|
||||
int airValveDiOpenSts;
|
||||
int airValveDiCloseSts;
|
||||
int runType{0};
|
||||
bool bRunning;
|
||||
|
||||
bool bAutoLoadUnloadFlag{false};
|
||||
|
||||
int RFIDCount{0};
|
||||
double Palletheight{0};
|
||||
double LaserMarkOffset_Y{0};
|
||||
double LaserMarkOffset_X{0};
|
||||
double workpieceHeight{0};
|
||||
//double ZZA{0};
|
||||
bool lastTaskIsFinish{true};
|
||||
QString lastTaskName;
|
||||
int AxisMoveSafeCheckXY(int axisBuf[4],double distPos[4],int moveMode[2]);
|
||||
void detectionZZAAxisPos();
|
||||
bool getDevIsReset();
|
||||
bool getDevIsInit();
|
||||
bool getLastTaskIsFinish();
|
||||
int ShangProc(void);
|
||||
int XiaProc(void);
|
||||
int deCode_file(QString strFileName);
|
||||
QString deCodeString;
|
||||
QStringList fFileContent;
|
||||
signals:
|
||||
void ShangLiaoFSGL(bool);
|
||||
void XiaLiaoFSGL(bool);
|
||||
void MsgLogInSuccess(bool);
|
||||
void MsgSetValueSGL(int);
|
||||
void RunSGL(bool);
|
||||
void MHCompOpenFSGL();
|
||||
void MHCompCloseFSGL();
|
||||
void MotionCompOpenFSGL();
|
||||
void MotionCompCloseFSGL();
|
||||
void laserOpenFSGL();
|
||||
void laserCloseFSGL();
|
||||
void suspendBufferFSGL();
|
||||
void continueBufferFSGL();
|
||||
void vacuumSuckerOpenFSGL();
|
||||
void vacuumSuckerCloseFSGL();
|
||||
void FindEdgeFinishSGL(int);
|
||||
void GetRatioP1P2FinishSGL(int);
|
||||
void ElectricResistanceCheckFinishSGL(int);
|
||||
void show_Q_PP_SGL();
|
||||
void CMDRunFinishSGL();
|
||||
void XAxisLimitStateSGL(LIMIT_STATE);
|
||||
void YAxisLimitStateSGL(LIMIT_STATE);
|
||||
void ZAxisLimitStateSGL(LIMIT_STATE);
|
||||
void ZAAxisLimitStateSGL(LIMIT_STATE);
|
||||
void XAxisEnableStateSGL(bool);
|
||||
void YAxisEnableStateSGL(bool);
|
||||
void ZAxisEnableStateSGL(bool);
|
||||
void ZAAxisEnableStateSGL(bool);
|
||||
void XAxisCtPosSGL(double);
|
||||
void YAxisCtPosSGL(double);
|
||||
void ZAxisCtPosSGL(double);
|
||||
void ZAAxisCtPosSGL(double);
|
||||
void DAxisCtPosSGL(double);
|
||||
void Z0AxisCtPosSGL(double);
|
||||
void Z2AxisCtPosSGL(double);
|
||||
void StepNameSGL(int);
|
||||
void TransferPLCSGL(int);
|
||||
void SeparatePLCSGL(int);
|
||||
void GetGlobalPhotoFinishSGL(int);
|
||||
void PowerMeterValueSGL(float,float);
|
||||
|
||||
|
||||
void EStopSGL(bool);
|
||||
void SETRfidText(char *);
|
||||
void DEVInitStateChangedSGL(bool);
|
||||
//void DEVResetStateChangedSGL(bool);
|
||||
void RSValueChangedSGL(double);
|
||||
void stateDetectExceptSGL(int exceptCode);
|
||||
void exceptSGL(MyException);
|
||||
void exceptSGL_lhc(MyException);
|
||||
void AutoExceptSGL_laser(MyException);
|
||||
|
||||
void AutoSmachStateSGL(bool);
|
||||
void StopStateSGL(bool);
|
||||
void SmachTypeStateSGL(bool);
|
||||
void VacuumSuckerOnOrOffStateSGL(bool);
|
||||
void GetRunTypeState();
|
||||
void AutoExceptSGL(MyException);
|
||||
void ShowSmallAreasSGL();
|
||||
void ShowMergeSGL();
|
||||
void DDEnableStateSGL(int);
|
||||
void DDLimitStateSGL(int,LIMIT_STATE);
|
||||
void InStateSGL(int);
|
||||
private slots:
|
||||
// 监控状态
|
||||
void stateDetection();
|
||||
void resetFHandl();
|
||||
void XAxisSMoveNFHandl();
|
||||
void XAxisSMovePFHandl();
|
||||
void YAxisSMoveNFHandl();
|
||||
void YAxisSMovePFHandl();
|
||||
void ZAxisSMoveNFHandl();
|
||||
void ZAxisSMovePFHandl();
|
||||
void ZAAxisSMoveNFHandl();
|
||||
void ZAAxisSMovePFHandl();
|
||||
|
||||
void DAxisSMoveNFHandl();
|
||||
void DAxisSMovePFHandl();
|
||||
void Z2AxisSMoveNFHandl();
|
||||
void Z2AxisSMovePFHandl();
|
||||
void Z0AxisSMoveNFHandl();
|
||||
void Z0AxisSMovePFHandl();
|
||||
|
||||
void ABSMoveFHandl();
|
||||
void toLoadAndUnloadPosFHandl();
|
||||
void toGlobalCameraPosFHandl();
|
||||
void toSScanStartPosFHandl();
|
||||
void toRSToZeroPosFHandl();
|
||||
void toLaserApTestPosFHandl();
|
||||
void toLaserMarkPosFHandl();
|
||||
void toHeightFindPosFHandl();
|
||||
void toEdgeSearchPosFHandl();
|
||||
void toCompenTestPosFHandl();
|
||||
void toRecordPosFHandl();
|
||||
void toZAAxisCPosFHandl();
|
||||
void MHToCameraFHandl();
|
||||
void CameraToMHFHandl();
|
||||
void RHToCameraFHandl();
|
||||
void CameraToRHFHandl();
|
||||
void RHToMHFHandl();
|
||||
void MHToRHFHandl();
|
||||
void RSToZeroFHandl();
|
||||
void MachSmallAreaFHandl();
|
||||
void SScanFHandl();
|
||||
void compSScanFHandl();
|
||||
void MHCompOpenFHandl();
|
||||
void FindEdgeFHandl(int result);
|
||||
void GetRatioP1P2FHandl(int result);
|
||||
void ElectricResistanceCheckFHandl(int result);
|
||||
void SMachFHandl();
|
||||
void semiAutoMachFHandl();
|
||||
void CSS_MHCompOpenFHandl();
|
||||
void GetGlobalPhotoFHandl(int result);
|
||||
|
||||
private:
|
||||
DeviceProxy();
|
||||
DeviceProxy(DeviceProxy const&) = delete;
|
||||
DeviceProxy& operator = (DeviceProxy const&) = delete;
|
||||
|
||||
//监控
|
||||
void startStateDetection();
|
||||
void stopStateDetection();
|
||||
void detectionAllAxisCtPos();
|
||||
void detectionAllAxisLimitState();
|
||||
void detectionAllAxisEnableState();
|
||||
void detectionCMDRunFState();
|
||||
void detectionEStopState();
|
||||
void detectionRCValue();
|
||||
void detectionLaserValue();
|
||||
void detectionInState();
|
||||
bool getResetState();
|
||||
|
||||
//使能
|
||||
void enableXAxis();
|
||||
void enableYAxis();
|
||||
void enableZAxis();
|
||||
void enableZAAxis();
|
||||
void disableXAxis();
|
||||
void disableYAxis();
|
||||
void disableZAxis();
|
||||
void disableZAAxis();
|
||||
void enableDAxis();
|
||||
void enableZ0Axis();
|
||||
void enableZ2Axis();
|
||||
void disableDAxis();
|
||||
void disableZ0Axis();
|
||||
void disableZ2Axis();
|
||||
|
||||
void readSScanData();
|
||||
void saveSScanData();
|
||||
void buildSScanDataTable();
|
||||
void saveSScanDataTable();
|
||||
|
||||
void readCompSScanData();
|
||||
void saveCompSScanData();
|
||||
void buildLookupTable();
|
||||
void buildLookupTable2();
|
||||
void buildLookupTable_lhc();
|
||||
void buildLookupTable_lhc2();
|
||||
|
||||
void saveLookupTable();
|
||||
void saveLookupTable_lhc();
|
||||
void saveLookupTable_load();
|
||||
void SScanDataCheck_lhc();
|
||||
void SScanDataCheck();
|
||||
void lookupTableHeadEndDataHandl();
|
||||
void lookupTableHeadEndDataHandl_lhc();
|
||||
void lookupTableHeadEndDataHandl_lhc2();
|
||||
double DataHandlCheck_lhc(double data[6]);
|
||||
void lookupTable_do_Gaussian();
|
||||
void lookupPeripheralMakeUpZero();
|
||||
void downLoadLookupTable();
|
||||
|
||||
void RSToZeroInSide();
|
||||
void MachSmallAreaInSide();
|
||||
void SScanInSide();
|
||||
void compSScanInSide();
|
||||
void MHCompOpenInSide();
|
||||
void compCloseInSide();
|
||||
void FindEdgeInSide();
|
||||
void GetRatoP1P2Side();
|
||||
void ElectricResistanceCheckSide();
|
||||
|
||||
// 过程位置
|
||||
void toLoadAndUnloadPosInSide();
|
||||
void GloblaCameraPosInSide();
|
||||
void toSScanStartPosInSide();
|
||||
void toRSToZeroPosInSide();
|
||||
void toLaserApTestPosInSide();
|
||||
void toLaserMarkPosInSide();
|
||||
void toLaserMarkPosThreadInSide();
|
||||
void toHeightFindPosInSide();
|
||||
void toEdgeSearchPosInSide();
|
||||
void toRecordPosInSide();
|
||||
void toEdgeSearchPosThreadInSide();
|
||||
void toCompenTestPosInSide();
|
||||
|
||||
void SMachInSide(int index);
|
||||
void semiAutoMachInSide();
|
||||
|
||||
void vacuumSuckerOpenInSide();
|
||||
void vacuumSuckerCloseInSide();
|
||||
|
||||
void laserOpenInSide();
|
||||
void laserCloseInSide();
|
||||
|
||||
void RHToMHInSide();
|
||||
void MHToRHInSide();
|
||||
|
||||
// 异常处理
|
||||
void exceptHandl(MyException mye);
|
||||
void exceptHandl_thread(MyException mye);
|
||||
|
||||
private:
|
||||
static DeviceProxy* uniqueInstance;
|
||||
ACSController *acsCtl;
|
||||
|
||||
QTimer *timer;
|
||||
LIMIT_STATE XAxisLimitState{NORMAL};
|
||||
LIMIT_STATE YAxisLimitState{NORMAL};
|
||||
LIMIT_STATE ZAxisLimitState{NORMAL};
|
||||
LIMIT_STATE ZAAxisLimitState{NORMAL};
|
||||
LIMIT_STATE Z0AxisLimitState{NORMAL};
|
||||
LIMIT_STATE Z2AxisLimitState{NORMAL};
|
||||
LIMIT_STATE DAxisLimitState{NORMAL};
|
||||
|
||||
volatile double XAxisCtPos{0.0};
|
||||
volatile double YAxisCtPos{0.0};
|
||||
volatile double ZAxisCtPos{0.0};
|
||||
volatile double ZAAxisCtPos{0.0};
|
||||
volatile double Z0AxisCtPos{0.0};
|
||||
volatile double Z2AxisCtPos{0.0};
|
||||
volatile double DAxisCtPos{0.0};
|
||||
|
||||
double XAxisMin{0.0};
|
||||
double XAxisMax{0.0};
|
||||
double YAxisMin{0.0};
|
||||
double YAxisMax{0.0};
|
||||
double ZAxisAddZA{0.0};
|
||||
|
||||
bool XAxisIsEnable{false};
|
||||
bool YAxisIsEnable{false};
|
||||
bool ZAxisIsEnable{false};
|
||||
bool ZAAxisIsEnable{false};
|
||||
bool Z0AxisIsEnable{false};
|
||||
bool Z2AxisIsEnable{false};
|
||||
bool DAxisIsEnable{false};
|
||||
|
||||
|
||||
bool devIsInit{false};
|
||||
|
||||
bool devIsReset{false};
|
||||
bool devIsAlarm{false};
|
||||
int devLightState{0};
|
||||
int devRunStopBtnState{100};
|
||||
bool devEStopState{false};
|
||||
|
||||
|
||||
bool XAxisMoving{false};
|
||||
bool YAxisMoving{false};
|
||||
bool ZAxisMoving{false};
|
||||
bool ZAAxisMoving{false};
|
||||
bool Z0AxisMoving{false};
|
||||
bool Z2AxisMoving{false};
|
||||
bool DAxisMoving{false};
|
||||
|
||||
bool XAxisIsInPos{false};
|
||||
bool YAxisIsInPos{false};
|
||||
bool ZAxisIsInPos{false};
|
||||
bool ZAAxisIsInPos{false};
|
||||
bool Z0AxisIsInPos{false};
|
||||
bool Z2AxisIsInPos{false};
|
||||
bool DAxisIsInPos{false};
|
||||
|
||||
bool reqCMDRunFState{false};
|
||||
|
||||
//bool lastTaskIsFinish{true};
|
||||
//QString lastTaskName;
|
||||
|
||||
QVector<double> CSS_RSData;
|
||||
QVector<double> CSS_XPosData;
|
||||
|
||||
QVector<double> SScanArMsrZ;
|
||||
QVector<double> SScanArPosY;
|
||||
|
||||
QVector<QVector<double>> SScanDataTable;
|
||||
QVector<QVector<double>> lookupTable;
|
||||
QVector<QVector<double>> lookupTable_Gaussian;
|
||||
double lookupTableStartY{0.0};
|
||||
|
||||
double SSStartYPos{0.0};
|
||||
double SSStartXPos{0.0};
|
||||
|
||||
bool XAxisErrorDetection{false};
|
||||
bool YAxisErrorDetection{false};
|
||||
bool ZAxisErrorDetection{false};
|
||||
bool ZAAxisErrorDetection{false};
|
||||
bool Z0AxisErrorDetection{false};
|
||||
bool Z2AxisErrorDetection{false};
|
||||
bool DAxisErrorDetection{false};
|
||||
|
||||
QThread thread;
|
||||
int step{0};
|
||||
CDeviceProxyWorker *worker;
|
||||
|
||||
QMutex mutex;
|
||||
|
||||
bool StopFindEdgeFlag{false};
|
||||
bool StopGonglvCheckFlag{false};
|
||||
bool StopGetRatioP1P2Flag{false};
|
||||
|
||||
bool ZZAPosCheckFlag{false};
|
||||
int lRunStopTime[2]{0,0};
|
||||
int lRunCheckAirValve{0};
|
||||
|
||||
|
||||
};
|
||||
class CDeviceProxyWorker :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CDeviceProxyWorker(DeviceProxy *parent) { mParent = parent; }
|
||||
virtual ~CDeviceProxyWorker() {}
|
||||
|
||||
public slots :
|
||||
void doWork_custom();
|
||||
private:
|
||||
DeviceProxy *mParent;
|
||||
signals:void finished();
|
||||
};
|
||||
#endif // DEVICEPROXY_H
|
||||
17
device/exception/exceptioncode.h
Normal file
17
device/exception/exceptioncode.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef EXCEPTIONCODE_H
|
||||
#define EXCEPTIONCODE_H
|
||||
|
||||
#define DEV_INIT_FAIL 10000 //控制初始化失败
|
||||
#define RESET_FAIL 10001 //复位失败
|
||||
#define IS_MOVE_VEL_SET_FAIL 10002 //轴移动中,速度设置失败
|
||||
#define IS_MOVE_DISEN_FAIL 10003 //轴移动中,取消使能失败
|
||||
#define IS_MOVE_CMD_FAIL 10004 //轴移动中,命令执行失败
|
||||
#define DEV_NOT_INIT 10005 //设备未初始化
|
||||
#define AXIS_NOT_RESET 10006 //轴未复位
|
||||
#define DEV_NOT_RESET 10007 //设备未完成复位
|
||||
#define MRCH_NOT_CALIB 10008
|
||||
#define MACHCODEPATHISEMPT 10009
|
||||
#define WRITE_LOG_FAIL 10002
|
||||
|
||||
|
||||
#endif // EXCEPTIONCODE_H
|
||||
70
device/exception/myexception.cpp
Normal file
70
device/exception/myexception.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "myexception.h"
|
||||
|
||||
MyException::MyException(ExceptLevel value)
|
||||
{
|
||||
exceptInfo = QString("");
|
||||
level = value;
|
||||
exceptCode = NOTHING;
|
||||
}
|
||||
|
||||
MyException::MyException(const QString& text,ExceptLevel value)
|
||||
{
|
||||
exceptInfo = text;
|
||||
level = value;
|
||||
exceptCode = NOTHING;
|
||||
}
|
||||
|
||||
MyException::MyException(int exceptCodeValue,ExceptLevel value)
|
||||
{
|
||||
exceptCode = exceptCodeValue;
|
||||
level = value;
|
||||
exceptInfo = QString("");
|
||||
}
|
||||
|
||||
MyException::MyException(QString text,int exceptCodeValue,ExceptLevel value)
|
||||
{
|
||||
exceptInfo = text;
|
||||
exceptCode = exceptCodeValue;
|
||||
level = value;
|
||||
}
|
||||
|
||||
void MyException::setExceptLevel(ExceptLevel levelValue)
|
||||
{
|
||||
level = levelValue;
|
||||
}
|
||||
|
||||
QString MyException::getExceptInfo()
|
||||
{
|
||||
return exceptInfo;
|
||||
}
|
||||
|
||||
QString MyException::getExceptInfoWithExceptCode()
|
||||
{
|
||||
return exceptInfo+getExceptCodeText();
|
||||
}
|
||||
|
||||
int MyException::getExceptCode()
|
||||
{
|
||||
return exceptCode;
|
||||
}
|
||||
void MyException::setExceptCode(int value)
|
||||
{
|
||||
exceptCode = value;
|
||||
}
|
||||
|
||||
ExceptLevel MyException::getExceptLevel()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
void MyException::setExceptInfo(QString text)
|
||||
{
|
||||
exceptInfo = text;
|
||||
}
|
||||
|
||||
QString MyException::getExceptCodeText()
|
||||
{
|
||||
return QString(" 异常代码为:%1").arg(exceptCode);
|
||||
}
|
||||
|
||||
|
||||
33
device/exception/myexception.h
Normal file
33
device/exception/myexception.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef MYEXCEPTION_H
|
||||
#define MYEXCEPTION_H
|
||||
#include <QString>
|
||||
|
||||
#define NOTHING 50000
|
||||
enum ExceptLevel {MY_WARN,
|
||||
MY_CRITICAL };
|
||||
|
||||
class MyException
|
||||
{
|
||||
public:
|
||||
MyException(ExceptLevel value = MY_CRITICAL);
|
||||
MyException(const QString& text,ExceptLevel value = MY_CRITICAL);
|
||||
MyException(int exceptCodeValue,ExceptLevel value = MY_CRITICAL);
|
||||
MyException(QString text,int exceptCodeValue,ExceptLevel value = MY_CRITICAL);
|
||||
void setExceptLevel(ExceptLevel levelValue);
|
||||
ExceptLevel getExceptLevel();
|
||||
void setExceptInfo(QString text);
|
||||
QString getExceptInfo();
|
||||
QString getExceptInfoWithExceptCode();
|
||||
int getExceptCode();
|
||||
void setExceptCode(int value);
|
||||
private:
|
||||
QString getExceptCodeText();
|
||||
|
||||
private:
|
||||
QString exceptInfo;
|
||||
ExceptLevel level;
|
||||
int exceptCode;
|
||||
|
||||
};
|
||||
|
||||
#endif // MYEXCEPTION_H
|
||||
BIN
device/laserCtl/BLLaserLib.dll
Normal file
BIN
device/laserCtl/BLLaserLib.dll
Normal file
Binary file not shown.
12
device/laserCtl/BLLaserLib_global.h
Normal file
12
device/laserCtl/BLLaserLib_global.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef BLLASERLIB_GLOBAL_H
|
||||
#define BLLASERLIB_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(BLLASERLIB_LIBRARY)
|
||||
# define BLLASERLIB_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define BLLASERLIB_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // BLLASERLIB_GLOBAL_H
|
||||
2
device/laserCtl/Param/Default.ini
Normal file
2
device/laserCtl/Param/Default.ini
Normal file
@@ -0,0 +1,2 @@
|
||||
[Cofing]
|
||||
IP=169.254.126.162
|
||||
6
device/laserCtl/Param/Param1.ini
Normal file
6
device/laserCtl/Param/Param1.ini
Normal file
@@ -0,0 +1,6 @@
|
||||
[Param1]
|
||||
AS=100
|
||||
AM=1
|
||||
AB=1
|
||||
APP=3.4
|
||||
PW=1200
|
||||
6
device/laserCtl/Param/Param2.ini
Normal file
6
device/laserCtl/Param/Param2.ini
Normal file
@@ -0,0 +1,6 @@
|
||||
[Param]
|
||||
AS=100
|
||||
AM=1
|
||||
AB=1
|
||||
APP=2.3
|
||||
PW=1200
|
||||
51
device/laserCtl/bllaserlib.h
Normal file
51
device/laserCtl/bllaserlib.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef BLLASERLIB_H
|
||||
#define BLLASERLIB_H
|
||||
|
||||
#include "BLLaserLib_global.h"
|
||||
#include "qttelnet.h"
|
||||
#include <QObject>
|
||||
|
||||
class BLLASERLIB_EXPORT BLLaserLib : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BLLaserLib();
|
||||
|
||||
public:
|
||||
void Connect();
|
||||
void DisConnect();
|
||||
void WriteParam(QString);
|
||||
void SetMode(int); //设置出发模式 =》 0为TOD模式, 1为GATE模式
|
||||
void SetEmissionOnOff(int); //设置内部激光器开光关光状态 =》 1为激光器出光, 0为激光器关光
|
||||
void SetExtTrigEnable(int); //设置外部激光器触发使能状态 =》 1为激光器使能开, 0为激光器使能关
|
||||
//
|
||||
void BLStart();
|
||||
void BLStop();
|
||||
|
||||
private:
|
||||
QtTelnet* _Telnet;
|
||||
private:
|
||||
void CreatFolder();
|
||||
private slots:
|
||||
void On_LaserOpen();
|
||||
void On_LaserClose();
|
||||
//参数1
|
||||
void On_WriteAS1();
|
||||
void On_WriteAM1();
|
||||
void On_WriteAB1();
|
||||
void On_WriteAPP1();
|
||||
void On_WritePW1();
|
||||
//参数2
|
||||
void On_WriteAS2();
|
||||
void On_WriteAM2();
|
||||
void On_WriteAB2();
|
||||
void On_WriteAPP2();
|
||||
void On_WritePW2();
|
||||
//设置模式
|
||||
void On_SetMode();
|
||||
//设置外部触发信号
|
||||
void On_SetExtTrigEnable();
|
||||
};
|
||||
|
||||
#endif // BLLASERLIB_H
|
||||
BIN
device/laserCtl/libBLLaserLib.a
Normal file
BIN
device/laserCtl/libBLLaserLib.a
Normal file
Binary file not shown.
1408
device/laserCtl/qttelnet.cpp
Normal file
1408
device/laserCtl/qttelnet.cpp
Normal file
File diff suppressed because it is too large
Load Diff
128
device/laserCtl/qttelnet.h
Normal file
128
device/laserCtl/qttelnet.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** This file is part of a Qt Solutions component.
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Solutions Commercial License Agreement provided
|
||||
** with the Software or, alternatively, in accordance with the terms
|
||||
** contained in a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain
|
||||
** additional rights. These rights are described in the Nokia Qt LGPL
|
||||
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
||||
** package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Please note Third Party Software included with Qt Solutions may impose
|
||||
** additional restrictions and it is the user's responsibility to ensure
|
||||
** that they have met the licensing requirements of the GPL, LGPL, or Qt
|
||||
** Solutions Commercial license and the relevant license of the Third
|
||||
** Party Software they are using.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at qt-sales@nokia.com.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QTTELNET_H
|
||||
#define QTTELNET_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QSize>
|
||||
#include <QtCore/QRegExp>
|
||||
#include <QtNetwork/QTcpSocket>
|
||||
|
||||
class QtTelnetPrivate;
|
||||
|
||||
#if defined(Q_WS_WIN)
|
||||
# if !defined(QT_QTTELNET_EXPORT) && !defined(QT_QTTELNET_IMPORT)
|
||||
# define QT_QTTELNET_EXPORT
|
||||
# elif defined(QT_QTTELNET_IMPORT)
|
||||
# if defined(QT_QTTELNET_EXPORT)
|
||||
# undef QT_QTTELNET_EXPORT
|
||||
# endif
|
||||
# define QT_QTTELNET_EXPORT __declspec(dllimport)
|
||||
# elif defined(QT_QTTELNET_EXPORT)
|
||||
# undef QT_QTTELNET_EXPORT
|
||||
# define QT_QTTELNET_EXPORT __declspec(dllexport)
|
||||
# endif
|
||||
#else
|
||||
# define QT_QTTELNET_EXPORT
|
||||
#endif
|
||||
|
||||
class QT_QTTELNET_EXPORT QtTelnet : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class QtTelnetPrivate;
|
||||
public:
|
||||
QtTelnet(QObject *parent = 0);
|
||||
~QtTelnet();
|
||||
|
||||
enum Control { GoAhead, InterruptProcess, AreYouThere, AbortOutput,
|
||||
EraseCharacter, EraseLine, Break, EndOfFile, Suspend,
|
||||
Abort };
|
||||
|
||||
void connectToHost(const QString &host, quint16 port = 4000);
|
||||
QString connectSuccessfully();
|
||||
|
||||
void login(const QString &user, const QString &pass);
|
||||
|
||||
void setWindowSize(const QSize &size);
|
||||
void setWindowSize(int width, int height); // In number of characters
|
||||
QSize windowSize() const;
|
||||
bool isValidWindowSize() const;
|
||||
|
||||
void setSocket(QTcpSocket *socket);
|
||||
QTcpSocket *socket() const;
|
||||
|
||||
void setPromptPattern(const QRegExp &pattern);
|
||||
void setPromptString(const QString &pattern)
|
||||
{ setPromptPattern(QRegExp(QRegExp::escape(pattern))); }
|
||||
public Q_SLOTS:
|
||||
void close();
|
||||
void logout();
|
||||
void sendControl(Control ctrl);
|
||||
void sendData(const QString &data);
|
||||
void sendSync();
|
||||
|
||||
Q_SIGNALS:
|
||||
void loginRequired();
|
||||
void loginFailed();
|
||||
void loggedIn();
|
||||
void loggedOut();
|
||||
void connectionError(QAbstractSocket::SocketError error);
|
||||
void message(const QString &data);
|
||||
|
||||
public:
|
||||
void setLoginPattern(const QRegExp &pattern);
|
||||
void setLoginString(const QString &pattern)
|
||||
{ setLoginPattern(QRegExp(QRegExp::escape(pattern))); }
|
||||
void setPasswordPattern(const QRegExp &pattern);
|
||||
void setPasswordString(const QString &pattern)
|
||||
{ setPasswordPattern(QRegExp(QRegExp::escape(pattern))); }
|
||||
|
||||
private:
|
||||
QtTelnetPrivate *d;
|
||||
};
|
||||
#endif
|
||||
BIN
device/lasermark/LaserMark.dll
Normal file
BIN
device/lasermark/LaserMark.dll
Normal file
Binary file not shown.
103
device/lasermark/LaserMark.h
Normal file
103
device/lasermark/LaserMark.h
Normal file
@@ -0,0 +1,103 @@
|
||||
#ifndef LASERMARK_H
|
||||
#define LASERMARK_H
|
||||
|
||||
#include "LaserMark_global.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlQuery>
|
||||
#include <QVariant>
|
||||
#include <QDateTime>
|
||||
//
|
||||
#include <QString>
|
||||
#include <QMessageBox>
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include "LaserMark_global.h"
|
||||
#include "MarkEzdDll.h"
|
||||
|
||||
#ifdef UNICODE
|
||||
|
||||
#define QStringToTCHAR(x) (wchar_t*) x.utf16()
|
||||
#define PQStringToTCHAR(x) (wchar_t*) x->utf16()
|
||||
#define TCHARToQString(x) QString::fromUtf16((x))
|
||||
#define TCHARToQStringN(x,y) QString::fromUtf16((x),(y))
|
||||
|
||||
#else
|
||||
|
||||
#define QStringToTCHAR(x) x.local8Bit().constData()
|
||||
#define PQStringToTCHAR(x) x->local8Bit().constData()
|
||||
#define TCHARToQString(x) QString::fromLocal8Bit((x))
|
||||
#define TCHARToQStringN(x,y) QString::fromLocal8Bit((x),(y))
|
||||
|
||||
#endif
|
||||
|
||||
class LASERMARK_EXPORT LaserMark : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LaserMark();
|
||||
|
||||
private:
|
||||
QSqlDatabase db;
|
||||
|
||||
private:
|
||||
HINSTANCE m_hEzdDLL;
|
||||
LMC1_INITIAL lmc1_Initial;
|
||||
LMC1_CLOSE lmc1_Close;
|
||||
LMC1_STOPMARK lmc1_StopMark;
|
||||
|
||||
LMC1_LOADEZDFILE lmc1_LoadEzdFile;
|
||||
|
||||
LMC1_MARKENTITY lmc1_MarkEntity;
|
||||
|
||||
LMC1_SETDEVCFG lmc1_SetDevCfg;
|
||||
|
||||
LMC1_GETPENPARAM lmc1_GetPenParam;
|
||||
LMC1_SETPENPARAM lmc1_SetPenParam;
|
||||
|
||||
LMC1_DELETEENT lmc1_DeleteEnt;
|
||||
|
||||
LMC1_CLEARENTLIB lmc1_ClearEntLib;
|
||||
LMC1_ADDTEXTTOLIB lmc1_AddTextToLib;
|
||||
LMC1_MARK lmc1_Mark;
|
||||
|
||||
LMC1_ISMARKING lmc1_IsMarking; //为判断是否正在标刻
|
||||
|
||||
LMC1_SETTEXTENTPARAM2 lmc1_SetTextEntParam2;
|
||||
|
||||
LMC1_SETTEXTENTPARAM4 lmc1_SetTextEntParam4;
|
||||
|
||||
LMC1_SETPENPARAM4 lmc1_SetPenParam4;
|
||||
|
||||
LMC1_SAVEENTLIBTOFILE lmc1_SaveEntLibToFile;
|
||||
|
||||
LMC1_SETFONTPARAM3 lmc1_SetFontParam3;
|
||||
|
||||
private:
|
||||
QString TempMarkTitle;
|
||||
bool IsMarkStatus{false};
|
||||
int MarkCount{0};
|
||||
int _nFreq{0};
|
||||
double _dQPulseWidth{0};
|
||||
|
||||
private:
|
||||
bool InitSQL();
|
||||
bool InitLaser(QString); //QString为 ezcad2.exe所处的目录的全路径名称,例如C:\WorkBook\20180528\EzCAD2\Debug
|
||||
QString GetMarkTitle(QString);
|
||||
|
||||
//多线程打标
|
||||
QMutex mutex;
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
public:
|
||||
bool Init(QString); //初始化
|
||||
void Start(QString,QString*,int,bool); //打标的字符 返回打标的字符 打标次数 true为自动,false为手动
|
||||
void Abort(); //停止打标
|
||||
void SetParam(); //设置金橙子参数
|
||||
bool GetMyMarkStatus(); //获取激光打标状态(true为正在打标,false为空闲状态)
|
||||
bool SetFontParam(double, double, double, int,double); //字符高度 字体宽度 字体间距 频率 脉宽
|
||||
};
|
||||
|
||||
#endif // LASERMARK_H
|
||||
BIN
device/lasermark/LaserMark.o
Normal file
BIN
device/lasermark/LaserMark.o
Normal file
Binary file not shown.
12
device/lasermark/LaserMark_global.h
Normal file
12
device/lasermark/LaserMark_global.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef LASERMARK_GLOBAL_H
|
||||
#define LASERMARK_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(LASERMARK_LIBRARY)
|
||||
# define LASERMARK_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define LASERMARK_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // LASERMARK_GLOBAL_H
|
||||
945
device/lasermark/MarkEzdDll.h
Normal file
945
device/lasermark/MarkEzdDll.h
Normal file
@@ -0,0 +1,945 @@
|
||||
#ifndef MARKEZDDLL_H
|
||||
#define MARKEZDDLL_H
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#pragma region Return Value
|
||||
|
||||
//所有函数都返回一个整形值
|
||||
#define LMC1_ERR_SUCCESS 0 //成功
|
||||
#define LMC1_ERR_EZCADRUN 1 //发现EZCAD在运行
|
||||
#define LMC1_ERR_NOFINDCFGFILE 2 //找不到EZCAD.CFG
|
||||
#define LMC1_ERR_FAILEDOPEN 3 //打开LMC1失败
|
||||
#define LMC1_ERR_NODEVICE 4 //没有有效的lmc1设备
|
||||
#define LMC1_ERR_HARDVER 5 //lmc1版本错误
|
||||
#define LMC1_ERR_DEVCFG 6 //找不到设备配置文件
|
||||
#define LMC1_ERR_STOPSIGNAL 7 //报警信号
|
||||
#define LMC1_ERR_USERSTOP 8 //用户停止
|
||||
#define LMC1_ERR_UNKNOW 9 //不明错误
|
||||
#define LMC1_ERR_OUTTIME 10 //超时
|
||||
#define LMC1_ERR_NOINITIAL 11 //未初始化
|
||||
#define LMC1_ERR_READFILE 12 //读文件错误
|
||||
#define LMC1_ERR_OWENWNDNULL 13 //窗口为空
|
||||
#define LMC1_ERR_NOFINDFONT 14 //找不到指定名称的字体
|
||||
#define LMC1_ERR_PENNO 15 //错误的笔号
|
||||
#define LMC1_ERR_NOTTEXT 16 //指定名称的对象不是文本对象
|
||||
#define LMC1_ERR_SAVEFILE 17 //保存文件失败
|
||||
#define LMC1_ERR_NOFINDENT 18 //找不到指定对象
|
||||
#define LMC1_ERR_STATUE 19 //当前状态下不能执行此操作
|
||||
#define LMC1_ERR_PARAM 20 //参数错误
|
||||
#define LMC1_ERR_DEVICE 21 //硬件错误
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Device
|
||||
|
||||
//初始化lmc1控制卡
|
||||
//输入参数: strEzCadPath EzCad软件的执行路径
|
||||
// bTestMode = TRUE 表示测试模式 bTestMode = FALSE 表示正常模式,默认TRUE
|
||||
// pOwenWnd 表示父窗口对象,如果需要实现停止打标,则系统会从此窗口截取消息
|
||||
typedef int(*LMC1_INITIAL)(TCHAR* strEzCadPath,//ezcad的工作目录
|
||||
BOOL bTestMode,//是否是测试模式
|
||||
HWND hOwenWnd);//父窗口
|
||||
|
||||
//关闭lmc1控制卡
|
||||
typedef int(*LMC1_CLOSE)();
|
||||
|
||||
//调用设置设备参数的对话框
|
||||
typedef int(*LMC1_SETDEVCFG)();
|
||||
|
||||
//调用设置设备参数的对话框,显示扩展轴参数
|
||||
typedef int(*LMC1_SETDEVCFG2)(BOOL bAxisShow0, BOOL bAxisShow1);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Mark
|
||||
|
||||
//标刻当前数据库里的所有数据
|
||||
//输入参数: bFlyMark = TRUE 使能飞动打标 bFlyMark = FALSE 使能飞动打标
|
||||
//此函数一直等待设备加工完毕后,或者用户停止才返回。即函数结束表示加工结束
|
||||
typedef int(*LMC1_MARK)(BOOL bFlyMark);
|
||||
|
||||
//标刻当前数据库里的指定对象
|
||||
//输入参数: strEntName 要加工的指定对象的名称
|
||||
//此函数一直等待设备加工完毕后才返回
|
||||
typedef int(*LMC1_MARKENTITY)(TCHAR* strEntName);
|
||||
|
||||
//飞行标刻当前数据库里的所有数据
|
||||
//在使用此函数后,软件开始等待飞行硬件信号(IN8/IN9,在飞行界面中设置的),有信号后开始加工
|
||||
typedef int(*LMC1_MARKFLYBYSTARTSIGNAL)();
|
||||
|
||||
//飞动标刻当前数据库里的指定对象
|
||||
//输入参数: strEntName 飞动打标指定对象的名称
|
||||
//此函数一直等待设备加工完毕后才返回
|
||||
typedef int(*LMC1_MARKENTITYFLY)(TCHAR* strEntName);
|
||||
|
||||
//标刻指定线段
|
||||
//输入参数 x1,y1起点坐标,x2y2终点坐标,pen 使用的笔号
|
||||
typedef int(*LMC1_MARKLINE)(double x1, double y1, double x2, double y2, int pen);
|
||||
|
||||
//标刻指定点
|
||||
//输入参数 x,y点坐标,delay打标时间,pen 使用的笔号
|
||||
typedef int(*LMC1_MARKPOINT)(double x, double y, double delay, int pen);
|
||||
|
||||
//标刻指定的多个点
|
||||
//输入参数 ptBuf点坐标组;ptBuf[n][0]表示第n个点的x坐标,ptBuf[n][1]表示第n个点的y坐标,dJumpSpeed在点之间的跳转速度,dLaserOnTimeMs点的打标时间,单位ms
|
||||
typedef int(*LMC1_MARKPOINTBUF2)(double ptBuf[][2], double dJumpSpeed, double dLaserOnTimeMs);
|
||||
|
||||
//判断卡正在处于工作状态
|
||||
typedef int(*LMC1_ISMARKING)();
|
||||
|
||||
//强制停止当前标刻
|
||||
typedef int(*LMC1_STOPMARK)();
|
||||
|
||||
//标刻一次红光显示框
|
||||
//预览一次全部对象的打标范围,即数据的包围盒
|
||||
typedef int(*LMC1_REDLIGHTMARK)();
|
||||
|
||||
//红光预览当前数据库里面所有数据轮廓一次
|
||||
//预览轨迹与打标轨迹一致。如果预览圆,轨迹就是一个圆
|
||||
typedef int(*LMC1_REDLIGHTMARKCONTOUR)();
|
||||
|
||||
//红光预览当前数据库里面指定对象
|
||||
//输入参数 strEntName对象名称;bContour显示的是否是轮廓,true显示轮廓,false显示范围
|
||||
typedef int(*LMC1_REDLIGHTMARKBYENT)(TCHAR* strEntName, BOOL bContour);
|
||||
|
||||
//获取当前的飞行速度
|
||||
//输入参数: FlySpeed流水线当前速度
|
||||
//在设备空闲时可查询流水线速度,即加工或红光过程中不可使用
|
||||
typedef int(*LMC1_GETFLYSPEED)(double& FlySpeed);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region EzdFile
|
||||
|
||||
//载入ezd文件,并清除数据库所有对象
|
||||
//输入参数: strFileName EzCad文件名称
|
||||
typedef int(*LMC1_LOADEZDFILE)(TCHAR* strFileName);
|
||||
|
||||
//保存当前数据库里所有对象到指定ezd文件里
|
||||
//输入参数: strFileName ezd文件名称
|
||||
typedef int(*LMC1_SAVEENTLIBTOFILE)(TCHAR* strFileName);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Preview
|
||||
|
||||
//得到当前数据库里的所有数据的预览图像
|
||||
//输入参数: hwnd需要显示当前图像的窗口句柄,nBMPWIDTH 需要生成的图像的像素宽度,nBMPHEIGHT需要生成的图像的像素高度
|
||||
//在程序中调用lmc1_GetPrevBitmap得到当前数据库里的所有对象的预览图像的指针,可以用于更新界面显示
|
||||
//typedef CBitmap* (*LMC1_GETPREVBITMAP)(HWND hwnd, int nBMPWIDTH, int nBMPHEIGHT);
|
||||
|
||||
//得到当前数据库里的指定对象数据的预览图像
|
||||
//输入参数: pWnd 预览图像显示到哪个窗口
|
||||
// nBMPWIDTH 预览图像的宽度
|
||||
// nBMPHEIGHT 预览图像的高度
|
||||
// strEntName 指定对象的名称
|
||||
//typedef CBitmap* (*LMC1_GETPREVBITMAPBYNAME)(TCHAR* strEntName, HWND hwnd, int nBMPWIDTH, int nBMPHEIGHT);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Operation Ent
|
||||
|
||||
//得到指定对象的最大最小坐标,如果pEntName==NULL表示读取数据库所有对象的最大最小坐标
|
||||
typedef int(*LMC1_GETENTSIZE)(TCHAR* pEntName,//字符串对象名称
|
||||
double& dMinx,//最小x坐标
|
||||
double& dMiny,//最小y坐标
|
||||
double& dMaxx,//最大x坐标
|
||||
double& dMaxy,//最大y坐标
|
||||
double& dZ);//对象的z坐标
|
||||
|
||||
//移动指定对象相对坐标
|
||||
typedef int(*LMC1_MOVEENT)(TCHAR* pEntName,//字符串对象名称
|
||||
double dMovex,//对象移动x距离
|
||||
double dMovey);//对象移动y距离
|
||||
|
||||
//缩放指定对象,
|
||||
typedef int(*LMC1_SCALEENT)(TCHAR* pEntName,//字符串对象名称
|
||||
double dCenx,//缩放的X中心
|
||||
double dCeny,//缩放的Y中心
|
||||
double dScaleX,//缩放的X比例
|
||||
double dScaleY);//缩放的Y比例
|
||||
|
||||
//镜像指定对象
|
||||
typedef int(*LMC1_MIRRORENT)(TCHAR* pEntName,//字符串对象名称
|
||||
double dCenx,// 镜像的X中心
|
||||
double dCeny,//镜像的Y中心
|
||||
BOOL bMirrorX,//是否X方向镜像,true表示镜像
|
||||
BOOL bMirrorY);//是否Y方向镜像,true表示镜像
|
||||
|
||||
//旋转指定对象
|
||||
typedef int(*LMC1_ROTATEENT)(TCHAR* pEntName,//字符串对象名称
|
||||
double dCenx,//旋转的X中心
|
||||
double dCeny,//旋转的Y中心
|
||||
double dAngle);//旋转的角度,(逆时针为正,单位为度)
|
||||
|
||||
//复制粘贴指定对象,并对新对象命名
|
||||
//输入参数:PEntName要复制的对象,pNewEntName复制后的对象名称
|
||||
typedef int(*LMC1_COPYENT)(TCHAR* pEntName, TCHAR* pNewEntName);
|
||||
|
||||
//得到当前数据库中的对象总数
|
||||
//输出参数: 对象总数
|
||||
typedef int(*LMC1_GETENTITYCOUNT)();
|
||||
|
||||
//得到指定序号的对象名称
|
||||
//输入参数: nEntityIndex 指定对象的序号(范围: 0 - (lmc1_GetEntityCount()-1))
|
||||
//输出参数: szEntName 对象的名称
|
||||
typedef int(*LMC1_GETENTITYNAME)(int nEntityIndex, TCHAR szEntName[256]);
|
||||
|
||||
//设置指定序号的对象名称
|
||||
typedef int(*LMC1_SETENTITYNAME)(int nEntityIndex, TCHAR* pEntName);
|
||||
|
||||
//修改对象名称
|
||||
typedef int(*lmc1_ChangeEntName)(TCHAR* pEntName, TCHAR* pNewEntName);
|
||||
|
||||
//设置旋转变换参数
|
||||
//输入参数: dCenterX 旋转中心x坐标
|
||||
// dCenterY 旋转中心y坐标
|
||||
// dRotateAng 旋转角度(弧度值)
|
||||
typedef void(*LMC1_SETROTATEPARAM)(double dCenterX, double dCenterY, double dRotateAng);
|
||||
|
||||
//设置旋转变换参数 不影响数据的显示,只是加工时才对对象进行旋转。
|
||||
typedef void(*LMC1_SETROTATEMOVEPARAM)( double dMoveX,//X方向移动距离
|
||||
double dMoveY,//Y方向移动距离
|
||||
double dCenterX, //旋转中心X坐标
|
||||
double dCenterY,//旋转中心Y坐标
|
||||
double dRotateAng); //旋转角度(弧度值)
|
||||
|
||||
//更改当前数据库里的指定文本对象的文本
|
||||
//输入参数: strTextName 要更改内容的文本对象的名称
|
||||
// strTextNew 新的文本内容
|
||||
typedef int(*LMC1_CHANGETEXTBYNAME)(TCHAR* strTextName, TCHAR* strTextNew);
|
||||
|
||||
//得到指定对象的文本
|
||||
//strTextName 要获取内容的文本对象的名称,szEntText 文本内容
|
||||
typedef int(*LMC1_GETTEXTBYNAME)(TCHAR* strTextName, TCHAR strText[256]);
|
||||
|
||||
//序列号复位为开始序号
|
||||
//输入参数:PTextName文本对象名称
|
||||
typedef int(*LMC1_TEXTRESETSN)(TCHAR* pTextName);
|
||||
|
||||
//群组2个对象,并设置群组新的对象名称,以及笔号
|
||||
typedef int(*LMC1_GROUPENT)(TCHAR* pEntName1,//群组对象1名称
|
||||
TCHAR* pEntName2,//群组对象2名称
|
||||
TCHAR* pEntNameNew,//群组后新对象名称
|
||||
int pen);//新对象使用的笔号
|
||||
|
||||
//解散群组
|
||||
//输入参数:pGroupEntName群组对象名称
|
||||
typedef int(*LMC1_UNGROUPENT)(TCHAR* pGroupEntName);
|
||||
|
||||
//群组N个对象,并设置群组新的对象名称,以及笔号
|
||||
typedef int(*LMC1_GROUPENT2)(TCHAR** strEntNameList,//对象名称列表
|
||||
int nEntCount,//群组对象数量
|
||||
TCHAR* strGroupName,//群组后对象名
|
||||
int nGroupPen);//新对象使用的笔号
|
||||
|
||||
//彻底解散群组对象为曲线
|
||||
typedef int(*LMC1_UNGROUPENT2)(TCHAR* pGroupEntName,//群组对象名称
|
||||
int nFlag);//标志位,默认=0
|
||||
|
||||
//向前移动对象
|
||||
typedef int(*LMC1_MOVEENTITYBEFORE)(int nMoveEnt, //要移动的对象在对象列表中的位置
|
||||
int nGoalEnt);//对象要在对象列表中移动到的位置
|
||||
|
||||
//向后移动对象
|
||||
typedef int(*LMC1_MOVEENTITYAFTER)(int nMoveEnt, //要移动的对象在对象列表中的位置
|
||||
int nGoalEnt);//对象要在对象列表中移动到的位置
|
||||
|
||||
//颠倒所有对象在对象列表中的顺序
|
||||
typedef int(*LMC1_REVERSEALLENTORDER)();
|
||||
|
||||
//获取指定位图的参数
|
||||
typedef int(*LMC1_GETBITMAPENTPARAM)(TCHAR* strEntName,//位图对象名称
|
||||
TCHAR BmpPath[256],//位图对象路径
|
||||
int& nBmpAttrib,//位图参数
|
||||
int& nScanAttrib,//扫描参数
|
||||
double& dBrightness,//亮度设置[-1, 1]
|
||||
double& dContrast,//对比度设置[-1, 1]
|
||||
double& dPointTime,//打点时间设置
|
||||
int& nImportDpi);//DPI
|
||||
|
||||
const int BMPSCAN_INVERT = 0x0001;//图像反转
|
||||
const int BMPSCAN_GRAY = 0x0002;//图像灰度
|
||||
const int BMPSCAN_LIGHT = 0x0004;//图像亮度
|
||||
const int BMPSCAN_DITHER = 0x0010;//网点处理
|
||||
const int BMPSCAN_BIDIR = 0x1000;//双向扫描
|
||||
const int BMPSCAN_YDIR = 0x2000;//Y向扫描
|
||||
const int BMPSCAN_DRILL = 0x4000;//打点模式
|
||||
const int BMPSCAN_POWER = 0x8000;//调整功率
|
||||
const int BMPATTRIB_DYNFILE = 0x1000;//动态文件
|
||||
const int BMPATTRIB_IMPORTFIXED_WIDTH = 0x2000;//固定文件输入宽
|
||||
const int BMPATTRIB_IMPORTFIXED_HEIGHT = 0x4000;//固定文件输入高
|
||||
const int BMPATTRIB_IMPORTFIXED_DPI = 0x8000;//固定DPI
|
||||
|
||||
//设置指定位图的参数
|
||||
typedef int(*LMC1_SETBITMAPENTPARAM2)(TCHAR* strEntName,//位图对象名称
|
||||
TCHAR* strBmpPath,//位图对象路径
|
||||
int nBmpAttrib,//位图参数
|
||||
int nScanAttrib,//扫描参数
|
||||
double dBrightness,//亮度设置[-1, 1]
|
||||
double dContrast,//对比度设置[-1, 1]
|
||||
double dPointTime,//打点时间设置
|
||||
int nImportDpi);//DPI
|
||||
|
||||
//获取指定文本的字体参数
|
||||
typedef int(*LMC1_GETTEXTENTPARAM2)(TCHAR* strTextName,//文本名称
|
||||
TCHAR sFontName[256],//字体名称
|
||||
double& dCharHeight,//字符高度
|
||||
double& dCharWidth,//字符宽度
|
||||
double& dCharAngle,//字符倾角(弧度值)
|
||||
double& dCharSpace,// 字符间距
|
||||
double& dLineSpace,//行间距
|
||||
double& dSpaceWidth,//空字符宽带
|
||||
BOOL& bEqualCharWidth);//等字符宽度模式
|
||||
|
||||
//设置指定文本的字体参数
|
||||
typedef int(*LMC1_SETTEXTENTPARAM2)(TCHAR* strTextName,//文本名称
|
||||
TCHAR* strFontName,//字体名称
|
||||
double dCharHeight,//字符高度
|
||||
double dCharWidth,//字符宽度
|
||||
double dCharAngle,//字符倾角(弧度值)
|
||||
double dCharSpace,//字符间距
|
||||
double dLineSpace,//行间距
|
||||
double dSpaceWidth,//空字符宽带
|
||||
BOOL bEqualCharWidth);//等字符宽度模式
|
||||
|
||||
//获取指定文本的字体参数
|
||||
typedef int(*LMC1_GETTEXTENTPARAM4)(TCHAR* strTextName,//文本名称
|
||||
TCHAR sFontName[256],//字体名称
|
||||
int& nTextSpaceMode,//文本间距模式
|
||||
double& dTextSpace,//文本间距距离
|
||||
double& dCharHeight,// 字符高度
|
||||
double& CharWidthRatio,//字符宽度
|
||||
double& dCharAngle,// 字符倾角(弧度值)
|
||||
double& dCharSpace,//字符间距
|
||||
double& dLineSpace,// 行间距
|
||||
double& spaceWidthRatio,//空字符宽带
|
||||
int& nTextAlign,//文本对齐方式
|
||||
BOOL& bBold,//粗体
|
||||
BOOL& bItalic);//斜体
|
||||
|
||||
//设置指定文本的字体参数
|
||||
typedef int(*LMC1_SETTEXTENTPARAM4)(TCHAR* strTextName,//文本名称
|
||||
TCHAR* strFontName,//字体名称
|
||||
int nTextSpaceMode,//文本间距模式
|
||||
double dTextSpace,//文本间距距离
|
||||
double dCharHeight,//字符高度
|
||||
double CharWidthRatio,//字符宽度
|
||||
double dCharAngle,//字符倾角(弧度值)
|
||||
double dCharSpace,// 字符间距
|
||||
double dLineSpace,//行间距
|
||||
double spaceWidthRatio,//空字符宽带
|
||||
int nTextAlign,//文本对齐方式
|
||||
bool bBold,//粗体
|
||||
bool bItalic);//斜体
|
||||
|
||||
|
||||
//删除对象库里指定对象
|
||||
typedef int(*LMC1_DELETEENT)(TCHAR* pEntName);
|
||||
|
||||
//清除对象库里所有数据
|
||||
typedef int(*LMC1_CLEARENTLIB)();
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region AddEnt
|
||||
|
||||
//对齐方式时数字代表的意义
|
||||
// 6 --- 5 --- 4
|
||||
// | |
|
||||
// | |
|
||||
// 7 8 3
|
||||
// | |
|
||||
// | |
|
||||
// 0 --- 1 --- 2
|
||||
//加入新文本到数据库中
|
||||
typedef int(*LMC1_ADDTEXTTOLIB)(TCHAR* pStr,//要添加的字符串
|
||||
TCHAR* pEntName,//字符串对象名称
|
||||
double dPosX,//字符串的左下角基点的x坐标
|
||||
double dPosY,//字符串的左下角基点的y坐标
|
||||
double dPosZ,//字符串对象的z坐标
|
||||
int nAlign,//对齐方式0-8
|
||||
double dTextRotateAngle,//字符串绕基点旋转的角度值(弧度值)
|
||||
int nPenNo,//对象使用的加工参数
|
||||
BOOL bHatchText);//是否填充文本对象
|
||||
|
||||
#define CIRTEXTFLAG_REVERSE 0x0001 //反转
|
||||
#define CIRTEXTFLAG_UPDOWN 0x0002 //上下反转
|
||||
|
||||
//添加圆弧文本
|
||||
typedef int(*LMC1_ADDCIRCLETEXTTOLIB)(TCHAR* pStr,//要添加的字符串
|
||||
TCHAR* pEntName,//字符串对象名称
|
||||
double dPosX,//文本所在基准圆的x坐标
|
||||
double dPosY,//文本所在基准圆的y坐标
|
||||
double dPosZ,//字符串对象的z坐标
|
||||
int nPenNo,//文本对象使用的笔号
|
||||
int bHatchText,//是否填充文本
|
||||
double dCirDiameter,//基准圆直径
|
||||
double dCirBaseAngle,//文字基准角度
|
||||
BOOL bCirEnableAngleLimit,//是否使能角度限制
|
||||
double dCirAngleLimit, //限制的角度
|
||||
int nCirTextFlag);//文本在圆上的方向
|
||||
|
||||
//获得指定圆弧文本对象的参数
|
||||
typedef int(*LMC1_GETCIRCLETEXTPARAM)( TCHAR* pEntName,//字符串对象名称
|
||||
double& dCenX,//文本所在基准圆的x坐标
|
||||
double& dCenY,//文本所在基准圆的y坐标
|
||||
double &dCenZ,//字符z坐标
|
||||
double& dCirDiameter,//基准圆直径
|
||||
double& dCirBaseAngle,//文字基准角度
|
||||
BOOL& bCirEnableAngleLimit,//是否使能角度限制
|
||||
double & dCirAngleLimit,//限制的角度
|
||||
int& nCirTextFlag); //文本在圆上的方向
|
||||
|
||||
//设置指定圆弧文本对象的参数
|
||||
typedef int(*LMC1_SETCIRCLETEXTPARAM)( TCHAR* pEntName,//字符串对象名称
|
||||
double dCenX,//文本所在基准圆的x坐标
|
||||
double dCenY,//文本所在基准圆的y坐标
|
||||
double dCenZ,//字符z坐标
|
||||
double dCirDiameter,//基准圆直径
|
||||
double dCirBaseAngle,//文字基准角度
|
||||
BOOL bCirEnableAngleLimit,//是否使能角度限制
|
||||
double dCirAngleLimit,//限制的角度
|
||||
int nCirTextFlag);//文本在圆上的方向
|
||||
|
||||
|
||||
//加入指定文件到数据库中
|
||||
//支持的文件有ezd,dxf,dst,plt,ai,bmp,jpg,tga,png,gif,tiff等
|
||||
typedef int(*LMC1_ADDFILETOLIB)(TCHAR* pFileName, //文件名称
|
||||
TCHAR* pEntName,//字符串对象名称
|
||||
double dPosX, //文件左下角基点x坐标
|
||||
double dPosY, //文件左下角基点y坐标
|
||||
double dPosZ, //文件z坐标
|
||||
int nAlign,//对齐方式0-8
|
||||
double dRatio,//文件缩放比例
|
||||
int nPenNo,//对象使用的加工参数
|
||||
BOOL bHatchFile);//是否填充文件对象 如果是ezd文件或位图文件此参数无效
|
||||
|
||||
|
||||
//加入曲线到数据库中
|
||||
typedef int(*LMC1_ADDCURVETOLIB)(double ptBuf[][2],//曲线顶点数组
|
||||
int ptNum,//曲线顶点数
|
||||
TCHAR* pEntName,//曲线对象名称
|
||||
int nPenNo,//曲线对象使用的笔号
|
||||
int bHatch);//曲线是否填充
|
||||
|
||||
//加入一组点到数据库中
|
||||
typedef int(*LMC1_ADDCURVETOLIB2)(double* ptBuf,//曲线顶点数组
|
||||
int ptNum,//曲线顶点数
|
||||
TCHAR* pEntName,//曲线对象名称
|
||||
int nPenNo,//曲线对象使用的笔号
|
||||
int bHatch);//曲线是否填充
|
||||
|
||||
//加入延时到数据库中
|
||||
//输入参数:延时时长,单位ms
|
||||
typedef int(*LMC1_ADDDELAYTOLIB)(double dDelayMs);
|
||||
|
||||
//加入输出口到数据库中
|
||||
typedef int(*lmc1_AddWritePortToLib)( int nOutPutBit,//输出口的值,0到15
|
||||
BOOL bHigh, //是否是高电平
|
||||
BOOL bPluse, //是否是脉冲
|
||||
double dPulseTimeMs);//脉冲长的,单位ms
|
||||
|
||||
|
||||
#define BARCODETYPE_39 0
|
||||
#define BARCODETYPE_93 1
|
||||
#define BARCODETYPE_128A 2
|
||||
#define BARCODETYPE_128B 3
|
||||
#define BARCODETYPE_128C 4
|
||||
#define BARCODETYPE_128OPT 5
|
||||
#define BARCODETYPE_EAN128A 6
|
||||
#define BARCODETYPE_EAN128B 7
|
||||
#define BARCODETYPE_EAN128C 8
|
||||
#define BARCODETYPE_EAN13 9
|
||||
#define BARCODETYPE_EAN8 10
|
||||
#define BARCODETYPE_UPCA 11
|
||||
#define BARCODETYPE_UPCE 12
|
||||
#define BARCODETYPE_25 13
|
||||
#define BARCODETYPE_INTER25 14
|
||||
#define BARCODETYPE_CODABAR 15
|
||||
#define BARCODETYPE_PDF417 16
|
||||
#define BARCODETYPE_DATAMTX 17
|
||||
#define BARCODETYPE_USERDEF 18
|
||||
#define BARCODETYPE_QRCODE 19
|
||||
#define BARCODETYPE_MINIDATAMTX 20
|
||||
|
||||
|
||||
|
||||
|
||||
#define BARCODEATTRIB_REVERSE 0x0008 //条码反转
|
||||
#define BARCODEATTRIB_HUMANREAD 0x1000 //显示人识别字符
|
||||
#define BARCODEATTRIB_CHECKNUM 0x0004 //需要校验码
|
||||
#define BARCODEATTRIB_PDF417_SHORTMODE 0x0040 //PDF417为缩短模式
|
||||
#define BARCODEATTRIB_DATAMTX_DOTMODE 0x0080 //DataMtrix为点模式
|
||||
#define BARCODEATTRIB_CIRCLEMODE 0x0100 //自定义二维码为圆模式
|
||||
|
||||
|
||||
#define DATAMTX_SIZEMODE_SMALLEST 0
|
||||
#define DATAMTX_SIZEMODE_10X10 1
|
||||
#define DATAMTX_SIZEMODE_12X12 2
|
||||
#define DATAMTX_SIZEMODE_14X14 3
|
||||
#define DATAMTX_SIZEMODE_16X16 4
|
||||
#define DATAMTX_SIZEMODE_18X18 5
|
||||
#define DATAMTX_SIZEMODE_20X20 6
|
||||
#define DATAMTX_SIZEMODE_22X22 7
|
||||
#define DATAMTX_SIZEMODE_24X24 8
|
||||
#define DATAMTX_SIZEMODE_26X26 9
|
||||
#define DATAMTX_SIZEMODE_32X32 10
|
||||
#define DATAMTX_SIZEMODE_36X36 11
|
||||
#define DATAMTX_SIZEMODE_40X40 12
|
||||
#define DATAMTX_SIZEMODE_44X44 13
|
||||
#define DATAMTX_SIZEMODE_48X48 14
|
||||
#define DATAMTX_SIZEMODE_52X52 15
|
||||
#define DATAMTX_SIZEMODE_64X64 16
|
||||
#define DATAMTX_SIZEMODE_72X72 17
|
||||
#define DATAMTX_SIZEMODE_80X80 18
|
||||
#define DATAMTX_SIZEMODE_88X88 19
|
||||
#define DATAMTX_SIZEMODE_96X96 20
|
||||
#define DATAMTX_SIZEMODE_104X104 21
|
||||
#define DATAMTX_SIZEMODE_120X120 22
|
||||
#define DATAMTX_SIZEMODE_132X132 23
|
||||
#define DATAMTX_SIZEMODE_144X144 24
|
||||
#define DATAMTX_SIZEMODE_8X18 25
|
||||
#define DATAMTX_SIZEMODE_8X32 26
|
||||
#define DATAMTX_SIZEMODE_12X26 27
|
||||
#define DATAMTX_SIZEMODE_12X36 28
|
||||
#define DATAMTX_SIZEMODE_16X36 29
|
||||
#define DATAMTX_SIZEMODE_16X48 30
|
||||
|
||||
//加入条码到数据库中
|
||||
typedef int(*LMC1_ADDBARCODETOLIB)(TCHAR* pStr, //字符串
|
||||
TCHAR* pEntName,//字符串对象名称
|
||||
double dPosX, //字符左下角基点x坐标
|
||||
double dPosY, //字符左下角基点y坐标
|
||||
double dPosZ, //字符z坐标
|
||||
int nAlign,//对齐方式0-8
|
||||
int nPenNo,
|
||||
int bHatchText,
|
||||
int nBarcodeType,//条码类型
|
||||
WORD wBarCodeAttrib,//条码属性
|
||||
double dHeight,//整个条码的高
|
||||
double dNarrowWidth,//最窄模块宽
|
||||
double dBarWidthScale[4],//条宽比例 (与最窄模块宽相比)
|
||||
double dSpaceWidthScale[4],//空宽比例(与最窄模块宽相比)
|
||||
double dMidCharSpaceScale,//字符间隔比例(与最窄模块宽相比)
|
||||
double dQuietLeftScale,//条码左空白宽度比例(与最窄模块宽相比)
|
||||
double dQuietMidScale,//条码中空白宽度比例(与最窄模块宽相比)
|
||||
double dQuietRightScale,//条码右空白宽度比例(与最窄模块宽相比)
|
||||
double dQuietTopScale,//条码上空白宽度比例(与最窄模块宽相比)
|
||||
double dQuietBottomScale,//条码下空白宽度比例(与最窄模块宽相比)
|
||||
int nRow,//二维码行数
|
||||
int nCol,//二维码列数
|
||||
int nCheckLevel,//pdf417错误纠正级别0-8
|
||||
int nSizeMode,//DataMatrix尺寸模式0-30
|
||||
double dTextHeight,//人识别字符字体高度
|
||||
double dTextWidth,//人识别字符字体宽度
|
||||
double dTextOffsetX,//人识别字符X方向偏移
|
||||
double dTextOffsetY,//人识别字符Y方向偏移
|
||||
double dTextSpace,//人识别字符间距
|
||||
double dDiameter,
|
||||
TCHAR* pTextFontName);//文本字体名称
|
||||
|
||||
//获取条码参数
|
||||
typedef int(*LMC1_GETBARCODEPARAM)( TCHAR* pEntName,//对象名称
|
||||
WORD&wBarCodeAttrib,//条码属性
|
||||
int& nSizeMode,//尺寸模式
|
||||
int& nCheckLevel,//错误纠正级别
|
||||
int& nLangPage,//语言编码页
|
||||
double& dDiameter,
|
||||
int&nPointTimesN,//点倍数
|
||||
double& dBiDirOffset);//双向扫描补偿
|
||||
|
||||
//语言编码 int
|
||||
//Default 0
|
||||
//ANSI(7Bit 1252) 437
|
||||
//Latin - 1(ISO 8859 - 1) 850
|
||||
//Japanese(SHIFT - JIS, 932) 932
|
||||
//Korea(Hangul, 949) 949
|
||||
//Simple Chinses(GB2312, 936) 936
|
||||
//Trad chinese(BIG5, 950) 950
|
||||
//UNICODE(UTF8) 65001
|
||||
|
||||
//设置条码参数
|
||||
typedef int(*LMC1_SETBARCODEPARAM)(TCHAR* pEntName,//对象名称
|
||||
WORD wBarCodeAttrib,//条码属性
|
||||
int nSizeMode,// 尺寸模式
|
||||
int nCheckLevel,//错误纠正级别
|
||||
int nLangPage,//语言编码页
|
||||
double dDiameter,//圆模式直径(矩形模式单元模块高)
|
||||
int nPointTimesN,//点倍数
|
||||
double dBiDirOffset);//双向扫描补偿
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region IO
|
||||
|
||||
// 读lmc1的输入端口
|
||||
//输入参数: 读入的输入端口的数据
|
||||
typedef int(*LMC1_READPORT)(WORD& data);
|
||||
|
||||
// 读lmc1的输出端口
|
||||
//输入参数: 读入的输出端口的数据
|
||||
typedef int(*LMC1_GETOUTPORT)(WORD& data);
|
||||
|
||||
// 写lmc1的输出端口
|
||||
//输入参数: 要写到的输出端口的数据
|
||||
typedef int(*LMC1_WRITEPORT)(WORD data);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Hatch
|
||||
|
||||
|
||||
const int HATCHATTRIB_ALLCALC = 0x01;//全部对象整体计算
|
||||
const int HATCHATTRIB_EDGE = 0x02;//绕边走一次
|
||||
const int HATCHATTRIB_MINUP = 0x04;//最少起笔
|
||||
const int HATCHATTRIB_BIDIR = 0x08;//双向填充
|
||||
const int HATCHATTRIB_LOOP = 0x10;//环行填充
|
||||
const int HATCHATTRIB_OUT = 0x20;//环行由内向外
|
||||
const int HATCHATTRIB_AUTOROT = 0x40;//自动角度旋转
|
||||
const int HATCHATTRIB_AVERAGELINE = 0x80;//自动分布填充线
|
||||
const int HATCHATTRIB_CROSELINE = 0x400;//交叉填充
|
||||
|
||||
typedef int(*LMC1_GETHATCHPARAM3)(bool& bEnableContour,
|
||||
int nParamIndex,
|
||||
int& bEnableHatch,
|
||||
int& nPenNo,
|
||||
int& nHatchType,
|
||||
bool& bHatchAllCalc,
|
||||
bool& bHatchEdge,
|
||||
bool& bHatchAverageLine,
|
||||
double& dHatchAngle,
|
||||
double& dHatchLineDist,
|
||||
double& dHatchEdgeDist,
|
||||
double& dHatchStartOffset,
|
||||
double& dHatchEndOffset,
|
||||
double& dHatchLineReduction,//直线缩进
|
||||
double& dHatchLoopDist,//环间距
|
||||
int& nEdgeLoop,//环数
|
||||
bool& nHatchLoopRev,//环形反转
|
||||
bool& bHatchAutoRotate,//是否自动旋转角度
|
||||
double& dHatchRotateAngle,
|
||||
bool& nHatchCross);
|
||||
|
||||
|
||||
typedef int(*LMC1_SETHATCHPARAM3)(BOOL bEnableContour,//使能轮廓本身
|
||||
int nParamIndex,//填充参数序号值为1,2,3
|
||||
int bEnableHatch,//使能填充
|
||||
int nPenNo,//填充参数笔号
|
||||
int nHatchType,//填充类型 0单向 1双向 2回形 3弓形 4弓形不反向
|
||||
bool bHatchAllCalc,//是否全部对象作为整体一起计算
|
||||
bool bHatchEdge,//绕边一次
|
||||
bool bHatchAverageLine,//自动平均分布线
|
||||
double dHatchAngle,//填充线角度
|
||||
double dHatchLineDist,//填充线间距
|
||||
double dHatchEdgeDist,//填充线边距
|
||||
double dHatchStartOffset,//填充线起始偏移距离
|
||||
double dHatchEndOffset,//填充线结束偏移距离
|
||||
double dHatchLineReduction,//直线缩进
|
||||
double dHatchLoopDist,//环间距
|
||||
int nEdgeLoop,//环数
|
||||
bool nHatchLoopRev,//环形反转
|
||||
bool bHatchAutoRotate,//是否自动旋转角度
|
||||
double dHatchRotateAngle,//自动旋转角度
|
||||
bool bHatchCross);
|
||||
|
||||
typedef int(*LMC1_GETHATCHENTPARAM2)(TCHAR* HatchName,
|
||||
bool& bEnableContour,
|
||||
int nParamIndex,
|
||||
int& bEnableHatch,
|
||||
bool& bContourFirst,
|
||||
int& nPenNo,
|
||||
int& nHatchType,
|
||||
bool& bHatchAllCalc,
|
||||
bool& bHatchEdge,
|
||||
bool& bHatchAverageLine,
|
||||
double& dHatchAngle,
|
||||
double& dHatchLineDist,
|
||||
double& dHatchEdgeDist,
|
||||
double& dHatchStartOffset,
|
||||
double& dHatchEndOffset,
|
||||
double& dHatchLineReduction,//直线缩进
|
||||
double& dHatchLoopDist,//环间距
|
||||
int& nEdgeLoop,//环数
|
||||
bool& nHatchLoopRev,//环形反转
|
||||
bool& bHatchAutoRotate,//是否自动旋转角度
|
||||
double& dHatchRotateAngle,
|
||||
bool& bHatchCrossMode,
|
||||
int& dCycCount);
|
||||
|
||||
|
||||
typedef int(*LMC1_SETHATCHENTPARAM2)(TCHAR* HatchName,
|
||||
bool bEnableContour,
|
||||
int nParamIndex,
|
||||
int bEnableHatch,
|
||||
bool bContourFirst,
|
||||
int nPenNo,
|
||||
int nHatchType,
|
||||
bool bHatchAllCalc,
|
||||
bool bHatchEdge,
|
||||
bool bHatchAverageLine,
|
||||
double dHatchAngle,
|
||||
double dHatchLineDist,
|
||||
double dHatchEdgeDist,
|
||||
double dHatchStartOffset,
|
||||
double dHatchEndOffset,
|
||||
double dHatchLineReduction,//直线缩进
|
||||
double dHatchLoopDist,//环间距
|
||||
int nEdgeLoop,//环数
|
||||
bool nHatchLoopRev,//环形反转
|
||||
bool bHatchAutoRotate,//是否自动旋转角度
|
||||
double dHatchRotateAngle,
|
||||
bool bHatchCrossMode,
|
||||
int dCycCount);
|
||||
|
||||
typedef int(*LMC1_HATCHENT)(TCHAR* strEntName, TCHAR* strHatchEntName);
|
||||
typedef int(*LMC1_UNHATCHENT)(TCHAR* strHatchEntName);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Font
|
||||
|
||||
//获取当前默认的字体参数
|
||||
typedef int(*LMC1_GETFONTPARAM3)(TCHAR* strFontName, //字体名称
|
||||
double& dCharHeight, //字符高度
|
||||
double& dCharWidth, //字体宽度
|
||||
double& dCharAngle, //字体角度
|
||||
double& dCharSpace, //字体间距
|
||||
double& dLineSpace, //行间距
|
||||
BOOL& EqualCharWidth,//空字符宽度
|
||||
int& nTextAlign, //文本对齐方式
|
||||
BOOL& bBold, //粗体
|
||||
BOOL& bItalic); //斜体
|
||||
|
||||
//设置当前默认的字体参数
|
||||
typedef int(*LMC1_SETFONTPARAM3)(TCHAR* strFontName, //字体名称
|
||||
double dCharHeight, //字符高度
|
||||
double dCharWidth, //字体宽度
|
||||
double dCharAngle, //字体角度
|
||||
double dCharSpace, //字体间距
|
||||
double dLineSpace, //行间距
|
||||
BOOL EqualCharWidth,//空字符宽度
|
||||
int nTextAlign, //文本对齐方式
|
||||
BOOL bBold, //粗体
|
||||
BOOL bItalic );//斜体
|
||||
|
||||
|
||||
|
||||
//字体类型属性定义
|
||||
#define FONTATB_JSF 0x0001 //JczSingle字型
|
||||
#define FONTATB_TTF 0x0002 //TrueType字型
|
||||
#define FONTATB_DMF 0x0004 //DotMatrix字型
|
||||
#define FONTATB_BCF 0x0008 //BarCode字型
|
||||
|
||||
//字型记录
|
||||
struct lmc1_FontRecord
|
||||
{
|
||||
TCHAR szFontName[256]; //字体名字
|
||||
DWORD dwFontAttrib; //字体属性
|
||||
};
|
||||
|
||||
typedef int(*LMC1_GETFONTRECORDCOUNT)(int& nFontNum);
|
||||
|
||||
//得到当前系统支持的所有字体参数
|
||||
//输入参数: 无
|
||||
//输出参数: nFontNum 字体数目
|
||||
//返回参数: lmc1_FontRecord* 字体记录数组
|
||||
typedef lmc1_FontRecord* (*LMC1_GETALLFONTRECORD)(int Index, TCHAR*FontName, DWORD & FontAttrib);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Pen
|
||||
|
||||
//得到指定笔号对应的加工参数
|
||||
typedef int(*LMC1_GETPENPARAM)( int nPenNo,//要设置的笔号(0-255)
|
||||
int& nMarkLoop,//加工次数
|
||||
double& dMarkSpeed,//标刻次数mm/s
|
||||
double& dPowerRatio,//功率百分比(0-100%)
|
||||
double& dCurrent,//电流A
|
||||
int& nFreq,//频率HZ
|
||||
double& dQPulseWidth,//Q脉冲宽度us
|
||||
int& nStartTC,//开始延时us
|
||||
int& nLaserOffTC,//激光关闭延时us
|
||||
int& nEndTC,//结束延时us
|
||||
int& nPolyTC,//拐角延时us
|
||||
double& dJumpSpeed, //跳转速度mm/s
|
||||
int& nJumpPosTC, //跳转位置延时us
|
||||
int& nJumpDistTC,//跳转距离延时us
|
||||
double& dEndComp,//末点补偿mm
|
||||
double& dAccDist,//加速距离mm
|
||||
double& dPointTime,//打点延时 ms
|
||||
BOOL& bPulsePointMode,//脉冲点模式
|
||||
int& nPulseNum,//脉冲点数目
|
||||
double& dFlySpeed);
|
||||
|
||||
//得到对应笔号的参数
|
||||
typedef int(*LMC1_GETPENPARAM2)(int nPenNo,//要设置的笔号(0-255)
|
||||
int& nMarkLoop,//加工次数
|
||||
double& dMarkSpeed,//标刻次数mm/s
|
||||
double& dPowerRatio,//功率百分比(0-100%)
|
||||
double& dCurrent,//电流A
|
||||
int& nFreq,//频率HZ
|
||||
double& dQPulseWidth,//Q脉冲宽度us
|
||||
int& nStartTC,//开始延时us
|
||||
int& nLaserOffTC,//激光关闭延时us
|
||||
int& nEndTC,//结束延时us
|
||||
int& nPolyTC,//拐角延时us //
|
||||
double& dJumpSpeed, //跳转速度mm/s
|
||||
int& nJumpPosTC, //跳转位置延时us
|
||||
int& nJumpDistTC,//跳转距离延时us
|
||||
double& dPointTime,//打点延时 ms
|
||||
int& nSpiWave,//SPI波形
|
||||
BOOL& bWobbleMode,//抖动模式
|
||||
double& bWobbleDiameter,//抖动直径
|
||||
double& bWobbleDist);//抖动间距
|
||||
|
||||
//得到对应笔号的参数
|
||||
typedef int(*LMC1_GETPENPARAM4)(int nPenNo,//要设置的笔号(0-255)
|
||||
TCHAR sPenName[256],// 笔名字,默认default
|
||||
int& clr,//笔颜色
|
||||
BOOL& bDisableMark,//是否使能笔号,true关闭笔号不标刻
|
||||
BOOL& bUseDefParam,//是否使用默认值
|
||||
int& nMarkLoop,//加工次数
|
||||
double& dMarkSpeed,//标刻次数mm/s
|
||||
double& dPowerRatio,//功率百分比(0-100%)
|
||||
double& dCurrent,//电流A
|
||||
int& nFreq,//频率HZ
|
||||
double& dQPulseWidth,//Q脉冲宽度us
|
||||
int& nStartTC,//开始延时us
|
||||
int& nLaserOffTC,//激光关闭延时us
|
||||
int& nEndTC,//结束延时us
|
||||
int& nPolyTC,//拐角延时us //
|
||||
double& dJumpSpeed, //跳转速度mm/s
|
||||
int& nMinJumpDelayTCUs, //最小跳转延时us
|
||||
int& nMaxJumpDelayTCUs,//最大跳转延时us
|
||||
double& dJumpLengthLimit,//跳转长的极限
|
||||
double& dPointTime,//打点时间 ms
|
||||
BOOL& nSpiSpiContinueMode,//SPI连续模式
|
||||
int& nSpiWave,// SPI波形选择
|
||||
int& nYagMarkMode,// YAG优化填充模式
|
||||
BOOL& bPulsePointMode,//脉冲点模式
|
||||
int& nPulseNum,// 脉冲点数
|
||||
BOOL& bEnableACCMode,//使能加速模式
|
||||
double & dEndComp,//末点补偿
|
||||
double& dAccDist,//加速距离
|
||||
double& dBreakAngle,//中断角度,角度值
|
||||
BOOL& bWobbleMode,//抖动模式
|
||||
double & bWobbleDiameter,//抖动直径
|
||||
double& bWobbleDist);//抖动间距
|
||||
|
||||
|
||||
//设置指定笔号对应的加工参数
|
||||
typedef int(*LMC1_SETPENPARAM)(int nPenNo,//要设置的笔号(0-255)
|
||||
int nMarkLoop,//加工次数
|
||||
double dMarkSpeed,//标刻次数mm/s
|
||||
double dPowerRatio,//功率百分比(0-100%)
|
||||
double dCurrent,//电流A
|
||||
int nFreq,//频率HZ
|
||||
double dQPulseWidth,//Q脉冲宽度us
|
||||
int nStartTC,//开始延时us
|
||||
int nLaserOffTC,//激光关闭延时us
|
||||
int nEndTC,//结束延时us
|
||||
int nPolyTC,//拐角延时us //
|
||||
double dJumpSpeed, //跳转速度mm/s
|
||||
int nJumpPosTC, //跳转位置延时us
|
||||
int nJumpDistTC,//跳转距离延时us
|
||||
double dEndComp,//末点补偿mm
|
||||
double dAccDist,//加速距离mm
|
||||
double dPointTime,//打点延时 ms
|
||||
BOOL bPulsePointMode,//脉冲点模式
|
||||
int nPulseNum,//脉冲点数目
|
||||
double dFlySpeed);//飞行速度==0
|
||||
|
||||
|
||||
//设置指定笔号对应的加工参数
|
||||
typedef int(*LMC1_SETPENPARAM2)(int nPenNo,//要设置的笔号(0-255)
|
||||
int nMarkLoop,//加工次数
|
||||
double dMarkSpeed,//标刻次数mm/s
|
||||
double dPowerRatio,//功率百分比(0-100%)
|
||||
double dCurrent,//电流A
|
||||
int nFreq,//频率HZ
|
||||
double dQPulseWidth,//Q脉冲宽度us
|
||||
int nStartTC,//开始延时us
|
||||
int nLaserOffTC,//激光关闭延时us
|
||||
int nEndTC,//结束延时us
|
||||
int nPolyTC,//拐角延时us //
|
||||
double dJumpSpeed, //跳转速度mm/s
|
||||
int nJumpPosTC, //跳转位置延时us
|
||||
int nJumpDistTC,//跳转距离延时us
|
||||
double dPointTime,//打点延时 ms
|
||||
int nSpiWave,//SPI激光器波形设置
|
||||
BOOL bWobbleMode,//是否开启抖动功能
|
||||
double bWobbleDiameter,//抖动直径
|
||||
double bWobbleDist);//抖动间距
|
||||
|
||||
//设置对应笔号的参数
|
||||
typedef int(*LMC1_SETPENPARAM4)(int nPenNo,//要设置的笔号(0-255)
|
||||
TCHAR* sPenName,// 笔名字,默认default
|
||||
int clr,//笔颜色
|
||||
BOOL bDisableMark,//是否使能笔号,true关闭不标刻
|
||||
BOOL bUseDefParam,//是否使用默认值
|
||||
int nMarkLoop,//加工次数
|
||||
double dMarkSpeed,//标刻次数mm/s
|
||||
double dPowerRatio,//功率百分比(0-100%)
|
||||
double dCurrent,//电流A
|
||||
int nFreq,//频率HZ
|
||||
double dQPulseWidth,//Q脉冲宽度us
|
||||
int nStartTC,//开始延时us
|
||||
int nLaserOffTC,//激光关闭延时us
|
||||
int nEndTC,//结束延时us
|
||||
int nPolyTC,//拐角延时us //
|
||||
double dJumpSpeed, //跳转速度mm/s
|
||||
int& nMinJumpDelayTCUs, //最小跳转延时us
|
||||
int nMaxJumpDelayTCUs,//最大跳转延时us
|
||||
double dJumpLengthLimit,//跳转长的极限
|
||||
double dPointTime,//打点时间 ms
|
||||
BOOL nSpiSpiContinueMode,//SPI连续模式
|
||||
int nSpiWave,// SPI波形选择
|
||||
int nYagMarkMode,// YAG优化填充模式
|
||||
BOOL bPulsePointMode,//脉冲点模式
|
||||
int& nPulseNum,// 脉冲点数
|
||||
BOOL bEnableACCMode,//使能加速模式
|
||||
double dEndComp,//末点补偿
|
||||
double dAccDist,//加速距离
|
||||
double dBreakAngle,//中断角度
|
||||
BOOL bWobbleMode,//抖动模式
|
||||
double bWobbleDiameter,//抖动直径
|
||||
double bWobbleDist);//抖动间距
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Axis
|
||||
|
||||
//复位扩展轴坐标
|
||||
//输入参数: bEnAxis0 = 使能轴0 bEnAxis1 = 使能轴1
|
||||
//在程序中调用扩展轴相关的函数,必须先调用lmc1_Reset来设置使能对应的轴;当扩展轴运动到极限位置时,可以用此函数复位扩展轴坐标。
|
||||
typedef double(*LMC1_RESET)(BOOL bEnAxis0, BOOL bEnAxis1);
|
||||
|
||||
//扩展轴移动到指定坐标位置
|
||||
//输入参数: axis 扩展轴 0 = 轴0 1 = 轴1
|
||||
// GoalPos 坐标位置
|
||||
//在程序中调用lmc1_AxisMoveTo可以使扩展轴移动到指定坐标位置,扩展轴的运动速度使用设备参数里定义的最大速度。
|
||||
typedef int(*LMC1_AXISMOVETO)(int axis, double GoalPos);
|
||||
|
||||
//扩展轴校正原点
|
||||
//输入参数: axis 扩展轴 0 = 轴0 1 = 轴1
|
||||
//在程序中调用lmc1_AxisCorrectOrigin可以使扩展轴自动校正原点。
|
||||
typedef int(*LMC1_AXISCORRECTORIGIN)(int axis);
|
||||
|
||||
//得到扩展轴的当前坐标
|
||||
//输入参数: axis扩展轴 0 = 轴0 1 = 轴1
|
||||
typedef double(*LMC1_GETAXISCOOR)(int axis);
|
||||
|
||||
//扩展轴移动到指定脉冲坐标位置
|
||||
//输入参数: axis 扩展轴 0 = 轴0 1 = 轴1
|
||||
// nGoalPos 脉冲坐标位置
|
||||
typedef int(*LMC1_AXISMOVETOPULSE)(int axis, int nGoalPos);
|
||||
|
||||
//得到扩展轴的当前脉冲坐标
|
||||
//输入参数: axis扩展轴 0 = 轴0 1 = 轴1
|
||||
typedef int(*LMC1_GETAXISCOORPULSE)(int axis);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user