Beispiel #1
0
bool supla_client_channels::remote_update_cv(void *srpc) {

	bool result = false;
	TSC_SuplaChannelValue channel_value;

	safe_array_lock(arr);

	for(int a=0;a<safe_array_count(arr);a++) {

		supla_client_channel *channel = (supla_client_channel *)safe_array_get(arr, a);
		if ( channel->marked_for_remote_update() == CC_REMOTEUPDATE_CHANNELVALUE ) {

			channel->proto_get_channel_value(&channel_value, client);
			channel->mark_for_remote_update(CC_REMOTEUPDATE_NONE);
			channel_value.EOL = get_marked() == NULL ? 1 : 0;

			result = true;
			break;

		}
	}

	safe_array_unlock(arr);

	if ( result ) {
		srpc_sc_async_channel_value_update(srpc, &channel_value);
	}

	return result;


}
Beispiel #2
0
void supla_client_channels::on_channel_value_changed(void *srpc, int DeviceId, int ChannelId) {

	supla_client_channel *channel;
	bool r = false;

	safe_array_lock(arr);

	for(int a=0;a<safe_array_count(arr);a++) {
		channel = (supla_client_channel *)safe_array_get(arr, a);
		if ( channel
			 && channel->getDeviceId() == DeviceId
			 && ( ChannelId == 0 || channel->getId() == ChannelId ) ) {

			channel->mark_for_remote_update(CC_REMOTEUPDATE_CHANNELVALUE);
			r = true;
		}
	}


	safe_array_unlock(arr);

	if ( srpc && r ) {
		remote_update(srpc);
	}

}
Beispiel #3
0
supla_client_channel *supla_client_channels::get_marked(void) {

	supla_client_channel *channel = NULL;

	for(int a=0;a<safe_array_count(arr);a++) {

		channel = (supla_client_channel *)safe_array_get(arr, a);
		if ( channel->marked_for_remote_update() != CC_REMOTEUPDATE_NONE ) {
			break;
		} else {
			channel = NULL;
		}
	}

	return channel;

}
Beispiel #4
0
bool supla_client_channels::remote_update_c(void *srpc) {

	TSC_SuplaChannelPack pack;
	memset(&pack, 0, sizeof(TSC_SuplaChannelPack));

	safe_array_lock(arr);

	for(int a=0;a<safe_array_count(arr);a++) {

		supla_client_channel *channel = (supla_client_channel *)safe_array_get(arr, a);

		if ( channel->marked_for_remote_update() == CC_REMOTEUPDATE_CHANNEL ) {

			if ( pack.count < SUPLA_CHANNELPACK_MAXSIZE ) {

				channel->proto_get_channel(&pack.channels[pack.count], client);
				pack.channels[pack.count].EOL = 0;
				channel->mark_for_remote_update(CC_REMOTEUPDATE_NONE);
		        pack.count++;

			} else {
				pack.total_left++;
			}

		}
	}

	safe_array_unlock(arr);

	if ( pack.count > 0 ) {

		if ( pack.total_left == 0 )
	    	pack.channels[pack.count-1].EOL = 1;

		srpc_sc_async_channelpack_update(srpc, &pack);
	}

	return pack.count > 0;


}
Beispiel #5
0
void supla_client_locations::load(int ClientID) {

	database *db = new database();
	int a, n;

	if ( db->connect() == true ) {

		safe_array_lock(arr);
		arr_clean();

		db->get_client_locations(ClientID, this);

		lck_lock(lck);
		ids_clean();

		n = safe_array_count(arr);

		if ( n > 0 ) {
			ids = (int*)malloc(sizeof(int)*n);
		}

		if ( ids )
			for(a=0;a<n;a++) {
				supla_client_location *loc = (supla_client_location *)safe_array_get(arr, a);
				if ( loc != NULL ) {
					ids[ids_count] = loc->getId();
					ids_count++;
				}
			}

		lck_unlock(lck);

		safe_array_unlock(arr);

	}

	delete db;

}
Beispiel #6
0
void supla_device_channels::get_temp_and_humidity(void *tarr) {

	int a;
	safe_array_lock(arr);

	for(a=0;a<safe_array_count(arr);a++) {

		supla_device_channel *channel = (supla_device_channel *)safe_array_get(arr, a);

		if ( channel != NULL ) {

			   supla_channel_temphum *temphum = channel->getTempHum();

			   if ( temphum != NULL )
				   safe_array_add(tarr, temphum);
		}

	}

	safe_array_unlock(arr);

}
Beispiel #7
0
void supla_datalogger::log_temperature() {
  supla_user *user;
  int a;
  int n = 0;
  void *tarr = safe_array_init();

  while ((user = supla_user::get_user(n)) != NULL) {
    n++;
    user->get_temp_and_humidity(tarr);
  }

  for (a = 0; a < safe_array_count(tarr); a++) {
    supla_channel_temphum *sct =
        (supla_channel_temphum *)safe_array_get(tarr, a);

    if (sct->isTempAndHumidity() == 1)
      db->add_temperature_and_humidity(
          sct->getChannelId(), sct->getTemperature(), sct->getHumidity());
    else
      db->add_temperature(sct->getChannelId(), sct->getTemperature());
  }

  supla_channel_temphum::free(tarr);
}
Beispiel #8
0
int supla_client_channels::count(void) {

	return safe_array_count(arr);

}