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

blues / note-arduino / 28679653251

03 Jul 2026 07:23PM UTC coverage: 75.549% (-17.5%) from 93.061%
28679653251

Pull #168

github

web-flow
Merge 5b716ba08 into 8e06624fe
Pull Request #168: feat: add Notecard ping

120 of 190 branches covered (63.16%)

Branch coverage included in aggregate %.

20 of 100 new or added lines in 4 files covered. (20.0%)

362 of 448 relevant lines covered (80.8%)

11.69 hits per line

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

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

3
#include "Notecard.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
#include "mock/mock-parameters.hpp"
12
#endif
13

14
#define NOTE_C_SERIAL_TIMEOUT_MS 3500
15

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

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

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

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

57
    return note_serial;
4✔
58
}
59

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

71
    // Wait for the serial port to be ready
72
    for (const size_t startMs = NoteGetMs()
22✔
73
       ; !_notecardSerial && ((NoteGetMs() - startMs) < NOTE_C_SERIAL_TIMEOUT_MS)
22!
74
       ;
75
    );
76
}
22✔
77

78
template <typename T>
79
NoteSerial_Arduino<T>::~NoteSerial_Arduino (
26✔
80
    void
81
)
82
{
83
    _notecardSerial.end();
22✔
84
}
26✔
85

86
template <typename T>
87
size_t
88
NoteSerial_Arduino<T>::available (
2✔
89
    void
90
)
91
{
92
    return _notecardSerial.available();
2✔
93
}
94

95
template <typename T>
96
char
97
NoteSerial_Arduino<T>::receive (
2✔
98
    void
99
)
100
{
101
    return _notecardSerial.read();
2✔
102
}
103

104
template <typename T>
105
bool
106
NoteSerial_Arduino<T>::reset (
5✔
107
    void
108
)
109
{
110
    _notecardSerial.end();
5✔
111
    _notecardSerial.begin(_notecardSerialSpeed);
5✔
112

113
    return true;
5✔
114
}
115

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

132
template <typename T>
133
bool
134
NoteSerial_Arduino<T>::setBaudRate (
1✔
135
    uint32_t rate
136
)
137
{
138
    _notecardSerial.end();
1✔
139
    _notecardSerial.begin(rate);
1✔
140
    _notecardSerialSpeed = rate;
1✔
141

142
    // Wait for the serial port to be ready, matching the constructor's
143
    // handling for native-USB boards where the Serial object becomes
144
    // truthy only after the USB CDC link is up.
145
    for (const size_t startMs = NoteGetMs()
1✔
146
       ; !_notecardSerial && ((NoteGetMs() - startMs) < NOTE_C_SERIAL_TIMEOUT_MS)
1!
147
       ;
148
    );
149

150
    return true;
1✔
151
}
152

153
template <typename T>
154
uint32_t
NEW
155
NoteSerial_Arduino<T>::getBaudRate (
×
156
    void
157
) const
158
{
NEW
159
    return _notecardSerialSpeed;
×
160
}
161

162
// Explicitly instantiate the classes and methods for the supported types
163
template class NoteSerial_Arduino<HardwareSerial>;
164
template NoteSerial * make_note_serial<MakeNoteSerial_ArduinoParameters<HardwareSerial>>(MakeNoteSerial_ArduinoParameters<HardwareSerial> &);
165

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

© 2026 Coveralls, Inc