#pragma once
#define _API_H_

#ifndef __cplusplus
//#include <stdbool.h>
//The definition of bool, true and false are included to support NI WindowsCVI 2012 and earlier.
//This should be replaced with the include above for CVI 2015
typedef enum { false = 0, true = 1 } bool;
#endif /* __cplusplus */


//success or failure return of a method, true if the method is successful
typedef bool success;

#ifdef __cplusplus
extern "C"
{
#endif
   // predfined configuration section types
   typedef enum
   {
       UnknownConfig,
       AbSplit,
       AmbSplit,
       Calibration,
       Fcm,
       Dcm,
       MultiSwitch,
       Path,
       Pna,
       PowerBridge,
       Scm,
       Sequence,
       ShortOpenLoad,
       Switch,
       UserDevice
   }EConfigType;

   // predefined short open load measure types
   typedef enum
   {
       SolShort,
       SolOpen,
       SolLoad
   }ESolMeasureType;

   // predefined file type produced by short open load measurements
   typedef enum
   {
       SolCharacterized,
       SolMeasured,
       SolDeembed
   }ESolFileType;

   // redefined file types produced by AMB split
   typedef enum
   {
       AmbShort,
       AmbThru
   }EAmbMeasureType;

   // predefined AB split measure types
   typedef enum
   {
       AbMeasuredThru,
       AbDeembedA,
       AbDeembedB,
   }EAbSplitFileType;

   // predefined AMB split measure types
   typedef enum
   {
       AmbMeasuredShort,
       AmbMeasuredThru,
       AmbDeembedA,
       AmbDeembedB,
       AmbDeembedM,
   }EAmbFileType;

   // callback function pointer for error messages.
   // the message pointer is valid only during the callback and should be copied if the message is to persist
   typedef void(*errorCallbackFn)(char* messsage);

   // Callback function pointer for SCPI command messages.
   // The event id is the serial id of the event.
   // The name is the device name that was being sent to when the event was generated.
   // The command is the command that was sent to the device.
   // The response may be null and usualy comes in on a secondary event,
   // with the update flag set to true and the eventId set to the primary event being responded to.
   typedef void(*commandCallbackFn)(int eventId, char* name, char* command, char* response, bool update);


   // returns the string provided, used to test DLL call
   __declspec(dllexport) char* Ping(char* ping);

   // Abort the given running calibration or sequence.
   __declspec(dllexport) void Abort(char* name);

   // Abort all running calibration or sequence..
   __declspec(dllexport) void AbortAll();

   // Calculate the AB split A and B de-embed files specified by the AB Split section with the given name.
   __declspec(dllexport) success AbSplitCalculate(char* abSplitName, char* pnaName);

   // Get the AB split filename to use
   __declspec(dllexport) int AbSplitFilename(char* abSplitName, EAbSplitFileType fileType, char* buffer, int bufferLen);

   // Calculate the AMB split A,B and M de-embed files specified by the AMB Split section with the given name.
   __declspec(dllexport) success AmbCalculate(char* ambName);

   // Get the AMB split filename to use
   __declspec(dllexport) int AmbFilename(char* ambName, EAmbFileType fileType, char* buffer, int bufferLen);

   // Execute a measure specified by the AMB Split section with the given name and enumerated AmbMeasuretype.
   __declspec(dllexport) success AmbMeasure(char* ambName, char* pnaName, EAmbMeasureType measureType);

   // Execute a calibration using the calibration with the given name and PNA as configured in the configuration file
   __declspec(dllexport) success Calibrate(char* calName, char* pnaName);

   // Returns the comma seperated list of config names in the configuration based on a key value
   // Returns the number of bytes copied into the buffer
   __declspec(dllexport) int GetConfigListByKey(char *keyName, char* keyValue, char* buffer, int bufferLen);

   // Returns the comma seperated list of config names in the configuration based on config type
   // Returns the number of bytes copied into the buffer
   __declspec(dllexport) int GetConfigTypeList(EConfigType configType, char* buffer, int bufferLen);

   // Gets the error message(s) and clears the error list. messages will be seperated by a new line.
   // Returns the number of bytes copied into the buffer
   __declspec(dllexport) int GetErrorMessage(char* buffer, int bufferLen);

   // Sets or modifies a key in the configuration file that was initialized
   // If a section name or key does not exist then it is created.
   // The program will return a failure if the configuration file was not initialized with a call to Initialize
   __declspec(dllexport) success IniFileModifyKey(char* sectionName, char *keyName, char* keyValue, char* keyComment);

   // Reads a key value from the configuration ini file given the section name and key.
   // The value is returned in the buffer and the byte count of the response is returned by the function.
   // A return byte count of zero means the key was either not present or not set.
   __declspec(dllexport) int IniFileReadKey(char* sectionName, char *keyName, char* buffer, int bufferLen);

   // Initialize the library to use the given configuration file.
   __declspec(dllexport) success Initialize(char* configFilename);

   // Execute a calibration using the calibration with the given name and PNA as configured in the configuration file
   __declspec(dllexport) success LogCalibrate(char* calName, char* pnaName, char* logFilename);

   // Execute a sequence of calibrations using the sequence with he given name and pna as configured in the configuration file
   // And log the commnd events.
   __declspec(dllexport) success LogSequence(char* seqName, char* logFilename);

   // Execute a sequence of calibrations using the sequence with he given name and pna as configured in the configuration file
   __declspec(dllexport) success RunSequence(char* seqName);

   // Send a SCPI command directly to a device with the given name as defined in the configuration.
   // if responseTimeoutSec 0 or negative the default timeout is used.
   __declspec(dllexport) int SendScpi(char* alias, char* command, int responseTimeoutSec, char * responseBuffer, int bufferLength);

   // Send a SCPI command directly to a device with the given name as defined in the configuration.
   __declspec(dllexport) int SendToUserDevice(char* alias, char* data, bool waitForResponse, int responseTimeoutSec, char * responseBuffer, int bufferLength);

   // Set the switches to the path with the given name as defined inthe configuration.
   __declspec(dllexport) success SetPath(char* pathName);

   // Set the switches to the path defined by the switch path string.
   __declspec(dllexport) success SetSwitchPath(char* switchPath);

   // Calculate the SOL de-embed file specified by the SOL section with the given name and enumerated SolMeasuretype.
   __declspec(dllexport) success SolCalculate(char* solName);

   // Get the SOL S1P filename to use
   // solName = name of the SOL configuration name
   __declspec(dllexport) int SolFilename(char* solName, int port, ESolFileType fileType, ESolMeasureType measureType, char* buffer, int bufferLen);

   // Execute a measure specified by the SOL section with the given name and enumerated SolMeasuretype.
   __declspec(dllexport) success SolMeasure(char* solName, char* pnaName, ESolMeasureType measureType);

   // Used to subscribe to error callback events, set subscribe to false to unsubscribe and true to subscribe.
   __declspec(dllexport) void SubscribeToErrorEvents(errorCallbackFn callbackPtr, bool subscribe);

   // Used to subscribe to SCPI command callback events, set subscribe to false to unsubscribe and true to subscribe.
   __declspec(dllexport) void SubscribeToScpiCommandEvents(commandCallbackFn callbackPtr, bool subscribe);

#ifdef __cplusplus
}
#endif