// Adds the row to the next element of the string labelTable lt struct labelTable * addRowToTable(struct labelTable * lt, struct labelTableRow *ltr) { if(lt->down != NULL) ErrorDeal(TableRow, 0); lt->down = newTable(); lt = lt->down; lt->down = NULL; lt->row = ltr; return lt; }
// Gets the address correponding to the label of // name labelName in the label table lt. It puts the // correponding struct found at pos int getLabelNumAddr(char * labelName, struct labelTable * lt, struct labelTable **pos) { while(lt != NULL && strcmp(labelName, lt->row->label)){ lt = lt->down; } if(lt == NULL) ErrorDeal(TableRow, 0); if(pos != NULL) *pos = lt; return lt->row->addr; }
//Creates the token of the element x of M(x) struct linkedListToken * getAddr(FILE * in, struct linkedListToken * end, int line) { struct token * t = malloc(sizeof(struct token)); char * word = malloc(sizeof(char)*MAX_OPERATION_SIZE); int i; fscanf(in, " %s", word); if(!strncmp(word, "M(", 2)){ for(i=0; i < (strlen(word)-1); i++) word[i] = word[i+2]; if(word[i-2] != ')') ErrorDeal(ParserError, line); word[i-2] = '\0'; } else ErrorDeal(ParserError, line); t->attributes.string = word; t->type = ADDR; end = addToken(end, t, line); return end; }
// Adds the token t to the next element of the // linked list lt. Line is the line of the token in // the text file, it is used to send the line of // the error in case of LinkedTokenError struct linkedListToken * addToken(struct linkedListToken * lt, struct token * t, int line) { struct linkedListToken * llt = malloc(sizeof(struct linkedListToken)); //If the linked list was not initiated yet if(lt == NULL){ lt = llt; lt->next = NULL; lt->t = t; } //Else if you are on the right place of the linked list else if(lt->next == NULL){ llt->next = NULL; llt->t = t; lt->next = llt; } else { ErrorDeal(LinkedTokenError, line); } return llt; }
/********************************************************************* 函数名称: void Key_FastSetState(void) 功 能: 快速设置状态按键处理 说 明: 入口参数: 返 回 值: 设 计: 丛海旭 时 间: 2014-1-17 修 改: 时 间: *********************************************************************/ void Key_FastSetState(void) { u8 i = 0; if (gu32_KeyCode == K_RIGHT) { if (++gu8_Item > REC_F1_6) gu8_Item = REC_F1_1; gb_FirstNumKeyFlg = true; ulParameter.ul = gu32_FastSetTemp[ gu8_Item - 3 ]; //获取对应项目的参数值 } //数据输入 ulParameter.ul = Key_NumInput(ulParameter.ul, 6); //每一项下的按键处理程序 switch (gu32_KeyCode) { case K_ESC: //退出键处理 gb_FlashFlg = false; gb_SetFlg = false; gb_FirstNumKeyFlg = true; gu8_DataInLength = 0; gb_FastSetFlg = false; if (gu8_FastSetSigTemp != 0) { if (gb_RunFlg == false) //按esc时仪表已经处于停止状态,并且有未更新的配方数据则立即更新 { for (i = 0; i <= 5; i++) { if (gu8_FastSetSigTemp & (0x01 << i)) { ulParameter.ul = gu32_FastSetTemp[i]; FRAM_WriteDW(GetRecipePort(i + 3), ulParameter.ul); } gu8_FastSetSigTemp = 0; } } } break; case K_ENTER: //确认键处理 gb_FirstNumKeyFlg = true; gu8_DataInLength = 0; if (RecDataInputCheck() || (gu8_Item == REC_F1_1 && ulParameter.ul == 0)) //输入数据范围检查 { ErrorDeal(0, 100); ulParameter.ul = gu32_FastSetTemp[gu8_Item - 3]; return; } if (gb_RunFlg == false) //停止状态下立刻更新配方 { gu32_FastSetTemp[gu8_Item - 3] = ulParameter.ul; FRAM_WriteDW(GetRecipePort(gu8_Item), ulParameter.ul); } else //运行状态下 { if (gu32_Process <= T1PROCESS) { //T1延时状态时立刻更新配方,比如无斗未夹袋状态下 gu32_FastSetTemp[gu8_Item - 3] = ulParameter.ul; FRAM_WriteDW(GetRecipePort(gu8_Item), ulParameter.ul); } else if (gu8_Item == REC_F1_5) { //运行时修改零区值实时保存,其他值下一秤启动时更新 gu32_FastSetTemp[4] = ulParameter.ul; FRAM_WriteDW(GetRecipePort(REC_F1_5), ulParameter.ul); } else { //如果输入数据改变则置相应的相据改变标志位 if (ulParameter.ul != gu32_FastSetTemp[gu8_Item-3]) { //将输入的参数先存入快速设置暂存数组中 注:REC_F1_1 = 3 gu8_FastSetSigTemp |= (0x01 << (gu8_Item - 3)); gu32_FastSetTemp[gu8_Item-3] = ulParameter.ul; } } } if (++gu8_Item > REC_F1_6) gu8_Item = REC_F1_1; ulParameter.ul = gu32_FastSetTemp[ gu8_Item - 3 ]; //得到对应参数的值 break; default: break; } }
/********************************************************************* 函数名称: void Key_StopState(void) 功 能: 停止时按键处理 说 明: 入口参数: 返 回 值: 设 计: 丛海旭 时 间: 2013-12-12 修 改: 时 间: *********************************************************************/ void Key_StopState(void) { u8 i; //防止结束输入后超欠差灯不灭问题 if(gb_OUOverFlg) { if(gu32_Sys10ms - gu32_OUDelayTimeBuf >= 200) gb_OUOverFlg = false; } if(gb_OUUnderFlg) { if(gu32_Sys10ms - gu32_OUDelayTimeBuf >= 200) gb_OUUnderFlg = false; } if (gb_FastSetFlg) //快速设置配方状态 { Key_FastSetState(); //快速设置按键处理 } else //停止状态下按键处理 { if (gb_AlarmFlg) //报警状态下只能按ESC ENTER ZERO { if ((gu32_KeyCode != K_ZERO) && (gu32_KeyCode != K_ESC) && (gu32_KeyCode != K_ENTER) && (gu32_KeyCode != K_NONE)) return; } switch (gu32_KeyCode) { case K_0: //开关量自定义 gu8_Item = 0; gu32_SystemState = IODEFINESTATE; gu32_KeyCode = 0; if (gu32_IoDefCodeSwitch == 0) //开关量测试开关关闭则直接进入测试 { gu8_Item = IODEF_IN1; ulParameter.ul = *gu32p_IoInBuf[1]; } else gu8_Item = IODEF_CHECKCODE; Key_IoDefState(); break; case K_1: //进入工作参数设置 gu8_Item = 0; gu32_SystemState = SETUPSTATE; gu32_KeyCode = 0; if (gu32_SetupCodeSwitch == 0) //工作参数密码开关关闭则直接进入F1 { gu8_Item = 1; gu32_TimeDelay = gu32_Sys10ms; } Key_SetupState(); break; case K_2: //进入标定 if (gb_CalLockDefFlg && gb_CalLockFlg == false) { //标定锁有定义但是输入无效,不能标定 break; } gu8_Item = 0; gb_FastCalFlg = false; //完整标定功能 gu32_SystemState = CALIBSTATE; gu32_KeyCode = 0; Key_CalibState(); break; case K_3: //进入批次数设置 gu8_Item = 0; gu32_SystemState = BATCHSTATE; ulParameter.ul = gu32_BatchTime; gu32_KeyCode = 0; Key_BatchState(); break; case K_4: //时间设置 gu8_Item = 0; gu32_SystemState = TIMESTATE; gu32_KeyCode = 0; Key_DateTimeState(); break; case K_5: //日期设置 gu8_Item = 0; gu32_SystemState = DATESTATE; gu32_KeyCode = 0; Key_DateTimeState(); break; case K_6: //进入累计查询 gu8_Item = 0; gu32_SystemState = SUMSTATE; gu32_KeyCode = 0; if(gs_Setup.SumCheckCodeSwitch != 0) //自定义密码开关打开 { gu8_Item = 0; } else { ulParameter.ul = gu32_SumWt; gu8_Item = 1; gb_SumFlg = true; //sum指示灯亮 } Key_SumState(); break; case K_7: //打印 gu8_Item = 0; if (gs_Setup.ComMode_1 == COM_PRINT || gs_Setup.ComMode_2 == COM_PRINT) {//有设置为打印功能才能进入打印界面 gu32_SystemState = PRINTSTATE; gu32_KeyCode = 0; ulParameter.ul = gu32_RecNum; gb_PrintAllFlg = false; gu8_Item = 1; gb_FirstPrintFlg_UART0 = true; gb_PrintAllRecFlg_UART0 = false; gb_FirstPrintFlg_UART1 = true; gb_PrintAllRecFlg_UART1 = false; Key_PrintState(); } else ErrorDeal(10, 100); break; case K_8: //开关量测试 gu8_Item = 0; gu32_SystemState = IOTESTSTATE; gu32_KeyCode = 0; IO_CloseOut(); //关闭所有开关量输出 if (gu32_IoTestCodeSwitch == 0) //开关量测试开关关闭则直接进入测试 gu8_Item = IOTEST; else gu8_Item = IOTEST_CHECKCODE; Key_IoTestState(); break; case K_9: //配方设置 gu8_Item = 0; gu32_SystemState = RECIPESTATE; gu32_KeyCode = 0; ulParameter.ul = gu32_RecNum; gb_FirstNumKeyFlg = true; Key_RecipeState(); break; case K_ZERO: //清零 if (gb_AlarmFlg == true) //有报警时该键无用 break; gb_ZeroKeyFlg = true; break; case K_ZERO_2S: //长按两秒标定零点 v1.01 //稳定并且AD不溢出才允许标零点 if (AdToMv(gu32_AdFedValue) <= 12000 * gs_Cal.Sensor && gb_AdOflFlg == false && gb_MvStabFlg == true) { gs_Cal.Zero = gu32_AdFedValue; FRAM_WriteDW(FMAddr_CalZero, gs_Cal.Zero); gu32_FloatZero = 0; gb_SigFZeroFlg = false; } else //不满足标定条件报错 ErrorDeal(0, 100); break; case K_RIGHT_2S: //进入快速标定零点和增益 if (gb_CalLockDefFlg && gb_CalLockFlg == false) { //标定锁有定义但是输入无效,不能标定 break; } gu8_Item = 0; gb_FastCalFlg = true; gu32_SystemState = CALIBSTATE; gu32_KeyCode = 0; Key_CalibState(); break; case K_SET_2S: // gu8_Item = 0; gu32_SystemState = DEBUGSTATE; gu32_KeyCode = 0; Key_DebugState(); break; case K_ENTER: gu8_Item = 0; gb_FastSetFlg = true; gu32_KeyCode = 0; gu8_Item = REC_F1_1; //进入后第一项为自定义为ON的参数 gu8_FastSetSigTemp = 0; for (i = 0; i <= 5; i++) //将F1.x读入到快速设置暂存 gu32_FastSetTemp[i] = GetRecipeItemValue(REC_F1_1 + i); ulParameter.ul = gu32_FastSetTemp[gu8_Item-3]; break; case K_ESC: Clr_Alarm(); //清报警 break; default: ulParameter.ul = 0xFFFFFFFF; gu8_DataInLength = 0; gb_SetFlg = false; gb_FirstNumKeyFlg = true; gb_FlashFlg = false; break; #ifdef DEBUG_RUN_STOP_BY_KEY case K_INC: //↑键启动 RunStopInit(true); break; #endif } } }
// Constructs the linked list of tokens that represent // the file in struct linkedListToken * getTokens(FILE * in, struct linkedListToken * begin) { char * word = malloc(sizeof(char)*MAX_OPERATION_SIZE); struct token * t = NULL; struct linkedListToken * end = begin; int line = 0; while(fscanf(in," %s",word) != EOF){ //Atualizate the line numbers line++; //If commentary discad line if(!strncmp(word, "@", 1)){ while(fgetc(in) != '\n'); } else{ t = malloc(sizeof(struct token)); //IAS Commands if(!strcmp(word, "LOADMQ")){ t->type = OP; t->attributes.needsAddress = false; t->tk.command = LOADMQ; end = addToken(end, t, line); } else if(!strcmp(word, "LOADMQMem")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = LOADMQMem; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "STOR")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = STOR; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "LOAD")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = LOAD; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "LOADNeg")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = LOADNeg; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "LOADMod")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = LOADMod; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "JUMP")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = JUMP; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "JUMPPos")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = JUMPplus; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "ADD")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = ADD; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "ADDMod")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = ADDMod; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "SUB")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = SUB; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "SUBMod")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = SUBMod; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "MUL")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = MUL; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "DIV")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = DIV; end = addToken(end, t, line); end = getAddr(in, end, line); } else if(!strcmp(word, "LSH")){ t->type = OP; t->attributes.needsAddress = false; t->tk.command = LSH; end = addToken(end, t, line); } else if(!strcmp(word, "RSH")){ t->type = OP; t->attributes.needsAddress = false; t->tk.command = RSH; end = addToken(end, t, line); } else if(!strcmp(word, "STORAddr")){ t->type = OP; t->attributes.needsAddress = true; t->tk.command = STORAddr; end = addToken(end, t, line); end = getAddr(in, end, line); } //Directives else if(!strcmp(word, ".org")){ t->type = Dir; t->attributes.string = ".org"; t->tk.dir = ORG; end = addToken(end, t, line); end = getDirArguments(in, end, line); } else if(!strcmp(word, ".align")){ t->type = Dir; t->attributes.string = ".align"; t->tk.dir = ALIGN; end = addToken(end, t, line); end = getDirArguments(in, end, line); } else if(!strcmp(word, ".wfill")){ t->type = Dir; t->attributes.string = ".wfill"; t->tk.dir = WFILL; end = addToken(end, t, line); end = getDirArguments(in, end, line); end = getDirArguments(in, end, line); } else if(!strcmp(word, ".word")){ t->type = Dir; t->attributes.string = ".word"; t->tk.dir = WORD; end = addToken(end, t, line); end = getDirArguments(in, end, line); } else if(!strcmp(word, ".set")){ t->type = Dir; t->attributes.string = ".set"; t->tk.dir = SET; end = addToken(end, t, line); end = getDirArguments(in, end, line); end = getDirArguments(in, end, line); } else if(word[strlen(word)-1] == ':'){ word[strlen(word)-1] = '\0'; t->type = Dir; t->attributes.string = word; t->tk.dir = LABEL; end = addToken(end, t, line); end = getTokens(in, end); word = malloc(sizeof(char)*MAX_OPERATION_SIZE); } else ErrorDeal(ParserError, line); } } free(word); return end; }