The picture shows the link between the FOX and the SX 16; the alarm system    architecture is, therefore,  scalable to all type of devices linux , for what there’s the possibility to compile  a C source code; the sensor board is required to be equipped with I2C bus.  
Full linux alarm system. This article provides a project to build a whole alarm system based on single computer board; the project architecture is based on  the FOX board, as processing unit, and teh SX 16 (or upper) from AreaSX  as sensor board.    Architecture.The system architecture, in the basic version, has 3 modules and is not general purpose but customized on a real apartment with two floors. Module P(principal).The first module consists of a logical board, numeric keypad and a modem GSM. It’s where we can activate or deactivate our alarm system.It’s the core of the system.Module S1(sensor). The second module consists of a logical board and a sensor board(SX 16). The logical board process the signals  coming from the sensor board. This module have to get signals relative to the first floor. Module S2(sensor). The third module is the specular of module S1. This module have to get signals relative to the other floor. The architecture is expandible. You can implement the system having only one module P and just one module S, but you can have a system with one module P and several modules S.   How’s the flow ?  What’s the way of information ?  Principal Module. In general,  at the principal side a thread is started. During its life, a socket  will  try to connect to every module configured in the main configuration file. The alarm system will start when a correct sequence of number will be entered by the linked numeric keypad. For the sake of semplicity only four keys are used. Obviously an other sequence of digits will kill the main thread and the alarm system will be paused. Now suppose that a user entered the correct sequence of digits, the threads (in our case two, there’s a thread for every floor), will stay up and running. When a socket client is connected, it will send to the master (principal module) a string containing the values get from the sensors linked to it. The program provides the feature to start the volumetric surveillance, the perimetric surveillance or both. The choose depends from the sequence of digit entered from user.  All sensor values are compared to the value memorized in the master. When a value is different from its corresponding no_alarm_value (there’s a no_alarm_value for every sensor) the alarm will be launched. What happens when the alarm takes place ? A Gsm modem will be initialized and a sms will notify the user that a sensor is in state different from its not_alarm_value, then….. ALARM. The values for the general setting, that’s  all the no_alarm_value, the sockets port, the alarm cycles, the number to call, the values of the digits to activate and deactivate the system are all put in  _alarm.conf file. The file is read at beginning of the program and a lot of variable will accept the values retrieved from it. Sensor Module.At the sensor module side something different happens. At beginning of the program, the configuration file, as usual, is read. After that, the process forks; we are interested in the first process, the other process is beyond the scope of the article.The process  starts an infinite loop where the sensors connected to the sensor-board are monitored. All values are converted in a pre formatted string and if the server is connected to module, it fires to the server the sensors information. All programs are written in C. We put our attention to the entire architecture of the prototype, so a monolithic not elegant code often takes place. In the following section we will show deeply the Pricipal side and the Sensor side.
Alarm SystemLINUX FOXSX 16 Gsm Modem Keypad
written by Ivan Cerrato
next
back to home
The principal module. This side is realised with the logical board, the numeric keypad and the GSM modem ( Siemens mc 35 ).  The numeric keypad is linked to the fox with the following pins //intput pins #define KEY_A  1<<22 // IOG22 (pin FOX-J7-3) --> KEY_A #define KEY_B  1<<20 // IOG20 (pin FOX-J7-5) --> KEY_B #define KEY_C  1<<18 // IOG18 (pin FOX-J7-7) --> KEY_C #define KEY_D  1<<16 // IOG16 (pin FOX-J7-9) --> KEY_D When the process starts the configuration file is read, the ip address of the target sensor module are set and the log file is opened. readConfigurationFile(); ip_address_F1 = FOX_DOWN_IP_ADDRESS;   ip_address_F2 = FOX_UP_IP_ADDRESS;   logFile = fopen(logFileName, "w+"); After that, the function launchAlarmThread(); is called. It  run the 2 threads( in this case ). Inside that we can see the creation of the threads. That’s one of the two: ret = pthread_create(&thread_down,       NULL,       thread_proc_down,       (void*) message_down); The thread_proc_down creates and manages the socket to the destination sensor module; following, the main section of the function  where we can see the isThereAlarm that get the string message from the net, examines  the values of the sensors, comparing these to the values retrieved from the configuration file; the function is split in two sub functions(one function for one target) and  after checked the type of alarm has been set (perimetic, volumetric, both) it does the real check upon sensor values. When a sensor presents a value different to its no_value_alarm the doAlarm function is called.   while(bAlarmActivated) {     rc=recv(socket_1_F1, buf, 256, 0);     if(rc==0)     {                 continue;     }     else if(rc==-1)     {         printf("%s -- error rc=-1", processName);         break;     }     else if(rc == _s(inp_F1))     {         memcpy(&inp_F1, buf, _s(inp_F1));                  //printf("%s -- inp_F1.msg: %s\n", processName, inp_F1.msg);         printValue(atoi(inp_F1.msg), "inp_F1.msg");                  if(isThereAlarm(&inp_F1, &foxMessage_1))         {             sleep(TIME_BEFORE_STARTING);             if( bAlarmActivated)             {                 doAlarm(foxMessage_1);                 printf("%s -- alarm: %s\n", processName, foxMessage_1);                                  time_t ltime;                 time( <ime );                 ret=fprintf(logFile, "%s %s -- =%s\n", ctime( <ime ), processName, foxMessage_1);                 ret=fflush(logFile);                              }         }             }     else     {                  printf("%s -- alarm in progress or error condition ....\n", processName);         printf("%s -- error retrieving data from socket socket_1_F1\n", processName);         printf("%s -- retrieved %d bytes\n", processName, rc);         continue;     }      } The doAlarm initializes the GSM modem and sends the sms to the target number whose value is retrieved from the configuration file. The initialization is tried 3 times and after that, the message is sent to the numbers retrieved from the configuration file.  if( bAlarmActivated && SEND_SMS) {     printf("%s -- sending sms\n", processName);          if(null != fox_message)     {         sprintf(_gb, "%s: %s", SMS_TEXT, fox_message);         //we limit the sms at 90 characters         _gb[90]='\0';     }          if( tty_Open("/dev/ttyUSB0") < 0 )     { printf("%s -- error on tty_Open\n", processName); }          if( !GSM_ModemInit() )     { sleep( 3 ); }     if( !GSM_ModemInit() )     { sleep( 3 ); }     if( !GSM_ModemInit() )     { sleep( 3 ); }          if(isConnected && strlen(NUMBER_1)>=9)     { GSM_SendSMS( _gb, NUMBER_1 ); }          if(isConnected && strlen(NUMBER_2)>=9)     { GSM_SendSMS( _gb, NUMBER_2 ); }          if(isConnected && strlen(NUMBER_3)>=9)     { GSM_SendSMS( _gb, NUMBER_3 ); }          if(isConnected && strlen(NUMBER_4)>=9)     { GSM_SendSMS( _gb, NUMBER_4 ); }               tty_Close(); } That’s all, in the next section we will see the sensor module.
back
LINUX FOXSX 16 Gsm Modem Keypad
The sensor module.   This side is realized with the logical board and the sensor board.   When the process starts the configuration file is read, the ip address of board is read.  readConfigurationFile(); After the function executes, the process forks; we will examine only the parent process. A thread  with an infinite loop starts. The thread will be listening until a client connects to it and the iterchange of information starts.  pid_t pid = fork(); if(pid!=0) {     printf("\n%s -- input - strInput management\n", processName);     //printf("-%s-\n", FOX_IP_ADDRESS);     struct sockaddr_in address;               while(true)     {         isConnect_1 = true;                  if( ( socket_1_f = socket( AF_INET, SOCK_STREAM, 0 ) ) > 0 )         { printf( "%s -- input - the socket was created\n", processName ); }                  _zm4(address)                  address.sin_family = AF_INET;         address.sin_addr.s_addr = INADDR_ANY;         address.sin_port = htons(SOCKET_PORT_ALARM);                           if( bind( socket_1_f, ( struct sockaddr *) &address, sizeof( address ) ) == 0 )         { printf("%s -- input - binding socket\n", processName); }                  listen( socket_1_f, 1 );         addrlen_1 = sizeof( struct sockaddr_in );         socket_2_f = accept( socket_1_f, ( struct sockaddr *) &address, &addrlen_1 );                  if (socket_2_f > 0)         { printf( "%s -- input - the client %s is connected...\n", processName, inet_ntoa( address.sin_addr ) ); }                           while(isConnect_1)         {             //input_pins_1=getInput();             //udelay(SLEEP_INTERVAL);             input_pins_2=getInput();                          _zm4(inp)            memcpy(inp.address, FOX_IP_ADDRESS, _s(inp.address));                      sprintf(&inp.msg, "%d", input_pins_2);        ////printf("%s\n", inp.msg);         if(isConnect_1)                         {                             ret=send( socket_2_f, &inp, _s(inp), 0 );                             if( (ret==0) || (ret==-1) )                             { isConnect_1=false; }                                                          sleep(INTERVAL_BETWEEN_CHECK);                         }                      }         udelay(SLEEP_INTERVAL);                  close( socket_2_f );         close( socket_1_f );     }      } What happens when a client connects to it? The process inits the monitoring of the sensor linked to the sensor board (SX 16); you can imagine the sensor board as a cluster of several chips with opto-insulated inputs and an encoder i2c   that transmits data toward the FOX.  Actually the function that monitor the inputs, getInput(),  makes an int (32 bit) where the last 24 bit are used to transmit the value of every sensor. Remember a sensor can have just two values: 0 and 1. When  someone of the inputs changes its value the relative bit of the created int changes. This is a limitation: this board can just have sensor with two value (0, 1) but changing the protocol of transmission you can adopt other sensor board providing an extended range of value for every sensor.  Following, the implementation of the function monitors the inputs. To be more precise, we retrieve data from I2C bus linked to the SX 16 board. int getInput() {   //int fdg_in=0;   int iomask_g=0;   int i=0;   int value=-1;   int ret_value=0;   if ((fdg_in = open("/dev/gpiog", O_RDWR))<0)    {     printf("%s -- Open error on /dev/gpiog\n", processName);     return -1;   }   // Set all the availables IOG lines on port G as output   iomask_g = OG5 | OG3;   ioctl(fdg_in, _IO(ETRAXGPIO_IOCTYPE, IO_SETGET_OUTPUT),&iomask_g);   ioctl(fdg_in, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS),iomask_g); //Tutte le linee a OFF   iomask_g = IG1;   ioctl(fdg_in, _IO(ETRAXGPIO_IOCTYPE, IO_SETGET_INPUT),&iomask_g);     STROBE_3     for (i=0;i<24;i++)      {       value=ioctl(fdg_in, _IO(ETRAXGPIO_IOCTYPE, IO_READBITS));     if( (value&(IG1))==0 )   {   ret_value=ret_value|1;   }     if(i<23)   {   ret_value=ret_value<<1;   }       CLOCK_3     }   close(fdg_in);   return ret_value; } So to recap when the Principal module hooks the socket, the process starts to send the packet with sensor information. In the download section you‘ll find _alarm.c (the program relative to the Principal module) and _server_tcp.c (the program relative to sensor module). I agree with you if you consider the names ….horrible.  That’s all.
_alarm.zip
_server_tcp.zip
Keypad FOX LINUX 
[if gte mso 9]> 0 0 1 40 232 extech 1 1 271 14.0 Normal 0 false false false EN-US JA X-NONE