#include <base/Application.h>
#include <base/string/FormatOutputStream.h>
#include <base/string/InvalidFormat.h>
#include <base/communication/IEEE1394.h>
#include <base/concurrency/Thread.h>
#include <base/Timer.h>
#include <base/Cast.h>
#include <base/UnsignedInteger.h>
#include <base/UnsignedLongInteger.h>
#include <base/mem/MemoryDump.h>
using namespace com::azure::dev::base;
private:
static const unsigned int MAJOR_VERSION = 1;
static const unsigned int MINOR_VERSION = 0;
public:
enum Command {
COMMAND_DUMP_ADAPTERS,
COMMAND_DUMP_TOPOLOGY,
COMMAND_DUMP_SPEEDS,
COMMAND_DUMP_NODES,
COMMAND_FCP,
COMMAND_ISOCHRONOUS,
COMMAND_RESET,
COMMAND_REGISTER_SPACE,
COMMAND_HELP,
COMMAND_VERSION,
COMMAND_USAGE,
COMMAND_ERROR
};
IEEE1394Application()
{
}
void dumpAdapters() noexcept
{
try {
fout << "No IEEE 1394 adapters available" << ENDL;
} else {
fout << "IEEE 1394 adapters:" << EOL;
fout << indent(2) << enu.
next() << EOL;
}
fout << FLUSH;
}
fout << ENDL;
ferr << "Unable to get available adapters" << EOL
<< e << ENDL;
return;
}
}
{
fout << "Opening IEEE 1394 adapter (" << id << ')' << ENDL;
}
void dumpAdapter() noexcept {
}
void dumpNodes(
const EUI64& guid) noexcept {
try {
ferr << "No adapters available" << ENDL;
return;
}
id = adapters[0];
}
fout << "Opening IEEE 1394 adapter (" << id << ')' << ENDL;
static const Literal STANDARDS[] = {
MESSAGE("Unspecified"),
MESSAGE("IEEE 1394"),
MESSAGE("IEEE 1394A"),
MESSAGE("IEEE 1394B")
};
MESSAGE("S100"),
MESSAGE("S200"),
MESSAGE("S400"),
MESSAGE("S800"),
MESSAGE("S1600"),
MESSAGE("S3200")
};
} else {
fout << "Bus manager: " << "(not present)" << EOL;
}
} else {
fout << "Cycle master: " << "(not present)" << EOL;
}
fout << "Isochronous resource manager: "
<< indent(2) << "Available bandwidth: "
<< indent(2) << "Available channels: "
<< BIN << setWidth(64) << ZEROPAD << NOPREFIX
} else {
fout << "Isochronous resource manager: " << "(not present)" << EOL;
}
fout << "Node: " << id << EOL;
fout << indent(2) << "link layer is not active" << EOL;
continue;
}
try {
fout << indent(2) << "standard: " << STANDARDS[standard] << EOL;
}
<< EOL;
}
try {
fout << indent(2) << "vendor: "
<< HEX << setWidth(2) << ZEROPAD << NOPREFIX << ((vendor >> 16) & 0xff) << ':'
<< HEX << setWidth(2) << ZEROPAD << NOPREFIX << ((vendor >> 8) & 0xff) << ':'
<< HEX << setWidth(2) << ZEROPAD << NOPREFIX << (vendor & 0xff) << EOL;
}
try {
fout << indent(2) << "description: " << description << EOL;
}
fout << indent(2) << "keywords: " << keywords << EOL;
}
}
try {
fout << indent(2) << "maximum asynchronous payload: " << max << EOL;
}
fout << indent(2) <<
"is contender: " << ieee1394.
isContender(
id)
<< EOL
<< indent(2) << "maximum physical speed: "
<< indent(2) << "maximum link speed: "
if (capabilities) {
fout << indent(2) << "capabilities: " << EOL;
if (capabilities & IEEE1394::ISOCHRONOUS_RESOURCE_MANAGER_CAPABLE) {
fout << indent(4) << "isochronous resource manager" << EOL;
}
if (capabilities & IEEE1394::CYCLE_MASTER_CAPABLE) {
fout << indent(4) << "cycle master" << EOL;
}
if (capabilities & IEEE1394::ISOCHRONOUS_TRANSACTION_CAPABLE) {
fout << indent(4) << "isochronous transaction" << EOL;
}
if (capabilities & IEEE1394::BUS_MASTER_CAPABLE) {
fout << indent(4) << "bus master" << EOL;
}
if (capabilities & IEEE1394::POWER_MANAGER_CAPABLE) {
fout << indent(4) << "power manager" << EOL;
}
}
fout << indent(2) << "roles: " << EOL;
fout << indent(4) << "cycle master" << EOL;
}
fout << indent(4) << "isochronous resource manager" << EOL;
}
fout << indent(4) << "bus manager" << EOL;
}
}
if (capabilities & IEEE1394::CYCLE_MASTER_CAPABLE) {
try {
fout << indent(2) << "bus time: " << busTime << EOL;
}
}
if (capabilities & IEEE1394::ISOCHRONOUS_TRANSACTION_CAPABLE) {
try {
fout << indent(2) << "cycle time: " << cycleTime << EOL;
}
}
}
fout << ENDL;
fout << ENDL;
ferr << "Exception: " << e << ENDL;
}
}
void dumpRegisterSpace(
uint64 firstAddress,
uint64 lastAddress,
const EUI64& guid,
int node) noexcept {
try {
ferr << "No adapters available" << ENDL;
return;
}
id = adapters[0];
}
fout << "Opening IEEE 1394 adapter (" << id << ')' << ENDL;
if (node < 0) {
}
const uint32 DEFAULT_VALUE = 0xdccd2332;
const uint64 endAddress = lastAddress + sizeof(uint32);
uint32 buffer[4096];
while (firstAddress < endAddress) {
uint32 bytesToRead = endAddress - firstAddress;
if (bytesToRead > getArraySize(buffer) * sizeof(uint32)) {
bytesToRead = getArraySize(buffer) * sizeof(uint32);
}
ieee1394.
read(node, firstAddress, buffer, bytesToRead/
sizeof(uint32), DEFAULT_VALUE);
for (unsigned int i = 0; i < bytesToRead/sizeof(uint32); ++i) {
uint32 value = buffer[i];
if (value != DEFAULT_VALUE) {
char characters[4];
fout << HEX << setWidth(16) << ZEROPAD << NOPREFIX << (firstAddress + i * sizeof(uint32)) << ' ' << ' '
<< HEX << setWidth(8) << ZEROPAD << NOPREFIX << value << ' ' << ' '
<< characters[0] << characters[1] << characters[2] << characters[3] << EOL;
} else {
fout << HEX << setWidth(16) << ZEROPAD << NOPREFIX << (firstAddress + i * sizeof(uint32)) << ' ' << ' '
<< "........" << EOL;
}
}
firstAddress += bytesToRead;
}
fout << ENDL;
ferr << "Exception: " << e << ENDL;
}
}
void onFCPRequest(
unsigned short nodeId, const uint8* buffer, unsigned int size) noexcept {
fout << "FCP request: " << EOL
<< EOL
<< ENDL;
fout << dump << ENDL;
}
void onFCPResponse(
unsigned short nodeId, const uint8* buffer, unsigned int size) noexcept {
fout << "FCP response: " << EOL
<< EOL
<< ENDL;
fout << dump << ENDL;
}
bool onIsochronousPacket(const uint8* buffer, unsigned int size) noexcept {
fout << dump << ENDL;
return false;
}
void fcp(
const EUI64& guid) noexcept {
try {
ferr << "No adapters available" << ENDL;
return;
}
id = adapters[0];
}
fout << "Opening IEEE 1394 adapter (" << id << ')' << ENDL;
ieee1394.
registerFCPListener(
this);
static const uint8 CMD[] = {1,2,3,4,5,6,7,8,9};
CMD,
sizeof(CMD)
);
CMD,
sizeof(CMD)
);
while (ieee1394.
wait(1000)) {
}
ieee1394.
unregisterFCPListener();
fout << ENDL;
ferr << "Exception: " << e << ENDL;
}
}
void isochronousTransfer(
const EUI64& guid,
unsigned int channel) noexcept {
try {
ferr << "No adapters available" << ENDL;
return;
}
id = adapters[0];
}
fout << "Opening IEEE 1394 adapter (" << id << ')' << ENDL;
fout << "Listening for isochronous packets on channel " << channel
<< "..." << ENDL;
ieee1394.
readIsochronous(channel,
this);
fout << ENDL;
ferr << "Exception: " << e << ENDL;
}
}
void resetBus(
const EUI64& guid) noexcept {
}
unsigned short getNodeId(
const String&
string)
const
{
unsigned int physicalId = 0;
if (index >= 0) {
if (bus != "local") {
string.substring(0, index),
);
bassert(
);
}
}
if (physical == "broadcast") {
} else {
}
bassert(
);
}
void main()
{
fout << getFormalName() << " version "
<< MAJOR_VERSION << '.' << MINOR_VERSION << EOL
<< "The Base Framework (Test Suite)" << EOL
<< ENDL;
Command command = COMMAND_ERROR;
uint64 firstAddress;
uint64 lastAddress;
int nodeId = -1;
int channel = 0;
try {
command = COMMAND_USAGE;
}
else if (arguments.
getSize() == 1) {
if (arguments[0] == "--help") {
command = COMMAND_HELP;
} else if (arguments[0] == "--version") {
command = COMMAND_VERSION;
} else if (arguments[0] == "--adapters") {
command = COMMAND_DUMP_ADAPTERS;
} else if (arguments[0] == "--topology") {
command = COMMAND_DUMP_TOPOLOGY;
} else if (arguments[0] == "--speed") {
command = COMMAND_DUMP_SPEEDS;
} else if (arguments[0] == "--nodes") {
command = COMMAND_DUMP_NODES;
}
}
else if (arguments.
getSize() == 2) {
if (arguments[0] == "--nodes") {
command = COMMAND_DUMP_NODES;
guid = arguments[1];
} else if (arguments[0] == "--reset") {
command = COMMAND_RESET;
guid = arguments[1];
}
}
else if (arguments.
getSize() >= 3) {
if (arguments[0] == "--fcp") {
command = COMMAND_FCP;
} else if (arguments[0] == "--iso") {
command = COMMAND_ISOCHRONOUS;
guid = arguments[1];
bassert(channel <= 63,
Exception(
"Invalid isochronous channel.",
this));
} else if (arguments[0] == "--registers") {
command = COMMAND_REGISTER_SPACE;
String registers = arguments[1];
const int plus = registers.
indexOf(
'+');
if (plus >= 0) {
);
) + firstAddress;
} else {
const int minus = registers.
indexOf(
'-');
if (minus >= 0) {
);
);
} else {
if (registers == "topology") {
lastAddress = firstAddress + 0x3fc;
} else if (registers == "speed") {
lastAddress = firstAddress + 0xffc;
} else if (registers == "csr") {
lastAddress = firstAddress + 0x1fc;
} else if (registers == "bus") {
lastAddress = firstAddress + 0x1fc;
} else if (registers == "rom") {
lastAddress = firstAddress + 0x3fc;
} else if (registers == "cycletime") {
lastAddress = firstAddress;
} else {
registers,
);
lastAddress = firstAddress;
}
}
}
(firstAddress > lastAddress)) {
errorMessage = MESSAGE("Misaligned register(s)");
command = COMMAND_ERROR;
}
guid = arguments[2];
case 2:
break;
case 3:
guid = arguments[2];
break;
case 4:
nodeId = getNodeId(arguments[3]);
break;
default:
command = COMMAND_ERROR;
}
}
}
command = COMMAND_ERROR;
}
if ((command != COMMAND_ERROR) && guid.
isProper()) {
try {
command = COMMAND_ERROR;
}
if (id.isInvalid()) {
command = COMMAND_ERROR;
}
if (command == COMMAND_ERROR) {
errorMessage = MESSAGE("Invalid GUID of adapter");
}
}
if ((command != COMMAND_ERROR) && (nodeId >= 0)) {
errorMessage = MESSAGE("Broadcast id not premitted");
command = COMMAND_ERROR;
errorMessage = MESSAGE("Invalid node id");
command = COMMAND_ERROR;
}
}
switch (command) {
case COMMAND_DUMP_ADAPTERS:
dumpAdapters();
break;
case COMMAND_DUMP_NODES:
dumpNodes(id);
break;
case COMMAND_RESET:
resetBus(id);
break;
case COMMAND_REGISTER_SPACE:
dumpRegisterSpace(firstAddress, lastAddress, id, nodeId);
break;
case COMMAND_ISOCHRONOUS:
isochronousTransfer(id, 1);
break;
case COMMAND_FCP:
fcp(id);
break;
case COMMAND_HELP:
fout << "Usage: " << getFormalName()
<< " [options] [adapter EUI-64] [node EUI-64 or physical id]" << ENDL;
break;
case COMMAND_VERSION:
break;
case COMMAND_USAGE:
fout << "Usage: " << getFormalName()
<< " [options] [adapter EUI-64] [node EUI-64 or physical id]" << ENDL;
break;
case COMMAND_ERROR:
ferr << "ERROR: Invalid arguments(s): " << errorMessage << EOL;
} else {
ferr << "ERROR: Invalid arguments(s)" << EOL;
}
ferr << "For help: " << getFormalName() << " --help" << ENDL;
break;
case COMMAND_DUMP_TOPOLOGY:
break;
case COMMAND_DUMP_SPEEDS:
break;
}
}
};
APPLICATION_STUB(IEEE1394Application);