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

📄 ui_ethernet.c

📁 Luminary Micro BLDC motor control software
💻 C
📖 第 1 页 / 共 5 页
字号:
                //
                ucSum =
                    g_pucUIEthernetReceive[(g_ulUIEthernetReceiveRead + 3) %
                                         UIETHERNET_MAX_RECV];
                ulIdx = UIEthernetFindParameter(ucSum);

                //
                // Fill in the response.
                //
                g_pucUIEthernetResponse[0] = TAG_STATUS;
                g_pucUIEthernetResponse[1] = 0x04;
                g_pucUIEthernetResponse[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_pucUIEthernetReceive[
                                (g_ulUIEthernetReceiveRead + ucSum + 4) %
                                UIETHERNET_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.
                    //
                    UIEthernetRangeCheck(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.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

                //
                // 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_pucUIEthernetResponse[0] = TAG_STATUS;
                g_pucUIEthernetResponse[1] = 0x04;
                g_pucUIEthernetResponse[2] = CMD_LOAD_PARAMS;

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

                //
                // 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_pucUIEthernetResponse[0] = TAG_STATUS;
                g_pucUIEthernetResponse[1] = 0x04;
                g_pucUIEthernetResponse[2] = CMD_LOAD_PARAMS;

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

                //
                // 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_pucUIEthernetResponse[0] = TAG_STATUS;
                g_pucUIEthernetResponse[1] = (g_ulUINumRealTimeData * 2) + 4;
                g_pucUIEthernetResponse[2] = CMD_GET_DATA_ITEMS;
                for(ulIdx = 0; ulIdx < g_ulUINumRealTimeData; ulIdx++)
                {
                    g_pucUIEthernetResponse[(ulIdx * 2) + 3] =
                        g_sUIRealTimeData[ulIdx].ucID;
                    g_pucUIEthernetResponse[(ulIdx * 2) + 4] =
                        g_sUIRealTimeData[ulIdx].ucSize;
                }

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

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

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

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

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

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

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

                //
                // Disable the data item if it is was validly specified.
                //
                ucSum = g_pucUIEthernetReceive[(g_ulUIEthernetReceiveRead + 3) %
                                                        UIETHERNET_MAX_RECV];
                if((ucSize == 5) && (ucSum < DATA_NUM_ITEMS))
                {
                    g_pulUIRealTimeData[ucSum / 32] &= ~(1 << (ucSum % 32));
                }

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

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

            //
            // The command to start the real-time data stream.
            //
            case CMD_START_DATA_STREAM:
            {
                //
                // Fill in the response.
                //
                g_pucUIEthernetResponse[0] = TAG_STATUS;
                g_pucUIEthernetResponse[1] = 0x04;
                g_pucUIEthernetResponse[2] = CMD_START_DATA_STREAM;

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

                //
                // Enable the real-time data stream.
                //
                g_bEnableRealTimeData = true;

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

            //
            // The command to stop the real-time data stream.
            //
            case CMD_STOP_DATA_STREAM:
            {
                //
                // Fill in the response.
                //
                g_pucUIEthernetResponse[0] = TAG_STATUS;
                g_pucUIEthernetResponse[1] = 0x04;
                g_pucUIEthernetResponse[2] = CMD_STOP_DATA_STREAM;

                //
                // Disable the real-time data stream.
                //
                g_bEnableRealTimeData = false;

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

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

            //
            // The command to start the motor drive.
            //
            case CMD_RUN:
            {
                //
                // Pass the run request to the application.
                //
                UIRun();

                //
                // Fill in the response.
                //
                g_pucUIEthernetResponse[0] = TAG_STATUS;
                g_pucUIEthernetResponse[1] = 0x04;
                g_pucUIEthernetResponse[2] = CMD_RUN;

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

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

            //
            // The command to stop the motor drive.
            //
            case CMD_STOP:
            {
                //
                // Pass the stop request to the application.
                //
                UIStop();

                //
                // Fill in the response.
                //
                g_pucUIEthernetResponse[0] = TAG_STATUS;
                g_pucUIEthernetResponse[1] = 0x04;
                g_pucUIEthernetResponse[2] = CMD_STOP;

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

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

            //
            // The command for an emmergency stop of the motor drive.
            //
            case CMD_EMERGENCY_STOP:
            {
                //
                // Pass the emergency stop request to the application.
                //
                UIEmergencyStop();

                //
                // Fill in the response.
                //
                g_pucUIEthernetResponse[0] = TAG_STATUS;
                g_pucUIEthernetResponse[1] = 0x04;
                g_pucUIEthernetResponse[2] = CMD_EMERGENCY_STOP;

                //
                // Send the response.
                //
                UIEthernetTransmit(g_pucUIEthernetResponse);

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

            //
            // An unrecognized command was received.  Simply ignore it.
            //
            default:
            {
                //
                // Done with this command.
                //
                break;
            }
        }

        //
        // Skip this command packet.
        //
        g_ulUIEthernetReceiveRead =
            (g_ulUIEthernetReceiveRead + ucSize) % UIETHERNET_MAX_RECV;
    }
}

//*****************************************************************************
//
//! Callback for Ethernet transmit.
//!
//! \param arg is not used in this implementation.
//! \param pcb is not used in this implementation.
//! \param len is not used in this implementation.
//!
//! This function is called when the lwIP TCP/IP stack has received an
//! acknowledgement for data that has been transmitted.
//!
//! \return This function will return an lwIP defined error code..
//
//*****************************************************************************
static err_t
UIEthernetSent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
    //
    // Reset the connection timeout.
    //
    g_ulConnectionTimeout = 0;

⌨️ 快捷键说明

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