コード例 #1
0
ファイル: srpc.c プロジェクト: SUPLA/arduino
_supla_int_t SRPC_ICACHE_FLASH srpc_async__call(void *_srpc, unsigned _supla_int_t call_type, char *data, unsigned _supla_int_t data_size, unsigned char *version) {

	Tsrpc *srpc = (Tsrpc*)_srpc;

	if ( srpc->params.before_async_call != NULL )
		srpc->params.before_async_call(_srpc, call_type, srpc->params.user_params);

	lck_lock(srpc->lck);

	sproto_sdp_init(srpc->proto, &srpc->sdp);

	if ( version != NULL )
		srpc->sdp.version = *version;

	if ( SUPLA_RESULT_TRUE == sproto_set_data(&srpc->sdp, data, data_size, call_type)
		 && srpc_out_queue_push(srpc, &srpc->sdp) ) {

        #ifndef __EH_DISABLED
    	if ( srpc->params.eh != 0 ) {
    		eh_raise_event(srpc->params.eh);
    	}
        #endif

    	return lck_unlock_r(srpc->lck, srpc->sdp.rr_id);
	}

	return lck_unlock_r(srpc->lck, SUPLA_RESULT_FALSE);
}
コード例 #2
0
ファイル: supla-client.c プロジェクト: SUPLA/supla-core
void supla_client_set_registered(void *_suplaclient, char registered) {
	TSuplaClientData *scd = (TSuplaClientData*)_suplaclient;

	lck_lock(scd->lck);
	scd->registered = registered;
	lck_unlock(scd->lck);
}
コード例 #3
0
ファイル: srpc.c プロジェクト: SUPLA/arduino
void SRPC_ICACHE_FLASH srpc_set_proto_version(void *_srpc, unsigned char version) {

	Tsrpc *srpc = (Tsrpc*)_srpc;

	lck_lock(srpc->lck);
	sproto_set_version(srpc->proto, version);
	lck_unlock(srpc->lck);
}
コード例 #4
0
ファイル: clientlocation.cpp プロジェクト: Alambos/supla-core
int supla_client_locations::count() {
	int result = 0;

	lck_lock(lck);
	result = ids_count;
	lck_unlock(lck);

	return result;
}
コード例 #5
0
ファイル: supla-client.c プロジェクト: SUPLA/supla-core
char supla_client_registered(void *_suplaclient) {
	TSuplaClientData *scd = (TSuplaClientData*)_suplaclient;
	char result;
	lck_lock(scd->lck);
	result = scd->registered;
	lck_unlock(scd->lck);

	return result;
}
コード例 #6
0
ファイル: clientlocation.cpp プロジェクト: Alambos/supla-core
void supla_client_locations::ids_clean(void) {
	lck_lock(lck);

	if ( ids )
		free(ids);

	ids_count = 0;

	lck_unlock(lck);
}
コード例 #7
0
ファイル: srpc.c プロジェクト: SUPLA/arduino
unsigned char SRPC_ICACHE_FLASH srpc_get_proto_version(void *_srpc) {

	unsigned char version;

	Tsrpc *srpc = (Tsrpc*)_srpc;
	lck_lock(srpc->lck);
	version = sproto_get_version(srpc->proto);
	lck_unlock(srpc->lck);

	return version;
}
コード例 #8
0
ファイル: client.cpp プロジェクト: jpalider/supla-core
int supla_client::getName(char *buffer, int size) {
  if (size < 1) return 0;

  buffer[0] = 0;

  lck_lock(lck);
  snprintf(buffer, size, "%s", this->name);
  lck_unlock(lck);

  buffer[size - 1] = 0;
  return strnlen(buffer, size - 1);
}
コード例 #9
0
ファイル: clientlocation.cpp プロジェクト: Alambos/supla-core
bool supla_client_locations::location_exists(int Id) {

	bool result = false;

	lck_lock(lck);
	for(int a=0;a<ids_count;a++)
		if ( ids[a] == Id ) {
			result = true;
			break;
		}
	lck_unlock(lck);

	return result;
}
コード例 #10
0
ファイル: supla-client.c プロジェクト: SUPLA/supla-core
char supla_client_open(void *_suplaclient, int ChannelID, char open) {

	TCS_SuplaChannelNewValue_B value;
	TSuplaClientData *suplaclient = (TSuplaClientData *)_suplaclient;
	char result = 0;

	lck_lock(suplaclient->lck);
	if ( supla_client_registered(_suplaclient) == 1 ) {

		memset(&value, 0, sizeof(TCS_SuplaChannelNewValue_B));
		value.ChannelId = ChannelID;
		value.value[0] = open;
		result =  srpc_cs_async_set_channel_value_b(suplaclient->srpc, &value) == SUPLA_RESULT_FALSE ? 0 : 1;

	}
	lck_unlock(suplaclient->lck);


	return result;
}
コード例 #11
0
ファイル: supla-client.c プロジェクト: SUPLA/supla-core
char supla_client_set_rgbw(void *_suplaclient, int ChannelID, int color, char color_brightness, char brightness) {

	TCS_SuplaChannelNewValue_B value;
	TSuplaClientData *suplaclient = (TSuplaClientData *)_suplaclient;
	char result = 0;

	lck_lock(suplaclient->lck);
	if ( supla_client_registered(_suplaclient) == 1 ) {

		memset(&value, 0, sizeof(TCS_SuplaChannelNewValue_B));
		value.ChannelId = ChannelID;
		value.value[0] = brightness;

		value.value[1] = color_brightness;
		value.value[2] = (char)((color & 0x000000FF));       // BLUE
		value.value[3] = (char)((color & 0x0000FF00) >> 8);  // GREEN
		value.value[4] = (char)((color & 0x00FF0000) >> 16); // RED

		result =  srpc_cs_async_set_channel_value_b(suplaclient->srpc, &value) == SUPLA_RESULT_FALSE ? 0 : 1;

	}
コード例 #12
0
ファイル: clientlocation.cpp プロジェクト: Alambos/supla-core
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;

}
コード例 #13
0
ファイル: client.cpp プロジェクト: jpalider/supla-core
void supla_client::setName(const char *name) {
  lck_lock(lck);
  snprintf(this->name, SUPLA_CLIENT_NAME_MAXSIZE, "%s", name);
  this->name[SUPLA_CLIENT_NAME_MAXSIZE - 1] = 0;
  lck_unlock(lck);
}
コード例 #14
0
ファイル: srpc.c プロジェクト: SUPLA/arduino
char SRPC_ICACHE_FLASH srpc_getdata(void *_srpc, TsrpcReceivedData *rd, unsigned _supla_int_t rr_id) {

	Tsrpc *srpc = (Tsrpc*)_srpc;
	char call_with_no_data = 0;
	rd->call_type = 0;

	lck_lock(srpc->lck);

	if ( SUPLA_RESULT_TRUE == srpc_in_queue_pop(srpc, &srpc->sdp, rr_id) ) {

		rd->call_type = srpc->sdp.call_type;
		rd->rr_id = srpc->sdp.rr_id;

		// first one
		rd->data.dcs_ping = NULL;


		switch(srpc->sdp.call_type) {

		   case SUPLA_DCS_CALL_GETVERSION:
		   case SUPLA_CS_CALL_GET_NEXT:
			   call_with_no_data = 1;
			   break;

		   case SUPLA_SDC_CALL_GETVERSION_RESULT:

			   if ( srpc->sdp.data_size == sizeof(TSDC_SuplaGetVersionResult) )
                 rd->data.sdc_getversion_result = (TSDC_SuplaGetVersionResult *)malloc(sizeof(TSDC_SuplaGetVersionResult));

			   break;

	       case SUPLA_SDC_CALL_VERSIONERROR:

			   if ( srpc->sdp.data_size == sizeof(TSDC_SuplaVersionError) )
                 rd->data.sdc_version_error = (TSDC_SuplaVersionError*)malloc(sizeof(TSDC_SuplaVersionError));

			   break;

		   case SUPLA_DCS_CALL_PING_SERVER:

			   if ( srpc->sdp.data_size == sizeof(TDCS_SuplaPingServer) )
                  rd->data.dcs_ping = (TDCS_SuplaPingServer*)malloc(sizeof(TDCS_SuplaPingServer));

			   break;

		   case SUPLA_SDC_CALL_PING_SERVER_RESULT:

			   if ( srpc->sdp.data_size == sizeof(TSDC_SuplaPingServerResult) )
                  rd->data.sdc_ping_result = (TSDC_SuplaPingServerResult*)malloc(sizeof(TSDC_SuplaPingServerResult));

			   break;

		   case SUPLA_DCS_CALL_SET_ACTIVITY_TIMEOUT:

			   if ( srpc->sdp.data_size == sizeof(TDCS_SuplaSetActivityTimeout) )
                  rd->data.dcs_set_activity_timeout = (TDCS_SuplaSetActivityTimeout*)malloc(sizeof(TDCS_SuplaSetActivityTimeout));

			   break;

		   case SUPLA_SDC_CALL_SET_ACTIVITY_TIMEOUT_RESULT:

			   if ( srpc->sdp.data_size == sizeof(TSDC_SuplaSetActivityTimeoutResult) )
                  rd->data.sdc_set_activity_timeout_result = (TSDC_SuplaSetActivityTimeoutResult*)malloc(sizeof(TSDC_SuplaSetActivityTimeoutResult));

			   break;

		   case SUPLA_DS_CALL_REGISTER_DEVICE:

			   if ( srpc->sdp.data_size >= (sizeof(TDS_SuplaRegisterDevice)-(sizeof(TDS_SuplaDeviceChannel)*SUPLA_CHANNELMAXCOUNT))
					&& srpc->sdp.data_size <= sizeof(TDS_SuplaRegisterDevice) ) {

				   rd->data.ds_register_device = (TDS_SuplaRegisterDevice*)malloc(sizeof(TDS_SuplaRegisterDevice));
			   }

			   break;

		   case SUPLA_DS_CALL_REGISTER_DEVICE_B: // ver. >= 2
			   
			   if ( srpc->sdp.data_size >= (sizeof(TDS_SuplaRegisterDevice_B)-(sizeof(TDS_SuplaDeviceChannel_B)*SUPLA_CHANNELMAXCOUNT))
					&& srpc->sdp.data_size <= sizeof(TDS_SuplaRegisterDevice_B) ) {

				   rd->data.ds_register_device_b = (TDS_SuplaRegisterDevice_B*)malloc(sizeof(TDS_SuplaRegisterDevice_B));
				   
			   }

			   break;

		   case SUPLA_SD_CALL_REGISTER_DEVICE_RESULT:

			   if ( srpc->sdp.data_size == sizeof(TSD_SuplaRegisterDeviceResult) )
                  rd->data.sd_register_device_result = (TSD_SuplaRegisterDeviceResult*)malloc(sizeof(TSD_SuplaRegisterDeviceResult));
			   break;

		   case SUPLA_CS_CALL_REGISTER_CLIENT:

			   if ( srpc->sdp.data_size == sizeof(TCS_SuplaRegisterClient) )
				   rd->data.cs_register_client = (TCS_SuplaRegisterClient*)malloc(sizeof(TCS_SuplaRegisterClient));

			   break;

		   case SUPLA_SC_CALL_REGISTER_CLIENT_RESULT:

			   if ( srpc->sdp.data_size == sizeof(TSC_SuplaRegisterClientResult) )
                  rd->data.sc_register_client_result = (TSC_SuplaRegisterClientResult*)malloc(sizeof(TSC_SuplaRegisterClientResult));

			   break;

		   case SUPLA_DS_CALL_DEVICE_CHANNEL_VALUE_CHANGED:

			   if ( srpc->sdp.data_size == sizeof(TDS_SuplaDeviceChannelValue) )
				   rd->data.ds_device_channel_value = (TDS_SuplaDeviceChannelValue*)malloc(sizeof(TDS_SuplaDeviceChannelValue));

			   break;

		   case SUPLA_SD_CALL_CHANNEL_SET_VALUE:

			   if ( srpc->sdp.data_size == sizeof(TSD_SuplaChannelNewValue) )
				   rd->data.sd_channel_new_value = (TSD_SuplaChannelNewValue*)malloc(sizeof(TSD_SuplaChannelNewValue));

			   break;

		   case SUPLA_DS_CALL_CHANNEL_SET_VALUE_RESULT:

			   if ( srpc->sdp.data_size == sizeof(TDS_SuplaChannelNewValueResult) )
				   rd->data.ds_channel_new_value_result = (TDS_SuplaChannelNewValueResult*)malloc(sizeof(TDS_SuplaChannelNewValueResult));

			   break;

		   case SUPLA_SC_CALL_LOCATION_UPDATE:

			   if ( srpc->sdp.data_size >= (sizeof(TSC_SuplaLocation)-SUPLA_LOCATION_CAPTION_MAXSIZE)
					&& srpc->sdp.data_size <= sizeof(TSC_SuplaLocation) ) {
				   rd->data.sc_location = (TSC_SuplaLocation*)malloc(sizeof(TSC_SuplaLocation));
			   }

			   break;

		   case SUPLA_SC_CALL_LOCATIONPACK_UPDATE:
			   srpc_getlocationpack(srpc, rd);
			   break;

		   case SUPLA_SC_CALL_CHANNEL_UPDATE:

			   if ( srpc->sdp.data_size >= (sizeof(TSC_SuplaChannel)-SUPLA_CHANNEL_CAPTION_MAXSIZE)
					&& srpc->sdp.data_size <= sizeof(TSC_SuplaChannel) ) {
				   rd->data.sc_channel = (TSC_SuplaChannel*)malloc(sizeof(TSC_SuplaChannel));
			   }

			   break;

		   case SUPLA_SC_CALL_CHANNELPACK_UPDATE:
			   srpc_getchannelpack(srpc, rd);
			   break;

		   case SUPLA_SC_CALL_CHANNEL_VALUE_UPDATE:

			   if ( srpc->sdp.data_size == sizeof(TSC_SuplaChannelValue) )
				   rd->data.sc_channel_value = (TSC_SuplaChannelValue*)malloc(sizeof(TSC_SuplaChannelValue));

			   break;

		   case SUPLA_CS_CALL_CHANNEL_SET_VALUE:

			   if ( srpc->sdp.data_size == sizeof(TCS_SuplaChannelNewValue) )
				   rd->data.cs_channel_new_value = (TCS_SuplaChannelNewValue*)malloc(sizeof(TCS_SuplaChannelNewValue));

			   break;

		   case SUPLA_CS_CALL_CHANNEL_SET_VALUE_B:

			   if ( srpc->sdp.data_size == sizeof(TCS_SuplaChannelNewValue_B) )
				   rd->data.cs_channel_new_value_b = (TCS_SuplaChannelNewValue_B*)malloc(sizeof(TCS_SuplaChannelNewValue_B));

			   break;

		   case SUPLA_SC_CALL_EVENT:

			   if ( srpc->sdp.data_size >= (sizeof(TSC_SuplaEvent)-SUPLA_SENDER_NAME_MAXSIZE)
					&& srpc->sdp.data_size <= sizeof(TSC_SuplaEvent) ) {
				   rd->data.sc_event = (TSC_SuplaEvent*)malloc(sizeof(TSC_SuplaEvent));
			   }

			   break;

		}

		if ( rd->data.dcs_ping != NULL || call_with_no_data == 1 ) {

			if ( srpc->sdp.data_size > 0 ) {
				memcpy(rd->data.dcs_ping, srpc->sdp.data, srpc->sdp.data_size);
			}


			return lck_unlock_r(srpc->lck, SUPLA_RESULT_TRUE);
		}


		return lck_unlock_r(srpc->lck, SUPLA_RESULT_DATA_ERROR);
	}

	return lck_unlock_r(srpc->lck, SUPLA_RESULT_FALSE);
}
コード例 #15
0
ファイル: srpc.c プロジェクト: SUPLA/arduino
char SRPC_ICACHE_FLASH srpc_iterate(void *_srpc) {

	Tsrpc *srpc = (Tsrpc*)_srpc;
	char data_buffer[srpc_BUFFER_SIZE];
	char result;
	unsigned char version;

	// --------- IN ---------------
	_supla_int_t data_size = srpc->params.data_read(data_buffer, srpc_BUFFER_SIZE, srpc->params.user_params);

	if ( data_size == 0 )
		return SUPLA_RESULT_FALSE;


	lck_lock(srpc->lck);

    if ( data_size > 0
    	 && SUPLA_RESULT_TRUE != ( result = sproto_in_buffer_append(srpc->proto, data_buffer, data_size) ) ) {

    	supla_log(LOG_DEBUG, "sproto_in_buffer_append: %i, datasize: %i", result, data_size);
    	return lck_unlock_r(srpc->lck, SUPLA_RESULT_FALSE);
    }

    if ( SUPLA_RESULT_TRUE == (result = sproto_pop_in_sdp(srpc->proto, &srpc->sdp) ) ) {

    	if ( SUPLA_RESULT_TRUE == srpc_in_queue_push(srpc, &srpc->sdp) ) {

    		if ( srpc->params.on_remote_call_received ) {

    			lck_unlock(srpc->lck);
    			srpc->params.on_remote_call_received(srpc, srpc->sdp.rr_id, srpc->sdp.call_type, srpc->params.user_params, srpc->sdp.version);
    			lck_lock(srpc->lck);
    		}


    	} else {
        	supla_log(LOG_DEBUG, "ssrpc_in_queue_push error");
        	return lck_unlock_r(srpc->lck, SUPLA_RESULT_FALSE);
    	}


    } else if ( result != SUPLA_RESULT_FALSE ) {

    	if ( result == SUPLA_RESULT_VERSION_ERROR ) {

    		if ( srpc->params.on_version_error ) {

    			version = srpc->sdp.version;
    			lck_unlock(srpc->lck);

    			srpc->params.on_version_error(srpc, version, srpc->params.user_params);
    			return SUPLA_RESULT_FALSE;
    		}
    	} else {
    		supla_log(LOG_DEBUG, "sproto_pop_in_sdp error: %i", result);
    	}

    	return lck_unlock_r(srpc->lck, SUPLA_RESULT_FALSE);
    }

    // --------- OUT ---------------


    if ( srpc_out_queue_pop(srpc, &srpc->sdp, 0) == SUPLA_RESULT_TRUE
    	 && SUPLA_RESULT_TRUE != (result = sproto_out_buffer_append(srpc->proto, &srpc->sdp) )
    	 && result != SUPLA_RESULT_FALSE ) {

    		supla_log(LOG_DEBUG, "sproto_out_buffer_append error: %i", result);
    		return lck_unlock_r(srpc->lck, SUPLA_RESULT_FALSE);
    	}


    data_size = sproto_pop_out_data(srpc->proto, data_buffer, srpc_BUFFER_SIZE);

    if ( data_size != 0 ) {
    	lck_unlock(srpc->lck);
    	srpc->params.data_write(data_buffer, data_size, srpc->params.user_params);
    	lck_lock(srpc->lck);

        #ifndef __EH_DISABLED
    	if ( srpc->params.eh != 0
    		 && sproto_out_dataexists(srpc->proto) == 1 ) {

    		eh_raise_event(srpc->params.eh);
    	}
        #endif

    }

    return lck_unlock_r(srpc->lck, SUPLA_RESULT_TRUE);
}