minor fix

This commit is contained in:
Joakim Eriksson 2012-05-14 18:02:48 +02:00
parent fdc856247f
commit 45dc922144
2 changed files with 25 additions and 2 deletions

View File

@ -54,7 +54,7 @@ public class CC2520SPI {
SPICommand[] commands = new SPICommand[256];
CC2520SPI() {
/* set up the commands */
for (int i = 0; i < spiCommands.length; i++) {
SPICommand c = spiCommands[i];
int maxv = 1 << (8 - c.bitCount);
@ -70,8 +70,18 @@ public class CC2520SPI {
}
}
SPICommand getCommand(int cmd) {
if (cmd < 256 && commands[cmd] != null)
return commands[cmd];
return null;
}
public static void main(String[] args) {
new CC2520SPI();
CC2520SPI spi = new CC2520SPI();
SPICommand cmd = spi.getCommand(0xff);
/* commands that take infinite number of bytes have the bitfield ... */
System.out.println("Has ... => " + cmd.getBitField("..."));
}
}

View File

@ -1,6 +1,7 @@
package se.sics.mspsim.chip;
import java.util.ArrayList;
import java.util.Iterator;
public class SPICommand {
/*
@ -93,6 +94,9 @@ public class SPICommand {
if (start != 0) {
System.out.println("Bitfield: " + currentName + ": [" +
start + " - " + (c - 1) + "]");
if (bitFields == null)
bitFields = new ArrayList<SPICommand.BitField>();
bitFields.add(new BitField(currentName, start, c - 1));
}
System.out.printf("Value %x\n", value);
@ -113,11 +117,20 @@ public class SPICommand {
return true;
}
/* for any command that is executable (finite commands) */
public boolean executeSPICommand(int[] spiData) {
System.out.println("Command " + name + " not implemented...");
return true;
}
public BitField getBitField(String arg) {
for (BitField b : bitFields) {
if (b.name.equals(arg)) return b;
}
/* not existing ... */
return null;
}
public static void main(String[] args) {
SPICommand c = new SPICommand("MEMXCP 0 1 0 1 0 1 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e") {
public boolean executeSPICommand(int[] spiData) {