Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
#include <stdio.h>
#include <malloc.h>
int main(int argc, char**argv){
char *p;
p = (char*)malloc( 5*sizeof( char ) );
printf("Hello,World\n");
return 0;
}
//Tectonas SoftSolutions (P) Ltd. ( www.tectonas.com )
//user.c Usage of functions of PLC.
//
//////////////////////////////////////////////////////////////////////
// By Nidhi Mishra ( [EMAIL PROTECTED] )
// Copyright (c) Tectonas 2002
// 4-30-2000
// Free usage granted in all applications including commercial.
// Do NOT distribute without permission from me. I can be reached
// at ( [EMAIL PROTECTED] ) , ( [EMAIL PROTECTED] )
// www.tectonas.com
//Please feel free to mail me about this project.
//
//
// REVISIONS:
//
//
//////////////////////////////////////////////////////////////////////
/* Usr Application */
#include<stdio.h>
#include<errno.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include "control.h"
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IWOTH | S_IRGRP | S_IWGRP)
#define DB_READ 0x04
#define DB_WRITE 0x03
#define DB_SYS 0x18
#define DB_DIR 0x1B
#define DB_BINFO 0x1A
#define DB_BOWRITE 0x08
char fifo[8];
Msg msg;
Com_port com;
static int flag = 0;
int usage(int a){
if ( a == 1){
printf("Usage: <./read> <init_addr> <final_addr>\n\n");
printf("User prog. to interact with as511 Siemens Protcol\n");
printf("___________________________________________________\n");
}
if ( a == 2){
printf("Usage: <./write> <init_addr> <final_addr>\n\n");
printf("User prog. to interact with as511 Siemens Protcol\n");
printf("___________________________________________________\n");
}
if ( a == 3){
printf("See, that as511.o driver is loaded or not..\n");
printf("Type ""lsmod"" to see driver listing...\n");
printf("-------------------------------------------------\n");
printf("Usage: <./app_name> <arg1> <arg2> ...<argN>\n");
}
return 0;
}
int main(int argc, char *argv[]){
int fd4,iNumber;
int index,count =0,read_n,dir_data;
unsigned short data=0x01,data_sys;
char *ans_buff;
int fd9,fd10;
int n,i;
char ret[2];
msg.len = 1;
msg.db_write = NULL;
printf("First Step\n");
if( ( fd4=open("/dev/rtf4",O_WRONLY|O_NONBLOCK)) < 0 ){
printf("Error in opening fifo /dev/rtf4...read this\n");
usage(3);
exit(1);
}
printf("Next Step\n");
if ( (ans_buff = (char *)malloc(48*sizeof(char))) == NULL){
printf("memory allocation error\n");
exit(1);
}
#ifdef __WRITE__
if ( argc < 3){
usage(2);
exit(0);
}
msg.len = atoi( argv[2] );
if ( argc < (msg.len + 3) ){
printf("Some datas are not specified on command line\n");
exit(0);
}
if((msg.db_write=(unsigned short *)malloc(msg.len*sizeof(unsigned short)
))==NULL ){
printf("Error:");
exit(1);
}
/* This is the location, where address value can be specified*/
msg.command = DB_WRITE;
msg.init_addr = strtoul(argv[1],NULL,16);
/* Data is written with increment of 1 but any data values can be
specified
*/
i = 3;
for(index = 0; index < msg.len; index++){
msg.db_write[index] = strtoul(argv[i],NULL,16);
}
/* Now, supply the data to driver for execution */
if( ( iNumber = write(fd4 ,&msg ,sizeof(msg)) ) < 0 ){
exit(1);
}
#endif
#ifdef __READ__
if ( argc != 2){
usage(1);
exit(0);
}
printf("Last Step\n");
com.port = 0;
if( (fd9 = open("/dev/rtf9", O_WRONLY | O_NONBLOCK )) < 0){
printf("Unable to open fifo 9");
exit(0);
}
n = write(fd9, &com, sizeof(com));
if ( n < 0) {
printf("Unable to write to fifo 9"); exit(0);
}
close(fd9);
msg.command= DB_READ;
msg.init_addr = strtoul(argv[1],NULL,16);
msg.final_addr = strtoul(argv[2],NULL,16);
if( ( iNumber = write(fd4 ,&msg ,sizeof(msg)) ) < 0 ){
exit(1);
}
sleep(5);
while( (read_n = read(fd4, ans_buff, 3)) > 0){
ans_buff [read_n] = 0;
printf("%s\n", ans_buff);
}
#endif
#ifdef __SYS__
msg.command=DB_SYS;
msg.init_addr=0x0000;
com.port = 0;
if( (fd9 = open("/dev/rtf9", O_WRONLY | O_NONBLOCK )) < 0){
printf("Unable to open fifo 9");
exit(0);
}
n = write(fd9, &com, sizeof(com));
if ( n < 0) {
printf("Unable to write to fifo 9"); exit(0);
}
close(fd9);
if( ( iNumber = write(fd4 ,&msg ,sizeof(msg)) ) < 0 ){
exit(1);
}
#endif
#ifdef __DIR__
msg.command = DB_DIR;
msg.len = 2;
msg.datablock = 0x02;
com.port = 0;
if( (fd9 = open("/dev/rtf9", O_WRONLY | O_NONBLOCK )) < 0){
printf("Unable to open fifo 9");
exit(0);
}
n = write(fd9, &com, sizeof(com));
if ( n < 0) {
printf("Unable to write to fifo 9"); exit(0);
}
close(fd9);
if( ( iNumber = write(fd4 ,&msg ,sizeof(msg)) ) < 0 ){
exit(1);
}
/*sleep(5);
while( (dir_data = read(fd7, ans_buff, 3)) > 0){
ans_buff [dir_data] = 0;
printf("%s\n", ans_buff);
}*/
#endif
#ifdef __BINFO__
msg.command = DB_BINFO;
msg.len = 0;
msg.datablock = 0x4C;
msg.blocknumber = 0x01;
com.port = 0;
if( (fd9 = open("/dev/rtf9", O_WRONLY | O_NONBLOCK )) < 0){
printf("Unable to open fifo 9");
exit(0);
}
n = write(fd9, &com, sizeof(com));
if ( n < 0) {
printf("Unable to write to fifo 9"); exit(0);
}
close(fd9);
if( ( iNumber = write(fd4 ,&msg ,sizeof(msg)) ) < 0 ){
exit(1);
}
/*sleep(5);
while( (dir_data = read(fd8, ans_buff, 3)) > 0){
ans_buff [dir_data] = 0;
printf("%s\n", ans_buff);
}*/
#endif
#ifdef __BOWRITE__
msg.len = atoi( argv[2] );
if((msg.db_write=(unsigned short *)malloc(msg.len*sizeof(unsigned short)
))==NULL ){
printf("Error:");
exit(1);
}
/* This is the location, where address value can be specified*/
msg.command = DB_BOWRITE;
msg.datablock = 0x01;
msg.blocknumber = 0x02;
com.port = 0;
if( (fd9 = open("/dev/rtf9", O_WRONLY | O_NONBLOCK )) < 0){
printf("Unable to open fifo 9");
exit(0);
}
n = write(fd9, &com, sizeof(com));
if ( n < 0) {
printf("Unable to write to fifo 9"); exit(0);
}
close(fd9);
/* Data to Be Written to the block */
for(index=0;index < msg.len; index++){
msg.db_write[index] = data;
data = data + 0x02;
}
/* Now, supply the data to driver for execution */
if( ( iNumber = write(fd4 ,&msg ,sizeof(msg)) ) < 0 ){
exit(1);
}
#endif
#ifdef __WRITE__
free(msg.db_write);
#endif
#ifdef __READ__
free(ans_buff);
close(fd9);
#endif
#ifdef __DIR__
free(ans_buff);
close(fd9);
#endif
#ifdef __BOWRITE__
free(msg.db_write);
close(fd9);
#endif
close(fd4);
close(fd9);
exit(0);
}
hello:
gcc -Wall -nostdlib -L/tmp/glibc-2.0.7/ -lc -O2 -o hello hello.c
