Skip to content

Commit

Permalink
[-] Fixed error with disabling and enabling bluetooth adapter on BLE …
Browse files Browse the repository at this point in the history
…connection
  • Loading branch information
Vitaly Kravtsov committed Jun 28, 2022
1 parent 58fee24 commit 8ec95bf
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 99 deletions.
7 changes: 7 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
Company : SHTRIH-M www.shtrih-m.ru (495) 787-6090
Url : https://github.com/shtrih-m/javapos_shtrih

********************************************************************************

21.06.2022
deviceServiceVersion = 1013667

[-] Fixed error with disabling and enabling bluetooth adapter on BLE connection

********************************************************************************

21.06.2022
Expand Down
32 changes: 22 additions & 10 deletions Source/Core/src/com/shtrih/fiscalprinter/PrinterProtocol_1.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ public class PrinterProtocol_1 implements PrinterProtocol {
private final static byte ACK = 0x06;
private final static byte NAK = 0x15;
// maximum counters
private int maxEnqNumber = 3;
private int maxNakCommandNumber = 3;
private int maxNakAnswerNumber = 3;
private int maxAckNumber = 3;
private int maxRepeatCount = 3;
private int maxEnqNumber = 1;
private int maxNakCommandNumber = 1;
private int maxNakAnswerNumber = 1;
private int maxAckNumber = 1;
private int maxRepeatCount = 1;
private byte[] txData = new byte[0];
private byte[] rxData = new byte[0];
private final Frame frame = new Frame();
private final boolean isReliable;
private static CompositeLogger logger = CompositeLogger.getLogger(PrinterProtocol_1.class);

public PrinterProtocol_1(PrinterPort port) {
this.port = port;
isReliable = port.readParameter(PrinterPort.PARAMID_IS_RELIABLE).equalsIgnoreCase("1");
}

private void portWrite(int b) throws Exception {
Expand Down Expand Up @@ -278,7 +280,9 @@ public void connect() throws Exception {
}

public void setMaxEnqNumber(int value) {
maxEnqNumber = value;
if (!isReliable) {
maxEnqNumber = value;
}
}

public int getMaxEnqNumber() {
Expand All @@ -302,19 +306,27 @@ public int getMaxRepeatCount() {
}

public void setMaxNakCommandNumber(int value) {
maxNakCommandNumber = value;
if (!isReliable) {
maxNakCommandNumber = value;
}
}

public void setMaxNakAnswerNumber(int value) {
maxNakAnswerNumber = value;
if (!isReliable) {
maxNakAnswerNumber = value;
}
}

public void setMaxAckNumber(int value) {
maxAckNumber = value;
if (!isReliable) {
maxAckNumber = value;
}
}

public void setMaxRepeatCount(int value) {
maxRepeatCount = value;
if (!isReliable) {
maxRepeatCount = value;
}
}

public byte[] getTxData() {
Expand Down
10 changes: 7 additions & 3 deletions Source/Core/src/com/shtrih/fiscalprinter/PrinterProtocol_2.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PrinterProtocol_2 implements PrinterProtocol {
private final Frame frame = new Frame();
byte[] rx = {};
private int byteTimeout = 100;
private int maxRepeatCount = 3;
private int maxRepeatCount = 1;
private final boolean isReliable;
private static CompositeLogger logger = CompositeLogger.getLogger(PrinterProtocol_2.class);

Expand All @@ -45,12 +45,16 @@ public void connect() throws Exception

public void send(PrinterCommand command) throws Exception
{
int repeatCount = maxRepeatCount;
if (isReliable){
repeatCount = 1;
}
synchronized (port.getSyncObject())
{
for (int i = 0; i < maxRepeatCount; i++)
for (int i = 0; i < repeatCount; i++)
{
if (i > 0){
logger.debug(String.format("Retry %d/%d", i ,maxRepeatCount));
logger.debug(String.format("Retry %d/%d", i ,repeatCount));
}
if (sendCommand(command, i + 1)) {
return;
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public interface SMFiscalPrinter {

public LongPrinterStatus connect() throws Exception;

public void disconnect();

public void check(int errorCode) throws Exception;

public void execute(PrinterCommand command) throws Exception;
Expand Down Expand Up @@ -534,6 +536,8 @@ public ReadOperationRegister readOperationRegister2(int number)

public FSReadSerial fsReadSerial() throws Exception;

public String getFullSerial();

public String readFullSerial() throws Exception;

public FSReadExpDate fsReadExpDate() throws Exception;
Expand Down
56 changes: 37 additions & 19 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ enum Boolean {
public boolean isTableTextCleared = false;
private final Map<Integer, Integer> taxRates = new HashMap<Integer, Integer>();
private int printMode = PrinterConst.PRINT_MODE_ENABLED;
private boolean connected = false;

public SMFiscalPrinterImpl(PrinterPort port, PrinterProtocol device,
FptrParameters params) {
Expand Down Expand Up @@ -236,8 +237,11 @@ public void deviceExecute(PrinterCommand command) throws Exception {
}

try {
if (connected){
port.open(getParams().portOpenTimeout);
}
device.send(command);
} catch (IOException e) {
} catch (Exception e) {
port.close();
throw new DeviceException(PrinterConst.SMFPTR_E_NOCONNECTION, e.getMessage());
}
Expand Down Expand Up @@ -369,10 +373,16 @@ public LongPrinterStatus connect() throws Exception {
}
check(readDeviceMetrics());
model = selectPrinterModel(getDeviceMetrics());
readFullSerial();
connected = true;
return checkEcrMode();
}
}

public void disconnect() {
connected = false;
}

private void beforeCommand(PrinterCommand command) throws Exception {
for (IPrinterEvents printerEvents : events) {
try {
Expand Down Expand Up @@ -3446,6 +3456,11 @@ public FSReadSerial fsReadSerial() throws Exception {
return command;
}

@Override
public String getFullSerial() {
return serial;
}

@Override
public String readFullSerial() throws Exception {
if (serial.isEmpty()) {
Expand Down Expand Up @@ -5273,28 +5288,31 @@ public void setPrintMode(int value) {
this.printMode = value;
}

public synchronized void sendFDODocuments() throws Exception {
byte[] data = fsReadBlockData();
if (data.length == 0) {
return;
}
// P-protocol version 0x0102 -> 0x0120
if ((data.length >= 30) && (data[6] == 0x01)
&& (data[28] == 0) && (data[29] == 0)) {
if (data[7] == 0x01) {
data[7] = 0x10;
public synchronized void sendFDODocuments() throws Exception
{
while (true) {
byte[] data = fsReadBlockData();
if (data.length == 0) {
return;
}
if (data[7] == 0x02) {
data[7] = 0x20;

// P-protocol version 0x0102 -> 0x0120
if ((data.length >= 30) && (data[6] == 0x01)
&& (data[28] == 0) && (data[29] == 0)) {
if (data[7] == 0x01) {
data[7] = 0x10;
}
if (data[7] == 0x02) {
data[7] = 0x20;
}
}
}

byte[] answer = sendFDOData(data);
if (answer.length == 0) {
return;
byte[] answer = sendFDOData(data);
if (answer.length == 0) {
return;
}
fsWriteBlockData(answer);
}
fsWriteBlockData(answer);

}

private byte[] sendFDOData(byte[] data) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public LongPrinterStatus connect() throws Exception {
return null;
}

public void disconnect() {
}

public void check(int errorCode) throws Exception {
}

Expand Down Expand Up @@ -907,6 +910,11 @@ public FSReadSerial fsReadSerial() throws Exception {
return null;
}

@Override
public String getFullSerial(){
return null;
}

@Override
public String readFullSerial() throws Exception {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ public void setDeviceEnabled(boolean deviceEnabled) throws Exception {
stopFDOService();
stopJsonUpdateService();
stopFirmwareUpdaterService();
getPrinter().disconnect();
connected = false;
setPowerState(JPOS_PS_UNKNOWN);
}
Expand Down Expand Up @@ -4513,12 +4514,8 @@ protected JposEntry createJposEntry(String logicalName,
}

public void saveProperties() {
if (params.fastConnect) {
return;
}

try {
String serial = "FiscalPrinter_" + getPrinter().readFullSerial();
String serial = "FiscalPrinter_" + getPrinter().getFullSerial();
XmlPropWriter writer = new XmlPropWriter("FiscalPrinter",
serial);
writer.write(getPrinterImages());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.shtrih.util;

public class ServiceVersion {
public static final String VERSION = "665";
public static final String VERSION = "666";
}
Loading

0 comments on commit 8ec95bf

Please sign in to comment.