EnOcean Link  1.14.0.0
Middleware to Connect EnOcean easily to other Projects
Tutorial 5

In this Tutorial tutorial5.cpp we show how to use Serial Commands.

#define SER_PORT "/dev/USB300"
#define SAVE_CONFIG "./learned.txt"
#define LEARN_TIME_S 1
#include "./eoLink.h"
#include <stdio.h>
int main(int argc, const char* argv[]) {
eoGateway myGateway;
uint16_t recv=0;
printf("Opening Connection to USB300 \n");
if (myGateway.Open(SER_PORT)!=OK)
{
printf("Failed to open USB300\n");
return 0;
}
eoSerialCommand cmd(&myGateway);
//Read Sw and HW version of the device
if (cmd.ReadVersion(version) == OK)
{
printf("%s %i.%i.%i.%i, ID:0x%08lX on %s\n",
version.appDescription,
version.appVersion[0], version.appVersion[1], version.appVersion[2], version.appVersion[3],
version.chipID,
SER_PORT);
}
//Failed to read the version of the device
else
{
printf("Failed to retrieve USB300 version\n");
return -1;
}
//Perform a built in self test
if (cmd.BIST() == OK)
printf ("Successful BIST performed!\n");
//Failed BIST
else
{
printf("Failed to perform BIST\n");
return -1;
}
//Read device ID base
if (cmd.ReadIDBase(baseID) == OK)
printf("Base ID: %08lX, %i writes left\n", baseID.baseID, baseID.remainingWrites);
else
{
printf("Failed to retrieve USB300 base ID\n");
return -1;
}
//Write repeater
uint8_t repLevel = 1;
if (cmd.WriteRepeater(true, repLevel) == OK)
printf("Repeater added!\n");
else
{
printf("Failed to add repeater\n");
return -1;
}
//Read repeater
if (cmd.ReadRepeater(repeater) == OK)
printf("Enabled: %s, Level: %i\n", repeater.repEnable ? "true":"false", repeater.repLevel);
else
{
printf("Failed to read repetear\n");
return -1;
}
//Add filter
if (cmd.AddFilter(CHOICE,0x11223344, BLOCK) == OK)
printf("Filter added!\n");
else
{
printf("Failed to add filter\n");
return -1;
}
//Read filter
uint8_t filterCount;
if (cmd.ReadFilter(filter, &filterCount, 1) == OK)
printf("Filter type: %i, Filter value: 0x%08lX\n", filter[0].filterType, filter[0].filterValue);
else
{
printf("Failed to read filter\n");
return -1;
}
//Delete filter
if (cmd.DeleteFilter(CHOICE, 0x11223344) == OK)
printf("Filter deleted\n");
else
{
printf("Failed to delete filter\n");
return -1;
}
//Enable filter
if (cmd.EnableFilter(true, OR) == OK)
printf("Filter enabled\n");
else
{
printf("Failed to enable filter\n");
return -1;
}
//Delete all filter
if (cmd.DeleteAllFilter() == OK)
printf("All filter has been deleted!\n");
else
{
printf("Failed to delete all filter\n");
return -1;
}
//Wait maturity time
if (cmd.WaitMaturity(true) == OK)
printf("Maturity turned on\n");
else
{
printf("Failed to turn on maturity\n");
return -1;
}
return 0;
}