WIP: pridani ring indikace (zatim nefunkcni)
This commit is contained in:
parent
49ffb2109c
commit
e2c5e5dcd9
119
src/DTE.h
119
src/DTE.h
@ -5,24 +5,22 @@
|
|||||||
* Author: Neta Yahav
|
* Author: Neta Yahav
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __DTE_H__
|
#pragma once
|
||||||
#define __DTE_H__
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
class DTE
|
class DTE
|
||||||
{
|
{
|
||||||
//variables
|
|
||||||
public:
|
public:
|
||||||
enum CommandResult
|
enum CommandResult
|
||||||
{
|
{
|
||||||
EXPECT_BUSY,
|
EXPECT_BUSY,
|
||||||
EXPECT_TIMEOUT,
|
EXPECT_TIMEOUT,
|
||||||
EXPECT_DELAY,
|
EXPECT_DELAY,
|
||||||
EXPECT_RESULT
|
EXPECT_RESULT,
|
||||||
|
EXPECT_RING
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
|
||||||
private:
|
private:
|
||||||
String buffer;
|
String buffer;
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
@ -33,33 +31,32 @@ private:
|
|||||||
unsigned long tick;
|
unsigned long tick;
|
||||||
unsigned int match;
|
unsigned int match;
|
||||||
CommandResult result;
|
CommandResult result;
|
||||||
//functions
|
|
||||||
public:
|
public:
|
||||||
DTE(Stream& stream, unsigned int size) : stream(stream), bufferSize(size), result(EXPECT_RESULT) { buffer.reserve(size); }
|
DTE(Stream& stream, unsigned int size)
|
||||||
|
: stream(stream)
|
||||||
|
, bufferSize(size)
|
||||||
|
, result(EXPECT_RESULT) {
|
||||||
|
buffer.reserve(size);
|
||||||
|
}
|
||||||
|
|
||||||
~DTE() {};
|
~DTE() {};
|
||||||
void SendCommand(const char* command, unsigned long timeout, const char* response1, const char* response2 = 0, const char* response3 = 0)
|
|
||||||
{
|
void SendCommand(const char* command, unsigned long timeout, const char* response1, const char* response2 = 0, const char* response3 = 0) {
|
||||||
match = 0;
|
match = 0;
|
||||||
result = EXPECT_BUSY;
|
result = EXPECT_BUSY;
|
||||||
response[0] = response1;
|
response[0] = response1;
|
||||||
response[1] = response2;
|
response[1] = response2;
|
||||||
response[2] = response3;
|
response[2] = response3;
|
||||||
this->timeout = timeout;
|
this->timeout = timeout;
|
||||||
// clear rx buffer
|
flush();
|
||||||
while (stream.available())
|
|
||||||
{
|
|
||||||
stream.read();
|
|
||||||
}
|
|
||||||
// send command
|
|
||||||
stream.print(command);
|
stream.print(command);
|
||||||
buffer = "";
|
buffer = "";
|
||||||
tick = millis();
|
tick = millis();
|
||||||
proccess();
|
proccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendCommand(const __FlashStringHelper* command, unsigned long timeout, const char* response1, const char* response2 = 0, const char* response3 = 0)
|
void SendCommand(const __FlashStringHelper* command, unsigned long timeout, const char* response1, const char* response2 = 0, const char* response3 = 0) {
|
||||||
{
|
|
||||||
// char cmd[32];
|
|
||||||
|
|
||||||
match = 0;
|
match = 0;
|
||||||
result = EXPECT_BUSY;
|
result = EXPECT_BUSY;
|
||||||
@ -68,81 +65,97 @@ public:
|
|||||||
response[2] = response3;
|
response[2] = response3;
|
||||||
this->timeout = timeout;
|
this->timeout = timeout;
|
||||||
// clear rx buffer
|
// clear rx buffer
|
||||||
while (stream.available())
|
flush();
|
||||||
{
|
|
||||||
stream.read();
|
|
||||||
}
|
|
||||||
// send command
|
// send command
|
||||||
// strcpy_P(cmd, command);
|
|
||||||
stream.print((const __FlashStringHelper *)command);
|
stream.print((const __FlashStringHelper *)command);
|
||||||
// stream.print(cmd);
|
|
||||||
buffer = "";
|
buffer = "";
|
||||||
tick = millis();
|
tick = millis();
|
||||||
proccess();
|
proccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Delay(unsigned long delay)
|
void Delay(unsigned long delay) {
|
||||||
{
|
|
||||||
timeout = delay;
|
timeout = delay;
|
||||||
result = EXPECT_DELAY;
|
result = EXPECT_DELAY;
|
||||||
tick = millis();
|
tick = millis();
|
||||||
proccess();
|
proccess();
|
||||||
}
|
}
|
||||||
bool getIsBusy()
|
|
||||||
{
|
bool getIsBusy(void) {
|
||||||
proccess();
|
proccess();
|
||||||
return (result == EXPECT_BUSY) || (result == EXPECT_DELAY);
|
return (result == EXPECT_BUSY) || (result == EXPECT_DELAY);
|
||||||
}
|
}
|
||||||
CommandResult getResult() { return result ; }
|
|
||||||
unsigned int getMatch() { return match; }
|
CommandResult getResult(void) {
|
||||||
String& getBuffer() { return buffer; }
|
return result;
|
||||||
protected:
|
}
|
||||||
|
|
||||||
|
unsigned int getMatch(void) {
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
String& getBuffer(void) {
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void proccess()
|
|
||||||
{
|
void flush(void) {
|
||||||
if(result == EXPECT_DELAY)
|
// clear rx buffer
|
||||||
{
|
while (stream.available()) {
|
||||||
|
stream.read();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void proccess(void) {
|
||||||
|
if (result == EXPECT_DELAY) {
|
||||||
if(millis() - tick >= timeout)
|
if(millis() - tick >= timeout)
|
||||||
result = EXPECT_RESULT;
|
result = EXPECT_RESULT;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result != EXPECT_BUSY) return;
|
if (result != EXPECT_BUSY) {
|
||||||
|
if (stream.available()) {
|
||||||
|
char c;
|
||||||
|
|
||||||
|
c = stream.read();
|
||||||
|
buffer += c;
|
||||||
|
if (buffer.length() > 4) {
|
||||||
|
if (buffer.endsWith(F("RING\n"))) {
|
||||||
|
result = EXPECT_RING;
|
||||||
|
}
|
||||||
|
buffer.remove(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
|
||||||
while(millis() - tick < timeout)
|
while (millis() - tick < timeout) {
|
||||||
{
|
while (stream.available() && (buffer.length() < bufferSize)) {
|
||||||
while(stream.available() && (buffer.length() < (bufferSize)))
|
|
||||||
{
|
|
||||||
c = stream.read();
|
c = stream.read();
|
||||||
buffer += c;
|
buffer += c;
|
||||||
if(buffer.endsWith(response[0]))
|
if (buffer.endsWith(response[0])) {
|
||||||
{
|
|
||||||
match = 0;
|
match = 0;
|
||||||
result = EXPECT_RESULT;
|
result = EXPECT_RESULT;
|
||||||
return;
|
return;
|
||||||
}else if(response[1].length() != 0)
|
} else if (response[1].length() != 0) {
|
||||||
{
|
if (buffer.endsWith(response[1])) {
|
||||||
if(buffer.endsWith(response[1]))
|
|
||||||
{
|
|
||||||
match = 1;
|
match = 1;
|
||||||
result = EXPECT_RESULT;
|
result = EXPECT_RESULT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}else if(response[2].length() != 0)
|
} else if (response[2].length() != 0) {
|
||||||
{
|
if (buffer.endsWith(response[2])) {
|
||||||
if(buffer.endsWith(response[2]))
|
|
||||||
{
|
|
||||||
match = 2;
|
match = 2;
|
||||||
result = EXPECT_RESULT;
|
result = EXPECT_RESULT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(millis() - now > 5)
|
if (millis() - now > 5)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,5 +163,3 @@ private:
|
|||||||
result = EXPECT_TIMEOUT;
|
result = EXPECT_TIMEOUT;
|
||||||
}
|
}
|
||||||
}; //DTE
|
}; //DTE
|
||||||
|
|
||||||
#endif //__DTE_H__
|
|
||||||
|
1208
src/ThreadedGSM.h
1208
src/ThreadedGSM.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user