Browse Source

Merge pull request #484 from kanoi/master

BTB show C/MHz/mV for device + api.c remove unused reply string
nfactor-troky
kanoi 12 years ago
parent
commit
ad18b4d584
  1. BIN
      MCast.class
  2. 333
      MCast.java
  3. 1
      api.c
  4. 9
      driver-avalon.c

BIN
MCast.class

Binary file not shown.

333
MCast.java

@ -0,0 +1,333 @@
/*
*
* Copyright (C) Andrew Smith 2013
*
* Usage: java MCast [-v] code toaddr port replyport wait
*
* If any are missing or blank they use the defaults:
*
* -v means report how long the last reply took
*
* code = 'FTW'
* toaddr = '224.0.0.75'
* port = '4028'
* replyport = '4027'
* wait = '1000'
*
*/
import java.net.*;
import java.io.*;
import java.util.*;
class MCast implements Runnable
{
static private final String MCAST_CODE = "FTW";
static private final String MCAST_ADDR = "224.0.0.75";
static private final int MCAST_PORT = 4028;
static private final int MCAST_REPORT = 4027;
static private final int MCAST_WAIT4 = 1000;
static private String code = MCAST_CODE;
static private String addr = MCAST_ADDR;
static private int port = MCAST_PORT;
static private int report = MCAST_REPORT;
static private int wait4 = MCAST_WAIT4;
private InetAddress mcast_addr = null;
static private final Integer lock = new Integer(666);
static private boolean ready = false;
static private Thread listen = null;
static public boolean verbose = false;
static private Date start = null;
static private Date last = null;
static boolean got_last = false;
static public void usAge()
{
System.err.println("usAge: java MCast [-v] [code [toaddr [port [replyport [wait]]]]]");
System.err.println(" -v=report elapsed ms to last reply");
System.err.println(" Anything below missing or blank will use it's default");
System.err.println(" code=X in cgminer-X-Port default="+MCAST_CODE);
System.err.println(" toaddr=multicast address default="+MCAST_ADDR);
System.err.println(" port=multicast port default="+MCAST_PORT);
System.err.println(" replyport=local post to listen for replies default="+MCAST_REPORT);
System.err.println(" wait=how long to wait for replies default="+MCAST_WAIT4+"ms");
System.exit(1);
}
private int port(String _port, String name)
{
int tmp = 0;
try
{
tmp = Integer.parseInt(_port);
}
catch (NumberFormatException nfe)
{
System.err.println("Invalid " + name + " - must be a number between 1 and 65535");
usAge();
System.exit(1);
}
if (tmp < 1 || tmp > 65535)
{
System.err.println("Invalid " + name + " - must be a number between 1 and 65535");
usAge();
System.exit(1);
}
return tmp;
}
public void set_code(String _code)
{
if (_code.length() > 0)
code = _code;
}
public void set_addr(String _addr)
{
if (_addr.length() > 0)
{
addr = _addr;
try
{
mcast_addr = InetAddress.getByName(addr);
}
catch (Exception e)
{
System.err.println("ERR: Invalid multicast address");
usAge();
System.exit(1);
}
}
}
public void set_port(String _port)
{
if (_port.length() > 0)
port = port(_port, "port");
}
public void set_report(String _report)
{
if (_report.length() > 0)
report = port(_report, "reply port");
}
public void set_wait(String _wait4)
{
if (_wait4.length() > 0)
{
try
{
wait4 = Integer.parseInt(_wait4);
}
catch (NumberFormatException nfe)
{
System.err.println("Invalid wait - must be a number between 0ms and 60000ms");
usAge();
System.exit(1);
}
if (wait4 < 0 || wait4 > 60000)
{
System.err.println("Invalid wait - must be a number between 0ms and 60000ms");
usAge();
System.exit(1);
}
}
}
public void run() // listen
{
byte[] message = new byte[1024];
DatagramSocket socket = null;
DatagramPacket packet = null;
try
{
socket = new DatagramSocket(report);
packet = new DatagramPacket(message, message.length);
synchronized (lock)
{
ready = true;
}
while (true)
{
socket.receive(packet);
synchronized (lock)
{
last = new Date();
}
int off = packet.getOffset();
int len = packet.getLength();
System.out.println("Got: '" + new String(message, off, len) + "' from" + packet.getSocketAddress());
}
}
catch (Exception e)
{
socket.close();
}
}
public void sendMCast()
{
try
{
String message = new String("cgminer-" + code + "-" + report);
MulticastSocket socket = null;
DatagramPacket packet = null;
socket = new MulticastSocket();
packet = new DatagramPacket(message.getBytes(), message.length(), mcast_addr, port);
System.out.println("About to send " + message + " to " + mcast_addr + ":" + port);
start = new Date();
socket.send(packet);
socket.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void init()
{
MCast lis = new MCast();
listen = new Thread(lis);
listen.start();
while (true)
{
synchronized (lock)
{
if (ready)
break;
}
try
{
Thread.sleep(100);
}
catch (Exception sl1)
{
}
}
try
{
Thread.sleep(500);
}
catch (Exception sl2)
{
}
sendMCast();
try
{
Thread.sleep(wait4);
}
catch (Exception sl3)
{
}
listen.interrupt();
if (verbose)
{
try
{
Thread.sleep(100);
}
catch (Exception sl4)
{
}
synchronized (lock)
{
if (last == null)
System.out.println("No replies received");
else
{
long diff = last.getTime() - start.getTime();
System.out.println("Last reply took " + diff + "ms");
}
}
}
System.exit(0);
}
public MCast()
{
}
public static void main(String[] params) throws Exception
{
int p = 0;
MCast mcast = new MCast();
mcast.set_addr(MCAST_ADDR);
if (params.length > p)
{
if (params[p].equals("-?")
|| params[p].equalsIgnoreCase("-h")
|| params[p].equalsIgnoreCase("-help")
|| params[p].equalsIgnoreCase("--help"))
MCast.usAge();
else
{
if (params[p].equals("-v"))
{
mcast.verbose = true;
p++;
}
if (params.length > p)
{
mcast.set_code(params[p++]);
if (params.length > p)
{
mcast.set_addr(params[p++]);
if (params.length > p)
{
mcast.set_port(params[p++]);
if (params.length > p)
{
mcast.set_report(params[p++]);
if (params.length > p)
mcast.set_wait(params[p]);
}
}
}
}
}
}
mcast.init();
}
}

1
api.c

@ -4311,7 +4311,6 @@ static void mcast()
char *expect_code; char *expect_code;
size_t expect_code_len; size_t expect_code_len;
char buf[1024]; char buf[1024];
char reply[] = "cgm-" API_MCAST_CODE "-"; // constant
char replybuf[1024]; char replybuf[1024];
memset(&grp, 0, sizeof(grp)); memset(&grp, 0, sizeof(grp));

9
driver-avalon.c

@ -1370,7 +1370,14 @@ static void get_avalon_statline_before(char *buf, size_t bufsiz, struct cgpu_inf
int lowfan = 10000; int lowfan = 10000;
if (usb_ident(avalon) == IDENT_BTB) { if (usb_ident(avalon) == IDENT_BTB) {
tailsprintf(buf, bufsiz, "%2d/%3dC %4dmV | ", info->temp0, info->temp2, info->core_voltage); int temp = info->temp0;
if (info->temp2 > temp)
temp = info->temp2;
if (temp > 99)
temp = 99;
if (temp < 0)
temp = 0;
tailsprintf(buf, bufsiz, "%2dC %3d %4dmV | ", temp, info->frequency, info->core_voltage);
} else { } else {
/* Find the lowest fan speed of the ASIC cooling fans. */ /* Find the lowest fan speed of the ASIC cooling fans. */
if (info->fan1 >= 0 && info->fan1 < lowfan) if (info->fan1 >= 0 && info->fan1 < lowfan)

Loading…
Cancel
Save