Обеспечение всемирной трансляции спортивных шахматных соревнований с применением разработанного в ходе проекта законченного программного продукта
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
sp;
rdgtSerialport.java
---
class rdgtSerialport implements SerialPortEventListener {
static CommPortIdentifier portid;
InputStream inStream;
OutputStream outStream;
SerialPort serialPort;
rdgtReceiver receiver;
public rdgtSerialport(rdgtReceiver r) {
receiver = r;
}
public boolean open(String portname) {
CommPortIdentifier id = null;
Enumeration portList;
portList = CommPortIdentifier.getPortIdentifiers();
System.out.println(portList.toString());
while (portList.hasMoreElements()) {
System.out.println("2");
id = (CommPortIdentifier) portList.nextElement();
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println("Ports: "+id.getName());
if (id.getName().equals(portname)) break; // found
}
id = null;
}
if (id == null) return false; // not found
try {
serialPort = (SerialPort) id.open("ttchess", 2000);
inStream = serialPort.getInputStream();
outStream = serialPort.getOutputStream();
serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
serialPort.setDTR(false);
serialPort.setRTS(false);
} catch (Exception e) { return false; }
return true;
}
public boolean write(byte[] data) {
char c[] = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F};
StringBuffer x = new StringBuffer(" Sending: ");
for (int i=0; i<data.length; i=i+1) {
int d = data[i];
if (d<0) d=256+d;
>4]).append(c[d&0x0F]).append("");">x.append(c[d>>4]).append(c[d & 0x0F]).append(" ");
}
if (rdgtChess.debug) System.out.println(x.toString());
try {
outStream.write(data);
} catch (IOException e) { return false; }
return true;
}
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[200];
try {
0){">while (inStream.available() > 0) {
int numBytes = inStream.read(readBuffer);
if (numBytes>0) {
int[] buf = new int[numBytes];
for (int i=0; i<numBytes; i=i+1) {
int tmp = readBuffer[i];
if (tmp<0) tmp=256+tmp;
buf[i]=tmp;
}
receiver.receive(buf);
}
}
} catch (IOException e) {}
break;
}
}
}
rdgtSnapshot.java
---
class rdgtSnapshot extends rdgtProtocol {
int[] pieces = new int[64];
Date time;
rdgtChessboard board;
boolean clkRunning, clkBatteryLow, clkFrontViewLeftSideHigh, clkBlackTurn, clkWhiteTurn;
int clkSecWhite, clkSecBlack;
public rdgtSnapshot(rdgtChessboard _board) {
time = new Date();
board = _board;
set_emptyboard();
}
public rdgtSnapshot(rdgtSnapshot x) {
for (int i=0; i<64; i=i+1) pieces[i] = x.pieces[i];
time = x.time;
board = x.board;
clkRunning = x.clkRunning;
clkBatteryLow = x.clkBatteryLow;
clkFrontViewLeftSideHigh = x.clkFrontViewLeftSideHigh;
clkBlackTurn = x.clkBlackTurn;
clkWhiteTurn = x.clkWhiteTurn;
clkSecWhite = x.clkSecWhite;
clkSecBlack = x.clkSecBlack;
}
rdgtSnapshot copy() {
return new rdgtSnapshot(this);
}
void set_clockdata(boolean running, boolean batteryLow, boolean frontViewLeftSideHigh,
boolean blackTurn, boolean whiteTurn, int secW, int secB) {
clkRunning = running;
clkBatteryLow = batteryLow;
clkFrontViewLeftSideHigh = frontViewLeftSideHigh;
clkBlackTurn = blackTurn;
clkWhiteTurn = whiteTurn;
clkSecWhite = secW;
clkSecBlack = secB;
}
public boolean sameas(rdgtSnapshot x) {
for (int i=0; i<64; i=i+1) if (pieces[i] != x.pieces[i]) return false;
return true;
}
Date get_time() { return time; }
void set_emptyboard() {
time = new Date();
for (int i=0; i<64; i=i+1) pieces[i]=EMPTY;
}
void set_boarddump(int[] all64, int startpos) {
time = new Date();
for (int i=0; i<64; i=i+1) {
int p = all64[i+startpos];
if (is_piece(p)==false) {
System.out.println("Confused: Boarddump contained an unknown piece");
pieces[i]=EMPTY;
} else {
pieces[i]=p;
}
}
}
void set_fieldupdate(int piece, int pos) {
time = new Date();
if (pos 63) {
System.out.println("Confused: Fieldupdate for pos outside 0..63");
return;
}
if (is_piece(piece)==false) {
System.out.println("Confused: Fieldupdate with an unknown piece");
return;
}
pieces[pos]=piece;
}
String seconds2hms(int s) {
return Integer.toString(s/36000)+Integer.toString((s000)/3600)+":"+
Integer.toString((s00)/600)+Integer.toString((s0)/60)+":"+
Integer.toString((s)/10)+Integer.toString(s);
}
String debugprint_clock() {
StringBuffer s = new StringBuffer(50);
s.append("Clock: White "); s.append(seconds2hms(clkSecWhite));
s.append(" Black "); s.append(seconds2hms(clkSecBlack));
System.out.println(s);
return s.toString();
}
String getTimeWhite(){
return seconds2hms(clkSecWhite);
}
String getTimeBlack(){
return seconds2hms(clkSecBlack);
}
boolean isWhiteTurn(){
return clkFrontViewLeftSideHigh;
}
String debugprint() {
debugprint_clock();
StringBuffer s = new StringBuffer(300);
for (int i=0; i<8; i=i+1) {
for (int j=0; j<8; j=j+1) {
int p = pieces[(i*8)+j];
if (p==EMPTY ) s.append(".");
if (p==WPAWN ) s.append("P");
if (p==WROOK ) s.append("R");
if (p==WKNIGHT) s.append("N");
if (p==WBISHOP) s.append("B");
if (p==WKING ) s.append("K");
if (p==WQUEEN ) s.append("Q");
if (p==BPAWN ) s.append("p");
if (p==BROOK ) s.append("r");
if (p==BKNIGHT) s.append("n");
if (p==BBISHOP) s.append("b");
if (p==BKING ) s.append("k");
if (p==BQUEEN ) s.append("q");
}
s.append("\n");
}
System.out.println(s);
return s.toString();
}
}
Приложение Д
Снимки экрана
Д.1 Снимок экрана главной страницы сервера трансляции шахматных партий rDGT
Д.2 Снимок экрана страницы авторизации пользователя
Д.3 Снимок экрана страницы просмотра текущих online трансляций
Д.4 Снимок экрана страницы просмотра шахматной партии
Приложение Е
Протокол DGT
#ifndef dgtbrd13
#define dgtbrd13
/*
Protocol description for DGT chess board.
Copyright 1998 DGT Projects B.V
Version: 1.03 Single computer and bus support in one .h file
*********************************************************
This protocol is protected under trade mark registration and copyrights.
It may not be used commercially without written permission
of DGT Projects B.V. It is illegal to transfer any registered trade mark
identifications by means of this protocol between any chessboard or other
application and any computer.
*********************************************************
Main functionality of the DGT Electronic Chess Board
----------------------------------------------------
The DGT board is basically a sensor which senses the presense of the special
chess set pieces on the squares of the board. The situation on the board is
measured and can be communicated with an average maximum time delay of
200 mS.
Besides t