Implemented parsing for new register-group-instance element in TDF scripts
This commit is contained in:
@@ -9,6 +9,7 @@ use Targets\TargetDescriptionFiles\MemorySegment;
|
||||
use Targets\TargetDescriptionFiles\MemorySegmentSection;
|
||||
use Targets\TargetDescriptionFiles\Module;
|
||||
use Targets\TargetDescriptionFiles\Peripheral;
|
||||
use Targets\TargetDescriptionFiles\RegisterGroupInstance;
|
||||
use Targets\TargetDescriptionFiles\Property;
|
||||
use Targets\TargetDescriptionFiles\PropertyGroup;
|
||||
use Targets\TargetDescriptionFiles\Register;
|
||||
@@ -687,26 +688,26 @@ class ValidationService
|
||||
$failures[] = 'Missing module key';
|
||||
}
|
||||
|
||||
if (empty($peripheral->registerGroupReferences) && empty($peripheral->signals)) {
|
||||
$failures[] = 'Empty - no register group references or signals';
|
||||
if (empty($peripheral->registerGroupInstances) && empty($peripheral->signals)) {
|
||||
$failures[] = 'Empty - no register group instances or signals';
|
||||
}
|
||||
|
||||
$processedChildKeys = [];
|
||||
foreach ($peripheral->registerGroupReferences as $registerGroupReference) {
|
||||
foreach ($peripheral->registerGroupInstances as $registerGroupInstance) {
|
||||
$failures = array_merge(
|
||||
$failures,
|
||||
$this->validateRegisterGroupReference(
|
||||
$registerGroupReference,
|
||||
$this->validateRegisterGroupInstance(
|
||||
$registerGroupInstance,
|
||||
$peripheral->moduleKey ?? '',
|
||||
$tdf
|
||||
)
|
||||
);
|
||||
|
||||
if ($registerGroupReference->key !== null && in_array($registerGroupReference->key, $processedChildKeys)) {
|
||||
$failures[] = 'Duplicate register group reference key ("' . $registerGroupReference->key . '") detected';
|
||||
if ($registerGroupInstance->key !== null && in_array($registerGroupInstance->key, $processedChildKeys)) {
|
||||
$failures[] = 'Duplicate register group instance key ("' . $registerGroupInstance->key . '") detected';
|
||||
}
|
||||
|
||||
$processedChildKeys[] = $registerGroupReference->key;
|
||||
$processedChildKeys[] = $registerGroupInstance->key;
|
||||
}
|
||||
|
||||
foreach ($peripheral->signals as $signal) {
|
||||
@@ -719,6 +720,64 @@ class ValidationService
|
||||
);
|
||||
}
|
||||
|
||||
protected function validateRegisterGroupInstance(
|
||||
RegisterGroupInstance $registerGroupInstance,
|
||||
string $moduleKey,
|
||||
TargetDescriptionFile $tdf
|
||||
): array {
|
||||
$failures = [];
|
||||
|
||||
if (empty($registerGroupInstance->key)) {
|
||||
$failures[] = 'Missing key';
|
||||
}
|
||||
|
||||
if (!mb_check_encoding((string) $registerGroupInstance->key, 'ASCII')) {
|
||||
$failures[] = 'Key contains non ASCII characters';
|
||||
}
|
||||
|
||||
if (str_contains((string) $registerGroupInstance->key, ' ')) {
|
||||
$failures[] = 'Key contains at least one period space';
|
||||
}
|
||||
|
||||
if (str_contains((string) $registerGroupInstance->key, '.')) {
|
||||
$failures[] = 'Key contains at least one period (".") character';
|
||||
}
|
||||
|
||||
if (empty($registerGroupInstance->registerGroupKey)) {
|
||||
$failures[] = 'Missing register group key';
|
||||
}
|
||||
|
||||
if (empty($registerGroupInstance->name)) {
|
||||
$failures[] = 'Missing name';
|
||||
}
|
||||
|
||||
if ($registerGroupInstance->offset === null) {
|
||||
$failures[] = 'Missing offset';
|
||||
|
||||
} elseif ($registerGroupInstance->offset > 0xFFFFFFFF) {
|
||||
$failures[] = 'Offset exceeds 32-bit unsigned integer';
|
||||
}
|
||||
|
||||
if (empty($registerGroupInstance->addressSpaceKey)) {
|
||||
$failures[] = 'Missing address space key';
|
||||
|
||||
} elseif ($tdf->getAddressSpace($registerGroupInstance->addressSpaceKey) === null) {
|
||||
$failures[] = 'Could not find address space "' . $registerGroupInstance->addressSpaceKey
|
||||
. '" - check address space key';
|
||||
}
|
||||
|
||||
if ($tdf->resolveRegisterGroupInstance($registerGroupInstance, $moduleKey) === null) {
|
||||
$failures[] = 'Could not resolve register group instance "' . $registerGroupInstance->key
|
||||
. '" - check register group key ("' . $registerGroupInstance->registerGroupKey . '")';
|
||||
}
|
||||
|
||||
return array_map(
|
||||
fn (string $failure): string => 'Register group instance (group key: "'
|
||||
. $registerGroupInstance->registerGroupKey . '") validation failure: ' . $failure,
|
||||
$failures
|
||||
);
|
||||
}
|
||||
|
||||
protected function validateSignal(Signal $signal): array
|
||||
{
|
||||
$failures = [];
|
||||
|
||||
@@ -14,6 +14,7 @@ use Targets\TargetDescriptionFiles\MemorySegmentSection;
|
||||
use Targets\TargetDescriptionFiles\MemorySegmentType;
|
||||
use Targets\TargetDescriptionFiles\Module;
|
||||
use Targets\TargetDescriptionFiles\Peripheral;
|
||||
use Targets\TargetDescriptionFiles\RegisterGroupInstance;
|
||||
use Targets\TargetDescriptionFiles\PhysicalInterface;
|
||||
use Targets\TargetDescriptionFiles\Property;
|
||||
use Targets\TargetDescriptionFiles\PropertyGroup;
|
||||
@@ -325,8 +326,8 @@ class FromXmlService
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($childNode->nodeName === 'register-group-reference') {
|
||||
$output->registerGroupReferences[] = $this->registerGroupReferenceFromElement($childNode);
|
||||
if ($childNode->nodeName === 'register-group-instance') {
|
||||
$output->registerGroupInstances[] = $this->registerGroupInstanceFromElement($childNode);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -356,6 +357,20 @@ class FromXmlService
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function registerGroupInstanceFromElement(DOMElement $element): RegisterGroupInstance
|
||||
{
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
|
||||
return new RegisterGroupInstance(
|
||||
$attributes['key'] ?? null,
|
||||
$attributes['name'] ?? null,
|
||||
$attributes['register-group-key'] ?? null,
|
||||
$attributes['address-space-key'] ?? null,
|
||||
$this->stringService->tryStringToInt($attributes['offset'] ?? null),
|
||||
$attributes['description'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public function signalFromElement(DOMElement $element): Signal
|
||||
{
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
|
||||
@@ -9,6 +9,7 @@ use Targets\TargetDescriptionFiles\MemorySegment;
|
||||
use Targets\TargetDescriptionFiles\MemorySegmentSection;
|
||||
use Targets\TargetDescriptionFiles\Module;
|
||||
use Targets\TargetDescriptionFiles\Peripheral;
|
||||
use Targets\TargetDescriptionFiles\RegisterGroupInstance;
|
||||
use Targets\TargetDescriptionFiles\PhysicalInterface;
|
||||
use Targets\TargetDescriptionFiles\Pin;
|
||||
use Targets\TargetDescriptionFiles\Pinout;
|
||||
@@ -135,8 +136,8 @@ class ToXmlService
|
||||
$element->setAttribute('name', $peripheral->name);
|
||||
$element->setAttribute('module-key', $peripheral->moduleKey);
|
||||
|
||||
foreach ($peripheral->registerGroupReferences as $registerGroupReference) {
|
||||
$element->append($this->registerGroupReferenceToXml($registerGroupReference, $document));
|
||||
foreach ($peripheral->registerGroupInstances as $registerGroupInstance) {
|
||||
$element->append($this->registerGroupInstanceToXml($registerGroupInstance, $document));
|
||||
}
|
||||
|
||||
if (!empty($peripheral->signals)) {
|
||||
@@ -151,6 +152,25 @@ class ToXmlService
|
||||
return $element;
|
||||
}
|
||||
|
||||
public function registerGroupInstanceToXml(
|
||||
RegisterGroupInstance $registerGroupInstance,
|
||||
DOMDocument $document
|
||||
): DOMElement {
|
||||
$element = $document->createElement('register-group-instance');
|
||||
$element->setAttribute('key', $registerGroupInstance->key);
|
||||
$element->setAttribute('name', $registerGroupInstance->name);
|
||||
|
||||
if (!empty($registerGroupInstance->description)) {
|
||||
$element->setAttribute('description', $registerGroupInstance->description);
|
||||
}
|
||||
|
||||
$element->setAttribute('register-group-key', $registerGroupInstance->registerGroupKey);
|
||||
$element->setAttribute('address-space-key', $registerGroupInstance->addressSpaceKey);
|
||||
$element->setAttribute('offset', $this->stringService->tryIntToHex($registerGroupInstance->offset));
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
public function signalToXml(Signal $signal, DOMDocument $document): DOMElement
|
||||
{
|
||||
$element = $document->createElement('signal');
|
||||
|
||||
Reference in New Issue
Block a user