modify recv wave
This commit is contained in:
parent
5d05252454
commit
fc73714812
@ -273,76 +273,127 @@ std::string JsonData::JsonCmd_Cgi_55(Param_55 ¶m) {
|
||||
double resolution = 0.0;
|
||||
SampleRate = atoi(res[23].c_str());
|
||||
zlog_info(zct,"sensor type %s", res[17].c_str());
|
||||
|
||||
std::string softVersion = res[9];
|
||||
char localtimestamp[32] = {0};
|
||||
std::string strWaveData = "";
|
||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!inFile) {
|
||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "error";
|
||||
if (compareVersions(softVersion, "2.6") == -1) {
|
||||
std::string filename = "/opt/data/" + param.mChannelId + "-VOL.dat";
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!inFile) {
|
||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "error";
|
||||
} else {
|
||||
float fTemp = 0.0f;
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
|
||||
int flag = param.mPackageFlag;
|
||||
flag = (flag + 1) * 1024;
|
||||
int number = vecWave.size();
|
||||
int start = param.mPackageFlag * 1024;
|
||||
if (number < 1024) {
|
||||
flag = number;
|
||||
start = 0;
|
||||
}
|
||||
char buf[32];
|
||||
for (int i = start; i < flag; i++) {
|
||||
if (i == start) {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", vecWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = waveTemp;
|
||||
|
||||
} else {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", vecWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
}
|
||||
int max = number / 1024;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
}
|
||||
|
||||
} else {
|
||||
float fTemp = 0;
|
||||
std::vector<float> hanningWave;
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
if (res[17] == "01") {
|
||||
zlog_info(zct,"sample_rate=%d", SampleRate);
|
||||
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
|
||||
|
||||
} else if (res[17] == "02") {
|
||||
std::string::size_type comper = param.mChannelId.find("Z");
|
||||
if (comper != std::string::npos) {
|
||||
resolution = (double)SampleRate / vecWave.size();
|
||||
zlog_info(zct,"sample_rate=%d,resolution = %f", SampleRate, resolution);
|
||||
} else {
|
||||
SampleRate = 8000;
|
||||
zlog_info(zct,"sample_rate=%d", SampleRate);
|
||||
resolution = (((double)SampleRate / 1024) * 1024) / 8192;
|
||||
}
|
||||
}
|
||||
|
||||
//积分
|
||||
Calculation::Integration(vecWave, IntegrationWave, resolution);
|
||||
|
||||
int flag = param.mPackageFlag;
|
||||
flag = (flag + 1) * 1024;
|
||||
int number = IntegrationWave.size();
|
||||
int start = param.mPackageFlag * 1024;
|
||||
if (number < 1024) {
|
||||
flag = number;
|
||||
start = 0;
|
||||
}
|
||||
char buf[32];
|
||||
for (int i = start; i < flag; i++) {
|
||||
if (i == start) {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", IntegrationWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = waveTemp;
|
||||
|
||||
} else {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", IntegrationWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
}
|
||||
|
||||
int max = number / 1024;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
}else{
|
||||
std::string filename = "/opt/data/" + param.mChannelId + ".dat";
|
||||
if (access(filename.c_str(), 0) >= 0) {
|
||||
std::ifstream inFile(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!inFile) {
|
||||
zlog_error(zct, "read channel data error, filename:%s", filename.c_str());
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "error";
|
||||
} else {
|
||||
float fTemp = 0;
|
||||
std::vector<float> hanningWave;
|
||||
inFile.read((char *)localtimestamp, sizeof(localtimestamp));
|
||||
while (inFile.read((char *)&fTemp, sizeof(fTemp))) {
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
if (res[17] == "01") {
|
||||
zlog_info(zct,"sample_rate=%d", SampleRate);
|
||||
resolution = (((double)SampleRate / 1000) * 1016) / vecWave.size();
|
||||
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
} else if (res[17] == "02") {
|
||||
std::string::size_type comper = param.mChannelId.find("Z");
|
||||
if (comper != std::string::npos) {
|
||||
resolution = (double)SampleRate / vecWave.size();
|
||||
zlog_info(zct,"sample_rate=%d,resolution = %f", SampleRate, resolution);
|
||||
} else {
|
||||
SampleRate = 8000;
|
||||
zlog_info(zct,"sample_rate=%d", SampleRate);
|
||||
resolution = (((double)SampleRate / 1024) * 1024) / 8192;
|
||||
}
|
||||
}
|
||||
|
||||
//积分
|
||||
Calculation::Integration(vecWave, IntegrationWave, resolution);
|
||||
|
||||
int flag = param.mPackageFlag;
|
||||
flag = (flag + 1) * 1024;
|
||||
int number = IntegrationWave.size();
|
||||
int start = param.mPackageFlag * 1024;
|
||||
if (number < 1024) {
|
||||
flag = number;
|
||||
start = 0;
|
||||
}
|
||||
char buf[32];
|
||||
for (int i = start; i < flag; i++) {
|
||||
if (i == start) {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", IntegrationWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = waveTemp;
|
||||
|
||||
} else {
|
||||
memset(buf, 0, 32);
|
||||
sprintf(buf, "%.2f", IntegrationWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
}
|
||||
|
||||
int max = number / 1024;
|
||||
if (max == 0 && number > 0) {
|
||||
max = 1;
|
||||
}
|
||||
jsBody["packageMax"] = max;
|
||||
}
|
||||
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "没有数据文件";
|
||||
}
|
||||
}
|
||||
|
||||
jsBody["channelId"] = param.mChannelId;
|
||||
|
||||
@ -51,12 +51,12 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
|
||||
DealReviveDuration(wave_shortAddr);
|
||||
zlog_warn(zct, "===============0x9999 timeout= %d offSize = %d===============shortAddr = %02x%02x", timeoutflag, offSize,UINT16_HIGH(wave_shortAddr),UINT16_LOW(wave_shortAddr));
|
||||
zlog_warn(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize);
|
||||
// printf("=============offSize = %d\n",offSize);
|
||||
// for (size_t i = 0; i < offSize; i++)
|
||||
// {
|
||||
// printf("%02x ",mUartRecvTmpBuf[i]);
|
||||
// }
|
||||
// printf("=============\n");
|
||||
printf("=============offSize = %d\n",offSize);
|
||||
for (size_t i = 0; i < 300; i++)
|
||||
{
|
||||
printf("%02x ",mUartRecvTmpBuf[i]);
|
||||
}
|
||||
printf("=============\n");
|
||||
FindRecvPackage(offSize, mUartRecvTmpBuf, head);
|
||||
now_task = -1;
|
||||
timeoutflag = 0;
|
||||
@ -470,9 +470,18 @@ int Uart::DealConfig(uint16_t ushortAdd){
|
||||
scheduler::instance().UpdateConfigResult(ushortAdd,0);
|
||||
return 0;
|
||||
}
|
||||
// 判断综合信号强度,低电量,停机状态,任一条件满足都不调度波形
|
||||
int Uart::WaveSendCondition(){
|
||||
int lowSignal = -1, signalThreshold = -1, lowBatteryLevel = -1, batteryLevelThreshold = -1;
|
||||
lowSignal = readIntValue("config", "lowSignal", (char *)GlobalConfig::Config_G.c_str());
|
||||
signalThreshold = readIntValue("config", "signalThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
lowBatteryLevel = readIntValue("config", "lowBatteryLevel", (char *)GlobalConfig::Config_G.c_str());
|
||||
batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str());
|
||||
}
|
||||
int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
|
||||
zlog_info(zct, "DealWaveCompress ");
|
||||
int ret = WaveSendCondition();
|
||||
now_task = WAVE_CMD;
|
||||
WaveResp(ushortAdd);
|
||||
char buf[20] = {0x00},whereCon[100] = {0};
|
||||
@ -482,7 +491,7 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
sprintf(whereCon,"zigbeeShortAddr = '%s' ",buf);
|
||||
std::string softVersion = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "softVersion", whereCon);
|
||||
compressWaveChannel tempchannel;
|
||||
if (compareVersions(softVersion, "2.6")){
|
||||
if (compareVersions(softVersion, "2.6") == -1){
|
||||
tempchannel.compressChannelX = pData[7];
|
||||
tempchannel.compressChannelY = pData[8];
|
||||
tempchannel.compressChannelZ = pData[9];
|
||||
@ -518,7 +527,6 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
g_mapCompress[strShortAddr] = tempchannel;
|
||||
wave_shortAddr = ushortAdd;
|
||||
|
||||
|
||||
if (!strcmp(sensor_rssi, "00") || !strcmp(sensor_rssi, "0")) {
|
||||
char errorInfo[100] = {0x00};
|
||||
sprintf(errorInfo, "No RSSI %s", sensor_rssi);
|
||||
@ -548,8 +556,11 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
}
|
||||
zlog_info(zct, "count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ);
|
||||
zlog_info(zct, "count X = %d,Y = %d,Z = %d,vol X = %d,vol Y = %d,vol X = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ,tempchannel.CountVolX,tempchannel.CountVolY,tempchannel.CountVolZ);
|
||||
zlog_info(zct, "compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ);
|
||||
zlog_info(zct, "compress vol X = %d,vol Y = %d,vol Z = %d ", tempchannel.compressChannelVolX, tempchannel.compressChannelVolY, tempchannel.compressChannelVolZ);
|
||||
zlog_info(zct, "samplerate X = %d,Y = %d,Z = %d ", tempchannel.samplerateX, tempchannel.samplerateY, tempchannel.samplerateZ);
|
||||
zlog_info(zct, "samplerate vol X = %d,vol Y = %d,vol Z = %d ", tempchannel.samplerateVolX, tempchannel.samplerateVolY, tempchannel.samplerateVolZ);
|
||||
return 0;
|
||||
}
|
||||
int Uart::DealSensorRSSI(const char *pData,uint16_t ushortAdd){
|
||||
@ -1402,6 +1413,11 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
}
|
||||
memcpy(RecvBuf, (char *)&UartRecvBuf[i], 100);
|
||||
DealDataNodeWave(RecvBuf, command);
|
||||
if (i < 200)
|
||||
{
|
||||
printf("%02x ",UartRecvBuf[i]);
|
||||
}
|
||||
|
||||
mPackgeIndex = (unsigned int)UartRecvBuf[i + 6];
|
||||
} else if (now_task != WAVE_CMD && ( command == ASK_TASK || command == DEVICE_INF || command == MEAS_EVAL || command == CONFIG || command == UPGRADE || command == DEVICE_INF2 || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION || command == UPGRADE_ASK)) {
|
||||
char RecvBuf[100] = {0x00};
|
||||
@ -1439,11 +1455,22 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
|
||||
DealRecvData(RecvBuf);
|
||||
|
||||
}else if( command == WAVE_COMPRESS && now_task != WAVE_CMD) {
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 24);
|
||||
if (!CheckCrc(RecvBuf, 23)) {
|
||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||
break;
|
||||
if (bytesRead > 30)
|
||||
{
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 100);
|
||||
if (!CheckCrc(RecvBuf, 99)) {
|
||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
memcpy(RecvBuf, &UartRecvBuf[i], 24);
|
||||
if (!CheckCrc(RecvBuf, 23)) {
|
||||
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// char tmp[23] = {0x00};
|
||||
// char tmp2[23] = {0x00};
|
||||
// for (int j = 0; j < 23; j++) {
|
||||
|
||||
@ -188,6 +188,7 @@ public:
|
||||
int DealSensorRSSI(const char *pData,uint16_t ushortAdd);
|
||||
int DealUpgrade(uint16_t ushortAdd,int status);
|
||||
void GetLocalZigbeeRSSI(uint16_t ushortAdd);
|
||||
int WaveSendCondition();
|
||||
|
||||
// feature parse
|
||||
int DealDataNodeFeature(const char* pData, int flag);
|
||||
@ -195,9 +196,9 @@ public:
|
||||
void DealDataNodeWave(const char* pData, int comand);
|
||||
void DealWaveThread();
|
||||
void DealWave();
|
||||
std::vector<float> DealData(int ichannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct);
|
||||
std::vector<float> DealData(int ichannel, float coe, unsigned int sampleRate, float ACCSampleTime, std::string strProduct,int version);
|
||||
float Calcoe(int ran, int iChannel, std::string& product, int range);
|
||||
void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData,std::string &product,int ACCSampleTime);
|
||||
void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData,std::string &product,float ACCSampleTime,int version);
|
||||
float ScaleConvert(int highbit);
|
||||
void DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n);
|
||||
|
||||
|
||||
@ -756,7 +756,7 @@ void Uart::DealWaveThread() {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct) {
|
||||
std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRate, float ACCSampleTime, std::string strProduct,int version) {
|
||||
|
||||
memset(data,0,sizeof(data));
|
||||
memset(dealdata,0,sizeof(dealdata));
|
||||
@ -776,10 +776,12 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
waveCount = VecWaveDataX.size();
|
||||
}
|
||||
waveCount = m_waveCountX;
|
||||
unsigned char tempdata[100] = {0},tempdata2[100] = {0};
|
||||
for (; j < waveCount; j++) {
|
||||
RecvData recvData = g_VecWaveDataX[j];
|
||||
memcpy(data + j * 92, recvData.Data, 92);
|
||||
}
|
||||
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
sprintf(buf, "%02x%02x", g_VecWaveDataX[0].ShortAddr[0], g_VecWaveDataX[0].ShortAddr[1]);
|
||||
strShortAddr = std::string(buf);
|
||||
@ -885,10 +887,20 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
memcpy(dealdata, data, j * 92);
|
||||
deallen = j * 92;
|
||||
}
|
||||
if(iChannel == WAVE_X){
|
||||
for (size_t i = 0; i < 200; i++) {
|
||||
float fTemp = 0.0f;
|
||||
memset(buf, 0, 8);
|
||||
sprintf(buf, "%02x%02x", dealdata[2 * i + 1], dealdata[i * 2]);
|
||||
printf("%s ", buf);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
for (size_t i = 0; i < deallen; i++) {
|
||||
float fTemp = 0.0f;
|
||||
memset(buf, 0, 8);
|
||||
sprintf(buf, "%02x%02x", dealdata[2 * i + 1], dealdata[i * 2]);
|
||||
|
||||
iTemp = strtol(buf, NULL, 16);
|
||||
if (iTemp < 0x8000) {
|
||||
fTemp = iTemp * coe * 9.8f; // convert to m/s2
|
||||
@ -896,7 +908,7 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
fTemp = (((~iTemp) & 0xffff) + 1) * -coe * 9.8f; // convert to m/s2
|
||||
}
|
||||
vecData.push_back(fTemp);
|
||||
if (strProduct == "01") {
|
||||
if (strProduct == "01" && version == 1) {
|
||||
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_X) { //过滤数据包结尾空数据
|
||||
zlog_info(zct, "%d vecData.size() == %d,sampleRate * ACCSampleTime = %d", iChannel, vecData.size(), sampleRate * ACCSampleTime);
|
||||
break;
|
||||
@ -910,7 +922,7 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (strProduct == "02") {
|
||||
} else if (strProduct == "02" && version == 1) {
|
||||
if (vecData.size() == 8192 && iChannel == WAVE_X) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
@ -920,6 +932,25 @@ std::vector<float> Uart::DealData(int iChannel, float coe, unsigned int sampleRa
|
||||
if (vecData.size() == sampleRate * ACCSampleTime && iChannel == WAVE_Z) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
}else if( version == 0){
|
||||
if (vecData.size() == 8192 && iChannel == WAVE_X) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 8192 && iChannel == WAVE_Y) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 24000 && iChannel == WAVE_Z) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 4096 && iChannel == WAVE_VOL_X) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 4096 && iChannel == WAVE_VOL_Y) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
if (vecData.size() == 4096 && iChannel == WAVE_VOL_Z) { //过滤数据包结尾空数据
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return vecData;
|
||||
@ -933,7 +964,9 @@ void Uart::DealWave() {
|
||||
std::string strMeasurementID = "";
|
||||
std::string strFileName = "";
|
||||
std::string strProduct = "";
|
||||
std::vector<float> vecDataX, vecDataY, vecDataZ;
|
||||
std::string softVersion = "";
|
||||
int version = 0;
|
||||
std::vector<float> vecDataX, vecDataY, vecDataZ,vecDataVolX, vecDataVolY, vecDataVolZ;
|
||||
bool z = false;
|
||||
if (wave_trans_) { //对每个传感器的每个通道进行遍历然后处理数据,例如:传感器1x轴的数据处理完后,再去处理y轴的。传感器1的所有数据处理完后,再处理传感器2的
|
||||
|
||||
@ -963,6 +996,8 @@ void Uart::DealWave() {
|
||||
int range = 0;
|
||||
float coe = 0;
|
||||
int sampleRate = 0, ACCSampleTime = 0;
|
||||
float accSampleTimeXY = 1.6 , accSampleTimeZ = 1.28;
|
||||
float volSampleTime = 3.2 ;
|
||||
char getrange[32] = {0};
|
||||
std::string str = "range";
|
||||
sprintf(getrange, "zigbeeShortAddr='%s'", strShortAddr.c_str());
|
||||
@ -970,14 +1005,26 @@ void Uart::DealWave() {
|
||||
sampleRate = atoi(res[23].c_str());
|
||||
ACCSampleTime = atoi(res[36].c_str());
|
||||
strProduct = res[17];
|
||||
softVersion = res[9];
|
||||
memset(getrange, 0, 32);
|
||||
sprintf(getrange, "%s", ran.c_str());
|
||||
n = (int)strtol(getrange, NULL, 32);
|
||||
if (compareVersions(softVersion, "2.6") == -1 && strProduct == "02") {
|
||||
accSampleTimeXY = (float)8192;
|
||||
accSampleTimeZ = (float)ACCSampleTime;
|
||||
version = 1;
|
||||
}
|
||||
if (compareVersions(softVersion, "2.6") == -1 && strProduct == "01") {
|
||||
accSampleTimeXY = (float)ACCSampleTime;
|
||||
accSampleTimeZ = (float)ACCSampleTime;
|
||||
version = 1;
|
||||
}
|
||||
if (m_waveCountX > 0 || VecWaveDataX.size() > 0) {
|
||||
zlog_info(zct, "m_waveCountX = %d,VecWaveData = %d", m_waveCountX, VecWaveDataX.size());
|
||||
coe = Calcoe(n, WAVE_X, strProduct, range);
|
||||
vecDataX = DealData(WAVE_X, coe, sampleRate, ACCSampleTime, strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_X, vecDataX,strProduct,ACCSampleTime);
|
||||
|
||||
vecDataX = DealData(WAVE_X, coe, sampleRate, accSampleTimeXY, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_X, vecDataX,strProduct,accSampleTimeXY,version);
|
||||
m_waveCountX = 0;
|
||||
g_VecWaveDataX.clear();
|
||||
VecWaveDataX.clear();
|
||||
@ -985,21 +1032,52 @@ void Uart::DealWave() {
|
||||
if (m_waveCountY > 0 || VecWaveDataY.size() > 0) {
|
||||
zlog_info(zct, "m_waveCountY = %d,VecWaveData = %d", m_waveCountY, VecWaveDataY.size());
|
||||
coe = Calcoe(n, WAVE_Y, strProduct, range);
|
||||
vecDataY = DealData(WAVE_Y, coe, sampleRate, ACCSampleTime, strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecDataY,strProduct,ACCSampleTime);
|
||||
vecDataY = DealData(WAVE_Y, coe, sampleRate, accSampleTimeXY, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecDataY,strProduct,accSampleTimeXY,version);
|
||||
m_waveCountY = 0;
|
||||
g_VecWaveDataY.clear();
|
||||
VecWaveDataY.clear();
|
||||
}
|
||||
if (m_waveCountZ > 0 || VecWaveDataZ.size() > 0) {
|
||||
//zlog_info(zct, "accSampleTimeXY = %f, accSampleTimeZ = %f,version = %d.softversion = %s", accSampleTimeXY, accSampleTimeZ,version,softVersion.c_str());
|
||||
zlog_info(zct, "m_waveCountZ = %d,VecWaveDataZ = %d", m_waveCountZ, VecWaveDataZ.size());
|
||||
coe = Calcoe(n, WAVE_Z, strProduct, range);
|
||||
vecDataZ = DealData(WAVE_Z, coe, sampleRate, ACCSampleTime, strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecDataZ,strProduct,ACCSampleTime);
|
||||
vecDataZ = DealData(WAVE_Z, coe, sampleRate, accSampleTimeZ, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecDataZ,strProduct,accSampleTimeZ,version);
|
||||
m_waveCountZ = 0;
|
||||
g_VecWaveDataZ.clear();
|
||||
VecWaveDataZ.clear();
|
||||
}
|
||||
zlog_info(zct,"m_waveCountVolX = %d,VecWaveDataVolX = %d", m_waveCountVolX, VecWaveDataVolX.size());
|
||||
if (m_waveCountVolX > 0 || VecWaveDataVolX.size() > 0) {
|
||||
zlog_info(zct, "m_waveCountVolX = %d,VecWaveDataVolX = %d", m_waveCountVolX, VecWaveDataVolX.size());
|
||||
coe = Calcoe(n, WAVE_VOL_X, strProduct, range);
|
||||
vecDataVolX = DealData(WAVE_VOL_X, coe, g_mapCompress[strShortAddr].samplerateVolX, volSampleTime, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_VOL_X, vecDataVolX,strProduct,volSampleTime,version);
|
||||
m_waveCountVolX = 0;
|
||||
g_VecWaveDataVolX.clear();
|
||||
VecWaveDataVolX.clear();
|
||||
}
|
||||
zlog_info(zct,"m_waveCountVolY = %d,VecWaveDataVolY = %d", m_waveCountVolY, VecWaveDataVolY.size());
|
||||
if (m_waveCountVolY > 0 || VecWaveDataVolY.size() > 0) {
|
||||
zlog_info(zct, "m_waveCountVolY = %d,VecWaveDataVolY = %d", m_waveCountVolY, VecWaveDataVolY.size());
|
||||
coe = Calcoe(n, WAVE_VOL_Y, strProduct, range);
|
||||
vecDataVolY = DealData(WAVE_VOL_Y, coe, g_mapCompress[strShortAddr].samplerateVolY, volSampleTime, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_VOL_Y, vecDataVolY,strProduct,volSampleTime,version);
|
||||
m_waveCountVolY = 0;
|
||||
g_VecWaveDataVolY.clear();
|
||||
VecWaveDataVolY.clear();
|
||||
}
|
||||
zlog_info(zct,"m_waveCountVolZ = %d,VecWaveDataVolZ = %d", m_waveCountVolZ, VecWaveDataVolZ.size());
|
||||
if (m_waveCountVolZ > 0 || VecWaveDataVolZ.size() > 0) {
|
||||
zlog_info(zct, "m_waveCountVolZ = %d,VecWaveDataVolZ = %d", m_waveCountVolZ, VecWaveDataVolZ.size());
|
||||
coe = Calcoe(n, WAVE_VOL_Z, strProduct, range);
|
||||
vecDataVolZ = DealData(WAVE_VOL_Z, coe, g_mapCompress[strShortAddr].samplerateVolZ, volSampleTime, strProduct,version);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_VOL_Z, vecDataVolZ,strProduct,volSampleTime,version);
|
||||
m_waveCountVolZ = 0;
|
||||
g_VecWaveDataVolZ.clear();
|
||||
VecWaveDataVolZ.clear();
|
||||
}
|
||||
char insertSql[100] = {0x00};
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "MeasurementID='%s'",strMeasurementID.c_str());
|
||||
@ -1062,9 +1140,18 @@ void Uart::DealWave() {
|
||||
g_mapCompress[strShortAddr].compressChannelX = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelY = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelZ = 0;
|
||||
g_mapCompress[strShortAddr].CountVolX = 0;
|
||||
g_mapCompress[strShortAddr].CountVolY = 0;
|
||||
g_mapCompress[strShortAddr].CountVolZ = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelVolX = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelVolY = 0;
|
||||
g_mapCompress[strShortAddr].compressChannelVolZ = 0;
|
||||
std::vector<float>().swap(vecDataX);
|
||||
std::vector<float>().swap(vecDataY);
|
||||
std::vector<float>().swap(vecDataZ);
|
||||
std::vector<float>().swap(vecDataVolX);
|
||||
std::vector<float>().swap(vecDataVolY);
|
||||
std::vector<float>().swap(vecDataVolZ);
|
||||
wave_trans_ = false;
|
||||
}
|
||||
}
|
||||
@ -1074,17 +1161,17 @@ float Uart::Calcoe(int ran, int iChannel, std::string &product, int range) {
|
||||
if (product == "01") {
|
||||
coe = pow(2, ran) * 8.0f / 32767;
|
||||
} else if (product == "02") {
|
||||
if (iChannel == WAVE_X || iChannel == WAVE_Y) {
|
||||
if (iChannel == WAVE_X || iChannel == WAVE_Y || iChannel == WAVE_VOL_X || iChannel == WAVE_VOL_Y) {
|
||||
coe = 0.00048828125f;
|
||||
}
|
||||
if (iChannel == WAVE_Z) {
|
||||
if (iChannel == WAVE_Z || iChannel == WAVE_VOL_Z) {
|
||||
coe = 0.00172607421875f;
|
||||
}
|
||||
}
|
||||
return coe;
|
||||
}
|
||||
|
||||
void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChannel, std::vector<float> &vecData,std::string &product,int ACCSampleTime) {
|
||||
void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChannel, std::vector<float> &vecData,std::string &product,float ACCSampleTime,int version) {
|
||||
if (vecData.size() <= 0) return;
|
||||
std::string strFileName = "";
|
||||
char localtimestamp[32] = {0};
|
||||
@ -1096,6 +1183,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
char buf[33] = {0x00};
|
||||
std::string strWaveData = "";
|
||||
WaveChannel wave_channel;
|
||||
WaveVolChannel wave_vol_channel;
|
||||
|
||||
memset(mqttData,0,sizeof(mqttData));
|
||||
switch (iChannel) {
|
||||
@ -1113,6 +1201,21 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-Z.dat";
|
||||
strChannelID = strMeasurementID + "-Z";
|
||||
|
||||
} break;
|
||||
case WAVE_VOL_X: {
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-X-VOL.dat";
|
||||
strChannelID = strMeasurementID + "-X-VOL";
|
||||
|
||||
} break;
|
||||
case WAVE_VOL_Y: {
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-Y-VOL.dat";
|
||||
strChannelID = strMeasurementID + "-Y-VOL";
|
||||
|
||||
} break;
|
||||
case WAVE_VOL_Z: {
|
||||
strFileName = "/opt/data/" + strMeasurementID + "-Z-VOL.dat";
|
||||
strChannelID = strMeasurementID + "-Z-VOL";
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
@ -1131,6 +1234,12 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
wave_channel.WaveChannelY[i] = frTemp;
|
||||
}else if (iChannel == WAVE_Z){
|
||||
wave_channel.WaveChannelZ[i] = frTemp;
|
||||
}else if (iChannel == WAVE_VOL_X){
|
||||
wave_vol_channel.WaveChannelVolX[i] = frTemp;
|
||||
}else if (iChannel == WAVE_VOL_Y){
|
||||
wave_vol_channel.WaveChannelVolY[i] = frTemp;
|
||||
}else if (iChannel == WAVE_VOL_Z){
|
||||
wave_vol_channel.WaveChannelVolZ[i] = frTemp;
|
||||
}
|
||||
if (i != vecData.size() -1){
|
||||
strncpy(mqttData + id ,buf,strlen(buf));
|
||||
@ -1142,14 +1251,17 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
if (product == "02" && sampleRate == 24000 && iChannel == WAVE_Z){
|
||||
if ((product == "02" && sampleRate == 24000 && iChannel == WAVE_Z && version == 0) ||
|
||||
(iChannel == WAVE_Z && version == 1) ||
|
||||
((iChannel == WAVE_VOL_X || iChannel == WAVE_VOL_Y || iChannel == WAVE_VOL_Z) && version == 1)){
|
||||
sampleRate = 25600;
|
||||
zlog_info(zct, " sampleRate = %d,product = %s ", sampleRate,product.c_str());
|
||||
zlog_info(zct, " sampleRate = %d,product = %s,ACCSampleTime = %f ", sampleRate,product.c_str(),ACCSampleTime);
|
||||
size_t outSize = 25600;
|
||||
std::vector<float> outputData,outputData2;
|
||||
if (ACCSampleTime == 1){
|
||||
float epsilon = 1e-6f;
|
||||
if (std::fabs(ACCSampleTime - 1) < epsilon){
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
}else if(ACCSampleTime == 2){
|
||||
}else if(std::fabs(ACCSampleTime - 2) < epsilon){
|
||||
std::vector<float> first_wave = std::vector<float>(vecData.begin(), vecData.begin() + vecData.size()/2);
|
||||
std::vector<float> second_wave = std::vector<float>(vecData.begin() + vecData.size()/2, vecData.end());
|
||||
outputData = Calculation::fftInterpolate(first_wave, outSize);
|
||||
@ -1158,6 +1270,11 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
{
|
||||
outputData.push_back(outputData2[i]);
|
||||
}
|
||||
}else if(std::fabs(ACCSampleTime - 1.28) < epsilon){
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
}else if(std::fabs(ACCSampleTime - 3.2) < epsilon){
|
||||
outSize = 2560;
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
}
|
||||
zlog_info(zct, " outputData_size %d ", outputData.size());
|
||||
float mean = Calculation::mean(outputData);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user