⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ui_serial.c

📁 Luminary Micro BLDC motor control software
💻 C
📖 第 1 页 / 共 4 页
字号:
            //
            case CMD_UPGRADE:
            {
                //
                // Pass the upgrade request to the application.
                //
                UIUpgrade();

                //
                // Control should never return here, but enter an infinite loop
                // just in case it does.
                //
                while(1)
                {
                }
            }

            //
            // The command to get a list of the parameters.
            //
            case CMD_GET_PARAMS:
            {
                //
                // Fill in the response.
                //
                g_pucUISerialResponse[0] = TAG_STATUS;
                g_pucUISerialResponse[1] = g_ulUINumParameters + 4;
                g_pucUISerialResponse[2] = CMD_GET_PARAMS;
                for(ulIdx = 0; ulIdx < g_ulUINumParameters; ulIdx++)
                {
                    g_pucUISerialResponse[ulIdx + 3] =
                        g_sUIParameters[ulIdx].ucID;
                }

                //
                // Send the response.
                //
                UISerialTransmit(g_pucUISerialResponse);

                //
                // Done with this command.
                //
                break;
            }

            //
            // The command to get a description of a parameter.
            //
            case CMD_GET_PARAM_DESC:
            {
                //
                // Find the parameter.
                //
                ucSum =
                    g_pucUISerialReceive[(g_ulUISerialReceiveRead + 3) %
                                         UISERIAL_MAX_RECV];
                ulIdx = UISerialFindParameter(ucSum);

                //
                // Fill in the response.
                //
                g_pucUISerialResponse[0] = TAG_STATUS;
                g_pucUISerialResponse[2] = CMD_GET_PARAM_DESC;

                //
                // If a parameter was not specified, or if the parameter could
                // not be found, then return a zero length.
                //
                if((ucSize != 5) || (ulIdx == 0xffffffff))
                {
                    g_pucUISerialResponse[1] = 0x05;
                    g_pucUISerialResponse[3] = 0x00;
                }

                //
                // If the length of the parameter is greater than a 32-bit
                // value, then return just the size of the parameter.
                //
                else if(g_sUIParameters[ulIdx].ucSize > 4)
                {
                    g_pucUISerialResponse[1] = 0x05;
                    g_pucUISerialResponse[3] = g_sUIParameters[ulIdx].ucSize;
                }

                //
                // Otherwise, return the size, minimum, maximum, and step size
                // for the parameter.
                //
                else
                {
                    //
                    // Set the size of the response packet.
                    //
                    g_pucUISerialResponse[1] =
                        (g_sUIParameters[ulIdx].ucSize * 3) + 5;

                    //
                    // Set the size of the parameter value.
                    //
                    g_pucUISerialResponse[3] = g_sUIParameters[ulIdx].ucSize;

                    //
                    // Loop through the bytes of the parameter value.
                    //
                    ucSize = g_sUIParameters[ulIdx].ucSize;
                    for(ucSum = 0; ucSum < ucSize; ucSum++)
                    {
                        //
                        // Set this byte of the parameter minimum value.
                        //
                        g_pucUISerialResponse[ucSum + 4] =
                            ((g_sUIParameters[ulIdx].ulMin >> (ucSum * 8)) &
                             0xff);

                        //
                        // Set this byte of the parameter maximum value.
                        //
                        g_pucUISerialResponse[ucSum + ucSize + 4] =
                            ((g_sUIParameters[ulIdx].ulMax >> (ucSum * 8)) &
                             0xff);

                        //
                        // Set this byte of the parameter step size.
                        //
                        g_pucUISerialResponse[ucSum + (ucSize << 1) + 4] =
                            ((g_sUIParameters[ulIdx].ulStep >> (ucSum * 8)) &
                             0xff);
                    }
                }

                //
                // Send the response.
                //
                UISerialTransmit(g_pucUISerialResponse);

                //
                // Done with this command.
                //
                break;
            }

            //
            // The command to get the value of a parameter.
            //
            case CMD_GET_PARAM_VALUE:
            {
                //
                // Find the parameter.
                //
                ucSum =
                    g_pucUISerialReceive[(g_ulUISerialReceiveRead + 3) %
                                         UISERIAL_MAX_RECV];
                ulIdx = UISerialFindParameter(ucSum);

                //
                // Fill in the response.
                //
                g_pucUISerialResponse[0] = TAG_STATUS;
                g_pucUISerialResponse[2] = CMD_GET_PARAM_VALUE;

                //
                // If a parameter was not specified, or if the parameter could
                // not be found, then return no value.
                //
                if((ucSize != 5) || (ulIdx == 0xffffffff))
                {
                    g_pucUISerialResponse[1] = 0x04;
                }

                //
                // Return the current value of the parameter.
                //
                else
                {
                    //
                    // Set the response packet size based on the size of the
                    // parameter.
                    //
                    g_pucUISerialResponse[1] =
                        g_sUIParameters[ulIdx].ucSize + 4;

                    //
                    // Copy the parameter value to the response packet.
                    //
                    for(ucSum = 0; ucSum < g_sUIParameters[ulIdx].ucSize;
                        ucSum++)
                    {
                        g_pucUISerialResponse[ucSum + 3] =
                            g_sUIParameters[ulIdx].pucValue[ucSum];
                    }
                }

                //
                // Send the response.
                //
                UISerialTransmit(g_pucUISerialResponse);

                //
                // Done with this command.
                //
                break;
            }

            //
            // The command to set the value of a parameter.
            //
            case CMD_SET_PARAM_VALUE:
            {
                //
                // Find the parameter.
                //
                ucSum =
                    g_pucUISerialReceive[(g_ulUISerialReceiveRead + 3) %
                                         UISERIAL_MAX_RECV];
                ulIdx = UISerialFindParameter(ucSum);

                //
                // Fill in the response.
                //
                g_pucUISerialResponse[0] = TAG_STATUS;
                g_pucUISerialResponse[1] = 0x04;
                g_pucUISerialResponse[2] = CMD_SET_PARAM_VALUE;

                //
                // Only set the value of the parameter if a value was
                // specified, the parameter could be found, and the parameter
                // is not read-only.
                //
                if((ucSize > 5) && (ulIdx != 0xffffffff) &&
                   (g_sUIParameters[ulIdx].ulStep != 0))
                {
                    //
                    // Loop through the bytes of this parameter value.
                    //
                    for(ucSum = 0; ucSum < g_sUIParameters[ulIdx].ucSize;
                        ucSum++)
                    {
                        //
                        // See if this byte was supplied.
                        //
                        if(ucSum < (ucSize - 5))
                        {
                            //
                            // Set this byte of the parameter value based on
                            // the supplied byte.
                            //
                            g_sUIParameters[ulIdx].pucValue[ucSum] =
                                g_pucUISerialReceive[(g_ulUISerialReceiveRead +
                                                      ucSum + 4) %
                                                     UISERIAL_MAX_RECV];
                        }
                        else
                        {
                            //
                            // Set this byte of the parameter value to zero
                            // since it was not supplied.
                            //
                            g_sUIParameters[ulIdx].pucValue[ucSum] = 0;
                        }
                    }

                    //
                    // Perform range checking on the parameter value.
                    //
                    UISerialRangeCheck(ulIdx);

                    //
                    // If there is an update function for this parameter then
                    // call it now.
                    //
                    if(g_sUIParameters[ulIdx].pfnUpdate)
                    {
                        g_sUIParameters[ulIdx].pfnUpdate();
                    }
                }

                //
                // Send the response.
                //
                UISerialTransmit(g_pucUISerialResponse);

                //
                // Done with this command.
                //
                break;
            }

            //
            // The command to load parameters from flash.
            //
            case CMD_LOAD_PARAMS:
            {
                //
                // Pass the parameter load request to the application.
                //
                UIParamLoad();

                //
                // Fill in the response.
                //
                g_pucUISerialResponse[0] = TAG_STATUS;
                g_pucUISerialResponse[1] = 0x04;
                g_pucUISerialResponse[2] = CMD_LOAD_PARAMS;

                //
                // Send the response.
                //
                UISerialTransmit(g_pucUISerialResponse);

                //
                // Done with this command.
                //
                break;
            }

            //
            // The command to save parameters to flash.
            //
            case CMD_SAVE_PARAMS:
            {
                //
                // Pass the parameter save request to the application.
                //
                UIParamSave();

                //
                // Fill in the response.
                //
                g_pucUISerialResponse[0] = TAG_STATUS;
                g_pucUISerialResponse[1] = 0x04;
                g_pucUISerialResponse[2] = CMD_LOAD_PARAMS;

                //
                // Send the response.
                //
                UISerialTransmit(g_pucUISerialResponse);

                //
                // Done with this command.
                //
                break;
            }

            //
            // The command to get a list of the real-time data items.
            //
            case CMD_GET_DATA_ITEMS:
            {
                //
                // Fill in the response.
                //
                g_pucUISerialResponse[0] = TAG_STATUS;
                g_pucUISerialResponse[1] = (g_ulUINumRealTimeData * 2) + 4;
                g_pucUISerialResponse[2] = CMD_GET_DATA_ITEMS;
                for(ulIdx = 0; ulIdx < g_ulUINumRealTimeData; ulIdx++)
                {
                    g_pucUISerialResponse[(ulIdx * 2) + 3] =
                        g_sUIRealTimeData[ulIdx].ucID;
                    g_pucUISerialResponse[(ulIdx * 2) + 4] =
                        g_sUIRealTimeData[ulIdx].ucSize;
                }

                //
                // Send the response.
                //
                UISerialTransmit(g_pucUISerialResponse);

                //
                // Done with this command.
                //
                break;
            }

            //
            // The command to enable a real-time data item.
            //
            case CMD_ENABLE_DATA_ITEM:
            {
                //
                // Fill in the response.
                //
                g_pucUISerialResponse[0] = TAG_STATUS;
                g_pucUISerialResponse[1] = 0x04;
                g_pucUISerialResponse[2] = CMD_ENABLE_DATA_ITEM;

                //
                // Enable the data item if it is was validly specified.
                //
                ucSum = g_pucUISerialReceive[(g_ulUISerialReceiveRead + 3) %
                                                        UISERIAL_MAX_RECV];
                if((ucSize == 5) && (ucSum < DATA_NUM_ITEMS))
                {
                    g_pulUIRealTimeData[ucSum / 32] |= 1 << (ucSum % 32);
                }

                //
                // Send the response.
                //
                UISerialTransmit(g_pucUISerialResponse);

                //
                // Done with this command.
                //
                break;
            }

            //
            // The command to disable a real-time data item.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -