Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <unordered_set>
- #include <map>
- // Переменные для поиска времени
- struct MainTime {
- int hour = 0;
- int nexthour = 0;
- int minute = 0;
- int nextminute = 0;
- float sec = 0.0;
- float nextsec = 0.0;
- float sum = 0.0;
- };
- // Cкладывает по принципу XOR
- int XOR(const char* s) {
- int c = 0;
- while (*s)
- c ^= *s++;
- return c;
- }
- int main() {
- int comma, key; // Переменная для подсчета запятых и проверки контрольной суммы
- MainTime time; //Структура времени
- // Переменные для работы со строками
- char linec_h[200];
- std::string line, key_s;
- // Работа с ведром номеров спутника
- std::unordered_set<std::string> Set; //сет номеров спутника
- std::string SatelliteNumber;
- // Работа со средним значением времени к каждому SNR
- int SNRnumber;
- std::map <int, float> Map;
- std::ifstream logs_("C:/Users/Dmitry/Desktop/ShortLog.txt"); // Откуда берем данные
- std::ofstream pout("C:/Users/Dmitry/Desktop/SNR.txt"); // Куда загружаем данные о спутниках
- std::ofstream tout("C:/Users/Dmitry/Desktop/Avarage Time.txt"); // Куда загружаем данные о среднем времени
- if (logs_.is_open()) {
- while (getline(logs_, line)) {
- if (line.substr(0, 10) == "RE005%off%") {
- pout << "End of cycle" << std::endl;
- }
- else if (line.substr(0, 9) == "RE004%on%") { // Если строка с включением, то
- pout << "Time of work: " << time.nexthour + time.nextminute + time.nextsec << " sec" << std::endl; // Выводим время работы цикла
- // Обнуляем переменные времени
- time.hour = 0;
- time.minute = 0;
- time.sec = 0.0;
- time.nexthour = 0;
- time.nextminute = 0;
- time.nextsec = 0.0;
- // Очищаем сет
- Set.clear();
- }
- else {
- //Проверяем контрольную сумму
- key_s = line.substr(line.length() - 2, 2);
- key = strtol(key_s.c_str(), nullptr, 16);
- line = line.substr(1, line.length() - 4);
- strcpy_s(linec_h, line.c_str());
- if (line != "E00" && key != XOR(linec_h)) pout << "Line is corrupted!" << std::endl;
- else { //Если выполняется, то
- comma = 0;
- // Находим время, переводим в секунды, находим отношение первого значения и всех следующих
- if (line.substr(0, 5) == "GPGGA") {
- if (time.hour == 0 && time.minute == 0 && time.sec == 0.0) {
- time.hour = stoi(line.substr(6, 2)) * 3600;
- time.minute = stoi(line.substr(8, 2)) * 60;
- time.sec = stof(line.substr(10, 4));
- }
- else {
- time.nexthour = stoi(line.substr(6, 2)) * 3600 - time.hour;
- time.nextminute = stoi(line.substr(8, 2)) * 60 - time.minute;
- time.nextsec = stof(line.substr(10, 4)) - time.sec;
- }
- time.sum = time.nexthour + time.nextminute + time.nextsec;
- }
- // Если строка GPGSV
- else if (line.substr(0, 5) == "GPGSV") {
- // Проходимся по строке
- for (size_t i = 0, N = 4, SNR = 7; i < line.size(); i++) {
- // Считаем количество запятых
- if (line[i] == ',') comma++;
- // При нахождении нужного количества
- if (comma == N) {
- SatelliteNumber = line.substr(i - 1, 2);
- }
- else if (comma == SNR) {
- if (Set.find(SatelliteNumber) == Set.end()) { // Если значение встречается в певрый раз, то
- SNRnumber = stoi(line.substr(i + 1, 2));
- int count = 0;
- /*if (Map.find(SNRnumber) == Map.end()) {
- count++;
- }
- else {
- count++;
- time.sum /= count;
- Map.at(SNRnumber) = time.sum;
- }*/
- Map.insert(std::pair<int, float>(SNRnumber, time.sum));
- pout << "Satellite name: " << SatelliteNumber << " " << "SNR: " << SNRnumber << " Elapsed time : " << time.sum << " sec" << std::endl;
- Set.insert(SatelliteNumber); // Добавляем его в сет
- }
- N += 4;
- SNR += 4;
- }
- }
- }
- }
- }
- }
- logs_.close();
- for (auto it = Map.begin(); it != Map.end(); ++it) {
- tout << "SNR: " << it->first << " Avarage time: " << it->second << " sec" << std::endl;
- }
- std::cout << "Success" << std::endl;
- }
- else std::cout << "File is not open" << std::endl;
- pout.close();
- tout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement