parse almost done!

This commit is contained in:
[ Kristjan Komloši HomePC ]
2017-02-05 13:46:11 +01:00
parent cf86a1d310
commit 4c415d2c81
2 changed files with 84 additions and 19 deletions

Binary file not shown.

View File

@@ -5,7 +5,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdint.h>
// Those are flags used for flow control inside the program
uint8_t whichDev;
uint8_t interfaceNum;
uint8_t writeFlag;
uint8_t readFlag;
uint8_t exitFlag;
uint8_t pinNumber;
uint8_t valueToWrite;
// those vars are to be used with locateDevice function // those vars are to be used with locateDevice function
const uint8_t maxDevs = 16; // 16 connected devices should be enough... const uint8_t maxDevs = 16; // 16 connected devices should be enough...
const CY_VID_PID deviceVidPid{UINT16(0x04b4), const CY_VID_PID deviceVidPid{UINT16(0x04b4),
@@ -15,8 +24,8 @@ uint8_t deviceCount;
CY_DEVICE_INFO deviceInfoList[maxDevs]; CY_DEVICE_INFO deviceInfoList[maxDevs];
// vars for deviceOpen function // vars for deviceOpen function
uint8_t whichDev;
uint8_t interfaceNum;
CY_HANDLE deviceHandleList[maxDevs]; CY_HANDLE deviceHandleList[maxDevs];
uint8_t defaultInterfaceNum = 0; uint8_t defaultInterfaceNum = 0;
@@ -158,39 +167,95 @@ int isstrdigit(const char *str) {
return 1; return 1;
} }
void unknownOptarg(int option, char *argument)
{
printf("Unknown option argument -- \'%s\' at option -%c \n", argument, option);
}
void pinNum2HiLo()
{
puts("Pin number you specified is too high.");
puts("Pin numbers must be between 0 and 11");
}
void rwConflict()
{
puts("Can't write and read at the same time!");
}
void test() { void test() {
char trash; char trash;
trash = getchar(); trash = getchar();
CySetGpioValue(deviceHandleList[0], 8, 0); CySetGpioValue(deviceHandleList[0], 8, 0);
} }
int parseCmdLine(int acount, char *const *arglist) { int parseCmdLine(int acount, char **arglist) {
int opt; int opt;
while ((opt = getopt(acount, arglist, "d:s:r:v:i:") != -1)) { opt = getopt(acount, arglist, "d:s:r:v:i:");
while (opt != -1) {
switch (opt) { switch (opt) {
case 'd': case 'd':
if (!(isstrdigit(optarg))) { if(!isstrdigit(optarg))
puts("Unknown argument for switch -d"); {
puts("Arguments MUST be integer numbers!"); unknownOptarg(opt, optarg);
return -1; }
} whichDev = atoi(optarg);
whichDev = atoi(optarg); break;
break;
case 's': case 's':
if (!(isstrdigit(optarg))) { if(!isstrdigit(optarg))
puts("Unknown argument for switch -s"); {
puts("Arguments MUST be integer numbers!"); unknownOptarg(opt, optarg);
return -1; return -1;
}
// TODO complete when set and read GPIO are done
break;
} }
if(pinNumber > 11) {
pinNum2HiLo();
return -1;
}
if(readFlag == 1){
rwConflict();
return -1;
}
writeFlag=1;
pinNumber=atoi(optarg);
break;
case 'r':
if(!isstrdigit(optarg))
{
unknownOptarg(opt, optarg);
return -1;
}
if(pinNumber > 11) {
pinNum2HiLo();
return -1;
}
if(writeFlag == 1){
rwConflict();
return -1;
}
readFlag=1;
pinNumber=atoi(optarg);
break;
case 'i':
if(!isstrdigit(optarg))
{
unknownOptarg(opt, optarg);
return -1;
}
interfaceNum=atoi(optarg);
break;
}
opt = getopt(acount, arglist, "d:s:r:v:i:");
} }
} }
int main(int argc, char const *argv[]) { int main(int argc, char **argv) {
initLib(); initLib();
locateDevice(); locateDevice();
attachDevices(); attachDevices();
parseCmdLine(argc, argv);
// test(); // test();
} }