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
63 virtual bool sendPhotoToOcrServer(const char *url,
64 const char *authkey,
65 char *resultBuffer,
66 int resultBufferSize,
67 const char *cropSettings) = 0;
68 void parseServerResponse(const char *response, int responseSize);
69
70 bool hasOcrConfig() const override;
71 void clearOcrConfig() override;
72 bool isOcrConfigMissing() const override;
73 uint8_t applyChannelConfig(TSD_ChannelConfig *result, bool local) override;
74 void fillChannelConfig(void *channelConfig, int *size) override;
75 void fillChannelOcrConfig(void *channelConfig, int *size) override;
76 void fixOcrLightingMode();
77 void stopResultCheck();
78
79 virtual bool getStatusFromOcrServer(const char *url,
80 const char *authkey,
81 char *buf,
82 int size) = 0;
83 void parseStatus(const char *response, int responseSize);
84
85 void generateUrl(char *url,
86 int urlSize,
87 const char *photoUuid = nullptr) const;
88
89 TChannelConfig_OCR ocrConfig = {};
90 bool ocrConfigReceived = false;
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
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition ocr_impulse_counter.cpp:218
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition ocr_impulse_counter.cpp:592
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition ocr_impulse_counter.cpp:211
void onLoadConfig(SuplaDeviceClass *sdc) override
First method called on element in SuplaDevice.begin().
Definition ocr_impulse_counter.cpp:529
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition ocr_impulse_counter.cpp:56
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition ocr_impulse_counter.cpp:72
bool iterateConnected() override
Method called on each SuplaDevice iteration when device is connected and registered to Supla server o...
Definition ocr_impulse_counter.cpp:235
Definition proto.h:3526
Definition proto.h:2912
Definition proto.h:2246