text: #include "include.h"
  #include "fitp.h"
  
  void joining_timer_f2() {
          cout << "Starting joining timer" << endl;
          NET_joining_enable();
          std::this_thread::sleep_for(std::chrono::milliseconds(30000));
          NET_joining_disable();
          cout << "Stopping joining timer" << endl;
  }
  
  void set_config(uint8_t *msg, uint8_t len) {
  	uint8_t i = 0;
  	uint8_t id_hodnoty = 0;
  	uint8_t dlzka_hodnoty = 0;
  
  	while (i < len) {
  		id_hodnoty = msg[i++]; //preskocenie na dlzku hodnoty
  		dlzka_hodnoty = msg[i++]; // preskocenie na data
  
  		//Cyklus, ktory prechadza data
  		for (uint8_t j = 0; j < dlzka_hodnoty; j++) {
  
  			//Vyber a ulozenie dat pre spravnu hodnotu
  			switch (id_hodnoty) {
  				case 0:
  					//printf("CMD: %d\n", msg[i+j]);
  					run_cmd(msg[i+j]);
  					break;
  				case 1:
  					GLOBAL_STORAGE.edid[j] = msg[i+j];
  					printf("EDID: %d\n", GLOBAL_STORAGE.edid[j]);
  					break;
  				case 3:
  					GLOBAL_STORAGE.nid[j] = msg[i+j];
  					printf("NID: %d\n", GLOBAL_STORAGE.nid[j]);
  					break;
  				case 4:
  					GLOBAL_STORAGE.channel = msg[i+j];
  					printf("CHANNEL: %d\n", GLOBAL_STORAGE.channel);
  					break;
  				case 5:
  					GLOBAL_STORAGE.bitrate = msg[i+j];
  					printf("BITRATE: %d\n", GLOBAL_STORAGE.bitrate);
  					break;
  				case 6:
  					GLOBAL_STORAGE.band = msg[i+j];
  					printf("BAND: %d\n", GLOBAL_STORAGE.band);
  					break;
  				case 7:
  					GLOBAL_STORAGE.rssi = msg[i+j];
  					printf("RSSI: %d\n", GLOBAL_STORAGE.rssi);
  					break;
  				case 8:
  					GLOBAL_STORAGE.tocoord = msg[i+j];
  					printf("TOCOORD: %d\n", GLOBAL_STORAGE.tocoord);
  					break;
  				case 9:
  					GLOBAL_STORAGE.toed[j] = msg[i+j];
  					printf("TOED: %d\n", GLOBAL_STORAGE.toed[j]);
  					break;
  				case 10:
  					GLOBAL_STORAGE.data_len = msg[i+j];
  					printf("DATA_LEN: %d\n", GLOBAL_STORAGE.data_len);
  					break;
  				case 11:
  					GLOBAL_STORAGE.data[j] = msg[i+j];
  					printf("DATA: %d\n", GLOBAL_STORAGE.data[j]);
  					break;
  			}
  		}
  
  
  
  		i += dlzka_hodnoty; //preskocenie dat a pokracovanie na dalsiu hodnotu
  	}
  }
  
  void run_cmd(uint8_t cmd) {
  	switch(cmd) {
  		case 0:
  			fitp_send(GLOBAL_STORAGE.tocoord,
  				   GLOBAL_STORAGE.toed,
  				   GLOBAL_STORAGE.data,
  				   GLOBAL_STORAGE.data_len);
  			break;
  		case 3:
  			{
  				std::thread joining_timer = std::thread(joining_timer_f2);
  				joining_timer.detach();
  			}
  			break;
  
  		case 6:
  			{
  			string msg = create_head();
  
  			//CID
  			//msg += "2,1," + to_string(GLOBAL_STORAGE.cid) + ",";
  
  			//NID
  			msg += "3,4,";
  			for (int i =0; i < 4; i++)
  				msg += to_string(GLOBAL_STORAGE.nid[i]) + ",";
  
  			//CHANNEL
  			msg += "4,1," + to_string(GLOBAL_STORAGE.channel) + ",";
  
  			//BITRATE
  			msg += "5,1," + to_string(GLOBAL_STORAGE.bitrate) + ",";
  
  			//BAND
  			msg += "6,1," + to_string(GLOBAL_STORAGE.band) + ",";
  
  			//RSSI
  			msg += "7,1," + to_string(GLOBAL_STORAGE.rssi) + ",";
  
  			mq->publish(NULL, "BeeeOn/config_from", msg.length(), msg.c_str());
  			}
  			break;
  
  		default:
  			printf("nefunkcne");
  	}
  }
  