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
|
||||
*/
|
||||
|
||||
#ifndef __DTE_H__
|
||||
#define __DTE_H__
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class DTE
|
||||
{
|
||||
//variables
|
||||
public:
|
||||
enum CommandResult
|
||||
{
|
||||
EXPECT_BUSY,
|
||||
EXPECT_TIMEOUT,
|
||||
EXPECT_DELAY,
|
||||
EXPECT_RESULT
|
||||
EXPECT_RESULT,
|
||||
EXPECT_RING
|
||||
};
|
||||
|
||||
protected:
|
||||
private:
|
||||
String buffer;
|
||||
Stream& stream;
|
||||
@ -33,33 +31,32 @@ private:
|
||||
unsigned long tick;
|
||||
unsigned int match;
|
||||
CommandResult result;
|
||||
//functions
|
||||
|
||||
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() {};
|
||||
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;
|
||||
result = EXPECT_BUSY;
|
||||
response[0] = response1;
|
||||
response[1] = response2;
|
||||
response[2] = response3;
|
||||
this->timeout = timeout;
|
||||
// clear rx buffer
|
||||
while (stream.available())
|
||||
{
|
||||
stream.read();
|
||||
}
|
||||
// send command
|
||||
flush();
|
||||
stream.print(command);
|
||||
buffer = "";
|
||||
tick = millis();
|
||||
proccess();
|
||||
}
|
||||
|
||||
void SendCommand(const __FlashStringHelper* command, unsigned long timeout, const char* response1, const char* response2 = 0, const char* response3 = 0)
|
||||
{
|
||||
// char cmd[32];
|
||||
void SendCommand(const __FlashStringHelper* command, unsigned long timeout, const char* response1, const char* response2 = 0, const char* response3 = 0) {
|
||||
|
||||
match = 0;
|
||||
result = EXPECT_BUSY;
|
||||
@ -68,81 +65,97 @@ public:
|
||||
response[2] = response3;
|
||||
this->timeout = timeout;
|
||||
// clear rx buffer
|
||||
while (stream.available())
|
||||
{
|
||||
stream.read();
|
||||
}
|
||||
flush();
|
||||
// send command
|
||||
// strcpy_P(cmd, command);
|
||||
stream.print((const __FlashStringHelper *)command);
|
||||
// stream.print(cmd);
|
||||
buffer = "";
|
||||
tick = millis();
|
||||
proccess();
|
||||
}
|
||||
|
||||
void Delay(unsigned long delay)
|
||||
{
|
||||
void Delay(unsigned long delay) {
|
||||
timeout = delay;
|
||||
result = EXPECT_DELAY;
|
||||
tick = millis();
|
||||
proccess();
|
||||
}
|
||||
bool getIsBusy()
|
||||
{
|
||||
|
||||
bool getIsBusy(void) {
|
||||
proccess();
|
||||
return (result == EXPECT_BUSY) || (result == EXPECT_DELAY);
|
||||
}
|
||||
CommandResult getResult() { return result ; }
|
||||
unsigned int getMatch() { return match; }
|
||||
String& getBuffer() { return buffer; }
|
||||
protected:
|
||||
|
||||
CommandResult getResult(void) {
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned int getMatch(void) {
|
||||
return match;
|
||||
}
|
||||
|
||||
String& getBuffer(void) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
void proccess()
|
||||
{
|
||||
if(result == EXPECT_DELAY)
|
||||
{
|
||||
|
||||
void flush(void) {
|
||||
// clear rx buffer
|
||||
while (stream.available()) {
|
||||
stream.read();
|
||||
}
|
||||
}
|
||||
|
||||
void proccess(void) {
|
||||
if (result == EXPECT_DELAY) {
|
||||
if(millis() - tick >= timeout)
|
||||
result = EXPECT_RESULT;
|
||||
|
||||
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;
|
||||
unsigned long now = millis();
|
||||
|
||||
while(millis() - tick < timeout)
|
||||
{
|
||||
while(stream.available() && (buffer.length() < (bufferSize)))
|
||||
{
|
||||
while (millis() - tick < timeout) {
|
||||
while (stream.available() && (buffer.length() < bufferSize)) {
|
||||
c = stream.read();
|
||||
buffer += c;
|
||||
if(buffer.endsWith(response[0]))
|
||||
{
|
||||
if (buffer.endsWith(response[0])) {
|
||||
match = 0;
|
||||
result = EXPECT_RESULT;
|
||||
return;
|
||||
}else if(response[1].length() != 0)
|
||||
{
|
||||
if(buffer.endsWith(response[1]))
|
||||
{
|
||||
} else if (response[1].length() != 0) {
|
||||
if (buffer.endsWith(response[1])) {
|
||||
match = 1;
|
||||
result = EXPECT_RESULT;
|
||||
return;
|
||||
}
|
||||
}else if(response[2].length() != 0)
|
||||
{
|
||||
if(buffer.endsWith(response[2]))
|
||||
{
|
||||
} else if (response[2].length() != 0) {
|
||||
if (buffer.endsWith(response[2])) {
|
||||
match = 2;
|
||||
result = EXPECT_RESULT;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(millis() - now > 5)
|
||||
if (millis() - now > 5)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -150,5 +163,3 @@ private:
|
||||
result = EXPECT_TIMEOUT;
|
||||
}
|
||||
}; //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