-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfalcon.h
137 lines (106 loc) · 3.55 KB
/
falcon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// falcon.h
// Created by Rodolphe Pineau on 2020/11/26.
// Pegasus Falcon Rotator X2 plugin
//
#ifndef __PEGASUS_FALCON__
#define __PEGASUS_FALCON__
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <memory.h>
#include <string.h>
#include <time.h>
#ifdef SB_MAC_BUILD
#include <unistd.h>
#endif
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <exception>
#include <typeinfo>
#include <stdexcept>
#include "../../licensedinterfaces/sberrorx.h"
#include "../../licensedinterfaces/serxinterface.h"
#include "../../licensedinterfaces/loggerinterface.h"
// #define PLUGIN_DEBUG 3
#define DRIVER_VERSION 1.0
#define PLUGIN_ID 2
#define SERIAL_BUFFER_SIZE 256
#define MAX_TIMEOUT 5000
#define LOG_BUFFER_SIZE 256
#define MAKE_ERR_CODE(P_ID, DTYPE, ERR_CODE) (((P_ID<<24) & 0xff000000) | ((DTYPE<<16) & 0x00ff0000) | (ERR_CODE & 0x0000ffff))
enum Falcon_Errors {PLUGIN_OK = 0, NOT_CONNECTED, FALCON_CANT_CONNECT, FALCON_BAD_CMD_RESPONSE, COMMAND_FAILED};
enum RotorStatus {IDLE = 0, MOVING};
enum RotorDir {NORMAL = 0 , REVERSE};
typedef struct {
bool bReady;
char szVersion[SERIAL_BUFFER_SIZE];
double dCurPos;
bool bMoving;
bool bReverse;
} FalconStatus;
// field indexes in response for A command
#define fSTATUS 0
#define fSTEPPOS 1
#define fDEGPOS 2
#define fMOVING 3
#define fLIMIT 4
#define fDEROT 5
#define fREVERSE 6
class CFalconRotator
{
public:
CFalconRotator();
~CFalconRotator();
int Connect(const char *pszPort);
void Disconnect(void);
bool IsConnected(void) { return m_bIsConnected; };
void SetSerxPointer(SerXInterface *p) { m_pSerx = p; };
// move commands
int haltFalcon();
int gotoPosition(double dPosDeg);
// command complete functions
int isGoToComplete(bool &bComplete);
int isMotorMoving(bool &bMoving);
// getter and setter
void setDebugLog(bool bEnable) {m_bDebugLog = bEnable; };
int getStatus(int &nStatus);
int getConsolidatedStatus(void);
int getFirmwareVersion(std::string &sVersion);
int getPosition(double &dPosition);
int syncMotorPosition(double dPos);
int setReverseEnable(bool bEnabled);
int getReverseEnable(bool &bEnabled);
protected:
int deviceCommand(const char *pszCmd, char *pszResult, int nResultMaxLen);
int deviceCommand(std::string sCmd, std::string &sResult);
int readResponse(char *pszRespBuffer, int nBufferLen);
int readResponse(std::string &RespBuffer);
int parseResp(std::string sIn, std::vector<std::string> &svFields, char cSeparator);
SerXInterface *m_pSerx;
bool m_bDebugLog;
bool m_bIsConnected;
std::string m_sFirmwareVersion;
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);
std::vector<std::string> m_svParsedRespForFA;
FalconStatus m_globalStatus;
double m_dTargetPos;
int m_nPosLimit;
bool m_bPosLimitEnabled;
bool m_bAbborted;
#ifdef PLUGIN_DEBUG
std::string m_sLogfilePath;
// timestamp for logs
char *timestamp;
time_t ltime;
FILE *Logfile; // LogFile
#endif
};
#endif //__PEGASUS_FALCON__