• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blues / note-arduino / 15450437587

04 Jun 2025 06:57PM CUT coverage: 88.189%. Remained the same
15450437587

push

github

web-flow
version v1.7.1 (#145)

111 of 165 branches covered (67.27%)

Branch coverage included in aggregate %.

337 of 343 relevant lines covered (98.25%)

14.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.05
/src/NoteSerial_Arduino.cpp
1
#include "NoteSerial_Arduino.hpp"
2

3
#include "NoteDefines.h"
4

5
#ifndef NOTE_MOCK
6
#ifdef NOTE_ARDUINO_SOFTWARE_SERIAL_SUPPORT
7
#include <SoftwareSerial.h>
8
#endif
9
#else
10
#include "mock/mock-arduino.hpp"
11
#endif
12

13
#define NOTE_C_SERIAL_TIMEOUT_MS 3500
14

15
// Template Meta-Programming (TMP) to extract the nested template type
16
template <typename nested_type>
17
struct ExtractNestedTemplateType {
18
    // Default case: no extraction
19
};
20
template <typename nested_type>
21
struct ExtractNestedTemplateType<MakeNoteSerial_ArduinoParameters<nested_type>> {
22
    using type = nested_type;
23
};
24

25
// Singleton instance of the NoteSerial_Arduino class
26
namespace instance {
27
    inline NoteSerial* & note_serial (void) {
7✔
28
        static NoteSerial* note_serial = nullptr;
29
        return note_serial;
7✔
30
    }
31
};
32

33
NoteSerial *
34
make_note_serial (
3✔
35
    nullptr_t
36
) {
37
    NoteSerial* & note_serial = instance::note_serial();
3✔
38
    if (note_serial) {
3!
39
        delete note_serial;
3!
40
        note_serial = nullptr;
3✔
41
    }
42
    return note_serial;
3✔
43
}
44

45
template <typename T>
46
NoteSerial *
47
make_note_serial (
4✔
48
    T & serial_parameters_
49
) {
50
    NoteSerial* & note_serial = instance::note_serial();
4✔
51
    if (!note_serial) {
4✔
52
        using serial_type = typename ExtractNestedTemplateType<T>::type;
53
        note_serial = new NoteSerial_Arduino<serial_type>(serial_parameters_.serial, serial_parameters_.baud_rate);
3!
54
    }
55

56
    return note_serial;
4✔
57
}
58

59
template <typename T>
60
NoteSerial_Arduino<T>::NoteSerial_Arduino
20✔
61
(
62
    T & serial_,
63
    size_t baud_rate_
64
) :
65
    _notecardSerial(serial_),
20✔
66
    _notecardSerialSpeed(baud_rate_)
20✔
67
{
68
    _notecardSerial.begin(_notecardSerialSpeed);
20!
69

70
    // Wait for the serial port to be ready
71
    for (const size_t startMs = ::millis() ; !_notecardSerial && ((::millis() - startMs) < NOTE_C_SERIAL_TIMEOUT_MS) ;);
20!
72
}
20✔
73

74
template <typename T>
75
NoteSerial_Arduino<T>::~NoteSerial_Arduino (
20✔
76
    void
77
)
78
{
79
    _notecardSerial.end();
20✔
80
}
20✔
81

82
template <typename T>
83
size_t
84
NoteSerial_Arduino<T>::available (
2✔
85
    void
86
)
87
{
88
    return _notecardSerial.available();
2✔
89
}
90

91
template <typename T>
92
char
93
NoteSerial_Arduino<T>::receive (
2✔
94
    void
95
)
96
{
97
    return _notecardSerial.read();
2✔
98
}
99

100
template <typename T>
101
bool
102
NoteSerial_Arduino<T>::reset (
4✔
103
    void
104
)
105
{
106
    _notecardSerial.end();
4✔
107
    _notecardSerial.begin(_notecardSerialSpeed);
4✔
108

109
    return true;
4✔
110
}
111

112
template <typename T>
113
size_t
114
NoteSerial_Arduino<T>::transmit (
6✔
115
    uint8_t *buffer,
116
    size_t size,
117
    bool flush
118
)
119
{
120
    size_t result;
121
    result = _notecardSerial.write(buffer, size);
6✔
122
    if (flush) {
6✔
123
        _notecardSerial.flush();
5✔
124
    }
125
    return result;
6✔
126
}
127

128
// Explicitly instantiate the classes and methods for the supported types
129
template class NoteSerial_Arduino<HardwareSerial>;
130
template NoteSerial * make_note_serial<MakeNoteSerial_ArduinoParameters<HardwareSerial>>(MakeNoteSerial_ArduinoParameters<HardwareSerial> &);
131

132
#ifdef NOTE_ARDUINO_SOFTWARE_SERIAL_SUPPORT
133
template class NoteSerial_Arduino<SoftwareSerial>;
134
template NoteSerial * make_note_serial<MakeNoteSerial_ArduinoParameters<SoftwareSerial>>(MakeNoteSerial_ArduinoParameters<SoftwareSerial> &);
135
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc