Hi,
I am not big champ. of C.Next thing I am trying to do using these value 0xFE and 0x02 to control the I/O of board using MYSQL C based API at baord side.And using PHP admin to insert the value in MYSQL Database.And
hotter_alert | varchar(40) | YES | | NULL | | hotter_alert is the field name and want to control the I/O of board from server side by inserting value.From BOARD side I am able tho fetch hooter_alert field value as row[0] and *PCDR is pointer to which want to assign row[0] value.Problem I am getting is that I am able to fetch the value from Database but Not able to assign properly this value *PCDR register.What I thought Problem is that row[0] value fetching from DATABASE come in string of character as such it's printing right value only when %s is given.And *PCDR is declared as unsigned int.Please suggest me How can I assign row[0] value to *PCDR register,so that I can control I/O from server side.
Code:
#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"
#include<unistd.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void exiterr(int exitcode)
{
fprintf( stderr, "%s\n", mysql_error(conn) );
exit( exitcode );
}
int main(int argc, char **argv)
{
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
uint i = 0;
char *server = "10.64.21.63";
char *user = "root";
char *password = "PASSWORD"; /* set me first */
char *database = "mysql";
unsigned char *start;
volatile unsigned int *PCDR, *PCDDR;
int fd = open("/dev/mem", O_RDWR);
start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x80840000);
PCDR = (unsigned int *)(start + 0x08); // port c data register
PCDDR = (unsigned int *)(start + 0x18); // port c direction register
(!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0))
exiterr(1);
if (mysql_select_db(conn,"location"))
exiterr(2);
if (mysql_query(conn,"SELECT hotter_alert from location"))
exiterr(3);
if (!(res = mysql_store_result(&mysql)))
exiterr(4);
while((row = mysql_fetch_row(res))) {
for (i=0 ; i < mysql_num_fields(res); i++)
char * val=row[0]
*PCDDR = 0x01; // Make bit 0 an output Port C bit 0 is connected to the FET
*PCDR = val; // Turn the FET on
printf("%s\n",row[0]);
}
if (!mysql_eof(res))
exiterr(5);
mysql_free_result(res);
mysql_close(&mysql);
close(fd);
return 0;
}