Commit 1c8925d9 authored by andz's avatar andz

-- Added minimal implementation of hamlib

parent 4defb5a5
Pipeline #11 canceled with stages
///
/// @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_);
}
///
/// @file hamlib.h
/// @copyright Christian Obersteiner, Andreas Müller - CC-BY-SA 4.0
///
/// @brief Contains all kind of hamlib functions
///
#ifndef HAMLIB_H
#define HAMLIB_H
#include <Arduino.h>
#include <Ethernet.h>
#include "settings.h"
#include "rotor.h"
class CHamlib
{
public:
enum hamlibError{HAMLIB_OK,
HAMLIB_NOK };
CHamlib();
void initHamlib(EthernetUDP *udp, CRotor *rotor);
void receiveHamlibPacket();
void sendHamlibPacket();
hamlibError parseHamlibPacket();
void debugOut();
private:
EthernetUDP *udp_;
CRotor *rotor_;
char received_packet_[UDP_TX_PACKET_MAX_SIZE];
char tx_packet_[UDP_TX_PACKET_MAX_SIZE];
bool packet_received_ = false;
bool packet_parsed_ = false;
hamlibError parse_error_ = HAMLIB_OK;
};
#endif //HAMLIB_H
......@@ -13,7 +13,7 @@
CRotor::CRotor()
{
initRotor();
initRotor();
}
///
......@@ -33,7 +33,7 @@ void CRotor::initRotor()
digitalWrite(AZIM_RE_CCW, HIGH);
digitalWrite(AZIM_RE_BREAK, HIGH);
//Initial Values
m_bAzimuthBreakReleased = 0;
m_bAzimuthBreakReleased = 0;
}
if(ELEV)
{
......@@ -42,11 +42,11 @@ void CRotor::initRotor()
pinMode(ELEV_RE_DWN, OUTPUT);
pinMode(ELEV_RE_BREAK, OUTPUT);
//All Relais Off
digitalWrite(ELEV_RE_UP, HIGH);
digitalWrite(ELEV_RE_DWN, HIGH);
digitalWrite(ELEV_RE_BREAK, HIGH);
//Initial Values
m_bElevationBreakReleased = 0;
digitalWrite(ELEV_RE_UP, HIGH);
digitalWrite(ELEV_RE_DWN, HIGH);
digitalWrite(ELEV_RE_BREAK, HIGH);
//Initial Values
m_bElevationBreakReleased = 0;
}
}
......
......@@ -30,14 +30,13 @@ public:
private:
rotorError readRotSensors();
uint16 readADC(int);
uint16 m_uActualAzimuth;
uint16 m_uActualElevation;
uint16 m_uSetAzimuth;
uint16 m_uSetElevation;
byte m_bAzimuthBreakReleased;
byte m_bElevationBreakReleased;
};
#endif //ROTOR_H
\ No newline at end of file
......@@ -8,6 +8,7 @@
#ifndef SETTINGS_H
#define SETTINGS_H
// MISC Settings
#define DEBUG
//// Rotor Settings
// Rotor present
......
......@@ -12,20 +12,24 @@
#include <Ethernet.h>
#include "rotor.h"
#include "hamlib.h"
// Network Settings
/// @todo move to settings.h
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0x13, 0x37 };
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x13, 0x37 };
IPAddress ip(83,133,178,126);
unsigned int localPort = 51337;
CRotor rotor;
EthernetUDP Udp;
CHamlib hamlib;
EthernetUDP udp;
int debugTime;
void setup()
{
// Init
rotor.initRotor();
// Open serial communications and wait for port to open:
Serial.begin(19200);
while (!Serial) {
......@@ -34,22 +38,26 @@ void setup()
// start the Ethernet connection:
Ethernet.begin(mac, ip);
Udp.begin(localPort);
Serial.print("Local IP: ");
Serial.println(Ethernet.localIP());
udp.begin(localPort);
// init Hamlbib
hamlib.initHamlib(&udp, &rotor);
//Debug
debugTime = 0;
}
void loop()
{
rotor.doRotor();
if(debugTime > 100)
{
rotor.debugOut();
debugTime = 0;
}
debugTime++;
}
\ No newline at end of file
hamlib.receiveHamlibPacket();
rotor.doRotor();
hamlib.sendHamlibPacket();
if(debugTime > 100)
{
hamlib.debugOut();
rotor.debugOut();
debugTime = 0;
}
debugTime++;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment