Skip to content

Commit

Permalink
[-] Fixed error with PPP port close
Browse files Browse the repository at this point in the history
  • Loading branch information
Kravtsov Vitaly committed Dec 13, 2022
1 parent 38e6971 commit 4ca7017
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 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

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

13.12.2022
deviceServiceVersion = 1013682

[-] Fixed error with PPP port close

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

05.12.2022
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void stop() {
} catch (Exception e) {
logger.error(e);
}
logger.debug("PPP thread stopped");
}

public boolean waitForContext(long timeout, long timeToSleep) throws InterruptedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void stop() throws Exception {
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(port);
while (!thread.isInterrupted()) {
while (!Thread.currentThread().isInterrupted()) {
try {
serverSocket.setSoTimeout(AcceptTimeout);
Socket socket = serverSocket.accept();
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 = "681";
public static final String VERSION = "681-1-g38e69718";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.shtrih.util.CompositeLogger;
import com.shtrih.util.Localizer;
import com.shtrih.util.StaticContext;
import com.shtrih.util.Hex;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -35,6 +36,7 @@ public class PPPPort implements PrinterPort, PrinterPort.IPortEvents {
private IPortEvents events;
private Socket socket = null;
private LocalSocket localSocket = null;
private boolean stopFlag = false;
private Thread dispatchThread = null;
private PPPThread pppThread = null;
private int openTimeout = 3000;
Expand Down Expand Up @@ -67,7 +69,9 @@ public synchronized void open(int timeout) throws Exception {
logger.debug("open: OK");
}

public synchronized void connect(int timeout) throws Exception {
public synchronized void connect(int timeout) throws Exception
{
logger.debug("connect...");
if (isOpened()) return;
openTimeout = timeout;
localSocketName = UUID.randomUUID().toString();
Expand All @@ -85,6 +89,7 @@ public synchronized void connect(int timeout) throws Exception {
if (events != null) {
events.onConnect();
}
logger.debug("connect: OK");
}

public void openSocket() throws Exception
Expand All @@ -103,7 +108,9 @@ public void openSocket() throws Exception
}
}

public void startPPPThread() throws Exception {
public void startPPPThread() throws Exception
{
logger.debug("startPPPThread()...");
if (pppThread != null) {
return;
}
Expand All @@ -122,6 +129,7 @@ public void startPPPThread() throws Exception {
pppThread = new PPPThread(config);
pppThread.start();
pppThread.waitForStatus("RUNNING", 5000);
logger.debug("startPPPThread(): OK");
}

public void openLocalSocket(int timeout) throws Exception {
Expand Down Expand Up @@ -191,6 +199,7 @@ public void startDispatchThread() {
if (dispatchThread != null) return;

logger.debug("startDispatchThread");
stopFlag = false;
dispatchThread = new Thread(new Runnable() {
@Override
public void run() {
Expand All @@ -202,13 +211,16 @@ public void run() {
}

public void stopDispatchThread() {
if (dispatchThread == null) return;

logger.debug("stopDispatchThread");
if (dispatchThread == null) return;
stopFlag = true;
dispatchThread.interrupt();
try {
dispatchThread.join();
} catch (InterruptedException e) {
} catch (InterruptedException e)
{
logger.error("stopDispatchThread ", e);
Thread.currentThread().interrupt();
}
dispatchThread = null;
logger.debug("stopDispatchThread: OK");
Expand All @@ -233,18 +245,23 @@ public void closeSocket() {
public void dispatchProc() {
logger.debug("dispatchProc.start");
try {
while (true) {
while (!stopFlag)
{
Thread.sleep(0);
dispatchPackets();
}
} catch (InterruptedException e) {
} catch (InterruptedException e)
{
logger.error("dispatchProc: ", e);
Thread.currentThread().interrupt();
} catch (Exception e) {
logger.error("dispatchProc: ", e);
}
logger.debug("dispatchProc.end");
}

public void dispatchPackets() throws Exception {
public void dispatchPackets() throws Exception
{
int count;
byte[] data;

Expand All @@ -256,7 +273,6 @@ public void dispatchPackets() throws Exception {
OutputStream os = localSocket.getOutputStream();
if (os != null) {
os.write(data, 0, count);
os.flush();
}
}
// read localSocket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,12 @@ protected String doInBackground(Void... params) {
printer.setLibraryContext(getApplicationContext());
// printer.addStatusUpdateListener(new FptrEventListener());
printer.claim(3000);
/*
for (int i=0;i<10;i++){
printer.setDeviceEnabled(true);
printer.setDeviceEnabled(false);
}
*/
printer.setDeviceEnabled(true);
model.ScocUpdaterStatus.set("");
printer.setParameter3(SmFptrConst.SMFPTR_DIO_PARAM_FIRMWARE_UPDATE_OBSERVER, this.params.observer);
Expand Down

0 comments on commit 4ca7017

Please sign in to comment.