Skip to content

Commit

Permalink
[+] Added directIO command SMFPTR_DIO_CHECK_FDO_CONNECTION = 0x93 to
Browse files Browse the repository at this point in the history
    check connection to FDO server
  • Loading branch information
Kravtsov Vitaly committed Jan 20, 2023
1 parent 517f990 commit 86cd47a
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 3 deletions.
8 changes: 8 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
Company : SHTRIH-M www.shtrih-m.ru (495) 787-6090
Url : https://github.com/shtrih-m/javapos_shtrih

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

20.01.2023
deviceServiceVersion = 1013686

[+] Added directIO command SMFPTR_DIO_CHECK_FDO_CONNECTION = 0x93 to
check connection to FDO server

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

16.01.2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,4 +738,5 @@ public ReadOperationRegister readOperationRegister2(int number)

public void writeTLVItems() throws Exception;

public void checkFDOConnection() throws Exception;
}
15 changes: 15 additions & 0 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5280,6 +5280,8 @@ public synchronized void sendFDODocuments() throws Exception {
return;
}

checkFDOConnection();

while (true) {
byte[] data = fsReadBlockData();
if (data.length == 0) {
Expand All @@ -5305,6 +5307,19 @@ public synchronized void sendFDODocuments() throws Exception {
}
}


public void checkFDOConnection() throws Exception
{
logger.debug("testOFDConnection");
FDOParameters parameters = getFDOParameters();
Socket socket = new Socket();
socket.setTcpNoDelay(true);
socket.setSoTimeout(parameters.getTimeoutInMSec());
socket.connect(new InetSocketAddress(parameters.getHost(), parameters.getPort()));
socket.close();
logger.debug("testOFDConnection: OK");
}

private byte[] sendFDOData(byte[] data) throws Exception {
FDOParameters parameters = getFDOParameters();
logger.debug(String.format("FDO %s:%d, connection timeout %d ms",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1317,4 +1317,7 @@ public void sendFDODocuments() throws Exception{

public void writeTLVItems() throws Exception{
}

public void checkFDOConnection() throws Exception{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2475,4 +2475,9 @@ public String[] readCommStatus() throws Exception
directIO(SmFptrConst.SMFPTR_DIO_FS_READ_COMM_STATUS, null, lines);
return lines;
}

public void checkFDOConnection() throws Exception{
directIO(SmFptrConst.SMFPTR_DIO_CHECK_FDO_CONNECTION, null, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,9 @@ private SmFptrConst() {
// Read communication status
public static final int SMFPTR_DIO_FS_READ_COMM_STATUS = 0x92;

// Check FDO connection
public static final int SMFPTR_DIO_CHECK_FDO_CONNECTION = 0x93;

// ///////////////////////////////////////////////////////////////////
// Parameter constants for directIO commands:
// FPTR_DIO_GET_DRIVER_PARAMETER,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.shtrih.jpos.fiscalprinter.directIO;

/**
*
* @author V.Kravtsov
*/

import com.shtrih.jpos.fiscalprinter.FiscalPrinterImpl;
import com.shtrih.fiscalprinter.command.FSReadCommStatus;
import com.shtrih.fiscalprinter.command.PrinterDate;
import com.shtrih.fiscalprinter.command.PrinterTime;
import com.shtrih.jpos.DIOUtils;
import com.shtrih.jpos.fiscalprinter.JposFiscalPrinterDate;

public class DIOCheckFDOConnection extends DIOItem {

public DIOCheckFDOConnection(FiscalPrinterImpl service) {
super(service);
}

public void execute(int[] data, Object object) throws Exception
{
service.getPrinter().checkFDOConnection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ public void directIO(int command, int[] data, Object object)
new DIOReadCommStatus(service).execute(data, object);
break;

case SmFptrConst.SMFPTR_DIO_CHECK_FDO_CONNECTION:
new DIOCheckFDOConnection(service).execute(data, object);
break;

default:
throw new JposException(JposConst.JPOS_E_ILLEGAL, Localizer.getString(Localizer.invalidParameterValue) + ", command");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ public void directIO(int command, int[] data, Object object)
new DIOReadCommStatus(service).execute(data, object);
break;

case SmFptrConst.SMFPTR_DIO_CHECK_FDO_CONNECTION:
new DIOCheckFDOConnection(service).execute(data, object);
break;

default:
throw new JposException(JposConst.JPOS_E_ILLEGAL, Localizer.getString(Localizer.invalidParameterValue) + ", command");
}
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 = "684-1-g85df88f1";
public static final String VERSION = "685";
}
6 changes: 4 additions & 2 deletions Source/FiscalPrinterTest/src/PrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,9 @@ public void printFiscalReceipt() {
*/

//printFiscalReceiptDate();
testRefundReceipt();
//testRefundReceipt();

printer.checkFDOConnection();

} catch (Exception e) {
e.printStackTrace();
Expand All @@ -1082,7 +1084,7 @@ public void testRefundReceipt() {
printer.resetPrinter();
printer.setFiscalReceiptType(FPTR_RT_REFUND);
printer.beginFiscalReceipt(true);
printer.printRecItemRefund("Описание отсутствует", 1, 1000000, 1, 1, "");
printer.printRecItemRefund("Описание отсутствует", 0, 1000000, 1, 1, "");
printer.printRecTotal(1, 1, "14");
printer.endFiscalReceipt(false);
} catch (Exception e) {
Expand Down

0 comments on commit 86cd47a

Please sign in to comment.