hamlib.cpp 1.47 KB
Newer Older
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
///
/// @file       hamlib.cpp
/// @copyright  Christian Obersteiner, Andreas Müller - CC-BY-SA 4.0
///
/// @brief  Contains all kind of hamlib functions
///

#include "hamlib.h"

///
/// @brief  Constructor
///

CHamlib::CHamlib()
{

}

///
/// @brief  Initialize Hamlib
///

void CHamlib::initHamlib(EthernetUDP *udp, CRotor *rotor)
{
    udp_ = udp;
    rotor_ = rotor;
}

///
/// @brief
///

void CHamlib::receiveHamlibPacket()
{
    if (packet_received_ == false) {
        int packet_size = udp_->parsePacket();
        if (packet_size) {
            packet_received_ = true;
            udp_->read(received_packet_, UDP_TX_PACKET_MAX_SIZE);
            parse_error_ = parseHamlibPacket();
        }
    }
}

///
/// @brief
///

void CHamlib::sendHamlibPacket()
{
    if (packet_parsed_) {
        udp_->beginPacket(udp_->remoteIP(), udp_->remotePort());
        udp_->write(tx_packet_);
        udp_->endPacket();
        packet_parsed_ = false;
    }
}

///
/// @brief
///

CHamlib::hamlibError CHamlib::parseHamlibPacket()
{
    packet_received_ = false;
    if ( received_packet_ == "rotor state\n" )
    {
        // Answer with max rotor values
        sprintf(tx_packet_, "%f/%f %f/%f", AZIM_MIN, AZIM_MAX, ELEV_MIN, ELEV_MAX);
        packet_parsed_ = true;
        sendHamlibPacket();
        return HAMLIB_OK;
    }
    return HAMLIB_NOK; 
}

///
/// @brief  Serial Debug output Function
///

void CHamlib::debugOut()
{
    Serial.print("Contents: ");
    Serial.println(received_packet_);
}