Skip to content

Commit

Permalink
First release for wb2ih
Browse files Browse the repository at this point in the history
  • Loading branch information
avp-avp committed Jan 29, 2017
2 parents 6d56462 + 83ec0ef commit 3c64c3a
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 17 deletions.
1 change: 1 addition & 0 deletions libcomm/libcomm.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<AdditionalIncludeDirectories>../libutils/jsoncpp.w32</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
21 changes: 20 additions & 1 deletion librf/RFM69OOK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,32 @@ bool RFM69OOK::receiveDone()
return false;
}

void RFM69OOK::exportGPIO(int num)
{
FILE *f = fopen("/sys/class/gpio/export", "w");
if (!f)
{
throw CHaException(CHaException::ErrBadParam, "Cannot open /sys/class/gpio/export");
}

char buffer[128];
snprintf(buffer, sizeof(buffer), "%d", num);

if (fwrite(buffer, strlen(buffer), 1, f)!=1)
throw CHaException(CHaException::ErrBadParam, "Write to export GPIO file failed");

fclose(f);
}

bool RFM69OOK::getGPIO(int num)
{
char buffer[128];
snprintf(buffer, sizeof(buffer), "/sys/class/gpio/gpio%d/value", num);
FILE *f = fopen(buffer, "r");
if (!f)
throw CHaException(CHaException::ErrBadParam, buffer);
{
exportGPIO(num);
}

if (fread(buffer, 1, 1, f)!=1)
throw CHaException(CHaException::ErrBadParam, "Read GPIO file failed");
Expand Down
1 change: 1 addition & 0 deletions librf/RFM69OOK.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class RFM69OOK {
int m_gpioInt;

bool getGPIO(int num);
void exportGPIO(int num);
};

unsigned long millis(void);
Expand Down
3 changes: 3 additions & 0 deletions librf/RFProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ void CRFProtocol::EncodePacket(const string &bits, uint16_t bitrate, uint8_t *bu

for (int j = 0; j < bits; j++)
{
if (bufferSize < (bitNum+7)>>3)
throw CHaException(CHaException::ErrBadParam, "Buffer too small");

if (pulse)
buffer[bitNum >> 3] |= (1 << (7-(bitNum & 7)));

Expand Down
37 changes: 31 additions & 6 deletions librf/RFProtocolLivolo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,42 @@ static range_type g_timing_pulse[8] =

static const uint16_t g_transmit_data[]=
{
500, 100, 300, 0, // Pauses
500, 200, 400, 0, // Pauses
500, 100, 300, 0 // Pulses
};



/* 1234567890123456 1234567
0011001111010001 0001000 - A
0011001111010001 0010000 - B
0011001111010001 0111000 - C
0011001111010001 0101010 - D
0011 0011 1101 0001 000 100 0 - A
0011 0011 1101 0001 001 000 0 - B
0011 0011 1101 0001 011 100 0 - C
0011 0011 1101 0001 010 101 0 - D
*/

/*
0110 1010 0100 = 06A4
1 - 000 000 0
2 - 110 000 0
3 - 111 100 0
4 - 001 100 0
5 - 110 110 0
+ - 101 110 0 !
- - 111 010 0 !
I - 101 101 0 !
II- 111 001 0 !
1 - 101 000 0
2 - 011 000 0
3 - 000 110 0
4 - 010 100 0
5 - 100 100 0
+ - 111 111 0 !
- - 010 010 0 !
I - 000 101 0 !
II- 001 001 0 !
C - 110 1010
*/


Expand Down Expand Up @@ -120,7 +145,7 @@ string CRFProtocolLivolo::bits2timings(const string &bits)
{
string result;

for (int pulse= 0; pulse <= 180; pulse = pulse+1) { // how many times to transmit a command
for (int pulse= 0; pulse <= 5; pulse = pulse+1) { // how many times to transmit a command
result+="A";
bool high = true; // first pulse is always high
for_each_const(string, bits, i)
Expand Down
2 changes: 1 addition & 1 deletion libutils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ libutils_la_SOURCES = Buffer.cpp Buffer.h Exception.cpp Exception.h \
Serializable.cpp Serializable.h XmlDocument.cpp Config.cpp Config.h \
XmlDocument.h ConfigItem.cpp ConfigItem.h libutils.cpp libutils.h locks.cpp locks.h \
logging.cpp logging.h md.h sha1c.cpp sha_locl.h stdafx.cpp stdafx.h strutils.cpp \
strutils.h targetver.h thread.cpp thread.h jsoncpp/jsoncpp.cpp
strutils.h targetver.h thread.cpp thread.h

AM_CFLAGS = -pthread
AM_CXXFLAGS = -pthread
Expand Down
3 changes: 2 additions & 1 deletion libutils/libutils.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;JSON_DLL_BUILD;LIBUTILS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>jsoncpp.w32</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -153,7 +154,7 @@
<ClCompile Include="ConfigItem.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="Exception.cpp" />
<ClCompile Include="jsoncpp\jsoncpp.cpp" />
<ClCompile Include="jsoncpp.w32\jsoncpp.cpp" />
<ClCompile Include="libutils.cpp" />
<ClCompile Include="locks.cpp" />
<ClCompile Include="logging.cpp" />
Expand Down
4 changes: 2 additions & 2 deletions libutils/libutils.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
<ClCompile Include="XmlDocument.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="jsoncpp\jsoncpp.cpp">
<ClCompile Include="Config.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Config.cpp">
<ClCompile Include="jsoncpp.w32\jsoncpp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down
13 changes: 8 additions & 5 deletions libutils/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ LogParam::LogParam()
#ifdef USE_CONFIG
LogParam::LogParam(CConfigItem node)
{
FileName = node.getStr("FileName");
LogTime = (node.getStr("LogTime", false, "yes")=="yes")?true:false;
ConsoleLevel = node.getInt("ConsoleLevel", false, -1);
FileLevel = node.getInt("FileLevel", false, 0);
FileName = node.getStr("FileName", false, node.getStr("file_name"));
LogTime = (node.getStr("LogTime", false, node.getStr("log_time", false, "yes"))=="yes")?true:false;
ConsoleLevel = node.getInt("ConsoleLevel", false, node.getInt("console_level", false, -1));
FileLevel = node.getInt("FileLevel", false, node.getInt("file_level", false, 0));
}
#endif

Expand Down Expand Up @@ -112,10 +112,13 @@ void CLog::Init(CConfigItem *Config)
{
CConfigItemList nodes;
Config->getList("Log", nodes);

if (nodes.size()==0)
Config->getList("log", nodes);

for(CConfigItemList::iterator i=nodes.begin();i!=nodes.end();i++)
{
m_LogsCfg[(*i)->getStr("Name")] = LogParam(**i);
m_LogsCfg[(*i)->getStr("Name", false, (*i)->getStr("name"))] = LogParam(**i);
}
}
#endif
Expand Down
25 changes: 25 additions & 0 deletions libwb/WBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ CWBDevice::CWBDevice(string Name, string Description)

}

CWBDevice::CWBDevice()
{

}


CWBDevice::~CWBDevice()
{
Expand Down Expand Up @@ -195,6 +200,16 @@ float CWBDevice::getF(string Name)
return i->second->fValue;
}

int CWBDevice::getI(string Name)
{
CControlMap::iterator i = m_Controls.find(Name);

if (i == m_Controls.end())
throw CHaException(CHaException::ErrBadParam, Name);

return atoi(i->second->sValue);
}

string CWBDevice::getS(string Name)
{
CControlMap::iterator i = m_Controls.find(Name);
Expand Down Expand Up @@ -262,6 +277,16 @@ bool CWBDevice::sourceExists(const string &source)
return false;
}

bool CWBDevice::controlExists(string Name)
{
CControlMap::iterator i = m_Controls.find(Name);

if (i == m_Controls.end())
return false;

return true;
}

void CWBDevice::setBySource(string source, string sourceType, string Value)
{
if (sourceType=="X10")
Expand Down
4 changes: 3 additions & 1 deletion libwb/WBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,23 @@ class LIBWB_API CWBDevice

public:
CWBDevice(string Name, string Description);
//CWBDevice();
CWBDevice();
~CWBDevice();

string getName(){return m_Name;};
string getDescription(){return m_Description;};
#ifdef USE_CONFIG
void Init(CConfigItem config);
#endif
bool controlExists(string source);
void addControl(const string &Name);
void addControl(const string &Name, CWBControl::ControlType Type, bool ReadOnly, const string &Source="", const string &SourceType="");
bool sourceExists(const string &source);
void setBySource(string source, string sourceType, string Value);
void set(string Name, string Value);
void set(string Name, float Value);
float getF(string Name);
int getI(string Name);
string getS(string Name);
const CWBControl* getControl(string Name);
void createDeviceValues(string_map &);
Expand Down
1 change: 1 addition & 0 deletions libwb/libwb.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBWB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../libutils/jsoncpp.w32</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down

0 comments on commit 3c64c3a

Please sign in to comment.