Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AStarBox Plugin #962

Merged
merged 14 commits into from
Aug 30, 2024
608 changes: 608 additions & 0 deletions indi-astarbox/AStarBox.cpp

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions indi-astarbox/AStarBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>

// C++ includes
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <chrono>
#include <thread>
#include <ctime>
#include <cmath>

#include "mcp3421.h"
#include "PCA9685.h"
#include "StopWatch.h"

#define NB_PORTS 6
#define ON true
#define OFF false

#define PORT_1 0
#define PORT_2 1
#define PORT_3 2
#define PORT_4 3
#define PORT_PWM1 4
#define PORT_PWM2 5

#define POWER_1 1
#define POWER_2 2
#define POWER_3 3
#define POWER_4 4
#define PWM_1 5
#define PWM_2 6


enum portErrors {PLUGIN_OK, P_ERROR, P_UKNOWN, P_INVALID};
enum methodErrors {OK, PORT_OPEN_ERROR, ERR_PARSE, ERR_FILE};

// #define PLUGIN_DEBUG 3
#define PLUGIN_VERSION 1.01

#define INTER_COMMAND_WAIT_MS 500 // ms

class CAStarBoxPowerPorts
{
public:
CAStarBoxPowerPorts();
~CAStarBoxPowerPorts();


virtual int connect();
virtual void disconnect();

virtual int openAllPorts();
virtual int getPortCount();
virtual int setPort(const int nPortID, const bool bOn);
virtual int getPortStatus(const int nPortID, bool &bOn);

virtual int setPortPWMDutyCyclePercent(const int nPortID, const int nDutyCiclePercent);
virtual int getPortPWMDutyCyclePercent(const int nPortID, int &nDutyCiclePercent);

virtual int loadBootStates(std::vector<int> &states);
virtual int saveBootStates(std::vector<int> &states);

virtual bool isMCP3421Present();
virtual int openMCP3421();
virtual int closeMCP3421();
virtual double getVoltage();

private:
int setPortPWM(const int nPortID, const int nDutyCycle);
int getPortPWM(const int nPortID, int &nDutyCycle);
void cmdWait();
int parseFields(const std::string sResp, std::vector<std::string> &svFields, char cSeparator);
std::string& trim(std::string &str, const std::string &filter );
std::string& ltrim(std::string &str, const std::string &filter);
std::string& rtrim(std::string &str, const std::string &filter);

CStopWatch pcaCommandTimer;
bool m_bLinked;

bool m_bPortsOpen;
// pwm ports
bool m_bPwm1On;
int m_nPwm1DutyCycle;

bool m_bPwm2On;
int m_nPwm2DutyCycle;

PCA9685 m_PortController;
mcp3421 m_mcp3421;
bool m_mcp3421Present;

#ifdef PLUGIN_DEBUG
// timestamp for logs
const std::string getTimeStamp();
std::ofstream m_sLogFile;
std::string m_sLogfilePath;
#endif

};

1 change: 1 addition & 0 deletions indi-astarbox/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Colin McGill and Rodolphe Pineau ([email protected])
43 changes: 43 additions & 0 deletions indi-astarbox/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.16)
PROJECT(indi-astarbox CXX C)

LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules/")
include(GNUInstallDirs)

set (VERSION_MAJOR 1)
set (VERSION_MINOR 0)

find_package(INDI REQUIRED)
find_package(Threads REQUIRED)
find_package(RT REQUIRED)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/indi_astarbox.xml.cmake ${CMAKE_CURRENT_BINARY_DIR}/indi_astarbox.xml)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${INDI_INCLUDE_DIR})

include(CMakeCommon)

################ ASI Power ################
set(indi_astarbox_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/indi-astarbox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/AStarBox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mcp3421.cpp
${CMAKE_CURRENT_SOURCE_DIR}/PCA9685.cpp
)

IF (UNITY_BUILD)
ENABLE_UNITY_BUILD(indi_astarbox indi_astarbox_SRCS 6 cpp)
ENDIF ()

add_compile_options(-Wall)

add_executable(indi_astarbox ${indi_astarbox_SRCS})
target_link_libraries(indi_astarbox ${INDI_LIBRARIES})

# Install indi_astarbox
install(TARGETS indi_astarbox RUNTIME DESTINATION bin )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indi_astarbox.xml DESTINATION ${INDI_DATA_DIR})
Loading
Loading