#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>

char  sendbuf[129];

float temp_lm73s = 5.5555, temp_lm73f = 7.7777, f_cold_junction_temperature = 22.2222, f_linearized_tc_temperature = 33.3333, rtd_temp = 44.4444;
bool bot_heat_state = false, top_heat_state = true;
uint8_t fans_rpm = 0xFF;

uint8_t var_tosend[] = {3, 4, 5, 6, 7}; // выход с парсера

int main(void) {
	
  char  temp_buf[129];
  char tmp_str[10];

  memset(temp_buf, 0, 129);

  snprintf(temp_buf, sizeof(temp_buf), "<S:0,%3.3f;1,%3.3f;2,%u;", temp_lm73s, temp_lm73f, fans_rpm);

  for(uint8_t k = 0; k < (sizeof(var_tosend) / sizeof(var_tosend[0])); k++)
  {
	//if((!var_tosend[k]) && (!var_tosend[k+1])){break;}; // if current element of array and element that going after it == 0 -> exit

    switch(var_tosend[k]){
      case 3:
    	snprintf(tmp_str, sizeof(tmp_str), "3,%3.3f;", f_cold_junction_temperature);
    	strcat(temp_buf, tmp_str);
    	break;

      case 4:
    	snprintf(tmp_str, sizeof(tmp_str), "4,%3.3f;", f_linearized_tc_temperature);
    	strcat(temp_buf, tmp_str);
    	break;

      case 5:
        snprintf(tmp_str, sizeof(tmp_str), "5,%3.3f;", rtd_temp);
        strcat(temp_buf, tmp_str);
        break;

      case 6:
    	snprintf(tmp_str, sizeof(tmp_str), "6,%d;", bot_heat_state ? 1 : 0);
    	strcat(temp_buf, tmp_str);
    	break;

      case 7:
        snprintf(tmp_str, sizeof(tmp_str), "7,%d;", top_heat_state ? 1 : 0);
        strcat(temp_buf, tmp_str);
        break;
    }
    memset(tmp_str, 0, 10);
  }
  
  strcat(temp_buf, ">");
  
  int res = strlen(temp_buf);
  if (res >= sizeof(sendbuf)) {
	printf("Data truncated.\n");
  }

printf("%s\n", temp_buf);

	return 0;
}
