Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FY6900 #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ TODO:
- rewrite whole thing to C++, so adding new AWGs would be easier
- add possibility to configure SSID/PSK + IP without flashing the new SW

Currently supported AWG's:
- FY6800
- FY6900

You can view a video with the SDS-1204X-E and the FY6900 here https://www.youtube.com/watch?v=3_4DelT9P2A

**!WARNING! FY6800 VCC level is 5V, so it has to be dropped somehow to 3.3V ESP may release the magic smoke otherwise.**

![image test](img/connection.png)
Expand Down
26 changes: 22 additions & 4 deletions espBode.ino
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#include <ESP8266WiFi.h>
#include "esp_network.h"
#include "esp_config.h"
#include "esp_fy6800.h"

#include "ESPTelnet.h"

#if AWG == FY6800
#include "esp_fy6800.h"
#elif AWG == FY6900
#include "esp_fy6900.h"
#else
#error "Please select an AWG in esp_config.h"
#endif

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

void setup() {

Serial.begin(115200);

pinMode(LED_BUILTIN, OUTPUT);

// We start by connecting to a WiFi network
DEBUG("Connecting to ");
DEBUG(WIFI_SSID);
Expand All @@ -33,11 +45,14 @@ void setup() {
while (WiFi.status() != WL_CONNECTED) {
delay(500);
DEBUG(".");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

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 @@ -68,12 +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));
}
}
}
}

13 changes: 11 additions & 2 deletions esp_config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#ifndef _ESP_CONFIG_H_
#define _ESP_CONFIG_H_

#include "ESPTelnet.h"
extern ESPTelnet telnet;

#define FY6800 1
#define FY6900 2

/* Select the FY6900 or FY6800 AWG*/
#define AWG FY6900

/* Select either AP or CLIENT mode:
- AP - creates new network that oscilloscope can connect to
- CLIENT - joins existing network
Expand All @@ -13,7 +22,7 @@
#define WIFI_PSK "wlan_key"

/* Comment this for DHCP. However you'll need to obtain IP somehow. */
#define STATIC_IP
//#define STATIC_IP

/* Static ip configuration */
#ifdef STATIC_IP
Expand Down Expand Up @@ -46,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_ */
23 changes: 15 additions & 8 deletions esp_fy6800.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include "esp_fy6800.h"
#include "esp_config.h"
#include <string.h>

#if AWG == FY6800
#warning Compiling for FY6800

#include "esp_fy6800.h"

volatile SDeviceState gDeviceState;

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 Expand Up @@ -36,12 +41,12 @@ void setCh1Output(uint32_t output)
if(output)
{
gDeviceState.ch1Output = 1;
fy6800_write("WMN1\n", 5);
fy6800_write((char*)"WMN1\n", 5);
}
else
{
gDeviceState.ch1Output = 0;
fy6800_write("WMN0\n", 5);
fy6800_write((char*)"WMN0\n", 5);
}
}

Expand All @@ -50,12 +55,12 @@ void setCh2Output(uint32_t output)
if(output)
{
gDeviceState.ch2Output = 1;
fy6800_write("WFN1\n", 5);
fy6800_write((char*)"WFN1\n", 5);
}
else
{
gDeviceState.ch2Output = 0;
fy6800_write("WFN0\n", 5);
fy6800_write((char*)"WFN0\n", 5);
}
}

Expand Down Expand Up @@ -97,15 +102,15 @@ void setCh2Ampl(uint32_t ampl)
/* Phase is in 0.1deg: 12.5deg = 125 */
void setCh1Phase(uint32_t phase)
{
char command[] = "WMA00.000\n";
char command[] = "WMP00.000\n";
snprintf(command, 11, "WMP%02u.%01u\n", phase/1000, (phase%1000)/100);
gDeviceState.ch1Phase = phase;
fy6800_write(command, 10);
}

void setCh2Phase(uint32_t phase)
{
char command[] = "WFA00.000\n";
char command[] = "WFP00.000\n";
snprintf(command, 11, "WFP%02u.%01u\n", phase/1000, (phase%1000)/100);
gDeviceState.ch2Phase = phase;
fy6800_write(command, 10);
Expand Down Expand Up @@ -160,3 +165,5 @@ void initDevice(void)
setCh2Offset(0);

}

#endif
6 changes: 5 additions & 1 deletion esp_fy6800.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if AWG == FY6800

#ifndef _ESP_FY6800_H_
#define _ESP_FY6800_H_

Expand Down Expand Up @@ -88,4 +90,6 @@ void setCh2Offset(int32_t offset);
/* Can be used to set some default parameters */
void initDevice(void);

#endif _ESP_FY6800_H_
#endif //_ESP_FY6800_H_

#endif
161 changes: 161 additions & 0 deletions esp_fy6900.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#include "esp_config.h"
#include <string.h>

#if AWG == FY6900
#warning Compiling for FY6900

#include "esp_fy6900.h"

volatile SDeviceState gDeviceState;

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

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

void setCh1Wave(EWaveType wave)
{
char command[] = "WMW00\n";
snprintf(command, 7, "WMW%02u\n", wave);
gDeviceState.ch1Wave = wave;
fy6900_write(command, 6);
}

void setCh2Wave(EWaveType wave)
{
char command[] = "WFW00\n";
snprintf(command, 7, "WFW%02u\n", wave);
gDeviceState.ch2Wave = wave;
fy6900_write(command, 6);
}

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

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

/* Set frequency in Hz */
void setCh1Freq(uint32_t frequency)
{
char command[] = "WMF00000000000000\n";
snprintf(command, 19, "WMF%08lu000000\n", frequency);
gDeviceState.ch1Freq = frequency;
fy6900_write(command, 18);
}

/* Set frequency in Hz */
void setCh2Freq(uint32_t frequency)
{
char command[] = "WFF00000000000000\n";
snprintf(command, 19, "WFF%08lu000000\n", frequency);
gDeviceState.ch2Freq = frequency;
fy6900_write(command, 18);
}

/* Ampl is in mV: 12.345V = 12345 */
void setCh1Ampl(uint32_t ampl)
{
char command[] = "WMA00.000\n";
snprintf(command, 11, "WMA%02u.%03u\n", ampl/1000, ampl%1000);
gDeviceState.ch1Ampl = ampl;
fy6900_write(command, 10);
}

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

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

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

void setCh1Offset(int32_t offset)
{
char command[] = "WMO00.00\n";
gDeviceState.ch1Offset = offset;
if(offset>=0)
{
snprintf(command, 10, "WMO%02u.%02u\n", offset/1000, offset%1000);
fy6900_write(command, 9);
}
else
{
snprintf(command, 11, "WMO-%02u.%02u\n", -offset/1000, -offset%1000);
fy6900_write(command, 10);
}
}

void setCh2Offset(int32_t offset)
{
char command[] = "WFO00.00\n";
gDeviceState.ch2Offset = offset;
if(offset>=0)
{
snprintf(command, 10, "WFO%02u.%02u\n", offset/1000, offset%1000);
fy6900_write(command, 9);
}
else
{
snprintf(command, 11, "WFO-%02u.%02u\n", -offset/1000, -offset%1000);
fy6900_write(command, 10);
}
}

void initDevice(void)
{
Serial.write((uint8_t*)"\n", 1);

setCh1Output(0);
setCh1Wave(EWaveType_Sine);
setCh1Freq(1000);
setCh1Ampl(1000);
setCh1Offset(0);

setCh2Output(0);
setCh2Wave(EWaveType_Sine);
setCh2Freq(1000);
setCh2Ampl(1000);
setCh2Offset(0);
}

#endif
Loading