В приведенном ниже коде кнопка сохранения вызывает sendCommandToBleService()
:
@OnClick(R.id.saveConfig)
public void onClick() {
sendCommandToBleService();
}
В этом методе первая проверка состоит в том, есть ли какие-либо значения, просто показывающие тост-сообщение.
Передача команд типа pollnumber, geoloaction, ...
.
Эти команды печатаются нормально.
После этого, используя bathAh,bathWatt
, передавая в качестве параметра другой метод:
private void sendCommandToBleService() {
String pollNumber = mPollNumber.getText().toString();
String geoLocation = mGeoLocation.getText().toString();
String luminairePower = mLuminourPower.getText().toString();
String projectName = mProjectName.getText().toString();
String battAh = mBatteryAh.getText().toString();
String pannelWatt = mPannelWatt.getText().toString();
if (TextUtils.isEmpty(pollNumber)) {
Toast.makeText(LightConfigurationActivity.this, R.string.poll_number_blank, Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(geoLocation) || geoLocation.equalsIgnoreCase("SET")) {
Toast.makeText(LightConfigurationActivity.this, R.string.geoLocation_blank, Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(luminairePower) || luminairePower.equalsIgnoreCase("SET")) {
Toast.makeText(LightConfigurationActivity.this, R.string.luminour_power_empty, Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(projectName)) {
Toast.makeText(LightConfigurationActivity.this, R.string.project_name_blank, Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(battAh)) {
Toast.makeText(LightConfigurationActivity.this, R.string.battery_ah_blank, Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(pannelWatt)) {
Toast.makeText(LightConfigurationActivity.this, R.string.pannel_watt_blank, Toast.LENGTH_SHORT).show();
return;
}
makeDefaultValues(pollNumber, geoLocation, luminairePower, projectName, battAh, pannelWatt);
if (battAh.length() == 1) {
battAh = "00" + battAh;
} else if (battAh.length() == 2) {
battAh = "0" + battAh;
}
if (pannelWatt.length() == 1) {
pannelWatt = "00" + pannelWatt;
} else if (pannelWatt.length() == 2) {
pannelWatt = "0" + pannelWatt;
}
sendCommandsToBleService(battAh,pannelWatt);
}
В приведенном ниже методе печать в logcat работает нормально:
private void sendCommandsToBleService(String batAhValue,String pannellwattValue) {
String command = mSolarController.generatePacket("pol " + mPollNumber.getText().toString(), "00");
String longCmd = mPref.getString(Constants.LAT_COMMAND, "");
String latCmd = mPref.getString(Constants.LONG_COMMAND, "");
String firstTimerCmd = mPref.getString(Constants.TIMER_ONE_CMD, "");
String secondTimerCmd = mPref.getString(Constants.TIMER_TWO_CMD, "");
String projectCmd = mSolarController.generatePacket("pro " + mProjectName.getText().toString(), "00");
String batAh = mSolarController.generatePacket("battah " + batAhValue, "00");
String pannelWatt = mSolarController.generatePacket("panelw " + pannellwattValue, "00");
String wattCommand = mPref.getString(Constants.BRIGHTNESS_CMD, "");
String luminaryWatt = mPref.getString(Constants.LUMINOURE_WATT_COMMAND, "");
mBleService.addCommandToQue(command);
mBleService.addCommandToQue(longCmd);
mBleService.addCommandToQue(latCmd);
mBleService.addCommandToQue(firstTimerCmd);
mBleService.addCommandToQue(secondTimerCmd);
mBleService.addCommandToQue(projectCmd);
mBleService.addCommandToQue(batAh);
mBleService.addCommandToQue(pannelWatt);
mBleService.addCommandToQue(wattCommand);
mBleService.addCommandToQue(luminaryWatt);
showProgressDialog();
mBleService.sendCommandToBle();
}
С broadcastreceiver
я не получаю никакого ответа. Я получаю ACTION_NO_RESPONSE_FOUND_TERMINATE
и progressdialog
меня уволили.
private BroadcastReceiver mBroadCastReciever = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equalsIgnoreCase(BleService.SAMPLE_RESPONSE_FOUND)) {
Toast.makeText(LightConfigurationActivity.this, "Response found is : "+intent.getStringExtra(BleService.COMMAND_RESPONSE), Toast.LENGTH_SHORT).show();
}
switch (action) {
case BleService.ACTION_LAST_RESPONSE_FOUND:
if (mProgressDialog != null) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mProgressDialog.dismiss();
showSuccessPopUp();
}
},15000);
}
break;
case BleService.ACTION_CHECKSUM_MATCH_FAILED:
if (mIsActivityRunning) {
resendconfig();
}
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
break;
case BleService.ACTION_GAT_FAILED_TO_RECIEVE_ACKNOWLEDGMENT:
/**
* ToDo : Need to remove Toast notification.
*/
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
if (mIsActivityRunning) {
showAlertDialog(getString(R.string.failed_to_get_response_from_device));
}
break;
case BleService.ACTION_NO_RESPONSE_FOUND_TERMINATE:
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
Toast.makeText(context, "Failed to get acknowledgment. Please try again...", Toast.LENGTH_SHORT).show();
break;
case BleService.ACTION_GATT_DISCONNECTED:
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
Toast.makeText(LightConfigurationActivity.this, R.string.disconnected, Toast.LENGTH_SHORT).show();
break;
}
}
};
Может ли кто-нибудь помочь мне решить эту проблему?