 //locals
 int8_t state = -1;
 uint16_t offsetTime = 0;
-uint8_t g_CsvHeadPacket[] = "time,met1,met2,met3";
+uint8_t headPacket[] = "time,met1,met2,met3";
+uint8_t lenHeadPacket = sizeof(headPacket); //19
 
 void setup(){
 	Serial.begin(BAUD_RATE);

void byteWrite(uint8_t protocol){
	uint8_t packet[32];
	uint8_t i = 0;
	uint8_t length = 0;
	
	packet[0] = 0xA7;
	packet[1] = protocol;
	
	switch(protocol){
		case 1:
			packet[2] = stamp.hour;
			packet[3] = stamp.minute;
			packet[4] = stamp.second.by.te3;
			packet[5] = stamp.second.by.te2;
			packet[6] = stamp.second.by.te1;
			packet[7] = stamp.second.by.te0;
			
			packet[8] = g_fMetric1.by.te3;
			packet[9] = g_fMetric1.by.te2;
			packet[10] = g_fMetric1.by.te1;
			packet[11] = g_fMetric1.by.te0;
			
			packet[12] = g_fMetric2.by.te3;
			packet[13] = g_fMetric2.by.te2;
			packet[14] = g_fMetric2.by.te1;
			packet[15] = g_fMetric2.by.te0;
			
			packet[16] = g_fMetric3.by.te3;
			packet[17] = g_fMetric3.by.te2;
			packet[18] = g_fMetric3.by.te1;
			packet[19] = g_fMetric3.by.te0;
			
			packet[20] = 0x00; //terminator
			length = 21;
			break;
		case 2:
			length = sizeof(g_CsvHeadPacket) + 3;
			for(i=0; i<length-3; i++){
				packet[2+i] = g_CsvHeadPacket[i];
			}
			packet[length-1] = 0x00; //terminator
			break;
		default:
			break;
	}
	Serial.write(packet, length);
}


		if (sf & 0x01){ //rts
			if ((sf & 0x02) >> 1){ //new_session
				byteWrite(SEND_HEADER);
        //11111101
				sf &= 0xFD; //new_session = false
			} else {
				getData();
				byteWrite(SEND_DATA);
			}
     //11111110
			sf &= 0xFE; //rts = false;
		}
	} else {
		sf &= 0xFE; //rts = false
	}
}

