void Statemachine::controlchange_statemachine()
{
    debugln("Control");

    if (new_state)
    {
        controlchange_state = controlchange_state_controller;
        new_state = false;
    }

    switch (controlchange_state)
    {
    case controlchange_state_controller:
        debugln("controller");
        controlchange_controller = midiByte;
        controlchange_state = controlchange_state_value;
        break;

    case controlchange_state_value:
    {
        debugln("value");
        controlchange_value = midiByte;
        if (cc_callback)
        {
            cc_callback(controlchange_controller, controlchange_value);
        }
        controlchange_state = controlchange_state_controller;
    }
    break;

    default:
        debugln("Unknown control state!");
    }
}
void Statemachine::pitchwheel_statemachine()
{
    debugln("Pitchwheel");

    if (new_state)
    {
        pitchwheel_state = pitchwheel_state_lo;
        new_state = false;
    }

    switch (pitchwheel_state)
    {
    case pitchwheel_state_lo:
        debugln("low byte");
        pitch_bend = midiByte;
        pitchwheel_state = pitchwheel_state_hi;
        break;

    case pitchwheel_state_hi:
    {
        debugln("high byte");
        pitch_bend |= midiByte<<7;
        pitchwheel_state = pitchwheel_state_lo;
    }
    break;

    default:
        debugln("Unknown note on state!");
    }
}
Esempio n. 3
0
void BroadcastNetwork::dumpRoutes() {
  for(byte i = 0; i < ROUTE_MEMORY; i++) {
    DistanceVector& v = routes[i];
    
    debugln(String("  Route for ") + v.destination + " via " + v.nextHop + " over " + v.getHops() + " hops with time: " + v.getTime());
  }
}
Esempio n. 4
0
/**
 * \brief GSM fecha conexão http
 * \param 
 * \return 0=erro, 1=ok
 */
boolean sATCIPCLOSEMulitple(uint8_t mux_id)
{
#ifdef GSM_CSTT
	
	char *data=reqHTTP;
	//eATCIPSTATUS();
	PGM_PRINTLN("CLO");
	//debugln(mux_id);
	esp8266Flush();
	#if USE_MUX == 1
	SSwifi.print("AT+CIPCLOSE=");
	SSwifi.print(mux_id);
	SSwifi.print("\r\n");
	#else
	SSwifi.print("AT+CIPCLOSE\r\n");
	#endif
	//bitSet(ccStatus,CC_DEBUG);
	#if ESP8266_VERSION_14 == 1
	recvString(data,"OK","xx","CLOSE", 10000,true);
	#else
	recvString(data,"OK","ERR","UNL", 10000,true);
	#endif
	debugln(data);
	if (data[0]=='O' || data[0]=='U') {
		return true;
	}
	return false;
#else
	return true;
#endif
}
void Statemachine::note_off_statemachine()
{
    debugln("Note off");

    if (new_state)
    {
        note_off_state = note_off_state_key;
        new_state = false;
    }

    switch (note_off_state)
    {
    case note_off_state_key:
        debugln("note off key");
        note_off_key = midiByte;
        note_off_state = note_off_state_velocity;
        break;

    case note_off_state_velocity:
    {
        debugln("note off velocity");
        note_off_velocity = midiByte;
        note_off_state = note_off_state_key;

        notesActive--;

        // only set volume if the current playing midi should be turned off
        if (active_key == note_off_key) // TODO??
        {
            // non-legato? -> always release.. otherwise in legato -> only release when this is the last note
            if (!legatoMode || (notesActive == 0))
            {
                stopped = true;
            }
        }
        else if (legatoMode && (notesActive == 0))
        {
            stopped = true;
        }
    }
    break;

    default:
        debugln("Unknown note on state!");
    }
}
Esempio n. 6
0
int main() {

	led_on();
	usart_init();
	debugln("\nUSART initialized");

	spi_init_master();
	debugln("SPI master");

	for(int i=0; i<5; i++) {
		debugx(spi_tx(42)); debugln(" spi_tx");
	}

	for (;;){}

	return 1;
}
void setup() {
	initDebug();
	setupChangeModePin();
	if (isCycleVoltageModeActive()) {
		cycleVoltageMode = true;
		sk720Mode = SK720Mode_off;
		debugln("Cycle mode activated");debug("Switching states every ");debugNum(CYCLE_MODE_DELAY_MS);debugln("ms.");
	} else {
		debugln("Normal mode activated");
		setupLEDPins();
		setuptInitialLedStates();
		setupWatchdogTimer();
		setupPinChangeInterrupts();
	}
	setupFastPWM();
	power_adc_disable();
	power_usi_disable();
}
Esempio n. 8
0
void parse_corrente(void)
{
	double Irms;
	uint16_t amostras=gParam.rede.nro_amostras_corrente;
	uint8_t bit_fase;
	uint8_t fases=gParam.rede.fases;
	#if TESTAR_SENSORES == 1
	testarSensores();
	#endif
	#if DEBUG > 0
	long tempoCorrente=millis();
	//SSdebug.write('#');
	#endif
	uint8_t tensao;
	tensao=bitRead(fases,B_TENSAO)?TENSAO_220:TENSAO_127;
	//Irms=0;
	#if HAS_BLUETOOTH >= 2 
	SSdebug.print("fases=");
	SSdebug.println(fases,BIN);
	#endif
	memset(correnteFase,0,3);
	for (bit_fase=0; bit_fase<MAX_CORRENTE_FASES ; bit_fase++) {
//		emon.current(CORRENTE_PIN[bit_fase], gParam.rede.calibragemFase1);             // Current: input pin, calibration.
//		emon.current(A0, gParam.rede.calibragemFase1);             // Current: input pin, calibration.
		if (bitRead(fases,bit_fase) && !bitRead(fases,B_PORTA_A0+bit_fase)) {
			#if HAS_EMONLIB == 1
			//cli();
//			Irms = emon.calcIrms(amostras);  // Calculate Irms only
			Irms = emon[bit_fase].calcIrms(amostras);  // Calculate Irms only
			//sei();
			#else
			Irms = readCalcIrms(CORRENTE_PIN[bit_fase], amostras);
			#endif
			correnteFase[bit_fase] = (uint16_t)(Irms * tensao);
			//correnteFase1 = constrain(correnteFase1,0,9999);
			#if DEBUG > 0
			debugvar(Irms);
			debugln(correnteFase[bit_fase]);
			#endif
			#if HAS_OLED == 1
				oled.setField(bit_fase+1,correnteFase[bit_fase]);
			#endif
		}
	}

	#if DEBUG >0
	tempoCorrente= millis()-tempoCorrente;
	debugvarln(tempoCorrente);
	#if HAS_EMONLIB == 1
	//int vcc=emon1.readVcc();
	//debugvar(vcc);
	#endif
	//debugvar(Irms);
	#endif
	//debugln(correnteFase[0]);
}
Esempio n. 9
0
int
main(int argc, char *argv[])
{
	int ret;
	RATDriver rat;

	ret = rat_driver_init();
	if (ret < 0) {
		debugln("Failed to initialize driver.");
		return 1;
	}


	ret = RATDriver_init(&rat, PRODUCT_ID, VENDOR_ID);

	if (ret != 0) {
		debugln("Failed to initialize driver instance.");
		return 1;
	}

#if DEBUG
	print_dpi_modes(&rat);
#endif

#if ! DEBUG
	daemonize();
#endif

	RATDriver_set_profile(&rat, RAT_PROFILE_1, handle_profile1);
	RATDriver_set_profile(&rat, RAT_PROFILE_2, handle_profile2);
	RATDriver_set_profile(&rat, RAT_PROFILE_3, handle_profile3);

	ret = 0;
	while (ret >= 0 && !rat.killme)
		ret = RATDriver_read_data(&rat);

	ret = RATDriver_fini(&rat);

	rat_driver_fini();

	return ret;
}
void Statemachine::programchange_statemachine()
{
    debugln("Program");

    if (new_state)
    {
        new_state = false;
    }

    program = midiByte;
}
void loop() {
	if (cycleVoltageMode == true) {
		outputSystemMode(sk720Mode);
#ifdef DEBUG
		debug("current state: ");
		printSystemMode(sk720Mode);
#endif
		sk720Mode = getNextSystemState(sk720Mode);
		delay(CYCLE_MODE_DELAY_MS);
	} else {
		if (wakeup == true) {
			wakeup = false;
			const unsigned long now = micros();
			if (pinChanged == true) {
				pinChanged = false;
				readLedStates(&systemLedState, now);
			}
			sk720ModeBuffer[currentSk720Mode] = inferSystemMode(&systemLedState,
					now);
#ifdef DEBUG
			SK720Mode oldState = sk720Mode;
#endif
			sk720Mode = getFilteredSk720Mode(sk720ModeBuffer, sk720Mode,
					sk720ModeBuffer[currentSk720Mode]);
#ifdef DEBUG
			if (sk720Mode != oldState) {
				debug("time ");
				debuglnNum(now);
				debug("redLed ");
				printSingleLedMode(systemLedState.red.mode);
				debug("greenLed ");
				printSingleLedMode(systemLedState.green.mode);
				debug("newState ");
				printSystemMode(sk720ModeBuffer[currentSk720Mode]);
				debug("filteredState ");
				printSystemState(sk720Mode);
				debug("filterIndex ");
				debuglnNum(currentSk720Mode);
				printLedState(&systemLedState.red);
				printLedState(&systemLedState.green);
				debugln("---");
			}
#endif

			if (currentSk720Mode == STATE_BUFFER_SIZE - 1) {
				currentSk720Mode = 0;
			} else {
				currentSk720Mode++;
			}
			outputSystemMode(sk720Mode);
		}
		enterSleepMode();
	}
}
Esempio n. 12
0
bool Cube_LoadTiles(Cube *cube, const char *tiles, const char *key)
{
	if (strlen(tiles) != FACES_PER_CUBE * TILES_PER_FACE) {
#ifndef NDEBUG
		if (strlen(tiles) > FACES_PER_CUBE * TILES_PER_FACE) {
			debugln("tile string too long");
		} else {
			debugln("tile string too short");
		}
#endif
		return false;
	}
	for (int face = 0; face < FACES_PER_CUBE; face++) {
		for (int tile = 0; tile < TILES_PER_FACE; tile++) {
			char *loc = strchr(key, tiles[face * TILES_PER_FACE + tile]);
			if (loc == NULL) return false;
			int color = loc - key;
			assert(color >= 0 && color < 6);
			cube->face[face].tile[tile] = color;
		}
	}
	return Cube_ValidateTiles(cube);
}
Esempio n. 13
0
int sHTTPREAD(void) {
 int nbytes;
 gprs.httpRead();
 nbytes = gprs.httpIsRead();
 
   if (gprs.httpState == HTTP_ERROR) {
	   PGM_PRINTLN("Read error");
	   nbytes = -1;
   }

 debugvar(nbytes);
 debugln(gprs.buffer);
 return nbytes;
}
Esempio n. 14
0
HapiliMessage* HapiliMessageSerializer::Deserialize(Stream& stream) {
    size_t nbytes = stream.available();
    if (nbytes < sizeof(HapiliMessage::Header)) {
        debug("Unexpected packet size ");
        debug(nbytes);
        debugln();
        return NULL;
    }

    HapiliMessage::Header header;
    nbytes = stream.readBytes((byte*)&header, (size_t)sizeof(HapiliMessage::Header));
    if (nbytes < sizeof(HapiliMessage::Header)) {
        debug("Unexpected packet size ");
        debug(nbytes);
        debugln();
        return NULL;
    }

    if (header.version != 1) {
        debug("Unexpected HapiliMessage version ");
        debug(header.version);
        debugln();
    }

    HapiliMessage *msg;
    switch (header.type) {
        case HapiliMessage::Set:
            debugln("SetMessage");
            msg = new SetMessage(header);
            break;

        case HapiliMessage::Configure:
            debugln("ConfigureMessage");
            msg = new ConfigureMessage(header);
            break;

        case HapiliMessage::Query:
        default:
            debugln("QueryMessage");
            msg = new QueryMessage(header);
            break;
    }

    msg->Deserialize(stream, true);
    return msg;
}
// read all MIDI bytes..
void Statemachine::run()
{
    // low-level.. get bytes
    uart.decode_runs();

    // read decoded bytes
    while(1)
    {
        short word_ = uart.read_byte();
        if (word_ < 0)
        {
            //debugln(word_);
            return;
        }
        debug("MIDI State = ");
        debughexln(state);
        debug("word_ = ");
        debughexln(word_);
        debug("cmd = ");
        debughexln(word_ & 0xF8);
        if (((uint8_t) word_ & (uint8_t) 0xF8) == 0xF8)
        {
            debugln("Change state!");
            if (word_ >= 0xF8)
            {
                // for (int i=0; i<maxCcObservers; i++)
                // {
                //   if (ccObservers[i])
                //   {
                //     ccObservers[i]->handle_beat(word_);
                //   }
                // }
            }
            return;
        }
        else if ((unsigned char) word_ & 0x80)
        {
            // printf("%02X\r\n", word_);
            state = (state_t) (word_ & 0xF0);
            rcvd_chan = (unsigned char) word_ & 0x0F;
            new_state = true;
            return;
        }
        // and else.. it's just the usual data byte..
        midiByte = word_;

        if (rcvd_chan != chan)
        {
            debugln("Not our midi channel!");
            return;
        }

        switch (state)
        {
        case state_idle:
            break;

        case state_note_on:
            note_on_statemachine();
            break;

        case state_note_off:
            note_off_statemachine();
            break;

        case state_pitchwheel_change:
            pitchwheel_statemachine();
            break;

        case state_controlchange:
            controlchange_statemachine();
            break;

        case state_programchange:
            programchange_statemachine();
            break;

        case state_channel_pressure:
            break;

        default:
            debug("Unhandled MIDI state 0x");
            debughexln(state);
        }
    }
}
Esempio n. 16
0
/**
 * \brief envia pacote de dados
 * \param mux_id  >  0   envia o AT+HTTPDATA e os dados
 * \param mux_id ==  0  somente dados
 * \param mux_id == -1  aguarda retorno de dados
 * \return 0=erro, 1=OK
 */
boolean sATCIPSENDMultiple(int mux_id, uint8_t tipo_buffer, uint8_t *buffer, boolean flag_flush)
{
	int len;
	
	if (mux_id==-1) {
			return gprs.sendCommand(0);
	}

	//debugvar(freeMemory());
	if (tipo_buffer == POINTER_CHAR_RAM)
	len=strlen((char*)buffer);
	else
	len=strlen_P((char*)buffer);

	if (!len) return true;
	
	///	rx_empty();
	//if (bitRead(ccStatus,CC_DEBUG))	debugvar(freeMemory());
	#if DEBUG >= 1 || HAS_BLUETOOTH >= 1
	debugvar(len);
		uint8_t *b=buffer;
		for (uint16_t i = 0; i < len; i++) {
			if (tipo_buffer==POINTER_CHAR_PROGMEM) {
				SSdebug.write(pgm_read_byte(b++));
				} else {
				SSdebug.write(*b++);
			}
		} // for
	SSdebug.write('\n');

	#endif
	
	#ifdef GSM_CSTT
	//	esp8266Flush();
	SSwifi.print("AT+CIPSEND=");
	#if USE_MUX == 1
	SSwifi.print(mux_id);
	SSwifi.print(",");
	#endif
	SSwifi.print(len);
	SSwifi.print("\r\n");
	SSwifi.flush();
	if (recvFind(">",6000)) {
		PGM_PRINT("+");
		//esp8266Flush();
		#if 0
		if (tipo_buffer==POINTER_CHAR_PROGMEM) {
			#if 0
			char *u;
			if (len < SERIAL_TX_BUFFER_SIZE-1 && (u=(char*)malloc(SERIAL_TX_BUFFER_SIZE))) {
				strcpy_P(u,(char*)buffer);
				SSwifi.print(u);
				SSwifi.flush();
				free(u);
			} else
			#endif
			for (uint16_t i = 0; i < len; i++) {
				// SSdebug.write(pgm_read_byte(buffer));
				SSwifi.write(pgm_read_byte(buffer++));
			}
			}else {
			SSwifi.print((char*)buffer);
		}
		#else
		for (uint16_t i = 0; i < len; i++) {
			if (tipo_buffer==POINTER_CHAR_PROGMEM) {
				//			SSdebug.write(pgm_read_byte(buffer));
				SSwifi.write(pgm_read_byte(buffer++));
				}else {
				//				SSdebug.write(*buffer);
				SSwifi.write(*buffer++);
			}
		}
		#endif
		//		ret=recvFind("SEND OK", 5000);
		PGM_PRINT("* ");
		SSwifi.write(0x1a);
		recvString(str_ret, "SEND OK", "busy","link is", 10000,flag_flush);
		#if DEBUG > 0
		//if (bitRead(ccStatus,CC_DEBUG))
		debugln(str_ret);
		#endif
		if (!strncmp(str_ret,"SEND OK",7)) {
			//			PGM_PRINTLN("SOK");
			//delay(100);
			//SSwifi.flush();
			//eATCIPSTATUS();

			return true;
		}
		if (!strncmp(str_ret,"link",4)) {
			sATCIPCLOSEMulitple(mux_id);
		}
	}
	return false;
	#else
	if (mux_id>0) {
		sprintf_P(gprs.buffer,PSTR("AT+HTTPDATA=%d,5000"),mux_id);
		gprs.sendCommand(gprs.buffer,5000,"DOWNLOAD");
	}
	for (uint16_t i = 0; i < len; i++) {
		if (tipo_buffer==POINTER_CHAR_PROGMEM) {
			SSwifi.write(pgm_read_byte(buffer++));
		} else {
			SSwifi.write(*buffer++);
		}
	}
	delay(150);
	return 1; 
	#endif
}
void Statemachine::note_on_statemachine()
{
    debugln("Note on");

    if (new_state)
    {
        note_on_state = note_on_state_key;
        new_state = false;
    }

    switch (note_on_state)
    {
    case note_on_state_key:
        debugln("note on key");
        note_on_key = midiByte;
        note_on_state = note_on_state_velocity;
        break;

    case note_on_state_velocity:
    {
        debugln("note on velocity");
        uint8_t velocity = midiByte;
        note_on_state = note_on_state_key;

        if (velocity == 0)
        {
            notesActive--;
        }
        else
        {
            notesActive++;
        }

        if (velocity == 0 && active_key == note_on_key)
        {
            // active note is deactivated.
            debugln("note stopped");
            // non-legato? -> always release.. otherwise in legato -> only release when this is the last note
            if (!legatoMode || (notesActive == 0))
            {
                stopped = true;
            }
        }
        else if (velocity)
        {
            // old note is deactivated or new note is activated, we should only handle the latter case!
            debugln("note triggered");
            // non-legato? -> always trigger.. otherwise in legato -> only trigger when this is the first note
            if (!legatoMode || (notesActive == 1))
            {
                triggered = true;
            }
            active_velocity = velocity;
            // remember currently playing key
            active_key = note_on_key;
        }
        // else nothing changes

    }
    break;

    default:
        debugln("Unknown note on state!");
    }
}
Esempio n. 18
0
/** 
 *  \brief Inicializa modulo GSM, detecta operadora e conecta no GPRS
 *  \param max numero maximo de tentativas
 */
void setup_gsm(uint8_t max)
{
  byte ret;
  char apn[50];
  //gprs.buffer=reqHTTP;
  PGM_PRINTLN("Resetting...");
  ret=gprs.init();
  if (!ret) {
		led2_status=LED_PISCA_FLASH;
		return;
  }

  ret=gprs.sim_detect();
  PGM_PRINT("SIM="); debugln(ret);
  if (0 && !ret) {
	  led2_status=LED_PISCA_FLASH;
	  return;
  }

  ret = gprs.setup(max);
	if (ret) {
		led2_status=LED_PISCA_FLASH;
		return;
	}
  
  gprs.getCIMI((char*)NULL);
  strcpy(apn,APN_string(gprs.buffer));
  /*
  if (gprs.getOperatorName()) {
	  PGM_PRINT("Operator:");
	  strupr(gprs.buffer);
	  debugln(gprs.buffer);
  }
*/
	gParam.web.ip[1][0]='\0';
	ret=apn[0];
	if (!ret) {
		led2_status=LED_PISCA_FLASH;
		return;
	}
	ret = gprs.join(apn,NULL,NULL, gParam.web.ip[1]);
	if (ret) {
		PGM_PRINT("Error code:");
		debugln(ret);
		debugln(gprs.buffer);
		return;
	}

  // TESTE DE PEGOU IP DA REDE
  	if (gParam.web.ip[1][0] && gParam.web.ip[1][0]!='0') {
	  	bitSet(ccStatus,CC_CWJAP);
		ccStatus |=  CC_WIFI_BITS_CWJAP_OK;
	  	}  else {
	  	bitClear(ccStatus,CC_CWJAP);
  	}

  #if DEBUG > 0
  ret = gprs.getSignalQuality();
  if (ret) {
     PGM_PRINT("Signal:");
     debug(ret);
     PGM_PRINTLN("dB");
  }
  #endif
  #if USE_LOCATION == 1
  ret=gprs.getLocation(&loc);
  #endif
  PGM_PRINTLN("Gsm: connecting...");
  
#ifndef GSM_CSTT
  ret=0;
  for (;;ret++) {
	  if (gprs.httpInit()) break;
	  debugvarln(gprs.buffer);
	  gprs.httpUninit();
	  if (!(ret%5)) gprs.gsm_reset();
	  delay(1000);
  }
  delay(3000);
#endif

  debugvarln(gParam.web.ip[1]);
  #if HAS_WEBSERVER_FULL == 1 || HAS_WEBSERVER_TINY == 1
  server.begin();
  #endif
}
Esempio n. 19
0
//////////////////////////////////
// PARSE
//////////////////////////////////
uint8_t parse_nrf24(void)
{
	uint8_t ret=0;
	uint8_t st;
	unsigned long time;
	char Taddr[6]="EILCT";
	char Raddr[6]="EILCT";
	struct TPackage recPack;
	boolean flag_send_data=false;
	uint8_t node_livre=0xff;
	uint8_t node;
	uint16_t addr_base=MAX_TSENSOR_CLIENT*(gParam.radio.serv_addr-SERV_ADDR_BASE);

	if(!Mirf.isSending() && Mirf.dataReady()){
//	if(Mirf.dataReady()){
		#if HAS_DISPLAY == 1
		lcd.setCursor(6,0);
		lcd.write('1');
		#endif
		#if DEBUG > 0
		uint8_t PIPE;
		Mirf.readRegister( STATUS, &PIPE, sizeof(PIPE) );
		PGM_PRINT("1.ST="); debugbinln(PIPE);
		#endif
		
		Mirf.getData((uint8_t*)&recPack);
	//	if (Mirf.dataReady()) {
	//		uint8_t rx_data;
	//		Mirf.readRegister(RX_PW_P1,&rx_data,1);
	//		debugvarln(rx_data);
	//	}

		#if DEBUG > 10
		Mirf.readRegister( STATUS, &PIPE, sizeof(PIPE) );	
		PGM_PRINT("2.ST="); debugbinln(PIPE);
		#endif

		//debugvarln(recPack.addr);
		debugvar(recPack.seq);
		debugvar(recPack.serie);
		//debugvarln(recPack.cmd);
		gPack=recPack;
//		if (Raddr[4]=='E') {
		if (recPack.addr=='X') {
			uint16_t recurso=recPack.data[0] <<8 | recPack.data[1];
			uint16_t serie=recPack.serie;
			uint16_t check;
			uint16_t check_in=recPack.data[2] <<8 | recPack.data[3];
			check=recurso ^ serie;
			// procura cliente/addr livre para alocar
			gPack.cmd=PKG_CMD_ERR_FULL_CLIENT;
			
			if (check != check_in) {
				gPack.cmd=PKG_CMD_ERR_UNKNOW_CLIENT;
				debugvar(recurso);
				debugvar(serie);
				debugvarln(check);
			} else {
				
				for (node=0;node<MAX_TSENSOR_CLIENT;node++) {
					if (!bitRead(gParam.radio.client,node)) {
						if (node_livre==0xff) node_livre=node;
					} else
						if (gParam.radio.serieClient[node]==serie) {
							node_livre=0xff;
							break;
						}
				}
				debugvar(node); debugvarln(node_livre);
				if (node == MAX_TSENSOR_CLIENT && node_livre < MAX_TSENSOR_CLIENT) {
					node=node_livre;
				}
				if (node < MAX_TSENSOR_CLIENT) {
						gParam.radio.serieClient[node]=serie;
						gParam.radio.seqClient[node]=0;
						gParam.radio.recursoClient[node]=recurso;
						gParam.radio.timeClient[node]=millis()/1000;
					//debugvarln(gParam.radio.recursoClient[node]);
					
						gPack.cmd=PKG_CMD_SET_NODE;
						gPack.addr=Raddr[0]=node+'0'+addr_base;
						gPack.data[0]=Raddr[0];
//						gPack.data[0]=TSENSOR_SERIE << 8;
//						gPack.data[1]=TSENSOR_SERIE & 0xff;
						if (node_livre!=0xff) {
							bitSet(gParam.status,P_STATUS_GRAVA_EEPROM);
							ret++;
							#if DEBUG>0
							SSdebug.write('+');
							#endif
						}
						bitSet(gParam.radio.client,node);
						PGM_PRINT("new=");debugln(Raddr[0]);
						// ativa NFR24L01 para receber o msg
						flag_send_data=true;
						#if HAS_DISPLAY == 1
						lcd.setCursor(6,0);
						lcd.write(Raddr[0]);
						#endif

				}
			} // check != check_in
		} else { //x
			uint8_t client=(recPack.addr-'0') % addr_base; // TCLIn
			debugvarln(client);
			Taddr[0]=recPack.addr;
			#if HAS_DISPLAY == 1
			lcd.setCursor(8+client,0);
			lcd.write(Taddr[0]);
			#endif
			gPack.cmd=PKG_CMD_ERR_COMMAND_CLIENT;
			// retorno de execução de comanto
			if (recPack.cmd==PKG_CMD_SEND_DATA_CMD_STATUS) {
				PGM_PRINT("% ");
				uint8_t status=recPack.data[0];
				debugvarln(status);
				if (!status)
					bitSet(gParam.radio.hasCmdOK,client);
				else
					bitSet(gParam.radio.hasCmdERR,client);
				gPack.cmd=PKG_CMD_RECEIVE_DATA;
				timerWeb=0; // forca envio para o site
			}
			// recebendo dados
			if (recPack.cmd==PKG_CMD_SEND_DATA) { //3
				// testa se cliente existe
				if (!bitRead(gParam.radio.client,client) || gParam.radio.serieClient[client]!=recPack.serie) { //2
					gPack.cmd=PKG_CMD_ERR_UNKNOW_CLIENT;
					gPack.data[0]=gParam.radio.serv_addr;
					PGM_PRINTLN("inv client");
								flag_send_data=true;
					
					} else {
					int t,t2=-1000;
					int	_min=gParam.lim.min[client];
					int _max=gParam.lim.max[client];
					gParam.radio.timeClient[client]=now();
					gParam.radio.vccClient[client]=recPack.data[0] <<8 | recPack.data[1];
					// Temperatura
					t=gParam.radio.dataClient[client][0]=(int)(recPack.data[2] <<8 | recPack.data[3]);
					PGM_PRINT("tmp ="); debugln(t);
					// sensores extras
					if (gParam.radio.recursoClient[client] & REC_SENSORES) {
						gParam.radio.sensor9_10[client]=recPack.data[4];
					}
					if (gParam.radio.recursoClient[client] & & (REC_DS18B20_EXTRA | bit(REC_HUMIDADE))) {
						t2=gParam.radio.dataClient[client][1]=(int)(recPack.data[5] <<8 | recPack.data[6]);
						PGM_PRINT("tmp2="); debugln(t2);
					}
					#if HAS_DISPLAY == 1
						// col,lin
					lcd.setCursor(client*4,1);
					lcd.print(t/10);
					lcd.print("  ");
					#endif
					bitSet(gParam.radio.hasData,client);
					// testa limites
					if (!_min || !_max) {
						if (t<_min || t>_max) {
							if (!bitRead(gParam.radio.lim_flag,client)) {
								bitSet(gParam.radio.lim_flag,client);
								timerWeb=0; // força envio
							}
							
						} else
							if (bitRead(gParam.radio.lim_flag,client)) {
								bitClear(gParam.radio.lim_flag,client);
								timerWeb=0; // força envio
							}
					}
					
					if (recPack.seq == gParam.radio.seqClient[client]) 
						gPack.cmd=PKG_CMD_ERR_SEQ_DUPLO;
					 else
						if (recPack.seq == gParam.radio.seqClient[client]+1) { // 1
						// pacote válido, testa se tem comando para enviar
							if (bitRead(gParam.radio.hasCmd,client)) {
								debugvarln(rf24_cmd);
								gPack.cmd=PKG_CMD_RECEIVE_DATA_WITH_CMD;
								gPack.data[0]=rf24_cmd;
								gPack.data[1]=rf24_par1>>8;
								gPack.data[2]=rf24_par1;
								gPack.data[3]=rf24_par2>>8;
								gPack.data[4]=rf24_par2;
								gPack.data[5]=rf24_par3>>8;
								gPack.data[6]=rf24_par3;
								bitClear(gParam.radio.hasCmd,client);
								flag_send_data=true;
							}
							else
								gPack.cmd=PKG_CMD_RECEIVE_DATA;
						} else {
							gPack.cmd=PKG_CMD_ERR_SEQ;
							} // 1

					gParam.radio.seqClient[client]=recPack.seq;

				} //2