Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	History.txt
  • Loading branch information
VitalyKravtsov2016 committed Mar 15, 2017
2 parents 1021f1f + d156d71 commit 8af6e39
Show file tree
Hide file tree
Showing 24 changed files with 849 additions and 276 deletions.
8 changes: 8 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

[-] Fixed error with last item in printRecItem method

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

March 13 2017, 15:06
deviceServiceVersion = 1013392

[+] Added stripExceptionDetails parameter
[+] Added FSSender

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

March 6 2017, 15:42
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ private byte[] readAnswer(int timeout) throws Exception {
int enqNumber = 0;
int nakCount = 0;
for (;;) {
Logger2.logTimeout(logger, timeout + byteTimeout);
port.setTimeout(timeout + byteTimeout);
// STX
while (portReadByte() != STX) {
}
// set byte timeout
Logger2.logTimeout(logger, byteTimeout);
port.setTimeout(byteTimeout);
// data length
int dataLength = portReadByte() + 1;
Expand Down Expand Up @@ -180,6 +182,7 @@ private byte[] send(byte[] data, int timeout) throws Exception {
int enqNumber = 0;

for (;;) {
Logger2.logTimeout(logger, byteTimeout);
port.setTimeout(byteTimeout);
portWrite(ENQ);
enqNumber++;
Expand Down Expand Up @@ -214,7 +217,7 @@ private byte[] send(byte[] data, int timeout) throws Exception {
}
}

public byte[] sendCommand(byte[] data, int timeout)
private byte[] sendCommand(byte[] data, int timeout)
throws Exception {
txData = frame.encode(data);
byte[] rx = send(txData, timeout);
Expand All @@ -228,6 +231,7 @@ public void connect() throws Exception {

for (;;) {
try {
Logger2.logTimeout(logger, byteTimeout);
port.setTimeout(byteTimeout);
portWrite(ENQ);

Expand Down Expand Up @@ -261,7 +265,7 @@ public void connect() throws Exception {
}
}

public void sendCommand(PrinterCommand command) throws Exception {
private void sendCommand(PrinterCommand command) throws Exception {
int repeatCount = 0;
while (true) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public synchronized boolean sendCmd(PrinterCommand command, int retryNum)
throws Exception {
port.open(0);
int timeout = command.getTimeout();
Logger2.logTimeout(logger, timeout + byteTimeout);
port.setTimeout(timeout + byteTimeout);
try {
sendCommand(command.encodeData());
Expand Down Expand Up @@ -106,6 +107,7 @@ public void synchronizeFrames(int timeout) throws Exception {
if (isSynchronized) {
return;
}
Logger2.logTimeout(logger, timeout);
port.setTimeout(timeout);
for (int i = 0; i < maxRepeatCount; i++) {
try {
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 @@ -522,5 +522,9 @@ public ReadOperationRegister readOperationRegister2(int number)
public void printReceiptHeader(String docName) throws Exception;

public String getReceiptName(int receiptType);

byte[] fsReadBlockData() throws Exception;

void fsWriteBlockData(byte[] data) throws Exception;
}

73 changes: 71 additions & 2 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2808,8 +2808,7 @@ public int fsWriteTLV(byte[] tlv) throws Exception {
}

public FSReadBufferStatus fsReadBufferStatus() throws Exception {
FSReadBufferStatus command = new FSReadBufferStatus();
command.setSysPassword(sysPassword);
FSReadBufferStatus command = new FSReadBufferStatus(sysPassword);
execute(command);
return command;
}
Expand Down Expand Up @@ -3038,4 +3037,74 @@ public String getReceiptName(int receiptType) {
return docNames[receiptType];
}
}

public FSReadBlock fsReadBlock(int offset, int size) throws Exception {
FSReadBlock command = new FSReadBlock(sysPassword, offset, size);
execute(command);
return command;
}

public FSStartWriteBlock fsStartWriteBlock(int size) throws Exception {
FSStartWriteBlock command = new FSStartWriteBlock();
command.setSysPassword(sysPassword);
command.setSize(size);
execute(command);
return command;
}

public FSWriteBlock fsWriteBlock(int offset, byte[] data) throws Exception {
FSWriteBlock command = new FSWriteBlock();
command.setSysPassword(sysPassword);
command.setOffset(offset);
command.setData(data);
execute(command);
return command;
}

public byte[] fsReadBlockData() throws Exception {
byte[] result = new byte[0];
ByteArrayOutputStream stream = new ByteArrayOutputStream();
FSReadBufferStatus status = fsReadBufferStatus();

if (status.getDataSize() == 0) {
return result;
}
if (status.getBlockSize() == 0) {
return result;
}

int count = (status.getDataSize() + status.getBlockSize() - 1)
/ status.getBlockSize();
for (int i = 0; i < count; i++) {
int offset = i * status.getBlockSize();
int dataSize = status.getDataSize() - offset;
if (dataSize > status.getBlockSize()) {
dataSize = status.getBlockSize();
}
FSReadBlock block = fsReadBlock(offset, dataSize);

stream.write(block.getData());
}
return stream.toByteArray();
}

public void fsWriteBlockData(byte[] data) throws Exception {
FSStartWriteBlock command = fsStartWriteBlock(data.length);

int blockSize = command.getBlockSize();
if (blockSize == 0) {
throw new Exception("blockSize = 0");
}
int count = (data.length + blockSize - 1) / blockSize;
for (int i = 0; i < count; i++) {
int offset = i * blockSize;
int dataSize = data.length - i * blockSize;
if (dataSize > blockSize) {
dataSize = blockSize;
}
byte[] blockData = new byte[dataSize];
System.arraycopy(data, offset, blockData, offset, dataSize);
fsWriteBlock(offset, blockData);
}
}
}
59 changes: 59 additions & 0 deletions Source/Core/src/com/shtrih/fiscalprinter/command/FSReadBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.shtrih.fiscalprinter.command;

/**
*
* Прочитать блок данных данных из буфера
* Код команды FF31h . Длина сообщения: 6 байт.
* Пароль системного администратора: (4 байта)
* Начальное смещение: 2 байта
* Количество запрашиваемых данных (1 байт)
* Ответ: FF31h Длина сообщения: 1+N байт.
* Код ошибки (1 байт)
* Данные (N байт)
*
*/
public class FSReadBlock extends PrinterCommand {

// in
private int sysPassword; // System sdministrator password (4 bytes)
private int offset;
private int size;
// out
private byte[] data;

public FSReadBlock(int sysPassword, int offset, int size) {
this.sysPassword = sysPassword;
this.offset = offset;
this.size = size;
}

public final int getCode() {
return 0xFF31;
}

public final String getText() {
return "Fiscal storage: read buffer block";
}

public void encode(CommandOutputStream out) throws Exception {
out.writeInt(sysPassword);
out.writeShort(offset);
out.writeByte(size);
}

public void decode(CommandInputStream in) throws Exception {
data = in.readBytes(in.getSize());
}

/**
* @return the data
*/
public byte[] getData() {
return data;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.shtrih.fiscalprinter.command;

import com.shtrih.ej.EJDate;
import com.shtrih.util.BitUtils;

/**
*
* @author V.Kravtsov
*/
/**
*
* Запросить наличие данных в буфере
Expand All @@ -22,31 +10,18 @@
* Количество байт в буфере ( 2 байта ) 0 – нет данных
* Максимальный размер блока данных ( 1 байт)
*
*
*/
public class FSReadBufferStatus extends PrinterCommand {

/**
* @return the sysPassword
*/
public int getSysPassword() {
return sysPassword;
}

/**
* @param sysPassword the sysPassword to set
*/
public void setSysPassword(int sysPassword) {
this.sysPassword = sysPassword;
}

// in
private int sysPassword; // System sdministrator password (4 bytes)

// out
private int dataSize; //
private int blockSize; //

public FSReadBufferStatus() {
public FSReadBufferStatus(int sysPassword) {
this.sysPassword = sysPassword;
}

public final int getCode() {
Expand All @@ -58,12 +33,12 @@ public final String getText() {
}

public void encode(CommandOutputStream out) throws Exception {
out.writeInt(getSysPassword());
out.writeInt(sysPassword);
}

public void decode(CommandInputStream in) throws Exception {
setDataSize(in.readShort());
setBlockSize(in.readByte());
dataSize = in.readShort();
blockSize = in.readByte();
}

/**
Expand All @@ -73,25 +48,11 @@ public int getDataSize() {
return dataSize;
}

/**
* @param dataSize the dataSize to set
*/
public void setDataSize(int dataSize) {
this.dataSize = dataSize;
}

/**
* @return the blockSize
*/
public int getBlockSize() {
return blockSize;
}

/**
* @param blockSize the blockSize to set
*/
public void setBlockSize(int blockSize) {
this.blockSize = blockSize;
}

}
Loading

0 comments on commit 8af6e39

Please sign in to comment.