-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.h
142 lines (113 loc) · 3.46 KB
/
main.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
138
139
140
141
//=========================================================================
// main.h
//
// An interface for the RM3100 3-axis magnetometer from PNI Sensor Corp.
//
// Author: David Witten, KD0EAG
// Date: December 18, 2023
// License: GPL 3.0
// Note: replaces i2c.c (using file system calls to read(), write(), etc.
// with calls to pigpio.
// Also adding callbacks on GPIO27 for PPS rising edge.
//=========================================================================
#ifndef SWX3100MAIN_h
#define SWX3100MAIN_h
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <math.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <time.h>
#include <sys/time.h>
#include <fcntl.h>
#include <memory.h>
//#include <linux/i2c-dev.h>
#include "MCP9808.h"
#include "rm3100.h"
//------------------------------------------
// Debugging output
//------------------------------------------
#define _DEBUG FALSE
#define CONSOLE_OUTPUT TRUE
#define USE_WAITFOREDGE TRUE
#define FOR_GRAPE2 TRUE
//------------------------------------------
// Macros and runtime options.
//------------------------------------------
#define RASPI_I2C_BUS0 0
#define RASPI_I2C_BUS1 1
#define PPS_GPIO_PIN 27
#define OUTPUT_PRINT stdout
#define OUTPUT_ERROR stderr
#define PPS_TIMEOUTSECS 2.0
#define USE_PIPES TRUE
#define MAGDATA_VERSION "0.0.2"
#define PPS_GPIO_PIN 27 // physical pin 36
#define PPS_FLAG_TRUE 999 // Flag Value if edge is received
#define PPS_FLAG_FALSE 0 // Flag Value for edge otherwise
#define UTCBUFLEN 64
#define MAXPATHBUFLEN 1025
#define XYZ_BUFLEN 9
//------------------------------------------
// Control Parameter List struct
//------------------------------------------
typedef struct tag_ctlList
{
int pi;
unsigned magHandle;
unsigned localTempHandle;
unsigned remoteTempHandle;
int magnetometerAddr;
int localTempAddr;
int remoteTempAddr;
int doBistMask;
int cc_x;
int cc_y;
int cc_z;
int x_gain;
int y_gain;
int z_gain;
int32_t XYZ[9];
int TMRCRate;
int CMMSampleRate;
int samplingMode;
int NOSRegValue;
int DRDYdelay;
int readBackCCRegs;
uint8_t magRevId;
int i2cBusNumber;
int tsMilliseconds;
char *Version;
int usePipes;
char *pipeInPath;
char *pipeOutPath;
} ctlList;
//------------------------------------------
// Prototypes
//------------------------------------------
int main(int argc, char** argv);
void onEdge(void);
char *formatOutput(volatile ctlList *p, char *outBuf);
int initGPIO(volatile ctlList *p);
void termGPIO(volatile ctlList *p);
int verifyMagSensor(volatile ctlList *p);
int initMagSensor(volatile ctlList *p);
struct tm *getUTC();
int readLocalTemp(volatile ctlList *p);
int readRemoteTemp(volatile ctlList *p);
int readMagPOLL(volatile ctlList *p);
void readCycleCountRegs(volatile ctlList *p);
unsigned short getMagSampleRate(volatile ctlList *p);
void showPIGPIOErrMsg(int rv);
int setNOSReg(volatile ctlList *p);
int setCycleCountsReg(volatile ctlList *p);
void setCycleCounts_by_Reg(volatile ctlList *p);
unsigned short getCCGainEquiv(unsigned short CCVal);
unsigned short getCCGainEquiv(unsigned short CCVal);
#endif //SWX3100MAIN_h