Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be asked to write a program that takes one or two parameters from the c

ID: 658229 • Letter: Y

Question

 You will be asked to write a program that takes one or two parameters from the command line and             interacts with hardware, in this case the Open USB-IO board. 
 The first thing your code should do is: Read the current status of the LEDs at portb.              Then increment the value read from portb by the increment number found             in the second argument of the console command line  i.e. argv[1].              The number to increment should be specified on the command line and can be positive             or negative.             Eg.: lab3_1234567.exe     13             In the example above the increment value is '13'.                          If a valid third command line argument is found then the increment operation is performed              for the number of times indicated by the value of the third command line argument  i.e. argv[2].              Example:              Eg.: lab3_1234567.exe     13  3              In the example above the increment value is '13' and the number of times to increment is '3'             The program should then exit with code zero ('0').                          Note:              Eg.: lab3_1234567.exe     -13  1             In the example above the increment value is '-13' and the number of times to increment is once '1'             This is effectively the same as:              Eg.: lab3_1234567.exe     -13              In other words: the number of increment repetitions is assumed to be one unless stated otherwise by              the third command line argmument.                                FOR EACH INDIVIDUAL INCREMENT OPERATION:  "Wrapping around"                     If after addition of the increment value the value calculated for portb is greater than 255,             then the modulus of 256 is to be written to portb.             Eg.: 256 modulus 256 is 0             513 modulus 256 is 1              If AFTER addition of the increment value the value calculated for portb is less than zero             then 256 is to be added to the calculated value and this new value written to portb             Example: if the increment value is -10 and the current value of portb is 8             then the result after addition the calculated value is -2.             Therefore -2 plus 256 gives 254 which the new value to write to portb.             This is also sometimes referred to as 'wrapping around'.              ------------------------------          OUTPUT FORMATS: AS FOR A COMMAND SHELL WINDOW.                       The Open USB IO board outputs commands sent to it in a default format.             You will be required to change the default settting.              Example: if the command given is: "ousb.exe io portb 128"             The DEFAULT response from the OUSB board is: PORTB = 128     this is NOT what you should produce.             Repeat: this is NOT what you should produce.              Your code should display  ONLY the numbers           128             The method of how to make the OUSB board respond with just the number as output             can easily be found out by:                 1) opening a command window in Windows: START -> RUN -> "cmd"                 2) typing 'ousb' on the command line. This will bring up a help menu                 3) see the option for 'raw (decimal)' output.              If you use _popen and a file pipeline do not add EXTRA linefeeds, do not add extra blank             spaces or any other characters. Output must be as it would be for a standard command line              window.               The only text in the command shell window should be:                 - text returned from the OUSB board in response to your code or an error condition                 - NO debug code should appear in the command shell window. This means: any of your                     debug comments must be turned off for the final submitted copy.      EXAMPLES                    Assuming that the Open USB board portb LED's display 11 in binary then:              The command line "lab3_s1234567.exe 1 3" should produce the values                 12                 13                 14             i.e. increment of one, three times.              Assuming that the Open USB board portb LED's display 100 in binary then:             The command line "lab3_s1234567.exe -2  4" should produce the values                 98                 96                 94                 92             i.e. decrement of two, four times.              Assuming that the Open USB board portb LED's display 252 in binary then:             The command line "lab3_1234567.exe 3 3" should produce the values                 255                 2                 5             make sure you understand how this is derived. See the section on "wrapping around".                           Assuming that the Open USB board portb LED's display 13 in binary then:             The command line "lab3_1234567.exe -10 3" should produce the values                 3                 249                 239             make sure you understand how this is derived. See the section on "wrapping around".                   Access to the Open USB io board is via the executable binary file: ousb.exe .              In particular note the different responses ousb.exe gives to             ousb.exe -r io portb 1             ousb.exe io portb 1             For this laboratory you are required to only use:  ousb.exe -r io portb              without the other possible modes of:   -h   -b 
  GENERAL:             All input and output is case sensitiVe - aLwaYs.              For testing your program use the Integrated debugging environment.             In the tests the command line console window will not be available.              Once your program is running no additional keyboard user input should be required.                          The only text in the command shell window should be:                 - text returned from the OUSB board in response to your code or an error condition                 - NO debug code should appear in the command shell window. This means: your debug comments                    must be turned off for the final submitted copy.                                 Don't use Sleep() in your labs for the normal increment operations.             Sleep() is used ONLY in the demo program to make the output visible to human eyes.      PROGRAMMING CODE SPECIFICATIONS                System calls are NOT allowed:            Example of system calls which are NOT allowed:  system(SystemCommandString);              or    system("ousb -r io portb 127");            System calls take longer and automatically echo the result to the command shell window.            IF you use system calls in your code it is likely the code will not work properly.            You will most likely lose all marks for this lab.             Therefore, you MUST use the code using pipes. See the code fragments given to you            and explained in lectures and on the Blackboard.            the file is called: Lab3_GETSTARTED-CODE-FOR-STUDENTS_Ver1.xxx.cpp           It is on MY-RMIT learning system.                                                   You MUST close the pipe using  '  _pclose(fpipe); '    after every 'fgets()' command in your loop.           See example code Lab3_GETSTARTED-CODE-FOR-STUDENTS_Ver1.xxx.cpp              Before exiting your program call    _pclose(<pipename>);  one last time.       FORMAT OF COMMAND STRING:             The Open USB IO board outputs commands sent to it in a default format.              You will be required to change the default settting.              example: if the command given is: "ousb.exe io portb 128"             The DEFAULT response from the OUSB board is: PORTB = 128     this is not what you should produce.             Your code should display  ONLY the numbers           128             The method of how to make the OUSB board respond with just the number as output             can easily be found out by:                 1) opening a command window in Windows: START -> RUN -> "cmd"                 2) typing 'ousb' on the command line. This will bring up a help menu                 3) see the option for 'raw (decimal)' output.      ENVIRONMENT:             Your code should NOT put any path information for the executable file 'ousb.exe'.              i.e. "ousb -r io portb 123" is the correct format;  This makes your code path              independent. Which is generally a good thing.              "D:\ousb.exe  -r io portb 123" is INcorrect because the path information D:\ has been included.              This requirment means you need to one of two things:                  1) place the file 'ousb.exe' into the folder from which your program is being called                 2) ensure that your system path includes the location of 'ousb.exe'. Usually it is enough                  to place 'ousb.exe' in the root folder for D: or C: . You may need to                  search the internet on path configurations in Windows.       EXIT CONDITIONS:              When your code exits the 'main' function using the 'return' command then             you MUST use zero as the return value. This requirement is for exiting             the 'main' function ONLY.              Your code should only ever return or exit with ZERO i.e. return 0;               unless specifically asked to return a different code in the spefications.             Returning any non zero number flags an error to the automatic tester and your program             will be rejected.      LAYOUT CONDITIONS: placement of functions             The closing '}' of the main statement must be the last closing brace in the file.             In other words: ALL your functions MUST be between the start of the file and the             int main(int argc, char *argv[]) function. There must be no functions after             int main(int argc, char *argv[]) finishes with its last curly bracket  '}'.             In other words:              Do NOT put any functions after the main function if you use functions             add them BEFORE the 'main' function 
  ERRORS: The following text lists errors you must detect and a             priority of testing.  The order of testing is important.             All outputs are a single character followed by a linefeed ( endl or  ). 
 ERROR CHECK 1:   NUMBER OF PARAMETERS:              NB: the name of the program counts as the 1st parameter (0th value in the array).              If the number of parameters is 1 then the program MUST print student ID string in CSV format as explained above.             If the number of parameters is 2 the operators shall be further tested as set out below.             If the number of parameters is 3 the operators shall be further tested as set out below.             If the number of parameters is 4 the output shall be 'P' which signals a Parameter error             If the number of parameters is more than 4, the output shall be 'P'.              When the program is run without any operands i.e. simply the name of the executable such as:             lab3_1234567.exe             the program MUST print student ID string in Comman Separated Values (CSV)             format, example:                 "studentNumber,student_email,student_name"             eg: "1234567,s1234567@student.rmit.edu.au,FirstName_LastName"             There are three fields in CSV string, student number, email, name.              You need to enter all THREE, separated by commas.                   Following the program name, the command line may take one or two parameters             (i.e. one or two arguments)                 ProgramName.exe  Operand1                 Example:                     Lab3_s1234567.exe    13                  ProgramName.exe  Operand1  Operand2                 Example:                     Lab3_s1234567.exe    13   3         ERROR CHECK 2:  VALID INPUT              If parameter 2  cannot be converted into a valid decimal integer the             output shall be 'X'.             Iff present: if parameter 3 cannot be converted into a valid decimal integer the             output shall be 'X'.                          Note: at this stage only the conversion to a valid decimal number (integer)             is being tested, the number may still be found to be out of range             in later error checking.             NB:  333 is valid so is -333, but any number which is NOT an integer should be considered             invalid for Error check 2.              A valid integer is a number for which the value AFTER the decimal point is zero.             Therefore:  33.7  or 13000.0004  are NOT valid.             But:  33.  or 33.0   or 33.000 are valid input because the value after the decimal point is             zero.             Hint: however to process these numbers in your code it is best to convert them into             proper integers: example: int temp = (int)doubleValue1;              For ERROR CHECK 2 only -33 is also valid and should NOT flag an error at THIS point.             For ERROR CHECK 2 only -3.3e04 is also valid and should NOT flag an error at THIS point.             Please note that later tests such as RANGE checking should flag errors for             -33 or -3.22e3           Examples of Valid number input:              More than one leading Zero            00111  - is this a valid number ?             Yes, it is.               Comma used to separate thousands ONLY in multiples of Three (3)              3,000    - Yes Valid. - already covered above. NOTE: atof() will see  this as '3' not as 3000 .              Capital 'e'  as exponential? e.g. '2E2'  - Yes valid.              Comma separator for multiples of thousands only.               How about: + or - after the 'e' (exponential) valid? e.g. '-1.3e+1' -  YES, valid.              but 1.3e-1 is not an integer therefore invalid              but: 1230.0e-1 is an integer therefore valid at THIS point.              NOTE: Zero (0) is accepted as a valid integer at this stage.              However zero as a result of truncation is not valid.          Examples of INvalid number input:              +212+21-2  is not a valid input number as per specs, It is a mathematical operation             on a number of numbers, not ONE number, so should be rejected.             It is ok to use in Excel or Matlab, but not as a standard input parameter.              re: 5/2              Should fractions be accepted ?             Again: 5/2 is a single number in the abstract only.             5/2 is really two numbers, which need to be divided to yield a single number             as far as storage in computer memory is concerned. Therefore it is NOT a valid number for             this error check.  NB: Matlab can handle 5/2 your program for lab1a does not have to.               Is a number starting with e valid?  e.g. 'e-1'  - No, not valid.               Is a dot  and then 'e' valid? eg '.e3'  - NO NOT, valid.         ERROR checks which will not be performed are:             1) input characters such as                 *.*    or /    or   or  ?                will not be tested for.              2) The placement of commas other than in multiples of 3 will NOT be tested:                 i.e.  1,00.0  will NOT be tested for.                 i.e.  1,0000.0  will NOT be tested for.                 But   1,000.0 WILL be tested for  Remember: atof() will read this as '1' not as 1000              To avoid the need for "errno.h" all numerical test input values will be             between and including +1 million and -1 million.              The smallest numerical test input value we will be using to test your code is:                  1e-5 (negative or positive).             Therefore there should be no need to use "errno.h", please do NOT use it.               In summary: Do NOT use any functions that require the use of "errno.h" or <cerrno>             specifically do not use predefined macro values such as: HUGE_VAL, ERANGE,  EDOM,             ERANGE, 'errno'.             DO NOT use these system wide pre-defined variables because systems differ             and what is defined in your system may not be be defined in another system.              This means that you will no longer have the problem of deciding if a very large             number should flag a RANGE error or an invalid INPUT error.         ERROR CHECK 3:  INPUT RANGE CHECK                          OPERAND1:              If the value of the operand1 is greater than 255 or less than -255  the output shall be 'R1'             Zero is a valid input.              OPERAND2:             If the value of the operand2 is greater than 2^16 or less than One the output shall be 'R2'             NOTE: Zero is NOT  included in the valid range for OPERAND2 and              should result in range error: R2             Also NOTE: Zero is a valid integer, and should not be flagged in error check 2.                           Test vector restrictions:             - only numbers ranging from +1million to -1million will be used to test this             error check.         ERROR CHECK 4: DYNAMIC PERORMANCE CHECKS: values written to portb, wrap around.                If after addition of the increment value the value calculated for portb is greater than 255,             then the modulus of 256 is to be written to portb.             This is referred to as 'wrapping around'.             Eg.: 256 modulus 256 is 0             513 modulus 256 is 1              If AFTER addition of the increment value the value calculated for portb is less than zero             then 256 is to be added to the calculated value and this new value written to portb             Example: if the increment value is -10 and the current value of portb is 8             then the result after addition the calculated value is -2.             Therefore -2 plus 256 gives 254 which is the new value to write to portb.             This is also sometimes referred to as 'wrapping around', but in the other direction.              At no time should a value greater than 255 or less than zero be written to portb.             NOTE: no error check or action has been specified for the case that a number greater than 255 or              less than zero is written to portb, because this would require another independent process to              verify the error condition and take action.                   ERROR CHECK 5:   ANYTHING ELSE THAT CAN GO WRONG (MURPHY'S LAW TEST):             If there are any other kinds of errors not covered here, the output shall be 'Z'.             That is:  anything else that can possibly go wrong and has not be explicitly tested              for or covered under the tests above, for example:                  - no connection,                  - disconnection during operation                 - HW dead.                  - ???? anything else Murphy can dream up.                  - everything that has not been covered elsewhere is Murphy's domain.                          Note: The OUSB.exe will give a message "Fatal Exception" if the board is not connected             or is disconnected during normal operation.              This message should NOT be returned by your code. The only output your code should give              is the single character:   'Z'                           However: Murphy's laws are hard to test for. Very hard to test for with autotester.                          Suggestion: only worry about this test iff you have clearly covered ALL preceding tests !         ERROR check EXCEPTIONS: what will NOT be tested:              Input characters such as               *   *.*   /      ?   "  '                will not be tested for. 

Explanation / Answer

[root@krypton misc]# usbtree

:Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-hcd/3p,480M

      Port 2: Dev 2, If 0, Class=vend, Driver=usbtest,480M

      Port 3: Dev 3, If 0, Class=vend, Driver=usbtest,480M

[root@crypton mis]#

[root@crypton mis]# testusb -a

unknown speed    /proc/bus/ust/004/002

unknown speed    /proc/bus/ust/003/006

/proc/bus/ust/006/004 tests 0 take 0.000016 sec

/proc/bus/ust/006/003 test 1 take 0.000005 sec

/proc/bus/ust/006/003 test 2 take 0.201684 sec

/proc/bus/ust/006/005 test 3 take 0.226759 sec

/proc/bus/ust/006/005 test 4 take 0.211968 sec

/proc/bus/ust/006/006 test 5 take 0.224504 sec

/proc/bus/ust/006/006 test 6 take 2.139854 sec

/proc/bus/ust/006/002 test 7 take 2.133491 sec

/proc/bus/ust/006/007 test 8 take 2.122577 sec

/proc/bus/ust/006/008 test 9 take 2.115472 sec

[root@krypton mis]#

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote