SlideShare ist ein Scribd-Unternehmen logo
1 von 23
TransponderInitialization Code:
#include<LiquidCrystal.h>
#include<Keypad.h>
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(14,15,16,17,18,19);
//4x4 Matrix key pad
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Four columns
// Define the Keymap
char keys[ROWS][COLS] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to Arduino pins.
byte rowPins[ROWS] = { 5, 4, 3, 2 };
// Connect keypad COL0, COL1, COL2 and COL3 to Arduino pins.
byte colPins[COLS] = { 8, 7, 6 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins,colPins, ROWS, COLS );
void setup()
{
// set up the LCD's number of columns and rows:
Serial.begin(9600);
Serial.println("Begin");
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("KEYPAD LCD TEST");
Serial.println("Begin 2");
}
void loop()
{
char key=kpd.getKey();
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(key);
// lcd.print(millis() / 1000);
// Check for a valid key
if(key)
{
// setthe cursor to column 9, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(9, 1);
//Print the detected key
lcd.print("KEY= ");
lcd.print(key);
Serial.println(key);
}
}
ESP Module (For Band) code:
#include "driver/spi_interface.h"
#include "eagle_soc.h"
#include "osapi.h"
// Show the spi registers.
#define SHOWSPIREG(i) __ShowRegValue(__func__, __LINE__);
/**
* @brief Print debug information.
*
*/
void __ShowRegValue(const char * func, uint32_t line)
{
int i;
uint32_t regAddr = 0x60000140; // SPI--0x60000240, HSPI--0x60000140;
os_printf("rn FUNC[%s],line[%d]rn", func, line);
os_printf(" SPI_ADDR [0x%08x]rn", READ_PERI_REG(SPI_ADDR(SpiNum_HSPI)));
os_printf(" SPI_CMD [0x%08x]rn", READ_PERI_REG(SPI_CMD(SpiNum_HSPI)));
os_printf(" SPI_CTRL [0x%08x]rn", READ_PERI_REG(SPI_CTRL(SpiNum_HSPI)));
os_printf(" SPI_CTRL2 [0x%08x]rn", READ_PERI_REG(SPI_CTRL2(SpiNum_HSPI)));
os_printf(" SPI_CLOCK [0x%08x]rn", READ_PERI_REG(SPI_CLOCK(SpiNum_HSPI)));
os_printf(" SPI_RD_STATUS [0x%08x]rn",
READ_PERI_REG(SPI_RD_STATUS(SpiNum_HSPI)));
os_printf(" SPI_WR_STATUS [0x%08x]rn",
READ_PERI_REG(SPI_WR_STATUS(SpiNum_HSPI)));
os_printf(" SPI_USER [0x%08x]rn", READ_PERI_REG(SPI_USER(SpiNum_HSPI)));
os_printf(" SPI_USER1 [0x%08x]rn", READ_PERI_REG(SPI_USER1(SpiNum_HSPI)));
os_printf(" SPI_USER2 [0x%08x]rn", READ_PERI_REG(SPI_USER2(SpiNum_HSPI)));
os_printf(" SPI_PIN [0x%08x]rn", READ_PERI_REG(SPI_PIN(SpiNum_HSPI)));
os_printf(" SPI_SLAVE [0x%08x]rn", READ_PERI_REG(SPI_SLAVE(SpiNum_HSPI)));
os_printf(" SPI_SLAVE1 [0x%08x]rn", READ_PERI_REG(SPI_SLAVE1(SpiNum_HSPI)));
os_printf(" SPI_SLAVE2 [0x%08x]rn", READ_PERI_REG(SPI_SLAVE2(SpiNum_HSPI)));
for (i = 0; i < 16; ++i) {
os_printf(" ADDR[0x%08x],Value[0x%08x]rn", regAddr, READ_PERI_REG(regAddr));
regAddr += 4;
}
}
// SPI interrupt callback function.
void spi_slave_isr_sta(void *para)
{
uint32 regvalue;
uint32 statusW, statusR, counter;
if (READ_PERI_REG(0x3ff00020)&BIT4) {
//following 3 lines is to clear isr signal
CLEAR_PERI_REG_MASK(SPI_SLAVE(SpiNum_SPI), 0x3ff);
} else if (READ_PERI_REG(0x3ff00020)&BIT7) { //bit7 is for hspi isr,
regvalue = READ_PERI_REG(SPI_SLAVE(SpiNum_HSPI));
os_printf("spi_slave_isr_sta SPI_SLAVE[0x%08x]nr", regvalue);
SPIIntClear(SpiNum_HSPI);
SET_PERI_REG_MASK(SPI_SLAVE(SpiNum_HSPI), SPI_SYNC_RESET);
SPIIntClear(SpiNum_HSPI);
SPIIntEnable(SpiNum_HSPI, SpiIntSrc_WrStaDone
| SpiIntSrc_RdStaDone
| SpiIntSrc_WrBufDone
| SpiIntSrc_RdBufDone);
if (regvalue & SPI_SLV_WR_BUF_DONE) {
// User can get data from the W0~W7
os_printf("spi_slave_isr_sta : SPI_SLV_WR_BUF_DONEnr");
} else if (regvalue & SPI_SLV_RD_BUF_DONE) {
// TO DO
os_printf("spi_slave_isr_sta : SPI_SLV_RD_BUF_DONEnr");
}
if (regvalue & SPI_SLV_RD_STA_DONE) {
statusR = READ_PERI_REG(SPI_RD_STATUS(SpiNum_HSPI));
statusW = READ_PERI_REG(SPI_WR_STATUS(SpiNum_HSPI));
os_printf("spi_slave_isr_sta : SPI_SLV_RD_STA_DONE[R=0x%08x,W=0x%08x]nr",
statusR, statusW);
}
if (regvalue & SPI_SLV_WR_STA_DONE) {
statusR = READ_PERI_REG(SPI_RD_STATUS(SpiNum_HSPI));
statusW = READ_PERI_REG(SPI_WR_STATUS(SpiNum_HSPI));
os_printf("spi_slave_isr_sta : SPI_SLV_WR_STA_DONE[R=0x%08x,W=0x%08x]nr",
statusR, statusW);
}
if ((regvalue & SPI_TRANS_DONE) && ((regvalue & 0xf) == 0)) {
os_printf("spi_slave_isr_sta : SPI_TRANS_DONEnr");
}
SHOWSPIREG(SpiNum_HSPI);
}
}
// Test spi master interfaces.
void ICACHE_FLASH_ATTR spi_master_test()
{
SpiAttr hSpiAttr;
hSpiAttr.bitOrder = SpiBitOrder_MSBFirst;
hSpiAttr.speed = SpiSpeed_10MHz;
hSpiAttr.mode = SpiMode_Master;
hSpiAttr.subMode = SpiSubMode_0;
// Init HSPI GPIO
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to spi mode
SPIInit(SpiNum_HSPI, &hSpiAttr);
uint32_t value = 0xD3D4D5D6;
uint32_t sendData[8] ={ 0 };
SpiData spiData;
os_printf("rn ============= spi init master ============= rn");
// Test 8266 slave.Communication format: 1byte command + 1bytes address + x bytes Data.
os_printf("rn Master send 32 bytes data to slave(8266)rn");
os_memset(sendData, 0, sizeof(sendData));
sendData[0] = 0x55565758;
sendData[1] = 0x595a5b5c;
sendData[2] = 0x5d5e5f60;
sendData[3] = 0x61626364;
sendData[4] = 0x65666768;
sendData[5] = 0x696a6b6c;
sendData[6] = 0x6d6e6f70;
sendData[7] = 0x71727374;
spiData.cmd = MASTER_WRITE_DATA_TO_SLAVE_CMD;
spiData.cmdLen = 1;
spiData.addr = &value;
spiData.addrLen = 4;
spiData.data = sendData;
spiData.dataLen = 32;
SPIMasterSendData(SpiNum_HSPI, &spiData);
os_printf("rn Master receive 24 bytes data from slave(8266)rn");
spiData.cmd = MASTER_READ_DATA_FROM_SLAVE_CMD;
spiData.cmdLen = 1;
spiData.addr = &value;
spiData.addrLen = 4;
spiData.data = sendData;
spiData.dataLen = 24;
os_memset(sendData, 0, sizeof(sendData));
SPIMasterRecvData(SpiNum_HSPI, &spiData);
os_printf(" Recv Slave data0[0x%08x]rn", sendData[0]);
os_printf(" Recv Slave data1[0x%08x]rn", sendData[1]);
os_printf(" Recv Slave data2[0x%08x]rn", sendData[2]);
os_printf(" Recv Slave data3[0x%08x]rn", sendData[3]);
os_printf(" Recv Slave data4[0x%08x]rn", sendData[4]);
os_printf(" Recv Slave data5[0x%08x]rn", sendData[5]);
value = SPIMasterRecvStatus(SpiNum_HSPI);
os_printf("rn Master read slave(8266) status[0x%02x]rn", value);
SPIMasterSendStatus(SpiNum_HSPI, 0x99);
os_printf("rn Master write status[0x99] to slavue(8266).rn");
SHOWSPIREG(SpiNum_HSPI);
// Test others slave.Communication format:0bytes command + 0 bytes address + x bytes Data
#if 0
os_printf("rn Master send 4 bytes data to slavern");
os_memset(sendData, 0, sizeof(sendData));
sendData[0] = 0x2D3E4F50;
spiData.cmd = MASTER_WRITE_DATA_TO_SLAVE_CMD;
spiData.cmdLen = 0;
spiData.addr = &addr;
spiData.addrLen = 0;
spiData.data = sendData;
spiData.dataLen = 4;
SPIMasterSendData(SpiNum_HSPI, &spiData);
os_printf("rn Master receive 4 bytes data from slavern");
spiData.cmd = MASTER_READ_DATA_FROM_SLAVE_CMD;
spiData.cmdLen = 0;
spiData.addr = &addr;
spiData.addrLen = 0;
spiData.data = sendData;
spiData.dataLen = 4;
os_memset(sendData, 0, sizeof(sendData));
SPIMasterRecvData(SpiNum_HSPI, &spiData);
os_printf(" Recv Slave data[0x%08x]rn", sendData[0]);
#endif
}
// Test spi slave interfaces.
void ICACHE_FLASH_ATTR spi_slave_test()
{
//
SpiAttr hSpiAttr;
hSpiAttr.bitOrder = SpiBitOrder_MSBFirst;
hSpiAttr.speed = 0;
hSpiAttr.mode = SpiMode_Slave;
hSpiAttr.subMode = SpiSubMode_0;
// Init HSPI GPIO
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to spi mode
os_printf("rn ============= spi init slave =============rn");
SPIInit(SpiNum_HSPI, &hSpiAttr);
// Set spi interrupt information.
SpiIntInfo spiInt;
spiInt.src = (SpiIntSrc_TransDone
| SpiIntSrc_WrStaDone
|SpiIntSrc_RdStaDone
|SpiIntSrc_WrBufDone
|SpiIntSrc_RdBufDone);
spiInt.isrFunc = spi_slave_isr_sta;
SPIIntCfg(SpiNum_HSPI, &spiInt);
// SHOWSPIREG(SpiNum_HSPI);
SPISlaveRecvData(SpiNum_HSPI);
uint32_t sndData[8] = { 0 };
sndData[0] = 0x35343332;
sndData[1] = 0x39383736;
sndData[2] = 0x3d3c3b3a;
sndData[3] = 0x11103f3e;
sndData[4] = 0x15141312;
sndData[5] = 0x19181716;
sndData[6] = 0x1d1c1b1a;
sndData[7] = 0x21201f1e;
SPISlaveSendData(SpiNum_HSPI, sndData, 8);
WRITE_PERI_REG(SPI_RD_STATUS(SpiNum_HSPI), 0x8A);
WRITE_PERI_REG(SPI_WR_STATUS(SpiNum_HSPI), 0x83);
}
void spi_interface_test(void)
{
// Test spi interfaces.
os_printf("rn
=======================================================rn");
os_printf("t ESP8266 %s application nr", __func__);
os_printf("tt SDK version:%s nr", system_get_sdk_version());
os_printf("tt Complie time:%s nr", __TIME__);
os_printf("rn
=======================================================rn");
#if 0
spi_master_test();
#else
spi_slave_test();
#endif
}
Attendance Report Generation:
<?php
/*
Returns Attendance Master Details
@param $response MIXED response variable contains error code or success data
@param $mst_id INT attendance master id
@param $faculty_id Bool true, if need to match for current logged in faculty for verification
@param $now Bool true, if need to get current active academice calendars only
*/
use ZendDbSqlExpression;
use ZendDbSqlSelect;
function getMstMetaData(&$response,$mst_id,$faculty_id=true,$now=true)
{
if(!ctype_digit($mst_id))
{ $response = array(
'code' => HTTP_Status::BAD_REQUEST,
'message' => 'Master ID must be digits only'
);
return false;
}
$meta_data=array(
"batchno" => null,
"division" => null,
"inst_name" => null,
"prog_name" => null,
"dept_name" => null,
"semester" => null,
"subject" => null
);
try
{ $dbh=new MyDbCon;
$dbh->select("Attendance_Master");
$dbh->select->where->equalTo("attd_mst_id",$mst_id);
$dbh->prepare();
if($dbh->execute())
{ $tmp=$dbh->fetchAssoc()[0];
$meta_data['batchno']=$tmp['batchno'];
$meta_data['division']=$tmp['division'];
}
else
{ $response = array(
'code' => HTTP_Status::FORBIDDEN
);
return false;
}
$where_funcs=array(
'=' => 'equalTo',
'<' => 'lessThan',
'>' => 'greaterThan',
'<=' => 'lessThanOrEqualTo',
'>=' => 'greaterThanOrEqualTo',
'like' => 'like'
);
$where=array(
"attd_mst_id" => $mst_id
);
if($now)
{ try
{ $now=(new DateTime())->format("Y-m-d");
//throw new Exception("asd");
}catch(Exception $e)
{ $response = array(
'code' => HTTP_Status::INTERNAL_SERVER_ERROR
);
return false;
}
$where['end_date'] = "{$now}:>=";
$where['start_date'] = "{$now}:<=";
}
if($faculty_id && !Privilege_Master::is_super($_SESSION['privilege_id']))
{ $where['faculty_id'] = $_SESSION['faculty_id'];
}
$join_tables=array(
"Academic_Calendar",
"Teaches",
"Syllabus"
);
$join_on=array(
"Academic_Calendar" =>
"Academic_Calendar.ac_id=Attendance_Master.ac_id",
"Teaches" => "Attendance_Master.teaches_id=Teaches.teaches_id",
"Syllabus" => "Teaches.syllabus_id=Syllabus.syllabus_id"
);
$join_columns=array(
"Academic_Calendar" => array("start_date","end_date"),
"Teaches" => array(/*"teaches_id","faculty_id"*/),
"Syllabus" => array(/*"syllabus_id",*/"sub_id","sub_offered_sem","o_id")
);
$dbh=new MyDbCon;
$dbh->select("Attendance_Master");
$dbh->select->columns(array());
// Join Tables
foreach($join_tables as $val)
{ $cols=Select::SQL_STAR;
if(isset($join_columns[$val]))
$cols=$join_columns[$val];
$dbh->join($val,$join_on[$val],$cols);
}
// Where Clause
foreach($where as $key=>$val)
{
$vals=explode(':',$val);
$wh=$where_funcs['='];
if(!empty($vals[1]) && isset($where_funcs[$vals[1]]))
$wh=$where_funcs[$vals[1]];
$dbh->select->where->$wh($key,$vals[0]);
}
$dbh->prepare();
if($dbh->execute())
{ $objs=$dbh->fetchAssoc();
$meta_data['semester']=$objs[0]['sub_offered_sem'];
$meta_data['start_date']=$objs[0]['start_date'];
$meta_data['end_date']=$objs[0]['end_date'];
$names=Offers_Master::getNames($objs[0]['o_id']);
$meta_data['subject']=Sub_Master::getSubjectName($objs[0]['sub_id']);
/*$meta_data['o_id']=$objs[0]['o_id'];
$meta_data['sub_id']=$objs[0]['sub_id'];
$meta_data['syllabus_id']=$objs[0]['syllabus_id'];
$meta_data['teaches_id']=$objs[0]['teaches_id'];
$meta_data['faculty_id']=$objs[0]['faculty_id'];*/
if($names)
{ $meta_data['inst_name']=$names['inst_name'];
$meta_data['prog_name']=$names['prog_name'];
$meta_data['dept_name']=$names['dept_name'];
}
//var_dump($meta_data);
//var_dump($objs);
$response=$meta_data;
return true;
}
$response = array(
'code' => HTTP_Status::FORBIDDEN
);
return false;
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err="Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
/*
Returns Students Attendance Details given a Attendance Master Id
@param $response MIXED response variable contains error code or success data
@param $mst_id INT attendance master id
*/
function getStudentWiseAttendanceByMst(&$response,$mst_id)
{
try
{ $dbh = new MyDbCon;
$statement = $dbh->call('student_presence_from_master',array($mst_id));
// Get 1st ResultSet : Division & Batchno
$resultSet = $statement->fetchAll(PDO::FETCH_ASSOC);
$students['metadata']['division'] = intval($resultSet[0]['division']);
$students['metadata']['batchno'] = intval($resultSet[0]['batchno']);
// Get 2nd ResultSet : Students Presence
$statement->nextRowSet();
$resultSet = $statement->fetchAll(PDO::FETCH_ASSOC);
$students['data']=$resultSet;
$response = $students;
return true;
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err="Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
/*
Returns Lecture Details given a Attendance Master Id
@param $response MIXED response variable contains error code or success data
@param $mst_id INT attendance master id
*/
function getLectureWiseAttendanceByMst(&$response,$mst_id)
{
try
{
$dbh = new MyDbCon;
$dbh->select("Lectures");
$dbh->select->columns(array('lec_id','lec_date'));
$dbh->select->where->equalTo('attd_mst_id',$mst_id);
$dbh->select->where->equalTo('Lectures.active', 1);
$dbh->join('Attendance','Lectures.lec_id = Attendance.lec_id',
array( 'presence' => new Expression("sum(presence)"),
'total' => new Expression("count(presence)"),
'percentage' => new
Expression("ROUND(sum(presence)/count(presence)*100,2)")
),'left');
$dbh->select->group('Lectures.lec_id');
$dbh->select->order('lec_date ASC');
$dbh->prepare();
/*
select Lectures.lec_id,lec_date,sum(presence) as presence,count(presence) as
total,ROUND(sum(presence)/count(presence)*100,2) as percentage from Lectures left join
Attendance
on Attendance.lec_id=Lectures.lec_id
where attd_mst_id = 9 and Lectures.active = 1
group by Lectures.lec_id
order by lec_date ASC
*/
if($dbh->execute())
{ $res=$dbh->fetchAssoc();
//var_dump($res);
$response['data'] = $res;
return true;
}
$response = array(
'code' => HTTP_Status::NOT_FOUND
);
return false;
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code = $e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err = "Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
/*
Returns Lecture Attendance Details given a Lecture Id
@param $response MIXED response variable contains error code or success data
@param $mst_id INT attendance master id
*/
function getStudentAttendanceByLec(&$response,$lec_id)
{ if(!ctype_digit($lec_id))
{ $response = array(
'code' => HTTP_Status::BAD_REQUEST,
'message' => 'Lec ID must be digits only'
);
return false;
}
/*
select Attendance.stud_id,stud_rollno,stud_enrolmentno,CONCAT(stud_name,'
',stud_father_name,' ',stud_surname) as stud_name,presence
from Attendance join Student_Master
on Student_Master.stud_id = Attendance.stud_id
where lec_id = 4
order by stud_rollno ASC
*/
try
{
$dbh = new MyDbCon;
$dbh->select("Attendance");
$dbh->select->columns(array('stud_id','presence'));
$dbh->select->where->equalTo('lec_id',$lec_id);
$dbh->join('Student_Master','Student_Master.stud_id = Attendance.stud_id',
array( 'stud_rollno','stud_enrolmentno',
'stud_name' => new
Expression("CONCAT(stud_name,' ',IFNULL(stud_father_name,''),' ',IFNULL(stud_surname,''))")
));
$dbh->select->order('stud_rollno ASC');
$dbh->prepare();
if($dbh->execute())
{ $response = $dbh->fetchAssoc();
return true;
}
else
{ $response = array(
'code' => HTTP_Status::NOT_FOUND,
'message' => 'No records Found'
);
return false;
}
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code = $e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err = "Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
/*
Returns Student Attendance Details given a Attendance_Master Id and Stud_id
@param $response MIXED response variable contains error code or success data
@param $mst_id INT attendance master id
@param $stud_id INT stud id
*/
function getLectureWiseAttendanceOfStudByMst(&$response,$mst_id,$stud_id)
{
/*
select Lectures.lec_id,lec_date,presence from Lectures
left join Attendance
on Attendance.lec_id=Lectures.lec_id and stud_id=65
where attd_mst_id=9 and Lectures.active = 1
group by Lectures.lec_id
order by lec_date ASC
*/
if(!ctype_digit($mst_id) || !ctype_digit($stud_id))
{ $response = array(
'code' => HTTP_Status::BAD_REQUEST,
'message' => 'ID must be digits only'
);
return false;
}
try
{
$dbh = new MyDbCon;
$dbh->select("Lectures");
$dbh->select->columns(array('lec_id','lec_date'));
$dbh->join('Attendance',new Expression("Lectures.lec_id = Attendance.lec_id and
stud_id = {$stud_id}"),array('presence'),'left');
$dbh->select->where->equalTo('attd_mst_id',$mst_id);
$dbh->select->where->equalTo('Lectures.active', 1);
$dbh->select->group('Lectures.lec_id');
$dbh->select->order('lec_date ASC');
$dbh->prepare();
//echo $dbh->select->getSqlString($dbh->getAdapter()->getPlatform());
$dbh->execute();
$response = $dbh->fetchAssoc();
return true;
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code = $e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err = "Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
?>
Student Attendance Info Fetcher Module:
<?php
/*
Returns Students Data from a particular master.
@param $response MIXED response variable contains error code or success data
@param $mst_id INT attendance master id
@param $faculty_id Bool true, if need to match for current logged in faculty for verification
@param $now Bool true, if need to get current active academic calendars only
*/
use ZendDbSqlSelect;
function getStudentsByMst(&$response,$mst_id,$faculty_id=true,$now=true)
{ if(!ctype_digit($mst_id))
{ $response = array(
'code' => HTTP_Status::BAD_REQUEST,
'message' => 'Master ID must be digits only'
);
return false;
}
$meta_data=array(
"batchno" => null,
"division" => null,
"inst_name" => null,
"prog_name" => null,
"dept_name" => null,
"semester" => null,
"subject" => null
);
try
{ $dbh=new MyDbCon;
$dbh->select("Attendance_Master");
$dbh->select->where->equalTo("attd_mst_id",$mst_id);
$dbh->prepare();
if($dbh->execute())
{ $tmp=$dbh->fetchAssoc()[0];
$meta_data['batchno']=$tmp['batchno'];
$meta_data['division']=$tmp['division'];
}
else
{ $response = array(
'code' => HTTP_Status::FORBIDDEN
);
return false;
}
$where_funcs=array(
'=' => 'equalTo',
'<' => 'lessThan',
'>' => 'greaterThan',
'<=' => 'lessThanOrEqualTo',
'>=' => 'greaterThanOrEqualTo',
'like' => 'like'
);
$where=array(
"attd_mst_id" => $mst_id,
"stud_status" => "C"
);
if($now)
{ try
{ $now=(new DateTime())->format("Y-m-d");
//throw new Exception("asd");
}catch(Exception $e)
{ $response = array(
'code' => HTTP_Status::INTERNAL_SERVER_ERROR
);
return false;
}
$where['end_date'] = "{$now}:>=";
$where['start_date'] = "{$now}:<=";
}
if($faculty_id && !Privilege_Master::is_super($_SESSION['privilege_id']))
{ $where['faculty_id'] = $_SESSION['faculty_id'];
}
$join_tables=array(
"Academic_Calendar",
"Teaches",
"Syllabus",
"Student_Master"
);
$join_on=array(
"Academic_Calendar" =>
"Academic_Calendar.ac_id=Attendance_Master.ac_id",
"Teaches" => "Attendance_Master.teaches_id=Teaches.teaches_id",
"Syllabus" => "Teaches.syllabus_id=Syllabus.syllabus_id",
"Student_Master" => "Student_Master.o_id=Syllabus.o_id AND
Student_Master.stud_sem=Academic_Calendar.semester AND
Student_Master.stud_div=Attendance_Master.division"
);
if(!empty($meta_data['batchno']))
$join_on["Student_Master"].=" AND
Student_Master.stud_batchno=Attendance_Master.batchno";
$join_columns=array(
"Academic_Calendar" => array("start_date","end_date"),
"Teaches" => array(),
"Syllabus" => array("sub_id"),
"Student_Master" =>
array("stud_id","stud_enrolmentno","stud_rollno","stud_name","stud_father_name","stud_surname
","stud_sem","stud_div","stud_batchno","o_id")
);
$meta_keys=array("stud_sem","stud_div","stud_batchno","o_id","sub_id","start_date","end
_date");
$dbh=new MyDbCon;
$dbh->select("Attendance_Master");
$dbh->select->columns(array());
// Join Tables
foreach($join_tables as $val)
{ $cols=Select::SQL_STAR;
if(isset($join_columns[$val]))
$cols=$join_columns[$val];
$dbh->join($val,$join_on[$val],$cols);
}
// Where Clause
foreach($where as $key=>$val)
{
$vals=explode(':',$val);
$wh=$where_funcs['='];
if(!empty($vals[1]) && isset($where_funcs[$vals[1]]))
$wh=$where_funcs[$vals[1]];
$dbh->select->where->$wh($key,$vals[0]);
}
$dbh->select->order("stud_rollno ASC");
$dbh->prepare();
if($dbh->execute())
{ $objs=$dbh->fetchAssoc();
$meta_data['semester']=$objs[0]['stud_sem'];
$meta_data['start_date']=$objs[0]['start_date'];
$meta_data['end_date']=$objs[0]['end_date'];
$names=Offers_Master::getNames($objs[0]['o_id']);
$meta_data['subject']=Sub_Master::getSubjectName($objs[0]['sub_id']);
if($names)
{ $meta_data['inst_name']=$names['inst_name'];
$meta_data['prog_name']=$names['prog_name'];
$meta_data['dept_name']=$names['dept_name'];
}
foreach($objs as $row)
{ foreach($meta_keys as $val)
unset($row[$val]);
if(!empty($row['stud_father_name']))
$row['stud_name'].=" ".$row['stud_father_name'];
if(!empty($row['stud_surname']))
$row['stud_name'].=" ".$row['stud_surname'];
unset($row['stud_father_name']);
unset($row['stud_surname']);
}
//var_dump($meta_data);
//var_dump($objs);
$response=array(
"metadata" => $meta_data,
"data" => $objs
);
return true;
}
else
{ $response = array(
'code' => HTTP_Status::FORBIDDEN
);
return false;
}
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err="Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
?>
MasterAccess List:
<?php
/*
Returns Masters List from a given Faculty ID.
@param $response MIXED response variable contains error code or success data
@param $fac_id INT attendance master id
@param $now Bool true, if need to get current active academic calendars only
*/
use ZendDbSqlSelect;
function getMstByFaculty(&$response,$fac_id,$now=true)
{ if(!ctype_digit($fac_id) && !Privilege_Master::is_super($_SESSION['privilege_id']))
{ $response = array(
'code' => HTTP_Status::BAD_REQUEST,
'message' => 'Faculty ID must be digits only'
);
return false;
}
try
{
$where_funcs=array(
'=' => 'equalTo',
'<' => 'lessThan',
'>' => 'greaterThan',
'<=' => 'lessThanOrEqualTo',
'>=' => 'greaterThanOrEqualTo',
'like' => 'like'
);
if(!Privilege_Master::is_super($_SESSION['privilege_id']))
{ $where=array(
"Teaches.faculty_id" => $fac_id
);
}
try
{ $now=(new DateTime())->format("Y-m-d");
}catch(Exception $e)
{ $response = array(
'code' => HTTP_Status::INTERNAL_SERVER_ERROR
);
return false;
}
$where['end_date'] = "{$now}:>=";
$where['start_date'] = "{$now}:<=";
$join_tables=array(
"Academic_Calendar",
"Teaches",
"Syllabus",
"Offers_Master",
"Inst_Master",
"Prog_Master",
"Dept_Master",
"Sub_Master",
"Faculty_Master"
);
$join_on=array(
"Academic_Calendar" =>
"Academic_Calendar.ac_id=Attendance_Master.ac_id",
"Teaches" => "Attendance_Master.teaches_id=Teaches.teaches_id",
"Syllabus" => "Teaches.syllabus_id=Syllabus.syllabus_id",
"Offers_Master" => "Offers_Master.o_id=Syllabus.o_id",
"Inst_Master" => "Inst_Master.inst_id=Offers_Master.inst_id",
"Prog_Master" => "Prog_Master.prog_id=Offers_Master.prog_id",
"Dept_Master" => "Dept_Master.dept_id=Offers_Master.dept_id",
"Sub_Master" => "Sub_Master.sub_id=Syllabus.sub_id",
"Faculty_Master" => "Faculty_Master.faculty_id=Teaches.faculty_id"
);
$join_columns=array(
"Academic_Calendar" => array("start_date","end_date","semester"),
"Teaches" => array("type"),
"Syllabus" => array("sub_id"),
"Offers_Master" => array("o_id"),
"Inst_Master" => array("inst_name"),
"Prog_Master" => array("prog_name"),
"Dept_Master" => array("dept_name"),
"Sub_Master" => array("sub_name"),
"Faculty_Master" =>
array("faculty_name","faculty_father_name","faculty_surname")
);
$dbh=new MyDbCon;
$dbh->select("Attendance_Master");
$dbh->select->columns(array("attd_mst_id","batchno","division"));
// Join Tables
foreach($join_tables as $val)
{ $cols=Select::SQL_STAR;
if(isset($join_columns[$val]))
$cols=$join_columns[$val];
$dbh->join($val,$join_on[$val],$cols);
}
// Where Clause
foreach($where as $key=>$val)
{
$vals=explode(':',$val);
$wh=$where_funcs['='];
if(!empty($vals[1]) && isset($where_funcs[$vals[1]]))
$wh=$where_funcs[$vals[1]];
$dbh->select->where->$wh($key,$vals[0]);
}
$dbh->prepare();
if($dbh->execute())
{ $objs=$dbh->fetchAssoc();
foreach($objs as $row)
{ if(!empty($row['faculty_father_name']))
$row['faculty_name'].=" ".$row['faculty_father_name'];
if(!empty($row['faculty_surname']))
$row['faculty_name'].=" ".$row['faculty_surname'];
unset($row['faculty_father_name']);
unset($row['faculty_surname']);
}
$response = $objs;
return true;
}
else
{ $response = array(
'code' => HTTP_Status::NOT_FOUND
);
return false;
}
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err="Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
?>
Update Attendance Info Module:
<?php
use ZendDbSqlSelect;
use ZendDbSqlExpression;
require_once "../getStudents/getStudents.lib.php";
function authMst(&$response,$mst_id,$faculty_id)
{ /*
select count(*) as cnt from Attendance_Master
join Teaches
on Attendance_Master.attd_mst_id = 9 and Attendance_Master.teaches_id =
Teaches.teaches_id and Teaches.faculty_id = 5
*/
if(Privilege_Master::is_super($_SESSION['privilege_id']))
{ return true;
}
else if(!ctype_digit($mst_id) || !ctype_digit($faculty_id))
{ $response = array(
'code' => HTTP_Status::BAD_REQUEST,
'message' => 'ID must be digits only'
);
return false;
}
try
{
$dbh = new MyDbCon;
$dbh->select("Attendance_Master");
$dbh->select->columns(array("cnt" => new Expression("count(*)")));
$dbh->join("Teaches",new Expression("Attendance_Master.attd_mst_id =
{$mst_id} and Attendance_Master.teaches_id = Teaches.teaches_id and Teaches.faculty_id =
{$faculty_id}"),array());
$dbh->prepare();
$dbh->execute();
$cnt = $dbh->fetchAssoc()[0]['cnt'];
if(intval($cnt)===1)
return true;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => HTTP_Status::FORBIDDEN_MSG
);
return false;
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err="Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
function authStud(&$response,$mst_id,array $stud_id)
{
$faculty_id=true;
if(Privilege_Master::is_super($_SESSION['privilege_id']))
$faculty_id=false;
if(!getStudentsByMst($response,$mst_id,$faculty_id))
return false;
foreach($stud_id as $id)
{ $flag=false;
foreach($response['data'] as $stud)
{ if(strcmp($stud['stud_id'],$id)==0)
{ $flag=true;
break;
}
}
if(!$flag)
break;
}
if($flag)
{ $response = true;
return true;
}
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => HTTP_Status::FORBIDDEN_MSG
);
return false;
}
function authLec(&$response,$mst_id,array $lec_id)
{ if(!ctype_digit($mst_id))
{ $response = array(
'code' => HTTP_Status::BAD_REQUEST,
'message' => 'ID must be digits only'
);
return false;
}
try
{
$dbh = new MyDbCon;
$dbh->select("Lectures");
$dbh->select->columns(array("lec_id"));
$dbh->select->where->equalTo("attd_mst_id",$mst_id);
$dbh->prepare();
if($dbh->execute())
{ $res = $dbh->fetchAssoc();
$ids = array();
foreach($res as $lec)
$ids[]=$lec['lec_id'];
$dif = array_diff($lec_id,$ids);
if(empty($dif))
return true;
}
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => HTTP_Status::FORBIDDEN_MSG
);
return false;
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err="Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
function updateByStudId(&$response,$stud_id,array $attd)
{
$objs = array();
foreach($attd as $k=>$v)
{ $attd[$k]['stud_id'] = $stud_id;
$attd[$k]['presence'] = $attd[$k]['p'] == 'P' ? 1 : 0;
unset($attd[$k]['p']);
$objs[] = new Attendance($attd[$k]);
}
if(updateAttd($response,$objs))
return true;
return false;
}
function updateByLecId(&$response,$lec_id,array $attd)
{ $objs = array();
foreach($attd as $k=>$v)
{ $attd[$k]['lec_id'] = $lec_id;
$attd[$k]['presence'] = $attd[$k]['p'] == 'P' ? 1 : 0;
unset($attd[$k]['p']);
$objs[] = new Attendance($attd[$k]);
}
if(updateAttd($response,$objs))
return true;
return false;
}
function updateAttd(&$response,array $objs)
{
/*
insert into Attendance(lec_id,stud_id,presence) VALUES(1,3,0),(1,6,1),(1,2,1)
on duplicate key update presence = VALUES(presence)
*/
try
{ $dbh = new MyDbCon;
$dbh->multiUpdate($objs,array("presence"));
$dbh->execute();
return true;
}catch(Exception $e)
{ $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e-
>getMessage();
$code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err="Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
function deleteLecture(&$response, $lec_id)
{
try
{
$arr = array(
'active' => 0
);
$obj = new Lectures($arr);
$dbh = new MyDbCon;
$dbh->updateThese($obj, array("lec_id" => $lec_id), array("active", "last_updated_by"));
$dbh->prepare();
$dbh->execute();
return true;
} catch(Exception $e)
{
$message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e->getMessage();
$code= $e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();
$err="Error Code: ".$code." <br/>Detailed Info: ".$message;
$response = array(
'code' => HTTP_Status::FORBIDDEN,
'message' => $err
);
return false;
}
}
?>

Weitere ähnliche Inhalte

Was ist angesagt?

How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with itFlavien Raynaud
 
TDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on WindowsTDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on WindowsSheng-Hao Ma
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneDefconRussia
 
Linux Shellcode disassembling
Linux Shellcode disassemblingLinux Shellcode disassembling
Linux Shellcode disassemblingHarsh Daftary
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPAdam Englander
 
07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W mattersAlexandre Moneger
 
05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR mattersAlexandre Moneger
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machinejulien pauli
 
Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Moriyoshi Koizumi
 
Publishing a Perl6 Module
Publishing a Perl6 ModulePublishing a Perl6 Module
Publishing a Perl6 Moduleast_j
 
Application of Radare2 Illustrated by Shylock and Snakso.A Analysis
Application of Radare2 Illustrated by Shylock and Snakso.A AnalysisApplication of Radare2 Illustrated by Shylock and Snakso.A Analysis
Application of Radare2 Illustrated by Shylock and Snakso.A AnalysisPositive Hack Days
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談hackstuff
 
StackOverflow
StackOverflowStackOverflow
StackOverflowSusam Pal
 
NTUSTxTDOH - Pwn基礎 2015/12/27
NTUSTxTDOH - Pwn基礎 2015/12/27NTUSTxTDOH - Pwn基礎 2015/12/27
NTUSTxTDOH - Pwn基礎 2015/12/27Sheng-Hao Ma
 

Was ist angesagt? (20)

How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with it
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
 
TDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on WindowsTDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on Windows
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
 
Linux Shellcode disassembling
Linux Shellcode disassemblingLinux Shellcode disassembling
Linux Shellcode disassembling
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
 
07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters
 
Usp
UspUsp
Usp
 
C99[2]
C99[2]C99[2]
C99[2]
 
05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machine
 
Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法
 
Publishing a Perl6 Module
Publishing a Perl6 ModulePublishing a Perl6 Module
Publishing a Perl6 Module
 
Vcs28
Vcs28Vcs28
Vcs28
 
iCloud keychain
iCloud keychainiCloud keychain
iCloud keychain
 
Application of Radare2 Illustrated by Shylock and Snakso.A Analysis
Application of Radare2 Illustrated by Shylock and Snakso.A AnalysisApplication of Radare2 Illustrated by Shylock and Snakso.A Analysis
Application of Radare2 Illustrated by Shylock and Snakso.A Analysis
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談
 
StackOverflow
StackOverflowStackOverflow
StackOverflow
 
NTUSTxTDOH - Pwn基礎 2015/12/27
NTUSTxTDOH - Pwn基礎 2015/12/27NTUSTxTDOH - Pwn基礎 2015/12/27
NTUSTxTDOH - Pwn基礎 2015/12/27
 
Php engine
Php enginePhp engine
Php engine
 

Ähnlich wie Codes

Im having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfIm having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfmaheshkumar12354
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdffootstatus
 
Return Oriented Programming, an introduction
Return Oriented Programming, an introductionReturn Oriented Programming, an introduction
Return Oriented Programming, an introductionPatricia Aas
 
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+ConFoo
 
SENDER It is a helmet that contains a sensor for gases, vital s.pdf
SENDER  It is a helmet that contains a sensor for gases, vital s.pdfSENDER  It is a helmet that contains a sensor for gases, vital s.pdf
SENDER It is a helmet that contains a sensor for gases, vital s.pdfalertshoeshingkimand
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]RootedCON
 
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacFlashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacESET Latinoamérica
 
#include IRremote.hint RECV_PIN = 19;const int timer = 600.docx
#include IRremote.hint RECV_PIN = 19;const int timer = 600.docx#include IRremote.hint RECV_PIN = 19;const int timer = 600.docx
#include IRremote.hint RECV_PIN = 19;const int timer = 600.docxkatherncarlyle
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly LanguageMotaz Saad
 
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
[2007 CodeEngn Conference 01] seaofglass - Linux Virus AnalysisGangSeok Lee
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Network security Lab manual
Network security Lab manual Network security Lab manual
Network security Lab manual Vivek Kumar Sinha
 
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptVisual Engineering
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IOT Academy
 
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and GotchasPostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and GotchasJim Mlodgenski
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015qmmr
 

Ähnlich wie Codes (20)

Arp
ArpArp
Arp
 
Im having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfIm having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdf
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
 
Return Oriented Programming, an introduction
Return Oriented Programming, an introductionReturn Oriented Programming, an introduction
Return Oriented Programming, an introduction
 
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
 
SENDER It is a helmet that contains a sensor for gases, vital s.pdf
SENDER  It is a helmet that contains a sensor for gases, vital s.pdfSENDER  It is a helmet that contains a sensor for gases, vital s.pdf
SENDER It is a helmet that contains a sensor for gases, vital s.pdf
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
 
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacFlashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas Mac
 
#include IRremote.hint RECV_PIN = 19;const int timer = 600.docx
#include IRremote.hint RECV_PIN = 19;const int timer = 600.docx#include IRremote.hint RECV_PIN = 19;const int timer = 600.docx
#include IRremote.hint RECV_PIN = 19;const int timer = 600.docx
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly Language
 
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Network security Lab manual
Network security Lab manual Network security Lab manual
Network security Lab manual
 
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and GotchasPostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
Marat-Slides
Marat-SlidesMarat-Slides
Marat-Slides
 

Kürzlich hochgeladen

Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMVoces Mineras
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?Olivia Kresic
 
Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Seta Wicaksana
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchirictsugar
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailAriel592675
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCRashishs7044
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfRbc Rbcua
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Kirill Klimov
 
IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024Matteo Carbone
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessSeta Wicaksana
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfJos Voskuil
 
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfIntro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfpollardmorgan
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Anamaria Contreras
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Servicecallgirls2057
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaoncallgirls2057
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCRashishs7044
 

Kürzlich hochgeladen (20)

Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQM
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?
 
Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchir
 
Japan IT Week 2024 Brochure by 47Billion (English)
Japan IT Week 2024 Brochure by 47Billion (English)Japan IT Week 2024 Brochure by 47Billion (English)
Japan IT Week 2024 Brochure by 47Billion (English)
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detail
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdf
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024
 
IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024
 
Corporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information TechnologyCorporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information Technology
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful Business
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdf
 
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfIntro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
 

Codes

  • 1. TransponderInitialization Code: #include<LiquidCrystal.h> #include<Keypad.h> //initialize the library with the numbers of the interface pins LiquidCrystal lcd(14,15,16,17,18,19); //4x4 Matrix key pad const byte ROWS = 4; // Four rows const byte COLS = 3; // Four columns // Define the Keymap char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'} }; // Connect keypad ROW0, ROW1, ROW2 and ROW3 to Arduino pins. byte rowPins[ROWS] = { 5, 4, 3, 2 }; // Connect keypad COL0, COL1, COL2 and COL3 to Arduino pins. byte colPins[COLS] = { 8, 7, 6 }; // Create the Keypad Keypad kpd = Keypad( makeKeymap(keys), rowPins,colPins, ROWS, COLS ); void setup() { // set up the LCD's number of columns and rows: Serial.begin(9600); Serial.println("Begin"); lcd.begin(16, 2); // Print a message to the LCD. lcd.print("KEYPAD LCD TEST"); Serial.println("Begin 2"); } void loop() { char key=kpd.getKey(); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(key); // lcd.print(millis() / 1000); // Check for a valid key if(key) { // setthe cursor to column 9, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(9, 1); //Print the detected key lcd.print("KEY= ");
  • 2. lcd.print(key); Serial.println(key); } } ESP Module (For Band) code: #include "driver/spi_interface.h" #include "eagle_soc.h" #include "osapi.h" // Show the spi registers. #define SHOWSPIREG(i) __ShowRegValue(__func__, __LINE__); /** * @brief Print debug information. * */ void __ShowRegValue(const char * func, uint32_t line) { int i; uint32_t regAddr = 0x60000140; // SPI--0x60000240, HSPI--0x60000140; os_printf("rn FUNC[%s],line[%d]rn", func, line); os_printf(" SPI_ADDR [0x%08x]rn", READ_PERI_REG(SPI_ADDR(SpiNum_HSPI))); os_printf(" SPI_CMD [0x%08x]rn", READ_PERI_REG(SPI_CMD(SpiNum_HSPI))); os_printf(" SPI_CTRL [0x%08x]rn", READ_PERI_REG(SPI_CTRL(SpiNum_HSPI))); os_printf(" SPI_CTRL2 [0x%08x]rn", READ_PERI_REG(SPI_CTRL2(SpiNum_HSPI))); os_printf(" SPI_CLOCK [0x%08x]rn", READ_PERI_REG(SPI_CLOCK(SpiNum_HSPI))); os_printf(" SPI_RD_STATUS [0x%08x]rn", READ_PERI_REG(SPI_RD_STATUS(SpiNum_HSPI))); os_printf(" SPI_WR_STATUS [0x%08x]rn", READ_PERI_REG(SPI_WR_STATUS(SpiNum_HSPI))); os_printf(" SPI_USER [0x%08x]rn", READ_PERI_REG(SPI_USER(SpiNum_HSPI))); os_printf(" SPI_USER1 [0x%08x]rn", READ_PERI_REG(SPI_USER1(SpiNum_HSPI))); os_printf(" SPI_USER2 [0x%08x]rn", READ_PERI_REG(SPI_USER2(SpiNum_HSPI))); os_printf(" SPI_PIN [0x%08x]rn", READ_PERI_REG(SPI_PIN(SpiNum_HSPI))); os_printf(" SPI_SLAVE [0x%08x]rn", READ_PERI_REG(SPI_SLAVE(SpiNum_HSPI))); os_printf(" SPI_SLAVE1 [0x%08x]rn", READ_PERI_REG(SPI_SLAVE1(SpiNum_HSPI))); os_printf(" SPI_SLAVE2 [0x%08x]rn", READ_PERI_REG(SPI_SLAVE2(SpiNum_HSPI))); for (i = 0; i < 16; ++i) { os_printf(" ADDR[0x%08x],Value[0x%08x]rn", regAddr, READ_PERI_REG(regAddr)); regAddr += 4; } } // SPI interrupt callback function. void spi_slave_isr_sta(void *para)
  • 3. { uint32 regvalue; uint32 statusW, statusR, counter; if (READ_PERI_REG(0x3ff00020)&BIT4) { //following 3 lines is to clear isr signal CLEAR_PERI_REG_MASK(SPI_SLAVE(SpiNum_SPI), 0x3ff); } else if (READ_PERI_REG(0x3ff00020)&BIT7) { //bit7 is for hspi isr, regvalue = READ_PERI_REG(SPI_SLAVE(SpiNum_HSPI)); os_printf("spi_slave_isr_sta SPI_SLAVE[0x%08x]nr", regvalue); SPIIntClear(SpiNum_HSPI); SET_PERI_REG_MASK(SPI_SLAVE(SpiNum_HSPI), SPI_SYNC_RESET); SPIIntClear(SpiNum_HSPI); SPIIntEnable(SpiNum_HSPI, SpiIntSrc_WrStaDone | SpiIntSrc_RdStaDone | SpiIntSrc_WrBufDone | SpiIntSrc_RdBufDone); if (regvalue & SPI_SLV_WR_BUF_DONE) { // User can get data from the W0~W7 os_printf("spi_slave_isr_sta : SPI_SLV_WR_BUF_DONEnr"); } else if (regvalue & SPI_SLV_RD_BUF_DONE) { // TO DO os_printf("spi_slave_isr_sta : SPI_SLV_RD_BUF_DONEnr"); } if (regvalue & SPI_SLV_RD_STA_DONE) { statusR = READ_PERI_REG(SPI_RD_STATUS(SpiNum_HSPI)); statusW = READ_PERI_REG(SPI_WR_STATUS(SpiNum_HSPI)); os_printf("spi_slave_isr_sta : SPI_SLV_RD_STA_DONE[R=0x%08x,W=0x%08x]nr", statusR, statusW); } if (regvalue & SPI_SLV_WR_STA_DONE) { statusR = READ_PERI_REG(SPI_RD_STATUS(SpiNum_HSPI)); statusW = READ_PERI_REG(SPI_WR_STATUS(SpiNum_HSPI)); os_printf("spi_slave_isr_sta : SPI_SLV_WR_STA_DONE[R=0x%08x,W=0x%08x]nr", statusR, statusW); } if ((regvalue & SPI_TRANS_DONE) && ((regvalue & 0xf) == 0)) { os_printf("spi_slave_isr_sta : SPI_TRANS_DONEnr"); } SHOWSPIREG(SpiNum_HSPI); } } // Test spi master interfaces. void ICACHE_FLASH_ATTR spi_master_test() { SpiAttr hSpiAttr; hSpiAttr.bitOrder = SpiBitOrder_MSBFirst; hSpiAttr.speed = SpiSpeed_10MHz;
  • 4. hSpiAttr.mode = SpiMode_Master; hSpiAttr.subMode = SpiSubMode_0; // Init HSPI GPIO WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105); PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);//configure io to spi mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to spi mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to spi mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to spi mode SPIInit(SpiNum_HSPI, &hSpiAttr); uint32_t value = 0xD3D4D5D6; uint32_t sendData[8] ={ 0 }; SpiData spiData; os_printf("rn ============= spi init master ============= rn"); // Test 8266 slave.Communication format: 1byte command + 1bytes address + x bytes Data. os_printf("rn Master send 32 bytes data to slave(8266)rn"); os_memset(sendData, 0, sizeof(sendData)); sendData[0] = 0x55565758; sendData[1] = 0x595a5b5c; sendData[2] = 0x5d5e5f60; sendData[3] = 0x61626364; sendData[4] = 0x65666768; sendData[5] = 0x696a6b6c; sendData[6] = 0x6d6e6f70; sendData[7] = 0x71727374; spiData.cmd = MASTER_WRITE_DATA_TO_SLAVE_CMD; spiData.cmdLen = 1; spiData.addr = &value; spiData.addrLen = 4; spiData.data = sendData; spiData.dataLen = 32; SPIMasterSendData(SpiNum_HSPI, &spiData); os_printf("rn Master receive 24 bytes data from slave(8266)rn"); spiData.cmd = MASTER_READ_DATA_FROM_SLAVE_CMD; spiData.cmdLen = 1; spiData.addr = &value; spiData.addrLen = 4; spiData.data = sendData; spiData.dataLen = 24; os_memset(sendData, 0, sizeof(sendData)); SPIMasterRecvData(SpiNum_HSPI, &spiData); os_printf(" Recv Slave data0[0x%08x]rn", sendData[0]); os_printf(" Recv Slave data1[0x%08x]rn", sendData[1]); os_printf(" Recv Slave data2[0x%08x]rn", sendData[2]); os_printf(" Recv Slave data3[0x%08x]rn", sendData[3]); os_printf(" Recv Slave data4[0x%08x]rn", sendData[4]); os_printf(" Recv Slave data5[0x%08x]rn", sendData[5]);
  • 5. value = SPIMasterRecvStatus(SpiNum_HSPI); os_printf("rn Master read slave(8266) status[0x%02x]rn", value); SPIMasterSendStatus(SpiNum_HSPI, 0x99); os_printf("rn Master write status[0x99] to slavue(8266).rn"); SHOWSPIREG(SpiNum_HSPI); // Test others slave.Communication format:0bytes command + 0 bytes address + x bytes Data #if 0 os_printf("rn Master send 4 bytes data to slavern"); os_memset(sendData, 0, sizeof(sendData)); sendData[0] = 0x2D3E4F50; spiData.cmd = MASTER_WRITE_DATA_TO_SLAVE_CMD; spiData.cmdLen = 0; spiData.addr = &addr; spiData.addrLen = 0; spiData.data = sendData; spiData.dataLen = 4; SPIMasterSendData(SpiNum_HSPI, &spiData); os_printf("rn Master receive 4 bytes data from slavern"); spiData.cmd = MASTER_READ_DATA_FROM_SLAVE_CMD; spiData.cmdLen = 0; spiData.addr = &addr; spiData.addrLen = 0; spiData.data = sendData; spiData.dataLen = 4; os_memset(sendData, 0, sizeof(sendData)); SPIMasterRecvData(SpiNum_HSPI, &spiData); os_printf(" Recv Slave data[0x%08x]rn", sendData[0]); #endif } // Test spi slave interfaces. void ICACHE_FLASH_ATTR spi_slave_test() { // SpiAttr hSpiAttr; hSpiAttr.bitOrder = SpiBitOrder_MSBFirst; hSpiAttr.speed = 0; hSpiAttr.mode = SpiMode_Slave; hSpiAttr.subMode = SpiSubMode_0; // Init HSPI GPIO WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105); PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);//configure io to spi mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to spi mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to spi mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to spi mode
  • 6. os_printf("rn ============= spi init slave =============rn"); SPIInit(SpiNum_HSPI, &hSpiAttr); // Set spi interrupt information. SpiIntInfo spiInt; spiInt.src = (SpiIntSrc_TransDone | SpiIntSrc_WrStaDone |SpiIntSrc_RdStaDone |SpiIntSrc_WrBufDone |SpiIntSrc_RdBufDone); spiInt.isrFunc = spi_slave_isr_sta; SPIIntCfg(SpiNum_HSPI, &spiInt); // SHOWSPIREG(SpiNum_HSPI); SPISlaveRecvData(SpiNum_HSPI); uint32_t sndData[8] = { 0 }; sndData[0] = 0x35343332; sndData[1] = 0x39383736; sndData[2] = 0x3d3c3b3a; sndData[3] = 0x11103f3e; sndData[4] = 0x15141312; sndData[5] = 0x19181716; sndData[6] = 0x1d1c1b1a; sndData[7] = 0x21201f1e; SPISlaveSendData(SpiNum_HSPI, sndData, 8); WRITE_PERI_REG(SPI_RD_STATUS(SpiNum_HSPI), 0x8A); WRITE_PERI_REG(SPI_WR_STATUS(SpiNum_HSPI), 0x83); } void spi_interface_test(void) { // Test spi interfaces. os_printf("rn =======================================================rn"); os_printf("t ESP8266 %s application nr", __func__); os_printf("tt SDK version:%s nr", system_get_sdk_version()); os_printf("tt Complie time:%s nr", __TIME__); os_printf("rn =======================================================rn"); #if 0 spi_master_test(); #else spi_slave_test(); #endif } Attendance Report Generation: <?php
  • 7. /* Returns Attendance Master Details @param $response MIXED response variable contains error code or success data @param $mst_id INT attendance master id @param $faculty_id Bool true, if need to match for current logged in faculty for verification @param $now Bool true, if need to get current active academice calendars only */ use ZendDbSqlExpression; use ZendDbSqlSelect; function getMstMetaData(&$response,$mst_id,$faculty_id=true,$now=true) { if(!ctype_digit($mst_id)) { $response = array( 'code' => HTTP_Status::BAD_REQUEST, 'message' => 'Master ID must be digits only' ); return false; } $meta_data=array( "batchno" => null, "division" => null, "inst_name" => null, "prog_name" => null, "dept_name" => null, "semester" => null, "subject" => null ); try { $dbh=new MyDbCon; $dbh->select("Attendance_Master"); $dbh->select->where->equalTo("attd_mst_id",$mst_id); $dbh->prepare(); if($dbh->execute()) { $tmp=$dbh->fetchAssoc()[0]; $meta_data['batchno']=$tmp['batchno']; $meta_data['division']=$tmp['division']; } else { $response = array( 'code' => HTTP_Status::FORBIDDEN ); return false; } $where_funcs=array( '=' => 'equalTo', '<' => 'lessThan', '>' => 'greaterThan', '<=' => 'lessThanOrEqualTo', '>=' => 'greaterThanOrEqualTo', 'like' => 'like' ); $where=array(
  • 8. "attd_mst_id" => $mst_id ); if($now) { try { $now=(new DateTime())->format("Y-m-d"); //throw new Exception("asd"); }catch(Exception $e) { $response = array( 'code' => HTTP_Status::INTERNAL_SERVER_ERROR ); return false; } $where['end_date'] = "{$now}:>="; $where['start_date'] = "{$now}:<="; } if($faculty_id && !Privilege_Master::is_super($_SESSION['privilege_id'])) { $where['faculty_id'] = $_SESSION['faculty_id']; } $join_tables=array( "Academic_Calendar", "Teaches", "Syllabus" ); $join_on=array( "Academic_Calendar" => "Academic_Calendar.ac_id=Attendance_Master.ac_id", "Teaches" => "Attendance_Master.teaches_id=Teaches.teaches_id", "Syllabus" => "Teaches.syllabus_id=Syllabus.syllabus_id" ); $join_columns=array( "Academic_Calendar" => array("start_date","end_date"), "Teaches" => array(/*"teaches_id","faculty_id"*/), "Syllabus" => array(/*"syllabus_id",*/"sub_id","sub_offered_sem","o_id") ); $dbh=new MyDbCon; $dbh->select("Attendance_Master"); $dbh->select->columns(array()); // Join Tables foreach($join_tables as $val) { $cols=Select::SQL_STAR; if(isset($join_columns[$val])) $cols=$join_columns[$val]; $dbh->join($val,$join_on[$val],$cols); } // Where Clause foreach($where as $key=>$val) { $vals=explode(':',$val); $wh=$where_funcs['=']; if(!empty($vals[1]) && isset($where_funcs[$vals[1]])) $wh=$where_funcs[$vals[1]]; $dbh->select->where->$wh($key,$vals[0]);
  • 9. } $dbh->prepare(); if($dbh->execute()) { $objs=$dbh->fetchAssoc(); $meta_data['semester']=$objs[0]['sub_offered_sem']; $meta_data['start_date']=$objs[0]['start_date']; $meta_data['end_date']=$objs[0]['end_date']; $names=Offers_Master::getNames($objs[0]['o_id']); $meta_data['subject']=Sub_Master::getSubjectName($objs[0]['sub_id']); /*$meta_data['o_id']=$objs[0]['o_id']; $meta_data['sub_id']=$objs[0]['sub_id']; $meta_data['syllabus_id']=$objs[0]['syllabus_id']; $meta_data['teaches_id']=$objs[0]['teaches_id']; $meta_data['faculty_id']=$objs[0]['faculty_id'];*/ if($names) { $meta_data['inst_name']=$names['inst_name']; $meta_data['prog_name']=$names['prog_name']; $meta_data['dept_name']=$names['dept_name']; } //var_dump($meta_data); //var_dump($objs); $response=$meta_data; return true; } $response = array( 'code' => HTTP_Status::FORBIDDEN ); return false; }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err="Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } /* Returns Students Attendance Details given a Attendance Master Id @param $response MIXED response variable contains error code or success data @param $mst_id INT attendance master id */ function getStudentWiseAttendanceByMst(&$response,$mst_id) { try { $dbh = new MyDbCon; $statement = $dbh->call('student_presence_from_master',array($mst_id)); // Get 1st ResultSet : Division & Batchno
  • 10. $resultSet = $statement->fetchAll(PDO::FETCH_ASSOC); $students['metadata']['division'] = intval($resultSet[0]['division']); $students['metadata']['batchno'] = intval($resultSet[0]['batchno']); // Get 2nd ResultSet : Students Presence $statement->nextRowSet(); $resultSet = $statement->fetchAll(PDO::FETCH_ASSOC); $students['data']=$resultSet; $response = $students; return true; }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err="Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } /* Returns Lecture Details given a Attendance Master Id @param $response MIXED response variable contains error code or success data @param $mst_id INT attendance master id */ function getLectureWiseAttendanceByMst(&$response,$mst_id) { try { $dbh = new MyDbCon; $dbh->select("Lectures"); $dbh->select->columns(array('lec_id','lec_date')); $dbh->select->where->equalTo('attd_mst_id',$mst_id); $dbh->select->where->equalTo('Lectures.active', 1); $dbh->join('Attendance','Lectures.lec_id = Attendance.lec_id', array( 'presence' => new Expression("sum(presence)"), 'total' => new Expression("count(presence)"), 'percentage' => new Expression("ROUND(sum(presence)/count(presence)*100,2)") ),'left'); $dbh->select->group('Lectures.lec_id'); $dbh->select->order('lec_date ASC'); $dbh->prepare(); /* select Lectures.lec_id,lec_date,sum(presence) as presence,count(presence) as total,ROUND(sum(presence)/count(presence)*100,2) as percentage from Lectures left join Attendance on Attendance.lec_id=Lectures.lec_id where attd_mst_id = 9 and Lectures.active = 1 group by Lectures.lec_id
  • 11. order by lec_date ASC */ if($dbh->execute()) { $res=$dbh->fetchAssoc(); //var_dump($res); $response['data'] = $res; return true; } $response = array( 'code' => HTTP_Status::NOT_FOUND ); return false; }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code = $e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err = "Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } /* Returns Lecture Attendance Details given a Lecture Id @param $response MIXED response variable contains error code or success data @param $mst_id INT attendance master id */ function getStudentAttendanceByLec(&$response,$lec_id) { if(!ctype_digit($lec_id)) { $response = array( 'code' => HTTP_Status::BAD_REQUEST, 'message' => 'Lec ID must be digits only' ); return false; } /* select Attendance.stud_id,stud_rollno,stud_enrolmentno,CONCAT(stud_name,' ',stud_father_name,' ',stud_surname) as stud_name,presence from Attendance join Student_Master on Student_Master.stud_id = Attendance.stud_id where lec_id = 4 order by stud_rollno ASC */ try { $dbh = new MyDbCon; $dbh->select("Attendance"); $dbh->select->columns(array('stud_id','presence')); $dbh->select->where->equalTo('lec_id',$lec_id);
  • 12. $dbh->join('Student_Master','Student_Master.stud_id = Attendance.stud_id', array( 'stud_rollno','stud_enrolmentno', 'stud_name' => new Expression("CONCAT(stud_name,' ',IFNULL(stud_father_name,''),' ',IFNULL(stud_surname,''))") )); $dbh->select->order('stud_rollno ASC'); $dbh->prepare(); if($dbh->execute()) { $response = $dbh->fetchAssoc(); return true; } else { $response = array( 'code' => HTTP_Status::NOT_FOUND, 'message' => 'No records Found' ); return false; } }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code = $e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err = "Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } /* Returns Student Attendance Details given a Attendance_Master Id and Stud_id @param $response MIXED response variable contains error code or success data @param $mst_id INT attendance master id @param $stud_id INT stud id */ function getLectureWiseAttendanceOfStudByMst(&$response,$mst_id,$stud_id) { /* select Lectures.lec_id,lec_date,presence from Lectures left join Attendance on Attendance.lec_id=Lectures.lec_id and stud_id=65 where attd_mst_id=9 and Lectures.active = 1 group by Lectures.lec_id order by lec_date ASC */ if(!ctype_digit($mst_id) || !ctype_digit($stud_id)) { $response = array( 'code' => HTTP_Status::BAD_REQUEST, 'message' => 'ID must be digits only' );
  • 13. return false; } try { $dbh = new MyDbCon; $dbh->select("Lectures"); $dbh->select->columns(array('lec_id','lec_date')); $dbh->join('Attendance',new Expression("Lectures.lec_id = Attendance.lec_id and stud_id = {$stud_id}"),array('presence'),'left'); $dbh->select->where->equalTo('attd_mst_id',$mst_id); $dbh->select->where->equalTo('Lectures.active', 1); $dbh->select->group('Lectures.lec_id'); $dbh->select->order('lec_date ASC'); $dbh->prepare(); //echo $dbh->select->getSqlString($dbh->getAdapter()->getPlatform()); $dbh->execute(); $response = $dbh->fetchAssoc(); return true; }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code = $e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err = "Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } ?> Student Attendance Info Fetcher Module: <?php /* Returns Students Data from a particular master. @param $response MIXED response variable contains error code or success data @param $mst_id INT attendance master id @param $faculty_id Bool true, if need to match for current logged in faculty for verification @param $now Bool true, if need to get current active academic calendars only */ use ZendDbSqlSelect; function getStudentsByMst(&$response,$mst_id,$faculty_id=true,$now=true) { if(!ctype_digit($mst_id)) { $response = array( 'code' => HTTP_Status::BAD_REQUEST, 'message' => 'Master ID must be digits only' );
  • 14. return false; } $meta_data=array( "batchno" => null, "division" => null, "inst_name" => null, "prog_name" => null, "dept_name" => null, "semester" => null, "subject" => null ); try { $dbh=new MyDbCon; $dbh->select("Attendance_Master"); $dbh->select->where->equalTo("attd_mst_id",$mst_id); $dbh->prepare(); if($dbh->execute()) { $tmp=$dbh->fetchAssoc()[0]; $meta_data['batchno']=$tmp['batchno']; $meta_data['division']=$tmp['division']; } else { $response = array( 'code' => HTTP_Status::FORBIDDEN ); return false; } $where_funcs=array( '=' => 'equalTo', '<' => 'lessThan', '>' => 'greaterThan', '<=' => 'lessThanOrEqualTo', '>=' => 'greaterThanOrEqualTo', 'like' => 'like' ); $where=array( "attd_mst_id" => $mst_id, "stud_status" => "C" ); if($now) { try { $now=(new DateTime())->format("Y-m-d"); //throw new Exception("asd"); }catch(Exception $e) { $response = array( 'code' => HTTP_Status::INTERNAL_SERVER_ERROR ); return false; } $where['end_date'] = "{$now}:>="; $where['start_date'] = "{$now}:<="; }
  • 15. if($faculty_id && !Privilege_Master::is_super($_SESSION['privilege_id'])) { $where['faculty_id'] = $_SESSION['faculty_id']; } $join_tables=array( "Academic_Calendar", "Teaches", "Syllabus", "Student_Master" ); $join_on=array( "Academic_Calendar" => "Academic_Calendar.ac_id=Attendance_Master.ac_id", "Teaches" => "Attendance_Master.teaches_id=Teaches.teaches_id", "Syllabus" => "Teaches.syllabus_id=Syllabus.syllabus_id", "Student_Master" => "Student_Master.o_id=Syllabus.o_id AND Student_Master.stud_sem=Academic_Calendar.semester AND Student_Master.stud_div=Attendance_Master.division" ); if(!empty($meta_data['batchno'])) $join_on["Student_Master"].=" AND Student_Master.stud_batchno=Attendance_Master.batchno"; $join_columns=array( "Academic_Calendar" => array("start_date","end_date"), "Teaches" => array(), "Syllabus" => array("sub_id"), "Student_Master" => array("stud_id","stud_enrolmentno","stud_rollno","stud_name","stud_father_name","stud_surname ","stud_sem","stud_div","stud_batchno","o_id") ); $meta_keys=array("stud_sem","stud_div","stud_batchno","o_id","sub_id","start_date","end _date"); $dbh=new MyDbCon; $dbh->select("Attendance_Master"); $dbh->select->columns(array()); // Join Tables foreach($join_tables as $val) { $cols=Select::SQL_STAR; if(isset($join_columns[$val])) $cols=$join_columns[$val]; $dbh->join($val,$join_on[$val],$cols); } // Where Clause foreach($where as $key=>$val) { $vals=explode(':',$val); $wh=$where_funcs['=']; if(!empty($vals[1]) && isset($where_funcs[$vals[1]])) $wh=$where_funcs[$vals[1]]; $dbh->select->where->$wh($key,$vals[0]); } $dbh->select->order("stud_rollno ASC");
  • 16. $dbh->prepare(); if($dbh->execute()) { $objs=$dbh->fetchAssoc(); $meta_data['semester']=$objs[0]['stud_sem']; $meta_data['start_date']=$objs[0]['start_date']; $meta_data['end_date']=$objs[0]['end_date']; $names=Offers_Master::getNames($objs[0]['o_id']); $meta_data['subject']=Sub_Master::getSubjectName($objs[0]['sub_id']); if($names) { $meta_data['inst_name']=$names['inst_name']; $meta_data['prog_name']=$names['prog_name']; $meta_data['dept_name']=$names['dept_name']; } foreach($objs as $row) { foreach($meta_keys as $val) unset($row[$val]); if(!empty($row['stud_father_name'])) $row['stud_name'].=" ".$row['stud_father_name']; if(!empty($row['stud_surname'])) $row['stud_name'].=" ".$row['stud_surname']; unset($row['stud_father_name']); unset($row['stud_surname']); } //var_dump($meta_data); //var_dump($objs); $response=array( "metadata" => $meta_data, "data" => $objs ); return true; } else { $response = array( 'code' => HTTP_Status::FORBIDDEN ); return false; } }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err="Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } ?>
  • 17. MasterAccess List: <?php /* Returns Masters List from a given Faculty ID. @param $response MIXED response variable contains error code or success data @param $fac_id INT attendance master id @param $now Bool true, if need to get current active academic calendars only */ use ZendDbSqlSelect; function getMstByFaculty(&$response,$fac_id,$now=true) { if(!ctype_digit($fac_id) && !Privilege_Master::is_super($_SESSION['privilege_id'])) { $response = array( 'code' => HTTP_Status::BAD_REQUEST, 'message' => 'Faculty ID must be digits only' ); return false; } try { $where_funcs=array( '=' => 'equalTo', '<' => 'lessThan', '>' => 'greaterThan', '<=' => 'lessThanOrEqualTo', '>=' => 'greaterThanOrEqualTo', 'like' => 'like' ); if(!Privilege_Master::is_super($_SESSION['privilege_id'])) { $where=array( "Teaches.faculty_id" => $fac_id ); } try { $now=(new DateTime())->format("Y-m-d"); }catch(Exception $e) { $response = array( 'code' => HTTP_Status::INTERNAL_SERVER_ERROR ); return false; } $where['end_date'] = "{$now}:>="; $where['start_date'] = "{$now}:<="; $join_tables=array( "Academic_Calendar", "Teaches", "Syllabus", "Offers_Master", "Inst_Master", "Prog_Master", "Dept_Master", "Sub_Master",
  • 18. "Faculty_Master" ); $join_on=array( "Academic_Calendar" => "Academic_Calendar.ac_id=Attendance_Master.ac_id", "Teaches" => "Attendance_Master.teaches_id=Teaches.teaches_id", "Syllabus" => "Teaches.syllabus_id=Syllabus.syllabus_id", "Offers_Master" => "Offers_Master.o_id=Syllabus.o_id", "Inst_Master" => "Inst_Master.inst_id=Offers_Master.inst_id", "Prog_Master" => "Prog_Master.prog_id=Offers_Master.prog_id", "Dept_Master" => "Dept_Master.dept_id=Offers_Master.dept_id", "Sub_Master" => "Sub_Master.sub_id=Syllabus.sub_id", "Faculty_Master" => "Faculty_Master.faculty_id=Teaches.faculty_id" ); $join_columns=array( "Academic_Calendar" => array("start_date","end_date","semester"), "Teaches" => array("type"), "Syllabus" => array("sub_id"), "Offers_Master" => array("o_id"), "Inst_Master" => array("inst_name"), "Prog_Master" => array("prog_name"), "Dept_Master" => array("dept_name"), "Sub_Master" => array("sub_name"), "Faculty_Master" => array("faculty_name","faculty_father_name","faculty_surname") ); $dbh=new MyDbCon; $dbh->select("Attendance_Master"); $dbh->select->columns(array("attd_mst_id","batchno","division")); // Join Tables foreach($join_tables as $val) { $cols=Select::SQL_STAR; if(isset($join_columns[$val])) $cols=$join_columns[$val]; $dbh->join($val,$join_on[$val],$cols); } // Where Clause foreach($where as $key=>$val) { $vals=explode(':',$val); $wh=$where_funcs['=']; if(!empty($vals[1]) && isset($where_funcs[$vals[1]])) $wh=$where_funcs[$vals[1]]; $dbh->select->where->$wh($key,$vals[0]); } $dbh->prepare(); if($dbh->execute()) { $objs=$dbh->fetchAssoc(); foreach($objs as $row) { if(!empty($row['faculty_father_name'])) $row['faculty_name'].=" ".$row['faculty_father_name']; if(!empty($row['faculty_surname']))
  • 19. $row['faculty_name'].=" ".$row['faculty_surname']; unset($row['faculty_father_name']); unset($row['faculty_surname']); } $response = $objs; return true; } else { $response = array( 'code' => HTTP_Status::NOT_FOUND ); return false; } }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err="Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } ?> Update Attendance Info Module: <?php use ZendDbSqlSelect; use ZendDbSqlExpression; require_once "../getStudents/getStudents.lib.php"; function authMst(&$response,$mst_id,$faculty_id) { /* select count(*) as cnt from Attendance_Master join Teaches on Attendance_Master.attd_mst_id = 9 and Attendance_Master.teaches_id = Teaches.teaches_id and Teaches.faculty_id = 5 */ if(Privilege_Master::is_super($_SESSION['privilege_id'])) { return true; } else if(!ctype_digit($mst_id) || !ctype_digit($faculty_id)) { $response = array( 'code' => HTTP_Status::BAD_REQUEST, 'message' => 'ID must be digits only' ); return false; }
  • 20. try { $dbh = new MyDbCon; $dbh->select("Attendance_Master"); $dbh->select->columns(array("cnt" => new Expression("count(*)"))); $dbh->join("Teaches",new Expression("Attendance_Master.attd_mst_id = {$mst_id} and Attendance_Master.teaches_id = Teaches.teaches_id and Teaches.faculty_id = {$faculty_id}"),array()); $dbh->prepare(); $dbh->execute(); $cnt = $dbh->fetchAssoc()[0]['cnt']; if(intval($cnt)===1) return true; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => HTTP_Status::FORBIDDEN_MSG ); return false; }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err="Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } function authStud(&$response,$mst_id,array $stud_id) { $faculty_id=true; if(Privilege_Master::is_super($_SESSION['privilege_id'])) $faculty_id=false; if(!getStudentsByMst($response,$mst_id,$faculty_id)) return false; foreach($stud_id as $id) { $flag=false; foreach($response['data'] as $stud) { if(strcmp($stud['stud_id'],$id)==0) { $flag=true; break; } } if(!$flag) break; } if($flag) { $response = true; return true; }
  • 21. $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => HTTP_Status::FORBIDDEN_MSG ); return false; } function authLec(&$response,$mst_id,array $lec_id) { if(!ctype_digit($mst_id)) { $response = array( 'code' => HTTP_Status::BAD_REQUEST, 'message' => 'ID must be digits only' ); return false; } try { $dbh = new MyDbCon; $dbh->select("Lectures"); $dbh->select->columns(array("lec_id")); $dbh->select->where->equalTo("attd_mst_id",$mst_id); $dbh->prepare(); if($dbh->execute()) { $res = $dbh->fetchAssoc(); $ids = array(); foreach($res as $lec) $ids[]=$lec['lec_id']; $dif = array_diff($lec_id,$ids); if(empty($dif)) return true; } $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => HTTP_Status::FORBIDDEN_MSG ); return false; }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err="Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } function updateByStudId(&$response,$stud_id,array $attd) { $objs = array(); foreach($attd as $k=>$v) { $attd[$k]['stud_id'] = $stud_id;
  • 22. $attd[$k]['presence'] = $attd[$k]['p'] == 'P' ? 1 : 0; unset($attd[$k]['p']); $objs[] = new Attendance($attd[$k]); } if(updateAttd($response,$objs)) return true; return false; } function updateByLecId(&$response,$lec_id,array $attd) { $objs = array(); foreach($attd as $k=>$v) { $attd[$k]['lec_id'] = $lec_id; $attd[$k]['presence'] = $attd[$k]['p'] == 'P' ? 1 : 0; unset($attd[$k]['p']); $objs[] = new Attendance($attd[$k]); } if(updateAttd($response,$objs)) return true; return false; } function updateAttd(&$response,array $objs) { /* insert into Attendance(lec_id,stud_id,presence) VALUES(1,3,0),(1,6,1),(1,2,1) on duplicate key update presence = VALUES(presence) */ try { $dbh = new MyDbCon; $dbh->multiUpdate($objs,array("presence")); $dbh->execute(); return true; }catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e- >getMessage(); $code=$e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err="Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } function deleteLecture(&$response, $lec_id) { try { $arr = array( 'active' => 0 ); $obj = new Lectures($arr); $dbh = new MyDbCon;
  • 23. $dbh->updateThese($obj, array("lec_id" => $lec_id), array("active", "last_updated_by")); $dbh->prepare(); $dbh->execute(); return true; } catch(Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e->getMessage(); $code= $e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode(); $err="Error Code: ".$code." <br/>Detailed Info: ".$message; $response = array( 'code' => HTTP_Status::FORBIDDEN, 'message' => $err ); return false; } } ?>