Reputation: 1
i have a cardlan reader https://es.cardlangroup.com/products/bus-card-reader-and-validator is androdi 5.3 Lollipop API 22
works process of the apk is this:
we have 3 problems.
any ideas?
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.test">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
tools:targetApi="31" >
<activity android:name=".activities.MainActivity" android:exported="true"
tools:ignore="MissingClass">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name=".broadcast.BootReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<receiver android:name=".broadcast.CheckConnectivity" android:exported="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" tools:ignore="BatteryLife" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
</intent-filter>
</receiver>
</application>
</manifest>
package com.example.test.activities;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.cardlan.twoshowinonescreen.CardLanDevCtrl;
import com.cardlan.twoshowinonescreen.CardLanSpiHelper;
import com.cardlan.utils.ByteUtil;
import com.example.test.R;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class MainActivity extends Activity implements CardLanSpiHelper.SpiCallBackLinstener {
CardLanDevCtrl mCardLanDevCtrl = new CardLanDevCtrl();
FileInputStream mFileInputStream;
byte[] buffer = new byte[32];
int size = 0;
private static final String procpath = "/proc/gpio_set/rp_gpio_set";
private static final String open_led_red = "d_26_0_1";
private static final String close_led_red = "d_26_0_0";
private static final String open_led_green = "c_5_1_1";
private static final String close_led_green = "c_5_1_0";
private static final String open_bee_voice = "c_24_1_1";
private static final String close_bee_voice = "c_24_1_0";
TextView qr;
TextView qr2;
TextView mensaje;
String qr4;
String fraccionamiento = "XXXXXX";
String URL;
private CardLanSpiHelper mSpiHelper;
private TextView spireceiver;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
setContentView(R.layout.main_activity);
if (mSpiHelper == null) {
mSpiHelper = new CardLanSpiHelper();
mSpiHelper.setSpiCallBackLinstener(this);
mSpiHelper.start();
}
mensaje = (TextView) findViewById(R.id.mensaje);
qr = (TextView) findViewById(R.id.qr);
qr2 = (TextView) findViewById(R.id.qr2);
spireceiver = findViewById(R.id.psam_tv);
new ReadThread().start();
}
// Inicio de programación del relay
@Override
public void receiveKeyCode(String keyCode, byte keyByte) {
if (ByteUtil.notNull(keyCode)) {
Log.d("keyCode", "keyCode = " + keyCode + ",keyBtye = " + ByteUtil.byteToHexString(keyByte));
}
}
@Override
public void receivePasmData(String code, final byte[] respondBuff) {
if (ByteUtil.notNull(respondBuff)) {
Log.d("respondBuff", "respondBuff = " + ByteUtil.byteArrayToHexString(respondBuff));
if ("pasm".equals(code)) {
if (respondBuff.length < 8) {
return;
}
byte head = respondBuff[0];
byte dev = respondBuff[1];
byte cmd = respondBuff[2];
byte ret_len = respondBuff[3];
byte end = respondBuff[7];
byte[] ret = ByteUtil.copyBytes(respondBuff, 8, ret_len);
byte[] mReadLength;
switch (cmd) {
case 0x01: { //open
if (ByteUtil.byteArrayToIntHighToLow(ret) != 0) {
return;
}
//设置波特率;
mSpiHelper.setBaudrate(ByteUtil.byteToHex(dev), "2580");
}
// break;
// case 0x02: {
//
// }
break;
case 0x03: {
//读数据(spi),获取可读数据长度;
mReadLength = mSpiHelper.getCanReadData(ByteUtil.byteToHex(dev));
}
break;
case 0x04: {
runOnUiThread(() -> {
if (respondBuff[3] == 0x00 && respondBuff[4] == 0x00 && respondBuff[5] == 0x00 && respondBuff[6] == 0x00) {
return;
}
String s_msg = ByteUtil.byteArrayToHexString(respondBuff);
String value = s_msg.substring(16);
});
}
break;
case 0x05: {
//写入psam卡;
mSpiHelper.writeScData(ByteUtil.byteToHex(dev), "00B0960006");
}
break;
case 0x07: {
mReadLength = ByteUtil.copyBytes(respondBuff, 3, 1);
if (mReadLength[0] == 0) {
return;
}
byte[] mReadData = ByteUtil.copyBytes(respondBuff, 8, mReadLength[0]);
if (ByteUtil.byteArrayToIntHighToLow(mReadData) == 0) {
return;
}
byte[] tmpbytes = mSpiHelper.readScData(ByteUtil.byteToHex(dev), mReadData);
}
break;
case 0x08: {
// if (ByteUtil.byteArrayToIntHighToLow(ret) != 0) {
// return;
// }
//冷启动复位;
mSpiHelper.coldStart(ByteUtil.byteToHex(dev));
}
break;
default: {
}
break;
}
}
}
}
@Override
public void receiveSpiData(String code, final byte[] respondBuff) {
if (ByteUtil.notNull(respondBuff)) {
runOnUiThread(() -> spireceiver.append(ByteUtil.byteArrayToHexString(respondBuff) + " "));
Log.d("respondBuff", "respondBuff = " + ByteUtil.byteArrayToHexString(respondBuff));
}
}
@Override
public void receiveUpmcu(String s, byte[] bytes) {
}
@Override
public void receiveMcuConfig(String s, byte[] bytes) {
}
// Fin de programación del relay
// Peticion GET comienza aqui
public static class GetXMLTask extends AsyncTask<String, Void, String> {
public interface AsyncResponse {
void onResponseListener(String acceso, String result);
}
public AsyncResponse response;
private String fraccionamiento;
private String qr4 = "";
public GetXMLTask(AsyncResponse response, String fraccionamiento, String qr4) {
this.response = response;
this.fraccionamiento = fraccionamiento;
this.qr4 = qr4;
}
@Override
protected String doInBackground(String... urls) {
String output = null;
for (String url : urls) {
output = getOutputFromUrl(url);
}
return output;
}
public String getOutputFromUrl(String url) {
StringBuffer output = new StringBuffer("");
try {
InputStream stream = getHttpConnection(url);
BufferedReader buffer = new BufferedReader(
new InputStreamReader(stream));
String s;
while ((s = buffer.readLine()) != null)
output.append(s);
} catch (IOException e1) {
e1.printStackTrace();
}
return output.toString();
}
// Makes HttpURLConnection and returns InputStream
public InputStream getHttpConnection(String urlString)
throws IOException {
InputStream stream = null;
URL url = new URL("http://192.168.1.1/lectortotem.php?idregistro=" + qr4);
URLConnection connection = url.openConnection();
try {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setRequestMethod("GET");
httpConnection.connect();
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
stream = httpConnection.getInputStream();
}
//Nueva linea agregada
else{
stream = httpConnection.getInputStream();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return stream;
}
public void onPostExecute(String output) {
try {
JSONObject jObject = new JSONObject(output);
String aJsonString = jObject.getString("status");
String result = jObject.getString("result");
Log.d("JSON Object", aJsonString);
response.onResponseListener(aJsonString, result);
// JSON_RESULT = aJsonString;
//Toast.makeText(MainActivity.this, JSON_RESULT, Toast.LENGTH_LONG).show();
//tvResult.setText(aJsonString);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
//Peticion GET termina aquí
private class ReadThread extends Thread {
@Override
public void run() {
super.run();
mensaje.setText("WELCOME, SCAN YOUR QR");
mensaje.setBackgroundColor(Color.parseColor("#4CAF50"));
FileDescriptor mFd = mCardLanDevCtrl.callSerialOpen("/dev/ttyAMA4", 115200, 0);
mFileInputStream = new FileInputStream(mFd);
while (!isInterrupted()) {
try {
if (mFileInputStream == null) return;
size = mFileInputStream.read(buffer);
runOnUiThread(() -> {
if (size > 0) {
//Buzzer
callProc(procpath, open_bee_voice);
callProc(procpath, close_bee_voice);
//Validar conexión a internet
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
mensaje.setText("WELCOME, SCAN YOUR QR");
mensaje.setBackgroundColor(Color.parseColor("#4CAF50"));
callProc(procpath, close_led_red);
//qr.setText("QR LEÍDO " + new String(buffer));
qr2.setText(new String(buffer));
qr4 = qr2.getText().toString().trim();
// Conexion a internet
new GetXMLTask((acceso , result)-> {
//Verifica string de la cadena
if (acceso.equals("ok")) {
// MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.open);
MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.ok);
mp.setVolume(1, 1);
mp.start();
//Encender led verde
callProc(procpath, open_led_green);
//Alert y diseño(toast_layout)
Toast toast4 = new Toast(getApplicationContext());
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.lytLayout));
TextView txtMsg = (TextView) layout.findViewById(R.id.txtMensaje);
txtMsg.setText("ACCESS CORRECT");
toast4.setDuration(Toast.LENGTH_LONG);
toast4.setView(layout);
toast4.show();
//Encender relay
if (mSpiHelper != null) {
byte[] arg = "A_08".getBytes();
//byte[] arg1 = {'B','0','6'};
//byte[] str_arg_len = new byte[4];
byte[] str_arg_len = {0x00, 0x00, 0x00, 0x00};
str_arg_len[0] = (byte) arg.length;
mSpiHelper.write((byte) 0x10, (byte) 0x01, str_arg_len, arg);
}
//Pausar hilo
try {
sleep(2500);
} catch (InterruptedException e) {
e.printStackTrace();
}
callProc(procpath, close_led_green);
//Apagar relay
if (mSpiHelper != null) {
byte[] arg = "A_08".getBytes();
//byte[] arg1 = {'B','0','6'};
byte[] str_arg_len = {0x00, 0x00, 0x00, 0x00};
str_arg_len[0] = (byte) arg.length;
mSpiHelper.write((byte) 0x10, (byte) 0x02, str_arg_len, arg);
}
} else {
MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.error);
mp.setVolume(0.5f, 0.5f);
mp.start();
// Encender led rojo
callProc(procpath, open_led_red);
//Segundo alert y diseño(toast_layout2)
Toast toast3 = new Toast(getApplicationContext());
LayoutInflater inflater2 = getLayoutInflater();
View layout2 = inflater2.inflate(R.layout.toast_layout2,
(ViewGroup) findViewById(R.id.lytLayout2));
TextView txtMsg2 = (TextView) layout2.findViewById(R.id.txtMensaje2);
txtMsg2.setText(result);
// txtMsg2.setText("QR INVALID " + acceso);
//txtMsg2.append(acceso);
toast3.setDuration(Toast.LENGTH_LONG);
toast3.setView(layout2);
toast3.show();
callProc(procpath, close_led_red);
}
}, fraccionamiento, qr4).execute(URL);
} else {
//Mensaje en caso de que no tengamos conexión a internet
mensaje.setText("OUR OF SERVICE, NO INTERNET:(");
mensaje.setBackgroundColor(Color.parseColor("#F44336"));
callProc(procpath, open_led_red);
}
}
});
} catch (IOException e) {
e.printStackTrace();
return;
}
}
}
//Función de los leds
public void callProc(String procpath, String cmd) {
writeProc(procpath, cmd.getBytes());
try {
//Tiempo de lectura
sleep(400);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private String writeProc(String path, byte[] buffer) {
try {
File file = new File(path);
FileOutputStream fos = new FileOutputStream(file);
fos.write(buffer);
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "write error!";
}
return (buffer.toString());
}
}
}
LOG CAT ANDROID
https://encer.mx/logs.pdf
We want to fix the bug and the apk can do this
apk kiosk mode - always on top on screen - internet go offline appears and send a message, go online dessapears message we can scan a QR with +17 lenght
Upvotes: 0
Views: 63