Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,17 @@ public ShimmerDevice getShimmerDeviceBtConnected(String connectionHandle){
return shimmerDevice;
}

public boolean checkIfAlgoEnabledonAnyConnectedDevice(String algoName) {
for (String comPort:mMapOfBtConnectedShimmers.keySet()) {
ShimmerDevice device = getShimmerDeviceBtConnected(comPort);
boolean algoenabled = device.isAlgorithmEnabled(algoName);
if(algoenabled) {
return true;
}
}
return false;
}

public ShimmerDevice getShimmerDeviceBtConnectedFromMac(String macAddress){
Iterator<ShimmerDevice> iterator = mMapOfBtConnectedShimmers.values().iterator();
while(iterator.hasNext()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Map.Entry;
import java.util.Random;
import java.util.TimeZone;
import java.util.regex.Pattern;

import org.apache.commons.lang3.ArrayUtils;

Expand Down Expand Up @@ -938,7 +939,19 @@ public int compare(Entry<Double, Double> o1,
}
return new ArrayList<Double>(sortedMap.keySet());
}

// Regex breakdown:
// ^ : Start of string
// [0-9a-fA-F]{2} : Two hex characters
// ( (:[0-9a-fA-F]{2}){5} | ([0-9a-fA-F]{2}){5} ) : Either 5 groups preceded by colons OR 5 groups with nothing
// $ : End of string
private static final String MAC_REGEX = "^([0-9a-fA-F]{2})((:[0-9a-fA-F]{2}){5}|([0-9a-fA-F]{2}){5})$";
private static final Pattern MAC_PATTERN = Pattern.compile(MAC_REGEX);

public static boolean isValidMacAddress(String mac) {
if (mac == null) return false;
return MAC_PATTERN.matcher(mac).matches();
}

public static boolean isValidMac(String mac) {
if(mac==null){
return false;
Expand All @@ -954,7 +967,7 @@ public static boolean isValidMac(String mac) {

return true;
}

public static String getDayString(int dayIndex) {
switch (dayIndex) {
case Calendar.SUNDAY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,62 @@

public class API_00007_UtilShimmerTest {

@Test
public void testValidMacWithColons() {
// Upper case
assertTrue("Should be valid: Uppercase with colons",
UtilShimmer.isValidMacAddress("00:1A:2B:3C:4D:5E"));
// Lower case
assertTrue("Should be valid: Lowercase with colons",
UtilShimmer.isValidMacAddress("00:1a:2b:3c:4d:5e"));
}

@Test
public void testValidMacWithoutColons() {
// Pure Hex string
assertTrue("Should be valid: Plain hex string",
UtilShimmer.isValidMacAddress("001A2B3C4D5E"));
assertTrue("Should be valid: Lowercase plain hex",
UtilShimmer.isValidMacAddress("001a2b3c4d5e"));
}

@Test
public void testInvalidCharacters() {
// Contains 'G' (non-hex)
assertFalse("Should be invalid: Contains non-hex character G",
UtilShimmer.isValidMacAddress("00:1A:2B:3C:4D:5G"));
// Contains special characters
assertFalse("Should be invalid: Contains symbols",
UtilShimmer.isValidMacAddress("00:1A:2B:3C:4D:5#"));
}

@Test
public void testInvalidLength() {
// Too short
assertFalse("Should be invalid: Too short",
UtilShimmer.isValidMacAddress("00:1A:2B"));
// Too long
assertFalse("Should be invalid: Too long",
UtilShimmer.isValidMacAddress("00:1A:2B:3C:4D:5E:6F"));
}

@Test
public void testMixedFormats() {
// Cannot mix "no-colon" with "colons" halfway through
assertFalse("Should be invalid: Inconsistent colon usage",
UtilShimmer.isValidMacAddress("001A2B:3C:4D:5E"));
}

@Test
public void testEdgeCases() {
assertFalse("Should be invalid: Null input",
UtilShimmer.isValidMacAddress(null));
assertFalse("Should be invalid: Empty string",
UtilShimmer.isValidMacAddress(""));
assertFalse("Should be invalid: Spaces included",
UtilShimmer.isValidMacAddress("00 1A 2B 3C 4D 5E"));
}

@Test
public void testRoundZeroDecimalPoints() {
assertTrue(UtilShimmer.round(5.567, 0) == 6.0);
Expand Down
Loading