supla-device
Loading...
Searching...
No Matches
ocr_impulse_counter.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_SENSOR_OCR_IMPULSE_COUNTER_H_
20#define SRC_SUPLA_SENSOR_OCR_IMPULSE_COUNTER_H_
21
22#include <supla/clock/clock.h>
23#include <supla/device/factory_test.h>
24
25#include "virtual_impulse_counter.h"
26
27namespace Supla {
28
29namespace Sensor {
30class OcrImpulseCounter : public VirtualImpulseCounter {
31 public:
32 OcrImpulseCounter();
33 virtual ~OcrImpulseCounter();
34 void onLoadConfig(SuplaDeviceClass *sdc) override;
35 void onLoadState() override;
36 void onSaveState() override;
37 void onInit() override;
38 void iterateAlways() override;
39 bool iterateConnected() override;
41
42 void addAvailableLightingMode(uint64_t mode);
43 void resetCounter() override;
44
45 void setFactoryTester(Supla::Device::FactoryTest *tester);
46 bool cleanupOcrTestModeConfig();
47
48 protected:
49 // takes photo and initialize photoDataBuffer and photoDataSize
50 // returns true if photo was taken successfully
51 virtual bool takePhoto() = 0;
52 // release photo resource by clearing photoDataBuffer and photoDataSize
53 // and calling releasePhoto for implementation specific actions
54 void releasePhotoResource();
55 // additional releasing of resources if needed by implementation
56 virtual void releasePhoto() = 0;
57 // implement turning on/off the LED. State == 0..100 %
58 virtual void setLedState(int state) = 0;
59 // turns on led if needed and handles delay between led turning on and photo
60 bool handleLedStateBeforePhoto();
61 void handleLedStateAfterPhoto();
62 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override;
63
64 virtual bool sendPhotoToOcrServer(const char *url,
65 const char *authkey,
66 char *resultBuffer,
67 int resultBufferSize,
68 const char *cropSettings) = 0;
69 void parseServerResponse(const char *response, int responseSize);
70
71 void clearOcrConfig();
72 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
73 bool local) override;
74 void fillChannelConfig(void *channelConfig,
75 int *size,
76 uint8_t configType) override;
77 void fixOcrLightingMode();
78 void stopResultCheck();
79
80 virtual bool getStatusFromOcrServer(const char *url,
81 const char *authkey,
82 char *buf,
83 int size) = 0;
84 void parseStatus(const char *response, int responseSize);
85
86 void generateUrl(char *url,
87 int urlSize,
88 const char *photoUuid = nullptr) const;
89
90 TChannelConfig_OCR ocrConfig = {};
91 uint64_t availableLightingModes = 0;
92 uint32_t lastPhotoTakeTimestamp = 0;
93 uint32_t lastOcrInteractionTimestamp = 0;
94 uint32_t ledTurnOnTimestamp = 0;
95 char lastUUIDToCheck[37] = {};
96 unsigned char *photoDataBuffer = nullptr;
97 int photoDataSize = 0;
98
99 // values stored in Storage
100 uint64_t lastCorrectOcrReading = 0;
101 time_t lastCorrectOcrReadingTimestamp = 0;
102 SuplaDeviceClass *sdc = nullptr;
103 bool testMode = false;
104 uint32_t testModeDelay = 0;
105 Supla::Device::FactoryTest *factoryTester = nullptr;
106 uint32_t photosCount = 0;
107 int32_t ocrTestExpectedResult = -1;
108};
109
110} // namespace Sensor
111} // namespace Supla
112
113#endif // SRC_SUPLA_SENSOR_OCR_IMPULSE_COUNTER_H_
Definition SuplaDevice.h:93
Definition factory_test.h:45
Definition supla_srpc.h:55
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition ocr_impulse_counter.cpp:208
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition ocr_impulse_counter.cpp:582
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition ocr_impulse_counter.cpp:201
void onLoadConfig(SuplaDeviceClass *sdc) override
First method called on element in SuplaDevice.begin().
Definition ocr_impulse_counter.cpp:519
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition ocr_impulse_counter.cpp:58
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override
Method called each time when device successfully registers to Supla server.
Definition ocr_impulse_counter.cpp:69
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition ocr_impulse_counter.cpp:74
bool iterateConnected() override
Method called on each SuplaDevice iteration when device is connected and registered to Supla server o...
Definition ocr_impulse_counter.cpp:225
Definition proto.h:3607
Definition proto.h:2987
Definition proto.h:2248