-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OCPP date-time types should have only seconds precision #384
Comments
@RobertDeLeeuw RFC on the OCPP handling |
Signed-off-by: Coury Richards <[email protected]>
Signed-off-by: Coury Richards <[email protected]>
Signed-off-by: Coury Richards <[email protected]>
Bit of background. Mean reason to ommit milliseconds in OCPP. OCPP is not real time. Sending over milliseconds in every message would only increase the amount of data over the line without adding anything useful for users. |
I think the best solution would be to have functionality to send and receive OCPP without milliseconds and when comparing OCPP "timestamps" to compare without milliseconds. So you could also opt for OCPP specific timestamp compare functions. That dont take milliseconds into account. Adding a new data type would result in the same kind of functions. On the otherhand. Adding a new datatype that supports comparing against its own type and DateTime-class would code wish maybe provides the cleanest code. |
That is just YOUR interpretation of "OCPP Legacy" ;) Fractions of seconds are often important when the order of events is important and TIME should be strictly growing monotonically. But it is a good question where we need this in "normal" OCPP. In most cases you can ignore it, but whenever we come to e.g. grid management operations you have to deal with msecs. So the OCPP text is quite good: Ignore the fractions, unless you have a good reason not to ignore them. |
Signed-off-by: Coury Richards <[email protected]>
The
DateTime
class inocpp/common/
uses internally thestd::chrono::time_point<date::utc_clock>
which has a sub-second precision by default (at least on most platforms). When thistime_point
is initialized with a value with lower precision, e.g. from a CSMS message or the database, then the sub-second fractions have arbitrary values. But the==
-equality-check is simply done on thetime_point
s:libocpp/lib/ocpp/common/types.cpp
Lines 95 to 97 in 6f73dec
That leads to a failure in the database-tests (thanks @couryrr-afs for catching it). It can be easy verified by using the
.to_time_point()
in the GTest assertions.Solution
The
DateTime
's internaltimepoint
should only have seconds precision. As in both OCPP-versions, the sub-second precision may be omitted:OCPP 1.6 spec (edition 2 FINAL, 2017-09-2), 3.15. Time notations:
OCPP 2.0.1 spec (Edition 2 FINAL, 2022-12-15), 3.1. Time Format Requirements:
But the
DateTime
-class is also used for other internal types (which are not OCPP-messages). At least changing the precision fails amessage_queue
unit-test which hints that perhaps the internal-types need sub-second precision. See #383Given that, I suggest to add a new type
DateTimeSeconds(Precision)
and deliberately use this in the OCPP-message related types. Then the remaining usages could be checked on precision-level later. (This approach resembles the Open-closed principle, I guess.)The text was updated successfully, but these errors were encountered: