Skip to content

Commit

Permalink
Seems to be working
Browse files Browse the repository at this point in the history
  • Loading branch information
timkoers committed Nov 20, 2020
1 parent f163d71 commit 7dd7c25
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 deletions.
11 changes: 9 additions & 2 deletions espBode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "esp_network.h"
#include "esp_config.h"

#include "ESPTelnet.h"

#if AWG == FY6800
#include "esp_fy6800.h"
#elif AWG == FY6900
Expand All @@ -12,6 +14,7 @@

WiFiServer rpc_server(RPC_PORT);
WiFiServer lxi_server(LXI_PORT);
ESPTelnet telnet;

void setup() {

Expand Down Expand Up @@ -47,7 +50,9 @@ void setup() {

DEBUG("WiFi connected");
DEBUG("IP address: ");
DEBUG(WiFi.localIP());
DEBUG(WiFi.localIP().toString());

telnet.begin();

rpc_server.begin();
lxi_server.begin();
Expand Down Expand Up @@ -78,13 +83,15 @@ void loop() {

while(1)
{
telnet.loop();
if(0 != handlePacket(lxi_client))
{
lxi_client.stop();
DEBUG("RESTARTING");
return;
}else{
// Lets give the user some feedback
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
}
}
}
5 changes: 4 additions & 1 deletion esp_config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef _ESP_CONFIG_H_
#define _ESP_CONFIG_H_

#include "ESPTelnet.h"
extern ESPTelnet telnet;

#define FY6800 1
#define FY6900 2

Expand Down Expand Up @@ -52,7 +55,7 @@
#ifdef DEBUG_PRINTS
#define DEBUG(TEXT) Serial.println(TEXT);
#else
#define DEBUG(TEXT)
#define DEBUG(TEXT) telnet.println(TEXT);
#endif

#endif /* _ESP_CONFIG_H_ */
2 changes: 1 addition & 1 deletion esp_fy6800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void fy6800_write(char* data, uint8_t len)
{
uint32_t timeout = 0;
Serial.write((uint8_t*)data, len);
while(0 == Serial.available())
while(!Serial.available())
{
delay(1);
if(timeout++>1000) return;
Expand Down
67 changes: 29 additions & 38 deletions esp_fy6900.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@

volatile SDeviceState gDeviceState;

void fy6900_write(char* data, uint8_t len)
bool fy6900_write(char* data, uint8_t len)
{
uint32_t timeout = 0;
Serial.write((uint8_t*)data, len);
while(0 == Serial.available())
telnet.print(data);
telnet.println("]");
while(!Serial.available())
{
delay(1);
if(timeout++>1000) return;
if(timeout++>1000) return false;
}
(void)Serial.read();
bool ok = false;
ok = (Serial.read() == 0x0a); // 0x0a == \n

if(!ok){
telnet.println("Invalid response for command");
}
return ok;
}

void setCh1Wave(EWaveType wave)
Expand All @@ -38,30 +46,14 @@ void setCh2Wave(EWaveType wave)

void setCh1Output(uint32_t output)
{
if(output)
{
gDeviceState.ch1Output = 1;
fy6900_write((char*)"WMN1\n", 5);
}
else
{
gDeviceState.ch1Output = 0;
fy6900_write((char*)"WMN0\n", 5);
}
gDeviceState.ch1Output = output;
fy6900_write((char*)(output ? "WMN1\n" : "WMN0\n"), 5);
}

void setCh2Output(uint32_t output)
{
if(output)
{
gDeviceState.ch2Output = 1;
fy6900_write((char*)"WFN1\n", 5);
}
else
{
gDeviceState.ch2Output = 0;
fy6900_write((char*)"WFN0\n", 5);
}
gDeviceState.ch2Output = output;
fy6900_write((char*)(output ? "WFN1\n" : "WFN0\n"), 5);
}

/* Set frequency in Hz */
Expand All @@ -85,35 +77,35 @@ void setCh2Freq(uint32_t frequency)
/* Ampl is in mV: 12.345V = 12345 */
void setCh1Ampl(uint32_t ampl)
{
char command[] = "WMA00.00\n";
snprintf(command, 10, "WMA%02u.%02u\n", ampl/1000, ampl%1000);
char command[] = "WMA00.000\n";
snprintf(command, 11, "WMA%02u.%03u\n", ampl/1000, ampl%1000);
gDeviceState.ch1Ampl = ampl;
fy6900_write(command, 9);
fy6900_write(command, 10);
}

void setCh2Ampl(uint32_t ampl)
{
char command[] = "WFA00.00\n";
snprintf(command, 10, "WFA%02u.%02u\n", ampl/1000, ampl%1000);
char command[] = "WFA00.000\n";
snprintf(command, 11, "WFA%02u.%03u\n", ampl/1000, ampl%1000);
gDeviceState.ch2Ampl = ampl;
fy6900_write(command, 9);
fy6900_write(command, 10);
}

/* Phase is in 0.1deg: 12.5deg = 125 */
void setCh1Phase(uint32_t phase)
{
char command[] = "WMP00.000\n";
snprintf(command, 11, "WMP%02u.%01u\n", phase/1000, (phase%1000)/100);
char command[] = "WMP000.000\n";
snprintf(command, 12, "WMP%03u.%03u\n", phase/1000, (phase%1000)/100);
gDeviceState.ch1Phase = phase;
fy6900_write(command, 10);
fy6900_write(command, 11);
}

void setCh2Phase(uint32_t phase)
{
char command[] = "WFP00.000\n";
snprintf(command, 11, "WFP%02u.%01u\n", phase/1000, (phase%1000)/100);
char command[] = "WFP000.000\n";
snprintf(command, 12, "WFP%03u.%03u\n", phase/1000, (phase%1000)/100);
gDeviceState.ch2Phase = phase;
fy6900_write(command, 10);
fy6900_write(command, 11);
}

void setCh1Offset(int32_t offset)
Expand All @@ -123,7 +115,7 @@ void setCh1Offset(int32_t offset)
if(offset>=0)
{
snprintf(command, 10, "WMO%02u.%02u\n", offset/1000, offset%1000);
fy6900_write(command, 10);
fy6900_write(command, 9);
}
else
{
Expand Down Expand Up @@ -163,7 +155,6 @@ void initDevice(void)
setCh2Freq(1000);
setCh2Ampl(1000);
setCh2Offset(0);

}

#endif

0 comments on commit 7dd7c25

Please sign in to comment.