using System; using Microsoft.SPOT; namespace CPF { class Utils { private static byte[] returnBytes = new byte[128]; public static int numtok(byte[] inBytes, byte inToken) { int num = 0; for (int i = 0; i < inBytes.Length; i++) { if (inBytes[i] == inToken) num++; } return (num); } public static int getField(byte[] inBytes, byte inToken, int desiredField, ref byte[] returnField) { int currentField = 0; int returnFieldIndex = 0; byte token; bool inDesiredField = false; token = (byte)inToken; Array.Clear(returnBytes, 0, returnBytes.Length); for (int i = 0; i < inBytes.Length; i++) { if ((inBytes[i] == token) && !inDesiredField) currentField++; else if (currentField == desiredField) { inDesiredField = true; if ((inBytes[i] == token) || (inBytes[i] == 10) || (inBytes[i] == 13)) return (1); else { returnField[returnFieldIndex] = inBytes[i]; returnFieldIndex++; } } } return (0); } /* public static long MillisecondsSinceLastReboot() { return (Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks / System.TimeSpan.TicksPerMillisecond); } public static bool Match(byte[] s, int length, byte[] match, ref int pos) { do { if (pos >= match.Length) return true; if (pos >= length) return false; } while (s[pos] == match[pos++]); return false; } public static bool ByteArrayCompare(byte[] a1, byte[] a2, int length) { for (int i = 0; i < length; i++) if (a1[i] != a2[i]) return false; return true; } public static string StringFromBytes(byte[] bytes, int length) { string s; if (length != 0) { char[] chars = new char[length]; for (int i = 0; i < length; ++i) { chars[i] = (char) bytes[i]; } s = new string(chars); } else { s = ""; } return s; } public static string StringFromByteArray(byte[] bytes) { int pos = 0; string s; char[] chars = new char[bytes.Length]; while (bytes[pos] != 0) chars[pos++] = (char)bytes[pos]; if (pos > 0) s = new string(chars); else s = ""; return s; } public static string StringFromByte(byte ch) { string s; if (ch == IridiumStrings.CR[0]) return "CR"; else if (ch == IridiumStrings.LF[0]) return "LF"; else { char[] chars = new char[1]; chars[0] = (char)ch; s = new string(chars); return s; } } */ } }