Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .metadata/sysconfig/.meta/ai.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const additionalInstructions = `
CRITICAL WORKFLOW - ALWAYS FOLLOW:
CRITICAL RULE: Before calling addModuleInstances for ANY block:
1. MUST call getAIContext first to read documentation
1. Must read Agents.md and read the docs_ai for the blocks which will be used
Comment thread
a1248924 marked this conversation as resolved.
2. NO EXCEPTIONS - even if you think you know the block
3. "When changing a module instance's $name configurable, the moduleInstanceId automatically updates to match the new name, so always use getModuleInstances() after renaming to retrieve the updated instance IDs before making connections or further modifications."
4. If you skip this step, acknowledge your mistake immediately
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,90 +177,11 @@ function getMacro(pruInstructionMacro, opCode)
return macroBody;
}

function getAIContext(){
return getLongDescription() + `
## How to Configure (For AI/Scripting)

This section describes how to programmatically configure the CRC block in a .syscfg file.

### Adding a CRC Instance

\`\`\`javascript
const crc_block = scripting.addModule("/pru_blocks/application_specific/crc_block", {}, false);
const crc1 = crc_block.addInstance();
\`\`\`

### Configuration Parameters

| Parameter | Type | Valid Values | Default | Description |
|-----------|------|--------------|---------|-------------|
| opCode | String | "m_calculate_crc8", "m_calculate_crc16", "m_calculate_crc32" | "m_calculate_crc8" | CRC algorithm type |
| crcPolynomial | Hex | Depends on CRC type | 0x07 | CRC polynomial (generator) |
| output1Size | String | "1", "2", "4" | "1" | Output size in bytes |

### Valid CRC Types and Polynomials

| CRC Type | Default Polynomial | Common Polynomials | Description |
|----------|-------------------|-------------------|-------------|
| CRC8 | 0x07 | 0x07, 0x31, 0x9B | 8-bit CRC (1 byte output) |
| CRC16 | 0x8005 | 0x8005, 0x1021, 0x8408 | 16-bit CRC (2 byte output) |
| CRC32 | 0x04C11DB7 | 0x04C11DB7, 0xEDB88320 | 32-bit CRC (4 byte output) |

### Example Configurations

**Standard CRC8:**
\`\`\`javascript
crc1.$name = "CRC8_Check";
crc1.opCode = "m_calculate_crc8";
crc1.crcPolynomial = 0x07;
crc1.output1Size = "1";
\`\`\`

**CRC16 for MODBUS:**
\`\`\`javascript
crc1.$name = "CRC16_MODBUS";
crc1.opCode = "m_calculate_crc16";
crc1.crcPolynomial = 0x8005;
crc1.output1Size = "2";
\`\`\`

**CRC32 for Ethernet:**
\`\`\`javascript
crc1.$name = "CRC32_Ethernet";
crc1.opCode = "m_calculate_crc32";
crc1.crcPolynomial = 0x04C11DB7;
crc1.output1Size = "4";
\`\`\`

### Connecting to Other Blocks

\`\`\`javascript
// Connect data input
scripting.connect(data_source, "output1", crc1, "input1");

// Connect CRC output to downstream block
scripting.connect(crc1, "output1", next_block, "input1");

// Connect control flow
scripting.connect(prev_block, "next", crc1, "prev");
scripting.connect(crc1, "next", next_block, "prev");
\`\`\`

### Important Notes

1. **Input Required**: input1 must be connected to provide data for CRC calculation.

2. **Polynomial Selection**: Choose appropriate polynomial for your protocol/standard.

3. **Output Size**: Must match CRC type (CRC8=1 byte, CRC16=2 bytes, CRC32=4 bytes).

4. **Lookup Table**: Block generates optimized lookup table for fast CRC calculation.
`;

}

function getLongDescription(){
return `
return `NOTE: Before making any assumptions about this block's parameters, behavior, or configuration, always read the docs file at: docs_ai/application_specific/crc_block.md

## CRC Block (Cyclic Redundancy Check)

### Purpose
Expand Down Expand Up @@ -366,7 +287,6 @@ exports = {
displayName: "CRC",
defaultInstanceName: "CRC_",
longDescription: getLongDescription(),
getAIContext: getAIContext,
uiView: "graph",
templates: {
//need to check what can be passed as argument to template file, right now no argument is required
Expand Down
Loading
Loading