MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / OpenDataCollectionFile

Function OpenDataCollectionFile

src/ClosedLoop/ClosedLoop.cpp:39–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37static CanAddress expectedRemoteBoardAddress = CanId::NoAddress;
38
39static bool OpenDataCollectionFile(const char *_ecv_array filename, unsigned int size) noexcept
40{
41 // Create the file
42 FileStore * const f = MassStorage::OpenFile(filename, OpenMode::write, size);
43 if (f == nullptr) { return false; }
44
45 // Write the header line
46 {
47 static constexpr const char *headings[16] =
48 {
49 ",Raw Encoder Reading",
50 ",Measured Motor Steps",
51 ",Target Motor Steps",
52 ",Current Error",
53 ",PID Control Signal",
54 ",PID P Term",
55 ",PID I Term",
56 ",PID D Term",
57
58 // The next two are out of order in the filter bits, they come later on
59 ",PID V Term",
60 ",PID A Term",
61
62 ",Measured Step Phase",
63 ",Desired Step Phase",
64 ",Phase Shift",
65 ",Coil A Current",
66 ",Coil B Current",
67 ",Unknown",
68 };
69 String<StringLength500> temp;
70 temp.copy("Sample,Timestamp");
71 uint16_t filter = (filterRequested & (CL_RECORD_CURRENT_STEP_PHASE - 1))
72 | ((filterRequested & (CL_RECORD_CURRENT_STEP_PHASE | CL_RECORD_DESIRED_STEP_PHASE | CL_RECORD_PHASE_SHIFT | CL_RECORD_COIL_A_CURRENT | CL_RECORD_COIL_B_CURRENT)) << 2)
73 | ((filterRequested & (CL_RECORD_PID_V_TERM | CL_RECORD_PID_A_TERM)) >> 5);
74 for (unsigned int i = 0; filter != 0; ++i)
75 {
76 if (filter & 1u)
77 {
78 temp.cat(headings[i]);
79 }
80 filter >>= 1;
81 }
82 temp.cat("\n");
83 f->Write(temp.c_str()); // this call could result in the file becoming invalidated
84 }
85
86 whenDataLastReceived = millis(); // prevent another request closing the file
87 closedLoopFile.store(f);
88 return true;
89}
90
91// Close the data collection file. Avoid a race between the two tasks that access it.
92static void CloseDataCollectionFile() noexcept

Callers 1

THROWSFunction · 0.85

Calls 3

copyMethod · 0.80
catMethod · 0.80
WriteMethod · 0.60

Tested by

no test coverage detected