/*
This software is subject to the license described in the License.txt file
included with this software distribution. You may not use this file except in compliance
with this license.
Copyright (c) Dynastream Innovations Inc. 2013
All rights reserved.
*/
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ANT_Managed_Library
{
///
/// This is a static class that manages all the functions and variables common to the whole scope of the library.
///
public static class ANT_Common
{
///
/// Enables or disables all devices from resetting on startup, shutdown, and on CWTestMode Failure.
/// Default = true.
///
static public bool autoResetIsEnabled = true;
#region constants
#if EXT_FUNCTIONALITY
#warning "The Extended build is for internal use only, and even then, only for specific projects, do not use without discussing with the ANT team"
internal const String ANT_UNMANAGED_WRAPPER = "ANT_WrappedLib_Ext.dll";
#else
internal const String ANT_UNMANAGED_WRAPPER = "ANT_WrappedLib";
#endif
internal const String ANT_SI_LIBRARY = "DSI_SiUSBXp_3_1";
internal const String ANT_SI_LIBRARY2 = "DSI_CP210xManufacturing_3_1";
#endregion
#region DLL imports
[DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
private static extern UInt32 ANT_GetNumDevices();
[DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
private static extern int ANT_EnableDebugLogging();
[DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
private static extern void ANT_DisableDebugLogging();
[DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
private static extern int ANT_SetDebugLogDirectory(string pcDirectory);
[DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention = CallingConvention.Cdecl)]
private static extern int ANT_DebugThreadInit(string pucName);
[DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention = CallingConvention.Cdecl)]
private static extern int ANT_DebugThreadWrite(string pcMessage);
[DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention = CallingConvention.Cdecl)]
internal static extern int ANT_DebugResetTime();
#endregion
///
/// Returns the number of ANT USB devices currently detected by the system.
///
public static UInt32 getNumDetectedUSBDevices()
{
return ANT_GetNumDevices();
}
/// Enables debug files
///
/// Initializes and enables debug logs for all devices
/// Note: For application specific logs to work properly
/// (e.g. ANT-FS logs), this needs to be called BEFORE
/// creating an ANT Device.
///
public static bool enableDebugLogs()
{
return ANT_EnableDebugLogging() == 1;
}
///
/// Initializes and enables debug logs for all devices,
/// and stores the log in the specified path.
/// Note: For application specific logs to work properly
/// (e.g. ANT-FS logs), this needs to be called BEFORE
/// creating an ANT Device.
///
/// Debug log directory
public static void enableDebugLogs(string debugPath)
{
enableDebugLogs();
setDebugLogDirectory(debugPath);
}
///
/// Disables and closes the debug logs
///
public static void disableDebugLogs()
{
ANT_DisableDebugLogging();
}
///
/// Set the directory the log files are saved to.
/// This string will prefix the file name so must end with a slash or will be part of the name.
/// ie: directoryPath='c:\ANT\logs' will result in files being saved to the \ANT directory named logsdevice0.txt.
/// Throws an exception if directory does not exist.
///
///
/// Path to directory to save log files in. Default is the running directory.
/// This string will prefix the file name so must end with a slash or will be part of the name.
/// ie: directoryPath='c:\ANT\logs' will result in files being saved to the \ANT directory named logsdevice0.txt.
///
public static bool setDebugLogDirectory(string directoryPath)
{
if (!System.IO.Directory.Exists(directoryPath))
throw new ANT_Exception("Path does not exist");
return ANT_SetDebugLogDirectory(directoryPath) == 1;
}
//
//Note: Access to the following logging functions is required by the current ANT-FS implementation
//
///
/// Creates a debug log for the currently executing thread
///
/// Name of file (will result in ao_debug_name)
/// True if successful
internal static bool initDebugLogThread(string name)
{
return ANT_DebugThreadInit(name) == 1;
}
///
/// Adds an application specific message to the log for the current thread
///
/// Message to write to the log
/// True on success
internal static bool writeToDebugLog(string message)
{
return ANT_DebugThreadWrite(message) == 1;
}
}
}