Skip to content

Commit

Permalink
[-] Fixed error with PPP connection
Browse files Browse the repository at this point in the history
[-] Fixed error with text strings in driver duplicate receipt
  • Loading branch information
VitalyKravtsov2016 committed Mar 27, 2023
1 parent c04630b commit e45b02b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 98 deletions.
2 changes: 1 addition & 1 deletion History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

23.03.2023
27.03.2023
deviceServiceVersion = 1013693

[-] Fixed error with PPP reconnection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ private void openReceipt(OpenReceipt command) throws Exception {
private void clearLastDoc() {
docLines.clear();
File file = new File(getLastDocFilePath());
file.delete();
if (!file.delete()){
logger.error("Failed to delete file, " + getLastDocFilePath());
}
}

private void openReceipt2(int receiptType) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3254,8 +3254,8 @@ public void endFiscalReceipt(boolean printHeader) throws Exception {
}

public void printDuplicateReceipt() throws Exception {
boolean filterEnabled = printer.getParams().textReportEnabled;
printer.getParams().textReportEnabled = false;
boolean filterEnabled = filter.getEnabled();
filter.setEnabled(false);
try {
checkPrinterState(FPTR_PS_MONITOR);
if (!getCapDuplicateReceipt()) {
Expand All @@ -3280,7 +3280,7 @@ public void printDuplicateReceipt() throws Exception {
}
duplicateReceipt = false;
} finally {
printer.getParams().textReportEnabled = filterEnabled;
filter.setEnabled(filterEnabled);
}
}

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 = "692-1-g63d02e5";
public static final String VERSION = "692-2-gc04630b";
}
5 changes: 5 additions & 0 deletions Source/FiscalPrinterTest/src/PrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,11 @@ public void printFiscalReceiptDate() {
printer.beginFiscalReceipt(true);
printer.printRecItem("Item 1", 100, 1000, 1, 100, "");
printer.printRecTotal(100, 100, "1");
printer.printRecMessage("-------------------------------");
printer.printRecMessage("Подвал строка 1");
printer.printRecMessage("Подвал строка 2");
printer.printRecMessage("Подвал строка 3");
printer.printRecMessage("-------------------------------");
printer.endFiscalReceipt(false);

System.out.println("Last document number : "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,17 @@
*/
public class PPPPort implements PrinterPort, PrinterPort.IPortEvents {

enum PortStatus{Disconnected, Connecting, Connected};
private int repeatCount = 0;
private IPortEvents events;
private Socket socket = null;
private PPPStatus pppStatus;
private LocalSocket localSocket = null;
private boolean stopFlag = false;
private Thread pppPollThread = null;
private Thread dispatchThread = null;
private PPPThread pppThread = null;
private int openTimeout = 3000;
private int connectTimeout = 3000;
private int readTimeout = 3000;
private PortStatus status = PortStatus.Disconnected;
private boolean opened = false;
private boolean portOpened = false;
private String localSocketName = null;
private static CompositeLogger logger = CompositeLogger.getLogger(PPPPort.class);
Expand All @@ -62,24 +59,21 @@ public PPPPort(FptrParameters params, PrinterPort2 printerPort) {
}

public boolean isOpened() {
return status == PortStatus.Connected;
return opened;
}

public synchronized void open(int timeout) throws Exception {
if (isOpened()) return;
logger.debug("open");
connect(timeout);
waitForConnection(60000);
portOpened = true;
logger.debug("open: OK");
}

public synchronized void connect(int timeout) throws Exception
{
if (status != PortStatus.Disconnected) return;

logger.debug("connect...");
status = PortStatus.Connecting;
if (isOpened()) return;
openTimeout = timeout;
localSocketName = UUID.randomUUID().toString();

Expand All @@ -88,19 +82,17 @@ public synchronized void connect(int timeout) throws Exception
printerPort.open(timeout);
printerPort.setPortEvents(this);
startPPPThread();
logger.debug("connect: OK");
}

public void waitForConnection(int timeout) throws Exception{
long time = Calendar.getInstance().getTimeInMillis() + timeout;
for (;;)
{
if (isOpened()) return;
if (Calendar.getInstance().getTimeInMillis() > time){
noConnectionError();
}
Thread.sleep(200);
openLocalSocket(timeout);
startDispatchThread();
if (!pppThread.waitForPhase("PPP_PHASE_RUNNING", 60000)){
noConnectionError();
}
openSocket();
opened = true;
if (events != null) {
events.onConnect();
}
logger.debug("connect: OK");
}

public void openSocket() throws Exception
Expand Down Expand Up @@ -135,54 +127,10 @@ public void startPPPThread() throws Exception
}
pppThread = new PPPThread(config);
pppThread.start();
// poll thread
pppPollThread = new Thread(new Runnable() {
@Override
public void run() {
pppPollProc();
}
});
pppPollThread.start();
pppThread.waitForStatus("RUNNING", 5000);
logger.debug("startPPPThread(): OK");
}

public void pppPollProc() {
logger.debug("pppPollProc.start");
try {
while (!Thread.currentThread().isInterrupted())
{
if (status == PortStatus.Disconnected) break;
String statusJson = pppThread.getStatus();
if (!statusJson.isEmpty()) {
PPPStatus status = PPPStatus.fromJson(statusJson);
if (status != null) {
if (!status.isEqual(pppStatus)) {
pppStatus = status;
if (status.status.equals("RUNNING")) {
openLocalSocket(openTimeout);
startDispatchThread();
}
if (status.phase.equals("PPP_PHASE_RUNNING")) {
openSocket();
this.status = PortStatus.Connected;
if (events != null) {
events.onConnect();
}
}
}
}
}
Thread.sleep(1000);
}
} catch (InterruptedException e)
{
Thread.currentThread().interrupt();
} catch (Exception e) {
logger.error("pppPollProc: ", e);
}
logger.debug("pppPollProc.end");
}

public void openLocalSocket(int timeout) throws Exception {
if (localSocket != null) {
return;
Expand Down Expand Up @@ -218,7 +166,7 @@ public synchronized void close() {
public synchronized void disconnect() {
if (!isOpened()) return;

status = PortStatus.Disconnected;
opened = false;
closeSocket();
stopDispatchThread();
closeLocalSocket();
Expand All @@ -241,17 +189,6 @@ public void closeLocalSocket() {

public void stopPPPThread() {
if (pppThread == null) return;
if (pppPollThread == null) return;

pppPollThread.interrupt();
try {
pppPollThread.join();
} catch (InterruptedException e)
{
logger.error("pppPollThread ", e);
Thread.currentThread().interrupt();
}
pppPollThread = null;

pppThread.stop();
pppThread = null;
Expand Down Expand Up @@ -332,11 +269,7 @@ public void dispatchPackets() throws Exception
//logger.debug("<- PPP " + Hex.toHex(data));
OutputStream os = localSocket.getOutputStream();
if (os != null) {
try {
os.write(data, 0, count);
}finally {
os.close();
}
os.write(data, 0, count);
}
}
// read localSocket
Expand Down Expand Up @@ -405,16 +338,11 @@ public void write(byte[] b) throws Exception {
try {
open();
//logger.debug("=>> write: " + Hex.toHex(b));
OutputStream os = socket.getOutputStream();
if (os != null)
{
os.write(b);
os.close();
}
socket.getOutputStream().write(b);
return;
} catch (SocketException e)
{
} catch (SocketException e) {
logger.error("write", e);
closeSocket();
if (i == 1) {
throw e;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/android/tinyJavaPosTester/assets/jpos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,6 @@
<!-- fdoMode, 0 - disabled, 1 - enabled, 2 - on z report, 3 - disable in receipt -->
<prop name="fdoMode" type="String" value="3"/>

<prop name="duplicateReceipt" type="String" value="0"/>
<prop name="duplicateReceipt" type="String" value="1"/>
</JposEntry>
</JposEntries>

0 comments on commit e45b02b

Please sign in to comment.