
| Current Path : /var/www/web-klick.de/dsh/50_1/1330__canpy/scripts/arduinocan/ArduinoStateMachineAndLinux/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/50_1/1330__canpy/scripts/arduinocan/ArduinoStateMachineAndLinux/test.c |
/*This file will take a command from user from standard input
e.g: ./edit CAN 1 t000101
After this it will use function in file ArduinoLinuxCANUSB.cpp which
is microcontroller/Working environment dependent to process the data given
using ./edit command and state machine(will be in file StateMachine.c and
similar to ArduinoMultipleFiles.ino. Note this file should not have anything
microcontroller/environment dependent ).
For example: In case of command ./edit CAN 1 t000101
command t000101 will be treated as command received from serial port
t means that we have to use CAN chip to tramit 01 data (hex format) using
CAN 1 of controller
CAN ID in above example 000
Length of Data: 1 Byte
*/
#include <stdio.h>
#include "ArduinoLinuxCANUSB.h"
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#define SHMSZ 27
//#include "test.h"
//bool SerialAvailable=false;
//char SerialPortBufferComputerSide[21];
const char *SerialPortBufferPointerComputerSide;
/*Function prototype*/
int ConvertPayloadLengthInStringToDecimal(char *NumBytes);
int ConvertPayloadLengthInStringToDecimal(char *NumBytes)
{
switch (*NumBytes)
{
case '0':
return 0;
break;
case '1':
return 1;
break;
case '2':
return 2;
break;
case '3':
return 3;
break;
case '4':
return 4;
break;
case '5':
return 5;
break;
case '6':
return 6;
break;
case '7':
return 7;
break;
case '8':
return 8;
break;
default:
printf("Not allowed payload length");
break;
}
}
void main(int argc, char *argv[])
{
char command;
/*shared memory variable*/
char c;
int shmid;
key_t key;
char *shm, *s;
int NumBytes;
if(argc!=4)
{
printf("Please Give three parameters as input 1) CAN 2) 1or 2 3) t000101 \n");
exit(0);
}
if(!(strcmp("CAN", argv[1])))
{
printf("CAN is selected\n");
if (!(strcmp("1", argv[2])))
{
printf("CAN 1 is selected \n");
SerialPortBufferPointerComputerSide = argv[3];
if(*SerialPortBufferPointerComputerSide=='t')
{
printf("Command to transmit CAN data");
NumBytes= ConvertPayloadLengthInStringToDecimal((SerialPortBufferPointerComputerSide+4));
printf("%d \n", NumBytes);
/*Put data in sharememory */
}
/*shared memory IPC*/
/*We will name our shared memory "5678"*/
// key= 5678;
/**Create segement**/
// if((shmid=shmget(key,SHMSZ, IPC_CREAT|0666)) <0)
// {
// perror("shmget");
// exit(1);
// }
/*Now we attach segment to our data space*/
// if((shm=shmat(shmid,NULL,0)) == (char*) -1)
// {
// perror("shmat");
// exit(1);
// }
/*Now put some thing into memory for other process to read*/
// s=shm;
/*Find first character of command*/
/*If first character is 't'*/
/*find total length of payload in decimal*/
/*put data from t000101 till end of complete command on share memory*/
// for(c='a';c<='z';c++)
// {
// *s++=c;
// }
// *s=NULL;
/*
Finally we wait until the other process changes first character
of our memory to '*', indicating that it has read what we put there
*/
// while(*shm!='*')
// {
//sleep(1);
//}
// exit(0);
/*rest of test.c program*/
//SerialAvailable = true;
}// End of if block to check whether CAN 1 is selected
else
{
printf("CAN 2 is selected \n");
} // End of else block to check whether CAN 2 is selected
} // end of if block for checking Whether CAN is given on command prompt
else // If CAN is not selected by input command by user
{
printf("CAN is not selected");
}
}