dev(UML-981): Отлажен обмен битами
This commit is contained in:
parent
fe46a8b03f
commit
847102ee66
@ -368,24 +368,55 @@ int main(int argc, char * argv[])
|
||||
{
|
||||
case BIT_SUBMOD_ID:
|
||||
{
|
||||
uint8_t bits = 0;
|
||||
static uint8_t value_bits[8];
|
||||
|
||||
uint8_t bits[8];
|
||||
//std::cout << "Bits: " << jx.dump() << std::endl;
|
||||
|
||||
/*in = jx["data"]["bytes"].get<std::vector<uint8_t>>();
|
||||
if (in.size() == 1)
|
||||
bits[0] = jx.at("data").at("I808OutBits").at("out_bit_0").get<uint8_t>();
|
||||
bits[1] = jx.at("data").at("I808OutBits").at("out_bit_1").get<uint8_t>();
|
||||
bits[2] = jx.at("data").at("I808OutBits").at("out_bit_2").get<uint8_t>();
|
||||
bits[3] = jx.at("data").at("I808OutBits").at("out_bit_3").get<uint8_t>();
|
||||
bits[4] = jx.at("data").at("I808OutBits").at("out_bit_4").get<uint8_t>();
|
||||
bits[5] = jx.at("data").at("I808OutBits").at("out_bit_5").get<uint8_t>();
|
||||
bits[6] = jx.at("data").at("I808OutBits").at("out_bit_6").get<uint8_t>();
|
||||
bits[7] = jx.at("data").at("I808OutBits").at("out_bit_7").get<uint8_t>();
|
||||
|
||||
bool newdata = false;
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
std::copy(in.begin(), in.end(), &bits);
|
||||
if (bits[i]!= value_bits[i])
|
||||
{
|
||||
newdata = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (bits != value_bit)
|
||||
if (newdata)
|
||||
{
|
||||
value_bit = bits;
|
||||
std::cout << "New bit data from PLC: " << std::endl;
|
||||
std::cout << "I808OutBits:" << std::endl;
|
||||
|
||||
std::cout << "New bit data from PLC: " << value_bit << std::endl;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
value_bits[i] = bits[i];
|
||||
std::cout << "out_bit_" << i << ":" << std::to_string(bits[i]) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
bits = ~bits;
|
||||
putCyclicData(j_set_echo_data, module_id, submodule_id, &bits, 1);*/
|
||||
json j_set_data;
|
||||
j_set_data["module_id"] = module_id;
|
||||
j_set_data["submodule_id"] = submodule_id;
|
||||
|
||||
auto& data = j_set_data["data"]["I808InpBits"];
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
bits[i] = (~bits[i]) & 0x01;
|
||||
std::string bit_name = "in_bit_" + std::to_string(i);
|
||||
data[bit_name] = bits[i];
|
||||
}
|
||||
j_set_echo_data["params"].push_back(j_set_data);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -407,7 +438,7 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
///Записываем данные
|
||||
*p_output_stream_ << j_set_echo_data.dump() << std::endl;
|
||||
std::cout << "OUT: " << j_set_echo_data.dump() << std::endl;
|
||||
//std::cout << "OUT: " << j_set_echo_data.dump() << std::endl;
|
||||
j_set_echo_data["params"].array().clear();
|
||||
answer_str.clear();
|
||||
///Ждем ответ
|
||||
|
@ -266,13 +266,13 @@ static bool programconf_getCyclicDataSettings(const json& j_cyc_data, std::map<s
|
||||
auto& usr_data = user_data.at(name);
|
||||
for (auto& j_bit : j_bits)
|
||||
{
|
||||
if (!j_bit.contains("name") || !j.contains("BitOffset"))
|
||||
if (!j_bit.contains("name") || !j_bit.contains("BitOffset"))
|
||||
continue;
|
||||
|
||||
auto name = j_bit.at("name").get<std::string>();
|
||||
auto Type = j_bit.at("BitOffset").get<uint32_t>();
|
||||
auto Pos = j_bit.at("BitOffset").get<uint32_t>();
|
||||
|
||||
usr_data.putBit(name, Type);
|
||||
usr_data.putBit(name, Pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "user_data.hpp"
|
||||
#include <bit>
|
||||
#include "../endian/endian.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
@ -34,7 +35,7 @@ const std::map<std::string, UserData::UserDataTypes> UserData::data_corr {
|
||||
|
||||
bool UserData::putBit(std::string& bit_name, uint32_t bit_pos)
|
||||
{
|
||||
if (bits_.size() >= size)
|
||||
if (bits_.size() >= size * 8)
|
||||
return false; /// Все биты уже заняты
|
||||
|
||||
bits_.push_back(UserDataBit{bit_name, bit_pos});
|
||||
@ -112,9 +113,9 @@ bool UserData::toRpcJson(nlohmann::json& j)
|
||||
return false;
|
||||
|
||||
json& j_bit = j[name];
|
||||
for (auto bit : bits_)
|
||||
for (auto& bit : bits_)
|
||||
{
|
||||
j_bit[bit.Name] = static_cast<bool>(data_.uint64 & (1 << bit.Pos));
|
||||
j_bit[bit.Name] = ( data_.uint64 & (1 << bit.Pos) ) ? (1) : (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user