Skip to content

Commit 6c82ba5

Browse files
AnlangAtommymalmqvistanlada
authored
Traits v2_1: rebase main (#165)
* linting * feat: Enhance BootNotification message for OCPP v2.1 - Add comprehensive BootNotificationRequest and BootNotificationResponse structs - Introduce new enumerations: BootReasonEnumType and RegistrationStatusEnumType - Implement validation for datetime and field lengths - Add support for custom data and modem information - Improve test coverage with various validation scenarios - Update Cargo.toml to include lazy_static and serde_json dependencies * feat: Add GenericStatusEnumType for OCPP v2.1 - Introduce new GenericStatusEnumType enumeration - Support serialization and deserialization of status - Add Accepted and Rejected status variants - Update enumerations module to export the new type * feat: Add HashAlgorithmEnumType for OCPP v2.1 - Introduce new HashAlgorithmEnumType enumeration - Support serialization and deserialization of hash algorithms - Include SHA256, SHA384, and SHA512 variants - Update enumerations module to export the new type * feat: Add AuthorizationStatusEnumType for OCPP v2.1 - Introduce new AuthorizationStatusEnumType enumeration - Support serialization and deserialization of authorization statuses - Include multiple status variants like Accepted, Blocked, Expired, etc. - Update enumerations module to export the new type * feat: Add CertificateSigningUseEnumType for OCPP v2.1 - Introduce new CertificateSigningUseEnumType enumeration - Support serialization and deserialization of certificate signing use types - Include variants for Charging Station, V2G, and V2G 2.0 certificates - Update enumerations module to export the new type * feat: Add OperationalStatusEnumType for OCPP v2.1 * Add ChangeAvailabilityStatusEnumType * feat: Add DayOfWeekEnumType for OCPP v2.1 - Introduce new DayOfWeekEnumType enumeration - Support serialization and deserialization of days of the week - Include all seven days from Monday to Sunday - Update enumerations module to export the new type * feat: Add EvseKindEnumType for OCPP v2.1 - Introduce new EvseKindEnumType enumeration - Support serialization and deserialization of EVSE types - Include AC and DC variants - Update enumerations module to export the new type * Added MessageFormatEnumType * feat: Add ChargingStateEnumType for OCPP v2.1 - Introduce new ChargingStateEnumType enumeration - Support serialization and deserialization of charging states - Include variants for EV connection, charging, suspended states, and idle - Update enumerations module to export the new type * feat: Add APNAuthenticationEnumType for OCPP v2.1 - Introduce new APNAuthenticationEnumType enumeration - Support serialization and deserialization of APN authentication methods - Include variants for PAP, CHAP, NONE, and AUTO authentication - Update enumerations module to export the new type * feat: Add ChargingRateUnitEnumType for OCPP v2.1 - Introduce new ChargingRateUnitEnumType enumeration - Support serialization and deserialization of charging rate units - Include variants for Watts (W) and Amperes (A) - Update enumerations module to export the new type * feat: Add ConnectorStatusEnumType for OCPP v2.1 - Introduce new ConnectorStatusEnumType enumeration - Support serialization and deserialization of connector statuses - Include variants for Available, Occupied, Reserved, Unavailable, and Faulted - Update enumerations module to export the new type * feat: Add ResetStatusEnumType for OCPP v2.1 - Introduce new ResetStatusEnumType enumeration - Support serialization and deserialization of reset statuses - Include variants for Accepted, Rejected, and Scheduled - Update enumerations module to export the new type * feat: Add GetCertificateStatusEnumType for OCPP v2.1 - Introduce new GetCertificateStatusEnumType enumeration - Support serialization and deserialization of certificate status retrieval - Include variants for Accepted and Failed - Update enumerations module to export the new type * feat: Add MessageTriggerEnumType for OCPP v2.1 - Introduce new MessageTriggerEnumType enumeration - Support serialization and deserialization of message trigger types - Include variants for various notification and status messages - Update enumerations module to export the new type * feat: Add OCPPInterfaceEnumType for OCPP v2.1 - Introduce new OCPPInterfaceEnumType enumeration - Support serialization and deserialization of network interfaces - Include variants for wired and wireless interfaces (0-3) and any interface - Update enumerations module to export the new type * feat: Add OCPPTransportEnumType for OCPP v2.1 - Introduce new OCPPTransportEnumType enumeration - Support serialization and deserialization of transport protocols - Include variants for SOAP and JSON - Update enumerations module to export the new type * feat: Add OCPPVersionEnumType for OCPP v2.1 - Introduce new OCPPVersionEnumType enumeration - Support serialization and deserialization of OCPP versions - Include variants for OCPP versions 1.2, 1.5, 1.6, 2.0, 2.0.1, and 2.1 - Update enumerations module to export the new type - Add note about backwards compatibility with JSON schema * feat: Add VPNEnumType for OCPP v2.1 - Introduce new VPNEnumType enumeration - Support serialization and deserialization of VPN types - Include variants for IKEv2, IPSec, L2TP, and PPTP - Update enumerations module to export the new type * feat: Add DERControlEnumType for OCPP v2.1 - Introduce new DERControlEnumType enumeration - Support serialization and deserialization of Distributed Energy Resource (DER) control types - Include variants for various control modes such as EnterService, FreqDroop, VoltVar, and more - Update enumerations module to export the new type * feat: Add EventNotificationEnumType for OCPP v2.1 - Introduce new EventNotificationEnumType enumeration - Support serialization and deserialization of event notification types - Include variants for HardWiredNotification, HardWiredMonitor, PreconfiguredMonitor, and CustomMonitor - Update enumerations module to export the new type * feat: Add ChargingProfilePurposeEnumType for OCPP v2.1 - Introduce new ChargingProfilePurposeEnumType enumeration - Support serialization and deserialization of charging profile purposes - Include variants for ChargingStationExternalConstraints, ChargingStationMaxProfile, TxDefaultProfile, TxProfile, PriorityCharging, and LocalGeneration - Update enumerations module to export the new type * feat: Add ChargingLimitSourceEnumType for OCPP v2.1 - Introduce new ChargingLimitSourceEnumType enumeration - Support serialization and deserialization of charging limit sources - Include variants for Energy Management System (EMS), System Operator (SO), Charging Station Operator (CSO), and Other - Update enumerations module to export the new type * feat: Add ChargingProfileKindEnumType for OCPP v2.1 - Introduce new ChargingProfileKindEnumType enumeration - Support serialization and deserialization of charging profile kinds - Include variants for Absolute, Recurring, Relative, and Dynamic - Update enumerations module to export the new type * feat: Add ChargingProfileStatusEnumType for OCPP v2.1 - Introduce new ChargingProfileStatusEnumType enumeration - Support serialization and deserialization of charging profile processing status - Include variants for Accepted and Rejected - Add documentation explaining the meaning of the status - Update enumerations module to export the new type * feat: Add OperationModeEnumType for OCPP v2.1 - Introduce new OperationModeEnumType enumeration - Support serialization and deserialization of charging operation modes - Include variants for Idle, ChargingOnly, CentralSetpoint, ExternalSetpoint, ExternalLimits, CentralFrequency, LocalFrequency, and LocalLoadBalancing - Add documentation explaining the default behavior when the mode is absent - Update enumerations module to export the new type * feat: Add ChargingProfileKindEnumType and ChargingProfileStatusEnumType to enumerations module - Import and expose new ChargingProfileKindEnumType and ChargingProfileStatusEnumType - Update module to include new enumeration types for OCPP v2.1 - Extend support for charging profile-related enumerations * feat: Add StatusInfoType for OCPP v2.1 status information - Introduce new StatusInfoType struct for providing detailed status information - Support serialization and deserialization of status details - Include fields for reason code, additional info, and optional custom data - Implement standard Rust derive traits for easy handling * feat: Add AdditionalInfoType, CustomDataType, and IdTokenType for OCPP v2.1 - Introduce new data types for handling additional identifier information - Implement AdditionalInfoType to support flexible additional ID tokens - Add CustomDataType for vendor-specific extensibility - Create IdTokenType to represent authorization identifiers with optional additional info - Support serialization and deserialization of these new data types * feat: Add Variable and Certificate-related Types for OCPP v2.1 - Introduce VariableType and VariableCharacteristicsType for handling component variables - Add DataEnumType to define variable data types - Create AuthorizeCertificateStatusEnumType for certificate validation - Implement AuthorizeRequest and AuthorizeResponse message structures - Add EnergyTransferModeEnumType to support different charging modes - Extend enumerations and datatypes modules with new types * feat: Add CancelReservation message types and status enumeration for OCPP v2.1 - Introduce CancelReservationStatusEnumType to represent reservation cancellation status - Create CancelReservationRequest and CancelReservationResponse message structures - Support serialization and deserialization of cancel reservation-related types - Update enumerations and messages modules to include new types * feat: Add CertificateSigned message types for OCPP v2.1 - Introduce CertificateSignedRequest and CertificateSignedResponse message structures - Create CertificateSignedStatusEnumType to represent certificate signing status - Support serialization and deserialization of certificate signing-related types - Update messages module to include new certificate signed types * refactor: Consolidate Authorize and CertificateSigned message types - Merge separate request and response files for Authorize and CertificateSigned messages - Update module to import and export types from consolidated files - Maintain existing functionality and structure of message types - Improve code organization in the messages module * Add enums * Add grid_even_fault * Fix imports * Add more types * refactor: Improve IslandingDetectionEnumType serialization and naming - Update import style for serde traits - Add serde rename attributes for UVP_OVP and UFP_OFP enum variants - Adjust enum variant names to follow Rust naming conventions * refactor: Remove Hash trait from ChargingScheduleUpdateType - Remove unnecessary Hash derive for ChargingScheduleUpdateType - Maintain other existing traits and serialization behavior * refactor: Update SalesTariffEntryType validation for e_price_level - Replace length validation with range validation for e_price_level - Modify validation constraint to allow zero and positive values * feat: Enhance IdTokenType validation and schema for OCPP v2.1 - Update IdTokenType to support comprehensive ID token validation - Modify type field to use string with predefined values - Increase max length for id_token to 255 characters - Add more detailed schema validation tests for ID token types * Add message types * Minor fixes * feat: Add OCPP 2.1 support and enhance schema validation - Bump version to 3.0.0 to reflect OCPP 2.1 support - Add jsonschema dependency - Improve schema validation for various message types - Add validation methods for BootNotificationRequest and CancelReservationRequest/Response - Update test cases to validate against JSON schemas - Modify CustomDataType with validation constraints - Expose more message types in the public API * Fix imports * feat: Enhance CustomDataType with additional properties support - Add support for arbitrary vendor-specific properties in CustomDataType - Use HashMap<String, Value> to allow flexible custom data storage - Remove Hash trait to improve type flexibility - Update serialization to skip empty additional properties * refactor: Cleanup and simplify message module imports - Remove unnecessary import of CertificateHashDataType in get_certificate_chain_status - Simplify import paths for custom data and status types - Update validation attributes for get_variables request and response - Streamline import statements in log_status_notification and notify_der_start_stop * Update tests * refactor: Enhance ChargingLimitSourceEnumType for OCPP 2.1 flexibility - Introduce a more flexible enum with standard and custom charging limit source values - Add support for untagged serialization and custom string values - Implement conversion and string representation methods - Update ReportChargingProfilesRequest to use the new enum type * feat: Add comprehensive ConnectorEnumType for OCPP 2.1 connector types - Introduce standardized enum for connector types with captive cable, socket, wireless, and battery connections - Support custom and standard connector type values - Implement serialization, deserialization, and conversion methods - Update ReserveNowRequest to use the new ConnectorEnumType - Add connector module to enumerations * feat: Add SigningMethodEnumType for OCPP 2.1 signing methods - Introduce comprehensive enum for standard and custom signing methods - Support ECDSA variants with different curves and SHA256 hash - Implement serialization, deserialization, and conversion methods - Add signing_method module to enumerations * refactor: Update SignedMeterValueType with improved signing method and key representation - Replace string-based signing method with SigningMethodEnumType - Adjust validation constraints for signed meter data and public key - Improve documentation for each field - Update import paths to use crate-relative references * add v2.1 doc (#163) Co-authored-by: anlada <bo.hou@en-plus.com.cn> * Fix imports * feat: add absolute_price_schedule.rs trait * feat: add ac_charging_parameters.rs trait * feat: Add validation and methods to AdditionalInfoType * feat: Add validation and methods to AdditionalSelectedServicesType * feat(address): add validation and methods to AddressType * feat(apn): add APNType constructor and methods for chaining * feat(authorization_data): enhance AuthorizationData with methods and tests * feat(battery_data): enhance BatteryDataType with detailed docs and methods * feat: Add validation and methods to CertificateHashDataChainType * refactor(v2_1/datatypes): Remove Validate derive from multiple structs * feat(v2_1/datatypes): enhance CertificateStatusType with methods and tests * feat: enhance CertificateStatusRequestInfoType with new methods and tests * feat(charging_limit): Add methods and tests for ChargingLimitType * feat: Add builder methods and tests for ChargingNeedsType and DCChargingParametersType * feat: Add methods and tests for ChargingPeriodType and CostDimensionType * feat(charging_profile): add new methods and tests for ChargingProfileType * feat(charging_schedule): add builder methods and tests for ChargingScheduleType * feat(charging_schedule_period): add methods for creating and modifying schedule periods * feat: Add builder methods and tests for ChargingProfileCriterion and ChargingScheduleUpdate * feat(charging_station): add methods and tests for ChargingStationType * feat(modem): add ModemType methods and tests * feat: Add methods to ClearChargingProfileType for easier configuration and testing * feat: enhance ComponentType and ComponentVariableType with additional fields and methods * feat(variable): add methods and tests for VariableType * feat(v2_1): add builder methods and tests for data types * feat(cost_details): add new methods and tests for CostDetailsType * format: cargo fmt * feat: add builder methods and tests for ClearMonitoringResultType, ClearTariffsResultType, CustomDataType, and StatusInfoType * feat: Add constructors and methods to DER data types for easier instantiation and manipulation * feat(v2_1): add default feature and enhance DER data types * feat(freq_droop): add constructor and methods for FreqDroopType and FreqDroopGetType * feat: Add constructors and methods to EV price schedule types * feat: Add builder methods and tests for EV energy offer and related types * feat(v2_1/datatypes): Add builder methods and tests for GetVariableDataType, TariffAssignmentType, TaxRateType, and VPNType * feat(v2_1/datatypes): Add builder methods and tests for IdTokenInfoType * feat(v2_1/datatypes): Implement builder methods and tests for IdTokenType * feat(v2_1/datatypes): Add constructors and methods for LimitAtSoCType, LimitMaxDischargeType, LogParametersType, MessageContentType, and MessageInfoType * feat(v2_1/datatypes): Add constructors and builder methods for TariffConditionsType, TariffConditionsFixedType, and TariffTimePriceType * feat(v2_1/datatypes): Add constructors and methods for V2XChargingParametersType, V2XFreqWattPointType, and V2XSignalWattPointType * feat(v2_1/datatypes): Add constructors and methods for TariffEnergyType, TariffEnergyPriceType, TariffFixedType, TariffFixedPriceType, and TariffTimeType * feat(v2_1/datatypes): Implement methods for TaxRuleType including constructors, setters, and tests * feat: Enhance transaction and variable data types with new methods and tests - Added `TransactionType` struct with methods for creating, getting, and setting transaction details. - Implemented optional fields handling in `TransactionType` for charging state, time start/end, ID tokens, and custom data. - Introduced `TransactionLimitType` struct with methods for managing energy and time limits, including custom data. - Enhanced `VariableAttributeType` with methods for setting persistent and constant flags, along with custom data. - Developed `VariableCharacteristicsType` to manage variable characteristics with comprehensive getter and setter methods. - Created `VariableMonitoringType` for monitoring variables with severity and custom data handling. - Added unit tests for all new methods to ensure functionality and correctness. * feat(v2_1/datatypes): Add constructors and methods for GetVariableResultType with associated tests * feat(v2_1/datatypes): Update tests to use new_without_severity method for VariableMonitoringType * Implement new data types and methods for monitoring and variable management - Added `SetMonitoringDataType` with methods for creating and modifying monitoring data, including custom data and severity. - Introduced `SetMonitoringResultType` with functionality to manage monitoring results, including status and custom data. - Created `SetVariableDataType` to handle variable attributes, allowing for custom data and attribute type management. - Developed `SignedMeterValueType` for handling signed meter values with methods for managing signatures and custom data. - Implemented `StreamDataElementType` for reporting stream data with methods for managing variable values and custom data. - Added `UnitOfMeasureType` to represent units of measurement with methods for managing multipliers and custom data. - Comprehensive unit tests for all new types and methods to ensure functionality and correctness. * feat: Add PriceRuleType and PriceRuleStackType with custom data support - Implemented PriceRuleType with methods for creating, setting, and getting various pricing parameters. - Added tests for PriceRuleType to ensure correct functionality. - Introduced PriceRuleStackType to manage a collection of PriceRuleType instances. - Included methods for setting custom data and managing the duration of the price rule stack. - Added tests for PriceRuleStackType to validate its behavior. feat: Enhance RationalNumberType with custom data handling - Added methods to RationalNumberType for creating instances, setting, and getting values and exponents. - Implemented custom data support in RationalNumberType. - Created tests to verify the functionality of RationalNumberType. feat: Extend ReportDataType with custom data and variable management - Implemented ReportDataType with methods for managing component and variable attributes. - Added support for custom data, variable values, and attributes. - Developed tests to ensure the correctness of ReportDataType functionality. * Refactor code for improved readability and consistency across multiple files - Adjusted formatting in `monitoring_data.rs`, `network_connection_profile.rs`, `overstay_rule.rs`, `overstay_rule_list.rs`, `rational_number.rs`, `relative_time_interval.rs`, `report_data.rs`, `sales_tariff.rs`, `sales_tariff_entry.rs`, `sampled_value.rs`, `set_monitoring_data.rs`, `set_monitoring_result.rs`, `set_variable_data.rs`, `stream_data_element.rs`, `tariff.rs`, `tariff_conditions.rs`, `tariff_conditions_fixed.rs`, `tariff_fixed.rs`, `tax_rate.rs`, `tax_rule.rs`, `total_cost.rs`, `transaction.rs`, `unit_of_measure.rs`, `v2x_charging_parameters.rs`, `v2x_freq_watt_point.rs`, `v2x_signal_watt_point.rs`, `variable_attribute.rs`, and `variable_monitoring.rs` to enhance code clarity. - Consolidated method chaining for setter functions to a single line where applicable. - Ensured consistent formatting for function parameters and return types. - Improved test assertions for better readability. * feat(v2_1/datatypes): Add constructors and methods for SetVariableResultType with associated tests * feat(v2_1/messages): add camelCase renaming to priority charging and VAT validation structs * refactor(v2_1): Update AbsolutePriceScheduleType to use DateTime<Utc> * docs: Fix punctuation in README.md usage section * refactor: Switch ACChargingParametersType to use Decimal for precision * feat(v2_1): enhance AbsolutePriceScheduleType with validation and new fields * feat: Add validation to AdditionalSelectedServicesType * refactor: relax length validation for additional_id_token and type_ * feat: Add validation to AddressType fields and implement unit tests * refactor(APNType): move custom_data field to end of struct * feat: add nested validation to data types and enhance tests * feat(battery_data): enhance battery data model with validation and new fields * feat: Add validation to CertificateHashDataChainType Add validation to CertificateHashDataType AI: I've added field length validations to CertificateHashDataType and marked nested fields for validation. * feat: Add URL validation and tests to CertificateStatusRequestInfoType * feat: Add validation and improve CertificateStatusType * feat(v2_1): Add validation and enhance ChargingLimitType and ChargingNeedsType * feat(v2_1/datatypes): add validation and optional fields to ChargingPeriodType * feat(v2_1): Add charging limit source to ChargingProfileCriterionType * refactor(v2_1/datatypes): Update serialization and validation for ChargingNeedsType and ChargingProfileType * refactor: update ChargingSchedulePeriodType with new fields and validations * refactor(v2_1/datatypes): Simplify ChargingScheduleType and ChargingScheduleUpdateType initialization and validation * refactor(v2_1/datatypes): Reorganize custom_data fields and add tests * refactor(v2_1/datatypes): Move custom_data field in ClearMonitoringResultType * refactor(ClearTariffsResultType): Move custom_data field and add tests * feat(v2_1): add validation and tests for ComponentType and ComponentVariableType * Add validation to params field and comprehensive tests * refactor:Set v2_1 as default feature and enhance ConsumptionCostType Update start_value from f64 to Decimal in ConsumptionCostType * Reorder fields and add validation tests for CompositeScheduleType * Add validation to custom_data field in ConstantStreamDataType * Add detailed validation test error messages and custom data tests * Add detailed test assertions with error messages * Make charging_periods optional with validation * refactor(v2_1/datatypes): Use Decimal for volume in CostDimensionType * feat(DCChargingParametersType): Add SoC, full SoC, and use Decimal for precision * feat(DERChargingParametersType): Add comprehensive DER charging parameters and methods * refactor(v2_1): add arbitrary precision to Decimal fields in DERChargingParametersType * refactor(v2_1/datatypes): Update serialization and deserialization tests for ChargingSchedule * refactor(DERCurveGetType): Move custom_data field and add validation tests * refactor: switch DERCurvePointsType to use Decimal for precision * refactor(v2_1/datatypes/der_curve): Use rust_decimal for precision in DERCurveType * feat(v2_1/datatypes): add validation and tests for EnterServiceGetType * refactor(enter_service): Use Decimal for precision in EnterServiceType * feat: add price rules to EVAbsolutePriceScheduleEntryType * feat(ev_absolute_price_schedule): add default, display, and JSON conversion implementations * refactor(EVPowerScheduleEntryType): use Decimal for power and add validation to custom_data * refactor(v2_1/datatypes): Use Decimal for precision in EV data types * refactor: Update data types to use Decimal for precision and add validation tests * refactor(v2_1/datatypes): Update FixedPFType to use Decimal for precision and add excitation, start_time, and duration fields * refactor(charging_needs): add nested validation to available_energy_transfer * feat(v2_1/datatypes): Add is_default field to FixedVarGetType * refactor(v2_1/datatypes): Add skip_serializing_if and default to Decimal fields * refactor(fixed_pf): Remove redundant serde skip_serializing_if attribute * Update dependencies and fix Cargo.lock * style: Fix serde attribute formatting in FixedVarType * feat(freq_droop_get): add is_default field and display, from impl * feat(freq_droop): enhance frequency droop settings with new fields and validation * Change attribute_type to use AttributeEnumType * Update Cargo.toml * Remove default v2_1 feature to require explicit version * refactor(v2_1/datatypes): Add nested validation to GetVariableDataType fields * refactor(GetVariableResultType): enhance structure and validation * feat(gradient): add soft gradient and use Decimal for rates * refactor(v2_1/datatypes): Remove is_superseded from GradientGetType * feat(hysteresis): add hysteresis high/low/delay/gradient fields * refactor(v2_1/datatypes): Simplify IdTokenInfoType creation and usage in tests * refactor(id_token): Rename 'type' to 'type_' in IdTokenType * refactor(v2_1/datatypes): Update LimitAtSoCType to use Decimal for power limit and rename fields * refactor(id_token_info): simplify and enhance IdTokenInfoType initialization and methods * feat(id_token): add additional_info method and validation tests * feat(v2_1/datatypes): Add is_default field to LimitMaxDischargeGetType * feat(v2_1/datatypes): enhance LimitMaxDischargeType with new fields and methods * refactor(v2_1/datatypes): Remove redundant parameter from LimitMaxDischargeType::new * refactor(v2_1/datatypes): Remove discharge_limit from LimitMaxDischargeType * feat(log_parameters): enhance LogParametersType with validation and datetime handling * feat(message_content): enhance MessageContentType with builder and validation * feat(message_info): enhance MessageInfoType with new fields and validation * feat(meter_value): enhance MeterValueType with detailed docs and validation * feat(modem): enhance validation and method chaining in ModemType * refactor(monitoring_data): enhance validation and method chaining clarity * refactor(NetworkConnectionProfileType): update fields and methods for OCPP 2.1 compatibility * refactor(ocsp_request_data): enhance OCSP request data structure and validation * feat(overstay_rule_list): add power and time thresholds, update validation * feat(overstay_rule): enhance overstay rule with new fields and methods * refactor(v2_1/datatypes): Update ConstantStreamData tests for new param * feat: Add interval and values to PeriodicEventStreamParamsType * feat(periodic_event_stream_params): add validation to custom_data * feat(price_level_schedule): add new fields and methods to PriceLevelScheduleType * Update price level range and description in schedule entry Modify the `PriceLevelScheduleEntryType` struct to update the `price_level` field range from -9..9 to 0..9 for consistency in representing price levels. Revise the associated comment to clarify that smaller values indicate cheaper prices and larger values indicate more expensive ones. Reorder fields to move `custom_data` to the end for better readability. * feat(v2_1/datatypes): Add placeholders and validate price rule stack * refactor(v2_1/datatypes): Simplify PriceRuleType creation in tests * refactor(v2_1/datatypes): Use RationalNumberType in ChargingSchedule tests * refactor(price_rule_stack): use RationalNumberType in tests * refactor(price_rule): update PriceRuleType to use RationalNumberType and add new fields * refactor(price_rule): restructure PriceRuleType, add validation and custom_data * refactor(price): switch to rust_decimal for price fields * refactor(v2_1/datatypes): Use Decimal for PriceType in tests * feat: enhance reactive power params and add tests for rational number * refactor(v2_1/datatypes): Move custom_data field in RelativeTimeIntervalType * Reformat imports with consistent ordering and grouping * refactor(v2_1/datatypes): Use Decimal for precision in charging parameters * refactor(v2_1/datatypes): Format and optimize code for readability and consistency * refactor(report_data): add validation and reorder fields in ReportDataType * feat(sales_tariff): enhance validation and structure in sales tariff and entry types * Change SalesTariff ID from string to integer and improve docs Commit message body: - Update SalesTariffType to use i32 ID instead of String - Add validation constraints for ID and numEPriceLevels - Improve documentation to align with ISO 15118-2 standard - Restructure SampledValueType fields for better alignment with spec - Add UnitOfMeasureType to SampledValueType - Remove unnecessary validate() method from SalesTariffEntryType * Refactor SetMonitoringDataType to use new schema * Add monitor type and severity to SetMonitoringResultType * Fix code formatting and trailing newlines * Refactor variable monitoring functionality AI: Add severity descriptions and update field order in monitoring types * Format code with consistent spacing and line breaks AI: Reformat code with consistent spacing for better readability * Refactor SetVariableResult with improved field organization * Refactor SignedMeterValueType to align with OCPP spec * Update string length limits and refactor StreamDataElementType * Fix code formatting in StreamDataElementType and tests * Redesign TariffType to better model EV charging price structures * Refactor TariffAssignmentType to use DateTime<Utc> and improve naming * Reimplement TariffConditionsType to use V2.1 spec * Improve code formatting in test assertions * Refactor TariffConditionsFixedType with multiple condition fields * Update TariffEnergyType to support multiple price elements * Refactor TariffEnergyPriceType with price_kwh and conditions * Add trailing newline in tariff_energy_price.rs * Refactor TariffFixedPriceType with price_fixed field * Fix code formatting in tariff tests * Update TariffTimeType to support multiple price elements * refactor: replace f64 with Decimal for precision in pricing and conditions * Improve tariff module with accurate descriptions and slices Improve tariff module with accurate descriptions and slices Updates the tariff module with more detailed and specific documentation that accurately describes each component's purpose. Improves type safety by returning slices instead of vector references, and updates the TariffFixedType to align with OCPP 2.1 specification by supporting multiple price elements. * Update tax_rule and total_cost to match ISO 15118-20 spec Update tax_rule and total_cost to match ISO 15118-20 spec * Update price and usage fields to match OCPP 2.1 spec AI: Update price and usage fields to match OCPP 2.1 spec * Replace float values with Decimal in TotalPrice and TotalUsage AI: I've reviewed the code changes and created a commit message that accurately describes the changes. The message reflects the main purpose of the commit - replacing floating point values with Decimal types in specific data structures. This will improve numerical precision and consistency in financial calculations. * Enhance TotalUsageType with f64 constructor and validation * Refactor transaction datatype to match OCPP specification * Fix UnitOfMeasureType implementation and constructor usage * Refactor V2XFreqWattPointType to use Decimal instead of f64 * Change V2XSignalWattPoint signal from f64 to i32 * Update VariableType to make instance field optional * Refactor VariableAttributeType to use enumerated attributes Refactor VariableAttributeType to use enumerated attributes Improves VariableAttributeType by switching from string-based type field to an enumerated AttributeEnumType. Updates related parts in the codebase to support this change including VariableCharacteristicsType which now uses improved builder pattern for optional fields. * Update VariableMonitoringType with required fields * Add v2_ feature that includes v2_0_1 and v2_1 Add v2_ feature that bundles v2_0_1 and v2_1 features AI: Add v2_ feature that bundles v2_0_1 and v2_1 features * Format code blocks with multiline assertions AI: Format multiline assertion statements for improved readability * Fix VPN import ordering in network_connection_profile tests * Reorder imports and format code * fix: make data_enum.rs --------- Co-authored-by: Tommy Malmqvist <tommy.malmqvist@codelabs.se> Co-authored-by: anlada <bo.hou@en-plus.com.cn>
1 parent ea31b3b commit 6c82ba5

File tree

519 files changed

+82430
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

519 files changed

+82430
-324
lines changed

Cargo.lock

Lines changed: 488 additions & 288 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust-ocpp"
3-
description = "ocpp 1.6 and 2.0.1 libraries"
3+
description = "ocpp 1.6, 2.0.1 and 2.1 libraries"
44
readme = "README.md"
55
license = "MIT OR Apache-2.0"
66
version = "3.0.1"
@@ -23,31 +23,35 @@ exclude = ["docs/", "src/tests"]
2323
all-features = true
2424

2525
[features]
26-
default = ["v2_0_1"]
26+
# No default feature, so each version must be explicitly enabled
2727
v1_6 = []
2828
v2_0_1 = []
29+
v2_1 = []
2930

3031

3132
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
3233

3334
[dependencies]
3435
serde = { version = "1", default-features = false, features = ["derive"] }
3536
chrono = { version = "0.4.39", default-features = false, features = [
37+
"now",
3638
"serde",
3739
"alloc",
3840
] }
3941
uuid = { version = "1", default-features = false, features = ["v4"] }
40-
validator = { version = "0.19.0", default-features = false, features = [
42+
validator = { version = "0.20.0", default-features = false, features = [
4143
"derive",
4244
] }
4345
regex = "1.11.1"
4446
rust_decimal = { version = "1.36.0", features = [
4547
"serde-with-arbitrary-precision",
4648
] }
49+
rust_decimal_macros = "1.36.0"
50+
serde_json = "1"
51+
lazy_static = "1.4"
52+
jsonschema = "0.30.0"
4753

4854
[dev-dependencies]
4955
chrono = { version = "0.4.39", default-features = false, features = ["clock"] }
50-
serde_json = "1"
5156
mockall = "0.13.1"
52-
jsonschema = "0.28"
53-
rust_decimal_macros = "1.36.0"
57+
jsonschema = "0.30.0"

README.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,39 @@
77
The `rust-ocpp` libs implements the Open Charge Point Protocol
88
used in charging stations. You can read more on the official [Open Charge Alliance](https://www.openchargealliance.org/) website.
99

10-
Both OCPP v1.6 and v2.0.1 are implemented and validated using the official json schemas from Open Charge Alliance.
10+
OCPP versions v1.6, v2.0.1, and v2.1 are implemented and validated using the official json schemas from Open Charge Alliance.
1111

12-
You can find the tests in `schema_validation.rs` for both `v.1.6` and `v2.0.1`
12+
You can find the tests in `schema_validation.rs` for all supported versions.
1313

1414
## repo structure
1515

16-
`src/` : library files for v1.6 and v2.0.1
16+
`src/` : library files for v1.6, v2.0.1, and v2.1
1717

1818
`docs/` : official ocpp specification
1919

2020
## How to Use
2121

22-
Add `rust-ocpp` as a dependency in your `Cargo.toml`. It will default to version `2.0.1` of OCPP.
22+
Add `rust-ocpp` as a dependency in your `Cargo.toml`. Note that there is no default version - you must explicitly specify which OCPP version(s) you want to use via feature flags.
2323

2424
```toml
2525
[dependencies]
2626
rust-ocpp = "3.0"
2727
```
2828

29-
To use `1.6` you need to specify a protocol version with a feature flag:
29+
To use a specific version, specify it with a feature flag:
3030

3131
```toml
3232
[dependencies]
33-
rust-ocpp = { version = "1.0", features = ["v1_6"] }
33+
rust-ocpp = { version = "2.0", features = ["v1_6"] } # For OCPP 1.6
34+
rust-ocpp = { version = "2.0", features = ["v2_0_1"] } # For OCPP 2.0.1
35+
rust-ocpp = { version = "2.0", features = ["v2_1"] } # For OCPP 2.1
3436
```
3537

36-
or use both versions
38+
You can also use multiple versions:
3739

3840
```toml
3941
[dependencies]
40-
rust-ocpp = { version = "1.0", features = ["v2_0_1", "v1_6"] }
42+
rust-ocpp = { version = "2.0", features = ["v2_0_1", "v2_1"] }
4143
```
4244

4345
## How to Build
@@ -59,7 +61,7 @@ Once you have Rust and Cargo installed, you can build the library using the foll
5961
cd rust-ocpp
6062
```
6163

62-
3. Build the library using Cargo for both `1.6` and `2.0.1`:
64+
3. Build the library using Cargo for all versions:
6365

6466
```bash
6567
cargo build --all-features
@@ -68,14 +70,14 @@ Once you have Rust and Cargo installed, you can build the library using the foll
6870
This command will compile the library and its dependencies. If the build is successful, you will find the compiled
6971
artifacts in the `target/debug` directory.
7072

71-
4. Run the tests on both versions:
73+
4. Run the tests on all versions:
7274

7375
```bash
7476
cargo test --all-features
7577

7678
```
7779

78-
This command will execute the tests for both OCPP versions. If all tests pass, it means that the library is
80+
This command will execute the tests for all OCPP versions. If all tests pass, it means that the library is
7981
functioning correctly.
8082

8183
5. Build a specific version:
@@ -93,6 +95,12 @@ Once you have Rust and Cargo installed, you can build the library using the foll
9395
cargo build --features v2_0_1
9496
```
9597

98+
To build `v2_1`:
99+
100+
```bash
101+
cargo build --features v2_1
102+
```
103+
96104
6. (Optional) Build for release:
97105

98106
If you want to build the library for release, with optimizations enabled, you can use the following command:
@@ -119,35 +127,23 @@ please check the project's issue tracker on GitHub or open a new issue for assis
119127

120128
## Testing
121129

122-
`rust-ocpp` provides testing against json schemas for both OCPP v1.6 and v2.0.1 versions. To run the tests, you can use
130+
`rust-ocpp` provides testing against json schemas for all supported OCPP versions. To run the tests, you can use
123131
Cargo's built-in test runner.
124132

125133
### Running Tests
126134

127-
To run the tests for a specific version, use the appropriate feature flag when running the tests.
128-
129-
For OCPP v1.6 tests:
130-
131-
```bash
132-
cargo test --features v1_6
133-
```
134-
135-
For OCPP v2.0.1 tests:
135+
To run the tests for a specific version, use the appropriate feature flag:
136136

137137
```bash
138-
cargo test --features v2_0_1
138+
cargo test --features v1_6 # For OCPP 1.6 tests
139+
cargo test --features v2_0_1 # For OCPP 2.0.1 tests
140+
cargo test --features v2_1 # For OCPP 2.1 tests
139141
```
140142

141-
To run all tests:
143+
To run all tests for all versions:
142144

143145
```bash
144-
cargo test
145-
```
146-
147-
or for a specific version
148-
149-
```bash
150-
cargo test --features v1_6
146+
cargo test --all-features
151147
```
152148

153149
### Test Coverage
@@ -172,6 +168,7 @@ Use `rustfmt` before you PR.
172168
pre-commit config is available. You can read more about it at [pre-commits](https://pre-commit.com) website and checkout their repo on [github](https://github.com/pre-commit/pre-commit)
173169

174170
## Releasing a new version
171+
175172
1. Update the version of the library and push the changes to the main branch.
176173
2. Create a [new release](https://github.com/codelabsab/rust-ocpp/releases/new) on GitHub with the new version number and some release notes (optional).
177174

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2.46 MB
Binary file not shown.

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ pub mod tests;
1919
pub mod v1_6;
2020
#[cfg(feature = "v2_0_1")]
2121
pub mod v2_0_1;
22+
#[cfg(feature = "v2_1")]
23+
pub mod v2_1;

src/tests/schema_validation/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
mod v1_6;
33
#[cfg(all(test, feature = "v2_0_1"))]
44
mod v2_0_1;
5+
#[cfg(all(test, feature = "v2_1"))]
6+
mod v2_1;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-06/schema#",
3+
"$id": "urn:OCPP:Cp:2:2025:1:AFRRSignalRequest",
4+
"comment": "OCPP 2.1 Edition 1 (c) OCA, Creative Commons Attribution-NoDerivatives 4.0 International Public License",
5+
"definitions": {
6+
"CustomDataType": {
7+
"description": "This class does not get 'AdditionalProperties = false' in the schema generation, so it can be extended with arbitrary JSON properties to allow adding custom data.",
8+
"javaType": "CustomData",
9+
"type": "object",
10+
"properties": {
11+
"vendorId": {
12+
"type": "string",
13+
"maxLength": 255
14+
}
15+
},
16+
"required": [
17+
"vendorId"
18+
]
19+
}
20+
},
21+
"type": "object",
22+
"additionalProperties": false,
23+
"properties": {
24+
"timestamp": {
25+
"description": "Time when signal becomes active.\r\n",
26+
"type": "string",
27+
"format": "date-time"
28+
},
29+
"signal": {
30+
"description": "Value of signal in _v2xSignalWattCurve_. \r\n",
31+
"type": "integer"
32+
},
33+
"customData": {
34+
"$ref": "#/definitions/CustomDataType"
35+
}
36+
},
37+
"required": [
38+
"timestamp",
39+
"signal"
40+
]
41+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-06/schema#",
3+
"$id": "urn:OCPP:Cp:2:2025:1:AFRRSignalResponse",
4+
"comment": "OCPP 2.1 Edition 1 (c) OCA, Creative Commons Attribution-NoDerivatives 4.0 International Public License",
5+
"definitions": {
6+
"GenericStatusEnumType": {
7+
"javaType": "GenericStatusEnum",
8+
"type": "string",
9+
"additionalProperties": false,
10+
"enum": [
11+
"Accepted",
12+
"Rejected"
13+
]
14+
},
15+
"StatusInfoType": {
16+
"description": "Element providing more information about the status.\r\n",
17+
"javaType": "StatusInfo",
18+
"type": "object",
19+
"additionalProperties": false,
20+
"properties": {
21+
"reasonCode": {
22+
"description": "A predefined code for the reason why the status is returned in this response. The string is case-insensitive.\r\n",
23+
"type": "string",
24+
"maxLength": 20
25+
},
26+
"additionalInfo": {
27+
"description": "Additional text to provide detailed information.\r\n",
28+
"type": "string",
29+
"maxLength": 1024
30+
},
31+
"customData": {
32+
"$ref": "#/definitions/CustomDataType"
33+
}
34+
},
35+
"required": [
36+
"reasonCode"
37+
]
38+
},
39+
"CustomDataType": {
40+
"description": "This class does not get 'AdditionalProperties = false' in the schema generation, so it can be extended with arbitrary JSON properties to allow adding custom data.",
41+
"javaType": "CustomData",
42+
"type": "object",
43+
"properties": {
44+
"vendorId": {
45+
"type": "string",
46+
"maxLength": 255
47+
}
48+
},
49+
"required": [
50+
"vendorId"
51+
]
52+
}
53+
},
54+
"type": "object",
55+
"additionalProperties": false,
56+
"properties": {
57+
"status": {
58+
"$ref": "#/definitions/GenericStatusEnumType"
59+
},
60+
"statusInfo": {
61+
"$ref": "#/definitions/StatusInfoType"
62+
},
63+
"customData": {
64+
"$ref": "#/definitions/CustomDataType"
65+
}
66+
},
67+
"required": [
68+
"status"
69+
]
70+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-06/schema#",
3+
"$id": "urn:OCPP:Cp:2:2025:1:AdjustPeriodicEventStreamRequest",
4+
"comment": "OCPP 2.1 Edition 1 (c) OCA, Creative Commons Attribution-NoDerivatives 4.0 International Public License",
5+
"definitions": {
6+
"PeriodicEventStreamParamsType": {
7+
"javaType": "PeriodicEventStreamParams",
8+
"type": "object",
9+
"additionalProperties": false,
10+
"properties": {
11+
"interval": {
12+
"description": "Time in seconds after which stream data is sent.\r\n",
13+
"type": "integer",
14+
"minimum": 0.0
15+
},
16+
"values": {
17+
"description": "Number of items to be sent together in stream.\r\n",
18+
"type": "integer",
19+
"minimum": 0.0
20+
},
21+
"customData": {
22+
"$ref": "#/definitions/CustomDataType"
23+
}
24+
}
25+
},
26+
"CustomDataType": {
27+
"description": "This class does not get 'AdditionalProperties = false' in the schema generation, so it can be extended with arbitrary JSON properties to allow adding custom data.",
28+
"javaType": "CustomData",
29+
"type": "object",
30+
"properties": {
31+
"vendorId": {
32+
"type": "string",
33+
"maxLength": 255
34+
}
35+
},
36+
"required": [
37+
"vendorId"
38+
]
39+
}
40+
},
41+
"type": "object",
42+
"additionalProperties": false,
43+
"properties": {
44+
"id": {
45+
"type": "integer",
46+
"minimum": 0.0
47+
},
48+
"params": {
49+
"$ref": "#/definitions/PeriodicEventStreamParamsType"
50+
},
51+
"customData": {
52+
"$ref": "#/definitions/CustomDataType"
53+
}
54+
},
55+
"required": [
56+
"id",
57+
"params"
58+
]
59+
}

0 commit comments

Comments
 (0)