?? ezlink_modem_cmd.c
字號:
/*
** ============================================================================
**
** FILE
** Id: EZLink_Modem_cmd.c, v2.0
**
** DESCRIPTION
** EZLink Modem Demo main file
**
** COPYRIGHT
** Copyright 2006 Integration Associates Inc. All rights reserved.
**
** LIMITED USE LICENSE.
** By using this software, the user agrees to the terms of the
** following license. If the user does not agree to these terms,
** then this software should be returned within 30 days and a full
** refund of the purchase price or license fee will provided.
** Integration Associates hereby grants a license to the user on the
** following terms and conditions: The user may use, copy, modify,
** revise, translate, abridge, condense, expand, collect, compile,
** link, recast, distribute, transform or adapt this software solely
** in connection with the development of products incorporating
** integrated circuits sold by Integration Associates. Any other use
** for any other purpose is expressly prohibited with the prior written
** consent of Integration Associates.
**
** Any copy or modification made must satisfy the following conditions:
**
** 1. Both the copyright notice and this permission notice appear in all copies of the software,
** derivative works or modified versions, and any portions thereof, and that both notices
** appear in supporting documentation.
**
** 2. All copies of the software shall contain the following acknowledgement: "Portions of this
** software are used under license from Integration Associates Inc. and are copyrighted."
**
** 3 Neither the name of Integration Associates Inc. nor any of its subsidiaries may be used
** to endorse or promote products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY "AS IS" AND ALL WARRANTIES OF ANY KIND, INCLUDING THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR USE, ARE EXPRESSLY DISCLAIMED. THE DEVELOPER
** SHALL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
** THIS SOFTWARE MAY NOT BE USED IN PRODUCTS INTENDED FOR USE IN IMPLANTATION OR OTHER DIRECT
** LIFE SUPPORT APPLICATIONS WHERE MALFUNCTION MAY RESULT IN THE DIRECT PHYSICAL HARM OR INJURY
** TO PERSONS. ALL SUCH IS USE IS EXPRESSLY PROHIBITED.
**
** ============================================================================
*/
//===============================================================================================
// Radio modem
// ASCIII command interpreter
//===============================================================================================
int cis; // CMD interpreter status
int iparam; // command parameter, 0-255
long lparam; // command parameter, 0-65535
void CMD_init(void)
{
cis = 0;
}
void printAbout(void)
{
printf("\r\nEZLink demo");
printf("\r\nRadio modem V");
printf(FW_VERSION);
printf("\r\nIntegration, 2008\r\n");
}
void printOK(void)
{
printf("\n\rOK\n\r>");
}
void printHelp(void)
{
printf("\r\nF=n : Set the rf channel (0-");
printf(MAX_FREQ);
printf(")");
printf("\r\nD=n : Set the rf datarate (e.g.: 9600)");
printf("\r\nP=n : Set the rf output power (0-7)");
printf("\r\nS? : Print the current settings");
printf("\r\nI : Print firmware version information");
printOK();
}
void CmdExec(char CMD) // CMD character interpreter
{
if ((CMD != '\n') && (CMD != ' ')) // don't use <space> and <LF>
switch (cis) // cis: Command Interpreter Status
{
case 0: // cis=0: basic state
switch (CMD)
{
case '\r':
printOK();
break;
case '?':
cis = 1;
break;
case 'I': case 'i':
cis = 2;
break;
case 'S': case 's':
cis = 3;
break;
case 'F': case 'f':
cis = 10;
iparam = 0;
break;
case 'D': case 'd':
cis = 20;
lparam = 0;
break;
case 'P': case 'p':
cis = 30;
iparam = 0;
break;
default:
cis = 255;
break;
}
break;
case 1: // cis=2: "?" arrived: print help
if (CMD == '\r')
{
printHelp();
cis = 0;
break;
}
else cis = 255;
break;
case 2: // cis=2: "I" arrived: print version info
if (CMD == '\r')
{
printAbout();
cis = 0;
break;
}
else cis = 255;
break;
case 3: // cis=2: "S" arrived: print current settings
switch (CMD)
{
case '=': break;
case '?': break;
case '\r':
printf("\r\nChannel : %U", read_EEPROM(EE_rf_ch));
lparam = read_EEPROM(EE_rf_dr + 1);
lparam = lparam << 8;
lparam += read_EEPROM(EE_rf_dr);
printf("\r\nDatarate: %Lu", lparam);
printf("\r\nRF power: %U", read_EEPROM(EE_rf_pwr));
printOK();
cis = 0;
break;
default:
cis = 255;
break;
}
break;
case 10: // cis=3: "F" arrived: frequency setting
switch (CMD)
{
case '=': break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
iparam = iparam * 10 + CMD - '0';
break;
case '\r':
if( iparam > FREQ_maxid )
{
iparam = 0;
}
Frequency_cmd = set_frq(iparam);
send_cmd(Frequency_cmd);
printOK();
cis = 0;
break;
default:
cis = 255;
break;
}
break;
case 20: // cis=3: "D" arrived: datarate setting
switch (CMD)
{
case '=': break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
lparam = lparam * 10 + CMD - '0';
break;
case '\r':
Data_rate_cmd = set_dr(lparam);
send_cmd(Data_rate_cmd);
printOK();
cis = 0;
break;
default:
cis = 255;
break;
}
break;
case 30: // cis=3: "P" arrived: output power setting
switch (CMD)
{
case '=': break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
iparam = iparam * 10 + CMD - '0';
break;
case '\r':
Transmitter_control_cmd = set_tx(RF_DEV, iparam);
send_cmd(Transmitter_control_cmd);
printOK();
cis = 0;
break;
default:
cis = 255;
break;
}
break;
case 255: // Bad command or parameter
if (CMD == 0x0D)
{
printf("\n\rERROR\n\r>");
cis = 0;
}
break;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -